Author: kmalhi
Date: Mon Feb 16 06:00:15 2009
New Revision: 744815
URL: http://svn.apache.org/viewvc?rev=744815&view=rev
Log:
Added the applet example which demonstrates how to communicate with a remote
stateless session bean from an applet. It also demonstrates how to sign your
applets and demonstrates solutions for common applet gotchas
Added:
openejb/trunk/openejb3/examples/webapps/applet/
openejb/trunk/openejb3/examples/webapps/applet/README.txt
openejb/trunk/openejb3/examples/webapps/applet/pom.xml
openejb/trunk/openejb3/examples/webapps/applet/src/
openejb/trunk/openejb3/examples/webapps/applet/src/main/
openejb/trunk/openejb3/examples/webapps/applet/src/main/java/
openejb/trunk/openejb3/examples/webapps/applet/src/main/java/org/
openejb/trunk/openejb3/examples/webapps/applet/src/main/java/org/superbiz/
openejb/trunk/openejb3/examples/webapps/applet/src/main/java/org/superbiz/applet/
openejb/trunk/openejb3/examples/webapps/applet/src/main/java/org/superbiz/applet/Calculator.java
openejb/trunk/openejb3/examples/webapps/applet/src/main/java/org/superbiz/applet/CalculatorApplet.java
openejb/trunk/openejb3/examples/webapps/applet/src/main/java/org/superbiz/applet/CalculatorImpl.java
openejb/trunk/openejb3/examples/webapps/applet/src/main/resources/
openejb/trunk/openejb3/examples/webapps/applet/src/main/webapp/
openejb/trunk/openejb3/examples/webapps/applet/src/main/webapp/WEB-INF/
openejb/trunk/openejb3/examples/webapps/applet/src/main/webapp/WEB-INF/web.xml
openejb/trunk/openejb3/examples/webapps/applet/src/main/webapp/index.jsp
openejb/trunk/openejb3/examples/webapps/applet/src/test/
openejb/trunk/openejb3/examples/webapps/applet/src/test/java/
openejb/trunk/openejb3/examples/webapps/applet/src/test/java/org/
openejb/trunk/openejb3/examples/webapps/applet/src/test/java/org/superbiz/
openejb/trunk/openejb3/examples/webapps/applet/src/test/java/org/superbiz/JNDILookupTest.java
Added: openejb/trunk/openejb3/examples/webapps/applet/README.txt
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/webapps/applet/README.txt?rev=744815&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/webapps/applet/README.txt (added)
+++ openejb/trunk/openejb3/examples/webapps/applet/README.txt Mon Feb 16
06:00:15 2009
@@ -0,0 +1,133 @@
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+-->
+============
+OVERVIEW
+============
+This example creates an applet which requires the user to enter two numbers.
+It then uses the Calculator EJB to add the numbers and displays the result.
+
+Before you run the example, there are a few things worth noting.
+One has to keep in mind that applets run in a very restrictive environment. A
couple of
+them are
+1. Applets can only establish a connection to the host they came from
+2. A signed applet gets around most of the restrictions (e.g. calls to
System.getProperty() etc)
+3. Any resources/classes needed by the applet should be available in the same
directory where
+the applet originated from, or its sub-directory/ies
+
+Since our applet will establish a connection back to the EJB, so we need to
make sure
+we are not trying to establish a connection to some other webapp. We will see
in a minute
+what that means.
+We shall also sign our applet using jarsigner, however would would first need
to create
+a certificate. We will get to this part also in a minute.
+
+Since our applet would be running in a remote JVM, it would use the
RemoteInitialContextFactory
+instead of the LocalInitialContextFactory. The RemoteInitialContextFactory is
available
+in openejb-client.jar. The applet would also need the java-ee-api.jar in its
class-path.
+
+Lets see how we can use maven + ant to get around the above restrictions of
applets:-
+
+The pom.xml of this project
+- adds the client and the ee jars as dependencies.
+- uses the ant jar task (in the maven-antrun-plugin) to jar up all classes in
WEB-INF/classes and puts them under the root
+directory of the web app (this is required, since web app clients cannot
access anything under
+WEB-INF directory, hence we copied those classes to web-apps root directory)
+[Note:- The ant script puts all classes under WEB-INF/classes inside a jar.
All classes
+are not required by the applet. Instead, the applet only needs the EJB
interface and Applet
+classes in the jar]
+- uses maven-dependency-plugin to copy javaee-api and openejb-client jars to
src/main/webapp (this is the webapp root directory)
+- uses the signjar ant task to sign all the jar files
+
+The APPLET is located inside index.jsp . Notice how the archive attribute of
the applet
+is used to add the applet , java ee and openejb client jars to the applets
classpath
+
+Since the APPLET can only communicate from the host it originates, notice how
the web context
+root is used in the provider url to obtain the InitialContext.
+ Properties props = new Properties();
+ props.put(Context.INITIAL_CONTEXT_FACTORY,
+
"org.apache.openejb.client.RemoteInitialContextFactory");
+
props.put(Context.PROVIDER_URL,"http://127.0.0.1:8080/applet/ejb");
+
+The example web-app has a context root named applet. If you were making
another webapp with a
+different context root, then you would use that in the provider url instead.
+If you open the web.xml of this project, you will find a <servlet-mapping>
section which
+actually maps the /ejb/* to a servlet named ServerServlet. This is another
thing which you need
+too keep in mind in your web-app. Yes, the provider url actually points to a
servlet named
+ServerServlet. This servlet is provided by openejb and is automatically added
to you webapps
+classpath.
+[Note:- All other clients (except applets) will use a provider url of
http://127.0.0.1:8080/openejb/ejb,
+since an applet cannot connect to another web-app, hence the above little
trick to work around this
+limitation. If you do not make the change, you will get a HTTP 403 error i.e.
server denied
+access to the ServerServlet . A unit test named JNDILookupTest has been added
to the example to
+show how a non-applet remote client would obtain the Context]
+
+HOW TO RUN THE EXAMPLE
+======================
+--USE KEYTOOL --
+You would need to do a bit of work (if you have not done that already) in
creating a self-signed
+certificate (in case you do not have one from one of the certificate
authorities).
+Here is the steps performed to create the certificate (notice the store
password is openejb -
+this password is also used in pom.xml while signing the jar -- if your store
passwd is different
+please update the pom.xml with the correct password before proceeding forward)
+Use the keytool as shown below (answer all questions asked by keytool -- the
answers do not
+have to match as shown below (except for store password and alias <mykey> --
since it is used by maven))
+
+ka...@jee:~$ keytool -genkey
+Enter keystore password: openejb
+What is your first and last name?
+ [Unknown]: karan malhi
+What is the name of your organizational unit?
+ [Unknown]: Superbiz
+What is the name of your organization?
+ [Unknown]: Superbiz
+What is the name of your City or Locality?
+ [Unknown]: Deptford
+What is the name of your State or Province?
+ [Unknown]: NJ
+What is the two-letter country code for this unit?
+ [Unknown]: US
+Is CN=karan malhi, OU=Superbiz, O=Superbiz, L=Deptford, ST=NJ, C=US correct?
+ [no]: yes
+
+Enter key password for <mykey>
+ (RETURN if same as keystore password):
+ka...@jee:~$
+
+-- INSTALL AND CONFIGURE TOMCAT --
+
+1. Install latest Tomcat
+2. Deploy OpenEJB WAR in tomcat
+3. Open <<tomcat-install>>/conf/tomcat-users.xml and add the following user
+ <user username="admin" password="" roles="manager"/>
+
+-- DEPLOY AND TEST THE EXAMPLE --
+1. Run the following command while in the applet directory
+ mvn clean install war:exploded tomcat:deploy -Dmaven.test.skip=true
+ [It is required to skip the test since the application is not yet deployed
on tomcat. If you run
+the test now, it will fail]
+2. The above will deploy this web application to tomcat.
+3. To test the application, open a web browser and navigate to
+ http://localhost:8080/applet
+4. You will be prompted to accept digital signature. Accept it to run the
applet
+5. Enter two numbers and click the add button, the result should be displayed
next
+to the button
+
+[Note:- If you make changes and want to redeploy the app use the following
command:
+ mvn clean install war:exploded tomcat:redeploy]
+
+
+
Added: openejb/trunk/openejb3/examples/webapps/applet/pom.xml
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/webapps/applet/pom.xml?rev=744815&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/webapps/applet/pom.xml (added)
+++ openejb/trunk/openejb3/examples/webapps/applet/pom.xml Mon Feb 16 06:00:15
2009
@@ -0,0 +1,122 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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>
+ <groupId>org.superbiz.applet</groupId>
+ <artifactId>applet</artifactId>
+ <packaging>war</packaging>
+ <version>1.0-SNAPSHOT</version>
+ <name>applet Maven Webapp</name>
+ <url>http://openejb.apache.org</url>
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.5</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.openejb</groupId>
+ <artifactId>javaee-api</artifactId>
+ <version>5.0-1</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.openejb</groupId>
+ <artifactId>openejb-client</artifactId>
+ <version>3.1</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <finalName>applet</finalName>
+ <pluginManagement>
+ <plugins>
+ </plugins>
+ </pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>tomcat-maven-plugin</artifactId>
+ <version>1.0-beta-1</version>
+ <configuration>
+
<url>http://localhost:8080/manager/html</url>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-antrun-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>process-classes</phase>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ <configuration>
+ <tasks>
+ <jar
destfile="src/main/webapp/app.jar" basedir="target/classes" />
+ <signjar
jar='src/main/webapp/app.jar' alias="mykey" storepass="openejb" />
+ <signjar
jar='src/main/webapp/openejb-client-3.1.jar' alias="mykey" storepass="openejb"
/>
+ <signjar
jar='src/main/webapp/javaee-api-5.0-1.jar' alias="mykey" storepass="openejb" />
+ </tasks>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>copy</id>
+ <phase>process-resources</phase>
+ <goals>
+ <goal>copy</goal>
+ </goals>
+ <configuration>
+ <artifactItems>
+ <artifactItem>
+
<groupId>org.apache.openejb</groupId>
+
<artifactId>openejb-client</artifactId>
+
<version>3.1</version>
+
<outputDirectory>src/main/webapp</outputDirectory>
+ </artifactItem>
+ <artifactItem>
+
<groupId>org.apache.openejb</groupId>
+
<artifactId>javaee-api</artifactId>
+
<version>5.0-1</version>
+
<outputDirectory>src/main/webapp</outputDirectory>
+ </artifactItem>
+ </artifactItems>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
Added:
openejb/trunk/openejb3/examples/webapps/applet/src/main/java/org/superbiz/applet/Calculator.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/webapps/applet/src/main/java/org/superbiz/applet/Calculator.java?rev=744815&view=auto
==============================================================================
---
openejb/trunk/openejb3/examples/webapps/applet/src/main/java/org/superbiz/applet/Calculator.java
(added)
+++
openejb/trunk/openejb3/examples/webapps/applet/src/main/java/org/superbiz/applet/Calculator.java
Mon Feb 16 06:00:15 2009
@@ -0,0 +1,25 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.superbiz.applet;
+
+import javax.ejb.Remote;
+
+...@remote
+public interface Calculator {
+ public double add(double x, double y);
+}
Added:
openejb/trunk/openejb3/examples/webapps/applet/src/main/java/org/superbiz/applet/CalculatorApplet.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/webapps/applet/src/main/java/org/superbiz/applet/CalculatorApplet.java?rev=744815&view=auto
==============================================================================
---
openejb/trunk/openejb3/examples/webapps/applet/src/main/java/org/superbiz/applet/CalculatorApplet.java
(added)
+++
openejb/trunk/openejb3/examples/webapps/applet/src/main/java/org/superbiz/applet/CalculatorApplet.java
Mon Feb 16 06:00:15 2009
@@ -0,0 +1,106 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.superbiz.applet;
+
+import java.awt.GridLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.Properties;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.rmi.PortableRemoteObject;
+import javax.swing.JApplet;
+import javax.swing.JButton;
+import javax.swing.JLabel;
+import javax.swing.JTextArea;
+import javax.swing.JTextField;
+import javax.swing.SwingUtilities;
+
+public class CalculatorApplet extends JApplet {
+ JTextArea area;
+
+ JTextField field1;
+ JTextField field2;
+ JLabel label1;
+ JLabel label2;
+ JButton button;
+ JLabel label3;
+ Context ctx;
+
+ public void init() {
+ try {
+ SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ createUI();
+ }
+ });
+ } catch (Exception e) {
+ System.err.println("createGUI didn't successfully
complete");
+ }
+
+ }
+
+ private void createUI() {
+ field1 = new JTextField();
+ field2 = new JTextField();
+ label1 = new JLabel("Enter first number");
+ label2 = new JLabel("Enter second number");
+ label3 = new JLabel("RESULT=");
+ button = new JButton("Add");
+
+ setLayout(new GridLayout(3, 2));
+ add(label1);
+ add(field1);
+ add(label2);
+ add(field2);
+ add(button);
+ add(label3);
+ Properties props = new Properties();
+ props.put(Context.INITIAL_CONTEXT_FACTORY,
+
"org.apache.openejb.client.RemoteInitialContextFactory");
+
props.put(Context.PROVIDER_URL,"http://127.0.0.1:8080/applet/ejb");
+ try {
+ ctx = new InitialContext(props);
+ } catch (NamingException e) {
+ throw new RuntimeException(e);
+ }
+ button.addActionListener(new ActionListener() {
+
+ public void actionPerformed(ActionEvent e) {
+
+ try {
+ final Object ref =
ctx.lookup("CalculatorImplRemote");
+ Calculator calc = (Calculator)
PortableRemoteObject.narrow(
+ ref, Calculator.class);
+ String text1 = field1.getText();
+ String text2 = field2.getText();
+ int num1 = Integer.parseInt(text1);
+ int num2 = Integer.parseInt(text2);
+ double result = calc.add(num1, num2);
+ label3.setText("RESULT=" + result);
+ } catch (NamingException ex) {
+ throw new RuntimeException(ex);
+ }
+
+ }
+ });
+
+ }
+}
Added:
openejb/trunk/openejb3/examples/webapps/applet/src/main/java/org/superbiz/applet/CalculatorImpl.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/webapps/applet/src/main/java/org/superbiz/applet/CalculatorImpl.java?rev=744815&view=auto
==============================================================================
---
openejb/trunk/openejb3/examples/webapps/applet/src/main/java/org/superbiz/applet/CalculatorImpl.java
(added)
+++
openejb/trunk/openejb3/examples/webapps/applet/src/main/java/org/superbiz/applet/CalculatorImpl.java
Mon Feb 16 06:00:15 2009
@@ -0,0 +1,29 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.superbiz.applet;
+
+import javax.ejb.Stateless;
+
+...@stateless
+public class CalculatorImpl implements Calculator {
+
+ public double add(double x, double y) {
+ return x+y;
+ }
+
+}
Added:
openejb/trunk/openejb3/examples/webapps/applet/src/main/webapp/WEB-INF/web.xml
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/webapps/applet/src/main/webapp/WEB-INF/web.xml?rev=744815&view=auto
==============================================================================
---
openejb/trunk/openejb3/examples/webapps/applet/src/main/webapp/WEB-INF/web.xml
(added)
+++
openejb/trunk/openejb3/examples/webapps/applet/src/main/webapp/WEB-INF/web.xml
Mon Feb 16 06:00:15 2009
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+-->
+<!DOCTYPE web-app PUBLIC
+ "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
+ "http://java.sun.com/dtd/web-app_2_3.dtd" >
+
+<web-app>
+ <servlet>
+ <servlet-name>ServerServlet</servlet-name>
+
<servlet-class>org.apache.openejb.server.httpd.ServerServlet</servlet-class>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>ServerServlet</servlet-name>
+ <url-pattern>/ejb/*</url-pattern>
+ </servlet-mapping>
+</web-app>
Added: openejb/trunk/openejb3/examples/webapps/applet/src/main/webapp/index.jsp
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/webapps/applet/src/main/webapp/index.jsp?rev=744815&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/webapps/applet/src/main/webapp/index.jsp
(added)
+++ openejb/trunk/openejb3/examples/webapps/applet/src/main/webapp/index.jsp
Mon Feb 16 06:00:15 2009
@@ -0,0 +1,26 @@
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+-->
+<html>
+<body>
+<applet alt="could not load applet" height="100" width="300"
+ codebase="."
+ archive="app.jar,javaee-api-5.0-1.jar,openejb-client-3.1.jar"
+ code="org.superbiz.applet.CalculatorApplet">
+</applet>
+</body>
+</html>
Added:
openejb/trunk/openejb3/examples/webapps/applet/src/test/java/org/superbiz/JNDILookupTest.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/webapps/applet/src/test/java/org/superbiz/JNDILookupTest.java?rev=744815&view=auto
==============================================================================
---
openejb/trunk/openejb3/examples/webapps/applet/src/test/java/org/superbiz/JNDILookupTest.java
(added)
+++
openejb/trunk/openejb3/examples/webapps/applet/src/test/java/org/superbiz/JNDILookupTest.java
Mon Feb 16 06:00:15 2009
@@ -0,0 +1,50 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.superbiz;
+
+import java.util.Properties;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.rmi.PortableRemoteObject;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.superbiz.applet.Calculator;
+
+
+public class JNDILookupTest {
+
+ @Test
+ public void test(){
+ Properties props = new Properties();
+
props.put(Context.INITIAL_CONTEXT_FACTORY,"org.apache.openejb.client.RemoteInitialContextFactory");
+ props.put(Context.PROVIDER_URL,
"http://127.0.0.1:8080/openejb/ejb");
+ try {
+ Context ctx = new InitialContext(props);
+ System.out.println("Found context "+ctx);
+ final Object ref = ctx.lookup("CalculatorImplRemote");
+ Calculator calc = (Calculator)
PortableRemoteObject.narrow(ref, Calculator.class);
+ double result = calc.add(10, 30);
+ Assert.assertEquals(40, result,0.5);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+}