Permalink
Browse files

Example showing remote access to EJBs (authored by Jaikiran Pai)

  • Loading branch information...
1 parent c1852eb commit f70497bb08f4a5a86f1d514da63b23d28731eaf1 @mmusgrov mmusgrov committed Jan 4, 2012
View
@@ -0,0 +1,78 @@
+Remote EJB Client Example
+=========================
+
+What is it?
+-----------
+
+This example shows how to access an EJB from a remote Java client program. It
+demonstrates the use of *EJB 3.1* and *JNDI* in *JBoss AS 7*.
+
+There are two parts to the example: a server side component and a remote client program
+that accesses it. Each part is in its own standalone Maven module, however the quickstart
+does provide a top level module to simplify the packaging of the artifacts.
+
+The server component is comprised of a stateful and a stateless EJB. The client program looks
+up the stateless and stateful beans via JNDI and invokes methods on them.
+
+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 a JBoss AS 7 or EAP 6.
+The following instructions target JBoss AS 7, but they also apply to JBoss EAP 6.
+
+Building and deploying the application
+-------------------------
+
+Start JBoss AS 7 (or EAP 6):
+
+ $JBOSS_HOME/bin/standalone.sh
+
+To build both the server side component and a remote client program change into the
+examples quickstart directory and type:
+
+ mvn clean package
+
+The server side component is packaged as a jar and needs deploying to the AS you just started:
+
+ cd server-side
+ mvn jboss-as:deploy
+
+This maven goal will deploy server-side/target/jboss-as-ejb-remote-app.jar. You can check the AS
+console to see information messages regarding the deployment.
+
+Note that you can also start JBoss AS 7 and deploy the project using Eclipse. See the JBoss AS 7
+Getting Started Guide for Developers for more information.
+
+Now start a client that will access the beans you just deployed:
+
+ cd ../client
+ mvn exec:exec
+
+You should see output showing:
+
+* the client sending a method invocation to the stateless bean to add
+two numbers and then a second invocation to subtract two numbers.
+
+* the client sends a method invocation to the statful bean asking it to increment a counter
+followed by a request to get the current value of the counter. To demonstrate that the bean
+is stateful it performs the same two invocations a number of times proving that the bean
+is maintaining the state of the counter between invocations.
+
+To undeploy the server side component from JBoss AS:
+
+ cd ../server-side
+ mvn jboss-as:undeploy
+
+Downloading the sources and Javadocs
+====================================
+
+If you want to be able to debug into the source code or look at the Javadocs
+of any library in the project, you can run either of the following two
+commands to pull them into your local repository. The IDE should then detect
+them.
+
+ mvn dependency:sources
+ mvn dependency:resolve -Dclassifier=javadoc
+
View
@@ -0,0 +1,185 @@
+<?xml version="1.0"?>
+<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>
+
+ <groupId>org.jboss.as.quickstarts</groupId>
+ <artifactId>jboss-as-quickstarts-ejb-remote-client</artifactId>
+ <version>7.1.0.CR1-SNAPSHOT</version>
+ <packaging>jar</packaging>
+ <name>JBoss AS Quickstarts: EJB Remote Client</name>
+ <description>JBoss AS Quickstarts: EJB Remoting</description>
+
+ <url>http://jboss.org/jbossas</url>
+ <licenses>
+ <license>
+ <name>Apache License, Version 2.0</name>
+ <distribution>repo</distribution>
+ <url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
+ </license>
+ </licenses>
+
+ <repositories>
+ <!-- Add the JBoss repository for org.jboss</groupId:jboss-ejb-client
+ this will not be necessary if it has been uploaded to central -->
+ <repository>
+ <id>jboss-public-repository-group</id>
+ <name>JBoss Public Repository Group</name>
+ <url>http://repository.jboss.org/nexus/content/groups/public/</url>
+ <layout>default</layout>
+ <releases>
+ <enabled>true</enabled>
+ <updatePolicy>never</updatePolicy>
+ </releases>
+ <snapshots>
+ <enabled>true</enabled>
+ <updatePolicy>never</updatePolicy>
+ </snapshots>
+ </repository>
+ </repositories>
+
+ <properties>
+ <!-- Explicitly declaring the source encoding eliminates the following
+ message: -->
+ <!-- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered
+ resources, i.e. build is platform dependent! -->
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+ <dependencyManagement>
+ <dependencies>
+ <!-- Define the version of JBoss' Java EE 6 APIs we want to use -->
+ <!-- JBoss distributes a complete set of Java EE 6 APIs including
+ a Bill of Materials (BOM). A BOM specifies the versions of a "stack" (or
+ a collection) of artifacts. We use this here so that we always get the correct
+ versions of artifacts. Here we use the jboss-javaee-web-6.0 stack (you can
+ read this as the JBoss stack of the Java EE 6 Web Profile APIs), and we use
+ version 2.0.0.Beta1 which is the latest release of the stack. You can actually
+ use this stack with any version of JBoss AS that implements Java EE 6, not
+ just JBoss AS 7! -->
+ <dependency>
+ <groupId>org.jboss.spec</groupId>
+ <artifactId>jboss-javaee-web-6.0</artifactId>
+ <version>2.0.0.Final</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <dependencies>
+
+ <!-- Import the transaction spec API, we use runtime scope because we aren't using any direct
+ reference to the spec API in our client code -->
+ <dependency>
+ <groupId>org.jboss.spec.javax.transaction</groupId>
+ <artifactId>jboss-transaction-api_1.1_spec</artifactId>
+ <scope>runtime</scope>
+ </dependency>
+
+ <!-- Import the EJB 3.1 API, we use runtime scope because we aren't using any direct
+ reference to EJB spec API in our client code -->
+ <dependency>
+ <groupId>org.jboss.spec.javax.ejb</groupId>
+ <artifactId>jboss-ejb-api_3.1_spec</artifactId>
+ <scope>runtime</scope>
+ </dependency>
+
+ <!-- We depend on the server side EJBs of this application -->
+ <dependency>
+ <groupId>org.jboss.as.quickstarts</groupId>
+ <artifactId>jboss-as-ejb-remote-server-side</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <!-- JBoss EJB client API jar. We use runtime scope because the EJB client API
+ isn't directly used in this example. We just need it in our runtime classpath -->
+ <dependency>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-ejb-client</artifactId>
+ <version>1.0.0.Beta9</version>
+ <scope>runtime</scope>
+ </dependency>
+
+ <!-- client communications with the server use XNIO -->
+ <dependency>
+ <groupId>org.jboss.xnio</groupId>
+ <artifactId>xnio-api</artifactId>
+ <version>3.0.0.CR5</version>
+ <scope>runtime</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.xnio</groupId>
+ <artifactId>xnio-nio</artifactId>
+ <version>3.0.0.CR5</version>
+ <scope>runtime</scope>
+ </dependency>
+
+ <!-- The client needs JBoss remoting to access the server -->
+ <dependency>
+ <groupId>org.jboss.remoting3</groupId>
+ <artifactId>jboss-remoting</artifactId>
+ <version>3.2.0.CR6</version>
+ <scope>runtime</scope>
+ </dependency>
+
+ <!-- Remote EJB accesses can be secured -->
+ <dependency>
+ <groupId>org.jboss.sasl</groupId>
+ <artifactId>jboss-sasl</artifactId>
+ <version>1.0.0.Beta9</version>
+ </dependency>
+
+ <!-- data serialization for invoking remote EJBs -->
+ <dependency>
+ <groupId>org.jboss.marshalling</groupId>
+ <artifactId>jboss-marshalling-river</artifactId>
+ <version>1.3.0.GA</version>
+ <scope>runtime</scope>
+ </dependency>
+
+ </dependencies>
+
+ <build>
+ <plugins>
+ <!-- Enforce Java 1.6 -->
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.3.1</version>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+
+ <!-- Add the maven exec plugin to allow us to run a java program via maven -->
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>exec-maven-plugin</artifactId>
+ <version>1.2.1</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>exec</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <executable>java</executable>
+ <workingDirectory>${project.build.directory}/exec-working-directory</workingDirectory>
+ <arguments>
+ <!-- automatically creates the classpath using all project dependencies,
+ also adding the project build directory -->
+ <argument>-classpath</argument>
+ <classpath>
+ </classpath>
+ <argument>org.jboss.as.quickstarts.ejb.remote.client.RemoteEJBClient</argument>
+ </arguments>
+ </configuration>
+ </plugin>
+ </plugins>
+
+ </build>
+
+</project>
Oops, something went wrong.

0 comments on commit f70497b

Please sign in to comment.