-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an inter-application communication quickstart
* Uses EJBs to communicate * Aliases EJBs as CDI beans to hide details from clients of the beans * Thanks to Jason Greene for part of description
- Loading branch information
Showing
22 changed files
with
965 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
Inter-app: Shows how to communicate between two applications using EJB and CDI | ||
====================================================== | ||
Author: Pete Muir | ||
|
||
What is it? | ||
----------- | ||
|
||
This quickstart shows you how to easily communicate between two modular deployments to JBoss AS 7. Two wars, with a shared API jar, are deployed to the app server. EJB is used to provide inter-application communication, with EJB beans alised to CDI beans, making the inter-application communication transparent to clients of the bean. | ||
|
||
CDI only provides intra-applicaion injection (i.e within a top level deployment, ear, war, jar etc). This improves performance of the application server, as to satisfy an injection point all possible candidates have to be scanned / analyzed. If inter-app injection was supported by CDI, performance would scale according to the number of deployments you have (the more deployments in the running system, the slower the deployment). Java EE injection uses unique JNDI names for the wiring, so each injection point is O(1). The approach shown here combines the two approaches such that you limit the name based wiring to one location in your code, and the main consumers of components can use CDI injection to reference these name wired components. For the name approach to work though, you still need to publish instances, and EJB singletons allow you to do that with just one extra annotation. | ||
|
||
|
||
In all, the project has three modules: | ||
|
||
* jboss-as-inter-app-A.war - the first war, whiches exposes an EJB singleton, and a simple UI that allows you to read the value set on the bean in appB | ||
* jboss-as-inter-app-B.war - the second war, whiches exposes an EJB singleton, and a simple UI that allows you to read the value set on the bean in appA | ||
|
||
System requirements | ||
------------------- | ||
|
||
All you need to build this project is Java 6.0 (Java SDK 1.6) or better, Maven 3.0 or better. | ||
|
||
The application this project produces is designed to be run on JBoss Enterprise Application Platform 6 or JBoss AS 7. | ||
|
||
|
||
Configure Maven | ||
--------------- | ||
|
||
If you have not yet done so, you must [Configure Maven](../README.md#mavenconfiguration) before testing the quickstarts. | ||
|
||
Start JBoss Enterprise Application Platform 6 or JBoss AS 7 | ||
------------------------- | ||
|
||
1. Open a command line and navigate to the root of the JBoss server directory. | ||
2. The following shows the command line to start the server with the web profile: | ||
|
||
For Linux: JBOSS_HOME/bin/standalone.sh | ||
For Windows: JBOSS_HOME\bin\standalone.bat | ||
|
||
|
||
Build and Deploy the Quickstart | ||
------------------------- | ||
|
||
_NOTE: The following build command assumes you have configured your Maven user settings. If you have not, you must include Maven setting arguments on the command line. See [Build and Deploy the Quickstarts](../README.md#buildanddeploy) for complete instructions and additional options._ | ||
|
||
1. Make sure you have started the JBoss Server as described above. | ||
2. Open a command line and navigate to the root directory of this quickstart. | ||
3. Type this command to build and deploy the archive: | ||
|
||
mvn clean package jboss-as:deploy | ||
4. This will deploy `shared/target/jboss-as-inter-app-shared.jar`, `appA/target/jboss-as-inter-app-A.war` and `appB/target/jboss-as-inter-app-B.war` to the running instance of the server. | ||
|
||
Access the application (For quickstarts that have a UI component) | ||
--------------------- | ||
|
||
|
||
Access the running application in a browser at the following URLs: | ||
|
||
* <http://localhost:8080/jboss-as-inter-app-A> | ||
* <http://localhost:8080/jboss-as-inter-app-B> | ||
|
||
You are presented with a form that allows you to set the value on the bean in the other application, as well as display of the value on this application's bean. Enter a new value and press "Update and Send!" to update the value on the other application. Do the same on the other application, and hit the button again on the first application. You should see the values shared between the applications. | ||
|
||
|
||
Undeploy the Archive | ||
-------------------- | ||
|
||
1. Make sure you have started the JBoss Server as described above. | ||
2. Open a command line and navigate to the root directory of this quickstart. | ||
3. When you are finished testing, type this command to undeploy the archive: | ||
|
||
mvn jboss-as:undeploy | ||
|
||
|
||
Run the Quickstart in JBoss Developer Studio or Eclipse | ||
------------------------------------- | ||
You can also start the server and deploy the quickstarts from Eclipse using JBoss tools. For more information, see [Use JBoss Developer Studio or Eclipse to Run the Quickstarts](../README.md#useeclipse) | ||
|
||
Debug the Application | ||
------------------------------------ | ||
|
||
If you want to debug the source code or look at the Javadocs of any library in the project, run either of the following commands to pull them into your local repository. The IDE should then detect them. | ||
|
||
mvn dependency:sources | ||
mvn dependency:resolve -Dclassifier=javadoc | ||
|
||
------------------------------------ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
<?xml version="1.0"?> | ||
<!-- JBoss, Home of Professional Open Source Copyright 2012, Red Hat, Inc. | ||
and/or its affiliates, and individual contributors by the @authors tag. See | ||
the copyright.txt in the distribution for a full listing of individual contributors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
use this file except in compliance with the License. You may obtain a copy | ||
of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required | ||
by applicable law or agreed to in writing, software distributed under the | ||
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS | ||
OF ANY KIND, either express or implied. See the License for the specific | ||
language governing permissions and limitations under the License. --> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>jboss-as-inter-app-A</artifactId> | ||
<packaging>war</packaging> | ||
<name>JBoss AS Quickstarts: Inter-application (Application A)</name> | ||
<description>Inter-application: Shows how to communicate between two applications using EJB and CDI</description> | ||
|
||
<parent> | ||
<groupId>org.jboss.as.quickstarts</groupId> | ||
<artifactId>jboss-as-inter-app-parent</artifactId> | ||
<version>7.1.1.Final</version> | ||
</parent> | ||
|
||
<dependencies> | ||
|
||
<!-- Import the CDI API, we use provided scope as the API is included | ||
in JBoss AS 7 --> | ||
<dependency> | ||
<groupId>javax.enterprise</groupId> | ||
<artifactId>cdi-api</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<!-- Import the EJB API, we use provided scope as the API is included | ||
in JBoss AS 7 --> | ||
<dependency> | ||
<groupId>org.jboss.spec.javax.ejb</groupId> | ||
<artifactId>jboss-ejb-api_3.1_spec</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<!-- Import the shared API module, which is used by Maven at compilation | ||
time. See the corresponding Dependencies entry in the MANIFEST.mf which defines | ||
the dependency at runtime. --> | ||
<dependency> | ||
<groupId>org.jboss.as.quickstarts</groupId> | ||
<artifactId>jboss-as-inter-app-shared</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
<build> | ||
<!-- Set the name of the war, used as the context root when the app | ||
is deployed --> | ||
<finalName>${project.artifactId}</finalName> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-war-plugin</artifactId> | ||
<version>2.1.1</version> | ||
<configuration> | ||
<!-- Java EE 6 doesn't require web.xml, Maven needs to | ||
catch up! --> | ||
<failOnMissingWebXml>false</failOnMissingWebXml> | ||
<!-- Define a dependency on the shared API, which will | ||
be used by JBoss Modules at runtime. See the corresponding dependency declared | ||
in the POM, which defines the dependency at compile time. --> | ||
<archive> | ||
<manifestEntries> | ||
<Dependencies>deployment.jboss-as-inter-app-shared.jar</Dependencies> | ||
</manifestEntries> | ||
</archive> | ||
</configuration> | ||
</plugin> | ||
<!-- JBoss AS plugin to deploy war --> | ||
<plugin> | ||
<groupId>org.jboss.as.plugins</groupId> | ||
<artifactId>jboss-as-maven-plugin</artifactId> | ||
<version>7.1.1.Final</version> | ||
</plugin> | ||
<!-- Compiler plugin enforces Java 1.6 compatibility and activates | ||
annotation processors --> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>2.3.1</version> | ||
<configuration> | ||
<source>1.6</source> | ||
<target>1.6</target> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> | ||
|
66 changes: 66 additions & 0 deletions
66
inter-app/appA/src/main/java/org/jboss/as/quickstarts/interapp/appA/ControllerA.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2012, Red Hat, Inc. and/or its affiliates, and individual | ||
* contributors by the @authors tag. See the copyright.txt in the | ||
* distribution for a full listing of individual contributors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.jboss.as.quickstarts.interapp.appA; | ||
|
||
import javax.inject.Inject; | ||
import javax.inject.Named; | ||
|
||
import org.jboss.as.quickstarts.interapp.shared.Bar; | ||
import org.jboss.as.quickstarts.interapp.shared.Foo; | ||
|
||
/** | ||
* <p> | ||
* JSF Controller class that allows manipulation of Foo and Bar. | ||
* </p> | ||
* <p> | ||
* Note that whilst EJBs are used to provide inter application communication, this is not apparent to consumers of Foo and Bar, | ||
* which use CDI style injection. | ||
* </p> | ||
* | ||
* @author Pete Muir | ||
* | ||
*/ | ||
@Named | ||
public class ControllerA { | ||
|
||
@Inject | ||
private Foo foo; | ||
|
||
@Inject | ||
private Bar bar; | ||
|
||
public String getFoo() { | ||
return foo.getName(); | ||
} | ||
|
||
public void setFoo(String name) { | ||
foo.setName(name); | ||
} | ||
|
||
public String getBar() { | ||
return bar.getName(); | ||
} | ||
|
||
public void setBar(String name) { | ||
bar.setName(name); | ||
} | ||
|
||
public void sendAndUpdate() { | ||
// No-op | ||
} | ||
|
||
} |
44 changes: 44 additions & 0 deletions
44
inter-app/appA/src/main/java/org/jboss/as/quickstarts/interapp/appA/FooImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2012, Red Hat, Inc. and/or its affiliates, and individual | ||
* contributors by the @authors tag. See the copyright.txt in the | ||
* distribution for a full listing of individual contributors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.jboss.as.quickstarts.interapp.appA; | ||
|
||
import javax.ejb.Singleton; | ||
|
||
import org.jboss.as.quickstarts.interapp.shared.Foo; | ||
|
||
/** | ||
* The Foo bean is registered as an EJB singleton, allowing it to be used in other applications. | ||
* | ||
* The {@link Foo} interface, which defines the contract that {@link FooImpl} exposes is placed in a shared jar. | ||
* | ||
* @author Pete Muir | ||
* | ||
*/ | ||
@Singleton | ||
public class FooImpl implements Foo { | ||
|
||
private String name; | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
inter-app/appA/src/main/java/org/jboss/as/quickstarts/interapp/appA/Imports.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2012, Red Hat, Inc. and/or its affiliates, and individual | ||
* contributors by the @authors tag. See the copyright.txt in the | ||
* distribution for a full listing of individual contributors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.jboss.as.quickstarts.interapp.appA; | ||
|
||
import javax.ejb.EJB; | ||
import javax.enterprise.inject.Produces; | ||
|
||
import org.jboss.as.quickstarts.interapp.shared.Bar; | ||
|
||
/** | ||
* The Imports class is used to alias EJBs imported from other applications as local CDI beans, thus allowing consumers to | ||
* ignore the details of inter-application communication. | ||
* | ||
* @author Pete Muir | ||
* | ||
*/ | ||
public class Imports { | ||
|
||
@SuppressWarnings("unused") | ||
@Produces | ||
@EJB(lookup = "java:global/jboss-as-inter-app-B/BarImpl!org.jboss.as.quickstarts.interapp.shared.Bar") | ||
private Bar bar; | ||
|
||
private Imports() { | ||
// Disable instantiation of this class | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<!-- JBoss, Home of Professional Open Source Copyright 2012, Red Hat, Inc. | ||
and/or its affiliates, and individual contributors by the @authors tag. See | ||
the copyright.txt in the distribution for a full listing of individual contributors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
use this file except in compliance with the License. You may obtain a copy | ||
of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required | ||
by applicable law or agreed to in writing, software distributed under the | ||
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS | ||
OF ANY KIND, either express or implied. See the License for the specific | ||
language governing permissions and limitations under the License. --> | ||
<!-- Marker file indicating CDI should be enabled --> | ||
<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation=" | ||
http://java.sun.com/xml/ns/javaee | ||
http://java.sun.com/xml/ns/javaee/beans_1_0.xsd"> | ||
|
||
</beans> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0"?> | ||
<!-- JBoss, Home of Professional Open Source Copyright 2012, Red Hat, Inc. | ||
and/or its affiliates, and individual contributors by the @authors tag. See | ||
the copyright.txt in the distribution for a full listing of individual contributors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
use this file except in compliance with the License. You may obtain a copy | ||
of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required | ||
by applicable law or agreed to in writing, software distributed under the | ||
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS | ||
OF ANY KIND, either express or implied. See the License for the specific | ||
language governing permissions and limitations under the License. --> | ||
<!-- Marker file indicating JSF should be enabled --> | ||
<faces-config version="2.0" xmlns="http://java.sun.com/xml/ns/javaee" | ||
xmlns:xi="http://www.w3.org/2001/XInclude" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"> | ||
|
||
</faces-config> |
Oops, something went wrong.