Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to deploy a Java application in WAS?

102 views
Skip to first unread message

Rune Hellem

unread,
Mar 26, 2002, 8:38:13 AM3/26/02
to
Hi

Just wondering if someone could be so kind to give me some advices on how to
deploy or maybe more correct how to run a Java application as a part of an
J2EE Enterprise Application running in Websphere.

The case is that we want an external application to communicate with our
J2EE application. The application uses standard socket api, so we have to
have a server running which handles all these requests. The socket server
then handles the request, and the work might involve request for data from
our database or through CICS. Communication with the database or CICS is
done through use of EJB's.

So back to my question - how should I run this "socket server". Is it
possible to let it run "inside" WAS, or am I wrong here? As I see it, if WAS
knows about it, then WAS could have the responsibility of starting it after
a shutdown etc. If I have to run the "socket server" in another VM on the
server, could I run in to problems when trying to talk with the EJB's? Heard
something about lookup could be a problem because of trouble getting the
correct InitialContext...

Hope this should be enough information....

In advance!

Rune

SantaClaws

unread,
Mar 26, 2002, 1:08:49 PM3/26/02
to
Hi,

Your socket server can run outside WAS. You will have to ensure the
uptime for the socket server. You will run into problems if you are
caching the Intial Contexts in your socket server and WAS goes down.
In this case the cached Intial contexts are invalid and you will get
an error when trying to fire the EJB.

But that is no problem either. You can trap that exception and try
to get the Initial Contexts again in some suitable method. The whole
thing about this is to get the logic right while doing the code for
connecting to WAS.

Hope this helps

Regards,
The SantaClaws

"Rune Hellem" <rune....@REMOVEstart.no> wrote in message news:<a7pthv$1134$1...@news.boulder.ibm.com>...

David Artus

unread,
Mar 26, 2002, 5:19:18 PM3/26/02
to

There are a few solutions to this but it's not quite a nice as one
might wish. My suggestion (without ever having done this myself)
is to have a load-on-startup servlet. Have it's init method spawn a
thread, and off you go. As servlets are quite happy about
calling EJBs you should be in an environment where everything
works just fine.

If you could amend the external app to use WebServices then
you could use a more supported equivalent of that socket
approach.

The Custom Service facility *sounds* like it might be what you
need but is documented as having a curious set of limitations
that seem too restrictive for your purpose.

Visvakumar Durairaj

unread,
May 2, 2002, 6:00:43 PM5/2/02
to
Hi Dave,

I also have the similar kind of problem. A startup class need to access
an EJB and call a method as part of the app server startup. As you have
mentioned, the custom service get called before all the services are
started. So custom service is not the option. The other option is to have
the load-on-startup servlet. The problem with the load-on-startup servlet is
that the init() method get called before the EJBs are initialized and thus
failed to lookup the bean.

In weblogic, there is a simple concept called "StartupClass". All you have
to specify is the class name and the arguments. The class get called right
after the app server is initialized.

We are in the process of evaluating to migrate from Weblogic to Websphere
and this is a big roadblock for us.

Thanks for any help.

Best regards,
Visvakumar Durairaj,
D2K Inc,
San Jose, CA.


"David Artus" <art...@uk.ibm.no.spam.com> wrote in message
news:3CA0F3E6...@uk.ibm.no.spam.com...

James You

unread,
Sep 20, 2002, 5:41:24 PM9/20/02
to
I have created an application to generate EJB session facade and
automatically
compile, deploy EJB, install EJB and run EJB client into the IBM
WebSphere Application server AE (Single Server Edition)
using ANT. All the operations are working well excpetion the final step
when use lauchClient tool provided by WAS to run the EJB client. I got
the follwing error in the server log file.

=====================================
[02.09.20 16:13:14:221 EDT] 6b14ba3d WebGroup I SRVE0091I: [Servlet
LOG]: action: starting EJBModuleRef:
[02.09.20 16:13:14:281 EDT] 6b14ba3d WebGroup I SRVE0091I: [Servlet
LOG]: action: EJBModuleRef_1
[02.09.20 16:13:14:712 EDT] 414f7a3b EJBEngine I WSVR0037I: Starting
EJB jar:
C:\WebSphere\AppServer/installedApps\bank_TellerEJB.ear/bank_TellerEJB.jar
[02.09.20 16:13:15:132 EDT] 6b14ba3d SystemOut U moduleState running
[02.09.20 16:14:08:459 EDT] 55b7ba3d SystemOut U setSessionContext
called
[02.09.20 16:14:08:479 EDT] 55b7ba3d SystemOut U ejbCreate called
[02.09.20 16:14:08:779 EDT] 55b7ba3d ExceptionUtil X CNTR0019E:
Non-application exception occurred while processing method
createAccount: com.ibm.ejs.container.CreateFailureException:
java.lang.reflect.InvocationTargetException; nested exception is:
java.lang.reflect.InvocationTargetException
java.lang.reflect.InvocationTargetException: javax.ejb.CreateException:
Failed to find environment value Name not found in context "java:".
at bank.TellerEJB.ejbCreate(TellerEJB.java:100)
at java.lang.reflect.Method.invoke(Native Method)
at com.ibm.ejs.container.StatelessBeanO.<init>(StatelessBeanO.java:96)
at
com.ibm.ejs.container.CMStatelessBeanO.<init>(CMStatelessBeanO.java:29)
at
com.ibm.ejs.container.CMStatelessBeanOFactory.create(CMStatelessBeanOFactory.java:17)
at com.ibm.ejs.container.EJSHome.createBeanO(EJSHome.java:941)
at com.ibm.ejs.container.EJSHome.createBeanO(EJSHome.java:990)
at
com.ibm.ejs.container.activator.UncachedActivationStrategy.atActivate(UncachedActivationStrategy.java:66)
at
com.ibm.ejs.container.activator.Activator.activateBean(Activator.java:171)
at com.ibm.ejs.container.EJSContainer.preInvoke(EJSContainer.java:2152)
at
bank.EJSRemoteStatelessTellerRemote.createAccount(EJSRemoteStatelessTellerRemote.java:24)
at
bank._EJSRemoteStatelessTellerRemote_Tie._invoke(_EJSRemoteStatelessTellerRemote_Tie.java:121)
at
com.ibm.CORBA.iiop.ExtendedServerDelegate.dispatch(ExtendedServerDelegate.java:506)
at com.ibm.CORBA.iiop.ORB.process(ORB.java:2294)
at com.ibm.CORBA.iiop.OrbWorker.run(OrbWorker.java:185)
at com.ibm.ejs.oa.pool.ThreadPool$PooledWorker.run(ThreadPool.java:95)
at com.ibm.ws.util.CachedThread.run(ThreadPool.java:122)
----- Begin backtrace for detail
java.lang.reflect.InvocationTargetException: javax.ejb.CreateException:
Failed to find environment value Name not found in context "java:".
at bank.TellerEJB.ejbCreate(TellerEJB.java:100)
at java.lang.reflect.Method.invoke(Native Method)
at com.ibm.ejs.container.StatelessBeanO.<init>(StatelessBeanO.java:96)
at
com.ibm.ejs.container.CMStatelessBeanO.<init>(CMStatelessBeanO.java:29)
at
com.ibm.ejs.container.CMStatelessBeanOFactory.create(CMStatelessBeanOFactory.java:17)
at com.ibm.ejs.container.EJSHome.createBeanO(EJSHome.java:941)
at com.ibm.ejs.container.EJSHome.createBeanO(EJSHome.java:990)
at
com.ibm.ejs.container.activator.UncachedActivationStrategy.atActivate(UncachedActivationStrategy.java:66)
at
com.ibm.ejs.container.activator.Activator.activateBean(Activator.java:171)
at com.ibm.ejs.container.EJSContainer.preInvoke(EJSContainer.java:2152)
at
bank.EJSRemoteStatelessTellerRemote.createAccount(EJSRemoteStatelessTellerRemote.java:24)
at
bank._EJSRemoteStatelessTellerRemote_Tie._invoke(_EJSRemoteStatelessTellerRemote_Tie.java:121)
at
com.ibm.CORBA.iiop.ExtendedServerDelegate.dispatch(ExtendedServerDelegate.java:506)
at com.ibm.CORBA.iiop.ORB.process(ORB.java:2294)
at com.ibm.CORBA.iiop.OrbWorker.run(OrbWorker.java:185)
at com.ibm.ejs.oa.pool.ThreadPool$PooledWorker.run(ThreadPool.java:95)
at com.ibm.ws.util.CachedThread.run(ThreadPool.java:122)
----- Begin backtrace for targetException
javax.ejb.CreateException: Failed to find environment value Name not
found in context "java:".
at bank.TellerEJB.ejbCreate(TellerEJB.java:100)
at java.lang.reflect.Method.invoke(Native Method)
at com.ibm.ejs.container.StatelessBeanO.<init>(StatelessBeanO.java:96)
at
com.ibm.ejs.container.CMStatelessBeanO.<init>(CMStatelessBeanO.java:29)
at
com.ibm.ejs.container.CMStatelessBeanOFactory.create(CMStatelessBeanOFactory.java:17)
at com.ibm.ejs.container.EJSHome.createBeanO(EJSHome.java:941)
at com.ibm.ejs.container.EJSHome.createBeanO(EJSHome.java:990)
at
com.ibm.ejs.container.activator.UncachedActivationStrategy.atActivate(UncachedActivationStrategy.java:66)
at
com.ibm.ejs.container.activator.Activator.activateBean(Activator.java:171)
at com.ibm.ejs.container.EJSContainer.preInvoke(EJSContainer.java:2152)
at
bank.EJSRemoteStatelessTellerRemote.createAccount(EJSRemoteStatelessTellerRemote.java:24)
at
bank._EJSRemoteStatelessTellerRemote_Tie._invoke(_EJSRemoteStatelessTellerRemote_Tie.java:121)
at
com.ibm.CORBA.iiop.ExtendedServerDelegate.dispatch(ExtendedServerDelegate.java:506)
at com.ibm.CORBA.iiop.ORB.process(ORB.java:2294)
at com.ibm.CORBA.iiop.OrbWorker.run(OrbWorker.java:185)
at com.ibm.ejs.oa.pool.ThreadPool$PooledWorker.run(ThreadPool.java:95)
at com.ibm.ws.util.CachedThread.run(ThreadPool.java:122)

[02.09.20 16:14:09:610 EDT] 55b7ba3d SystemOut U setSessionContext
called
[02.09.20 16:14:09:610 EDT] 55b7ba3d SystemOut U ejbCreate called
[02.09.20 16:14:09:881 EDT] 55b7ba3d ExceptionUtil X CNTR0019E:
Non-application exception occurred while processing method remove:
com.ibm.ejs.container.CreateFailureException:
java.lang.reflect.InvocationTargetException; nested exception is:
java.lang.reflect.InvocationTargetException
java.lang.reflect.InvocationTargetException: javax.ejb.CreateException:
Failed to find environment value Name not found in context "java:".
at bank.TellerEJB.ejbCreate(TellerEJB.java:100)
at java.lang.reflect.Method.invoke(Native Method)
at com.ibm.ejs.container.StatelessBeanO.<init>(StatelessBeanO.java:96)
at
com.ibm.ejs.container.CMStatelessBeanO.<init>(CMStatelessBeanO.java:29)
at
com.ibm.ejs.container.CMStatelessBeanOFactory.create(CMStatelessBeanOFactory.java:17)
at com.ibm.ejs.container.EJSHome.createBeanO(EJSHome.java:941)
at com.ibm.ejs.container.EJSHome.createBeanO(EJSHome.java:990)
at
com.ibm.ejs.container.activator.UncachedActivationStrategy.atActivate(UncachedActivationStrategy.java:66)
at
com.ibm.ejs.container.activator.Activator.activateBean(Activator.java:171)
at com.ibm.ejs.container.EJSContainer.preInvoke(EJSContainer.java:2152)
at
com.ibm.ejs.container.EJSContainer.removeBean(EJSContainer.java:1927)
at com.ibm.ejs.container.EJSWrapper.remove(EJSWrapper.java:325)
at
bank._EJSRemoteStatelessTellerRemote_Tie._invoke(_EJSRemoteStatelessTellerRemote_Tie.java:84)
at
com.ibm.CORBA.iiop.ExtendedServerDelegate.dispatch(ExtendedServerDelegate.java:506)
at com.ibm.CORBA.iiop.ORB.process(ORB.java:2294)
at com.ibm.CORBA.iiop.OrbWorker.run(OrbWorker.java:185)
at com.ibm.ejs.oa.pool.ThreadPool$PooledWorker.run(ThreadPool.java:95)
at com.ibm.ws.util.CachedThread.run(ThreadPool.java:122)
----- Begin backtrace for detail
java.lang.reflect.InvocationTargetException: javax.ejb.CreateException:
Failed to find environment value Name not found in context "java:".
at bank.TellerEJB.ejbCreate(TellerEJB.java:100)
at java.lang.reflect.Method.invoke(Native Method)
at com.ibm.ejs.container.StatelessBeanO.<init>(StatelessBeanO.java:96)
at
com.ibm.ejs.container.CMStatelessBeanO.<init>(CMStatelessBeanO.java:29)
at
com.ibm.ejs.container.CMStatelessBeanOFactory.create(CMStatelessBeanOFactory.java:17)
at com.ibm.ejs.container.EJSHome.createBeanO(EJSHome.java:941)
at com.ibm.ejs.container.EJSHome.createBeanO(EJSHome.java:990)
at
com.ibm.ejs.container.activator.UncachedActivationStrategy.atActivate(UncachedActivationStrategy.java:66)
at
com.ibm.ejs.container.activator.Activator.activateBean(Activator.java:171)
at com.ibm.ejs.container.EJSContainer.preInvoke(EJSContainer.java:2152)
at
com.ibm.ejs.container.EJSContainer.removeBean(EJSContainer.java:1927)
at com.ibm.ejs.container.EJSWrapper.remove(EJSWrapper.java:325)
at
bank._EJSRemoteStatelessTellerRemote_Tie._invoke(_EJSRemoteStatelessTellerRemote_Tie.java:84)
at
com.ibm.CORBA.iiop.ExtendedServerDelegate.dispatch(ExtendedServerDelegate.java:506)
at com.ibm.CORBA.iiop.ORB.process(ORB.java:2294)
at com.ibm.CORBA.iiop.OrbWorker.run(OrbWorker.java:185)
at com.ibm.ejs.oa.pool.ThreadPool$PooledWorker.run(ThreadPool.java:95)
at com.ibm.ws.util.CachedThread.run(ThreadPool.java:122)
----- Begin backtrace for targetException
javax.ejb.CreateException: Failed to find environment value Name not
found in context "java:".
at bank.TellerEJB.ejbCreate(TellerEJB.java:100)
at java.lang.reflect.Method.invoke(Native Method)
at com.ibm.ejs.container.StatelessBeanO.<init>(StatelessBeanO.java:96)
at
com.ibm.ejs.container.CMStatelessBeanO.<init>(CMStatelessBeanO.java:29)
at
com.ibm.ejs.container.CMStatelessBeanOFactory.create(CMStatelessBeanOFactory.java:17)
at com.ibm.ejs.container.EJSHome.createBeanO(EJSHome.java:941)
at com.ibm.ejs.container.EJSHome.createBeanO(EJSHome.java:990)
at
com.ibm.ejs.container.activator.UncachedActivationStrategy.atActivate(UncachedActivationStrategy.java:66)
at
com.ibm.ejs.container.activator.Activator.activateBean(Activator.java:171)
at com.ibm.ejs.container.EJSContainer.preInvoke(EJSContainer.java:2152)
at
com.ibm.ejs.container.EJSContainer.removeBean(EJSContainer.java:1927)
at com.ibm.ejs.container.EJSWrapper.remove(EJSWrapper.java:325)
at
bank._EJSRemoteStatelessTellerRemote_Tie._invoke(_EJSRemoteStatelessTellerRemote_Tie.java:84)
at
com.ibm.CORBA.iiop.ExtendedServerDelegate.dispatch(ExtendedServerDelegate.java:506)
at com.ibm.CORBA.iiop.ORB.process(ORB.java:2294)
at com.ibm.CORBA.iiop.OrbWorker.run(OrbWorker.java:185)
at com.ibm.ejs.oa.pool.ThreadPool$PooledWorker.run(ThreadPool.java:95)
at com.ibm.ws.util.CachedThread.run(ThreadPool.java:122)
=======================================================================================================================================================


The strange thing is that in the client side I got the following debug
output.

==================================================================================================
C:\WebSphere\AppServer\bin>launchClient
C:\WebSphere\AppServer\installedApps\bank_TellerEJB.ear
IBM WebSphere Application Server, Release 4.0
J2EE Application Client Tool, Version 1.0
Copyright IBM Corp., 1997-2001

WSCL0012I: Processing command line arguments.
WSCL0013I: Initializing the J2EE Application Client Environment.
WSCL0035I: Initialization of the J2EE Application Client Environment has
completed.
WSCL0014I: Invoking the Application Client class
bank_Client.TellerEJBClient

Beginning of bank_Client.TellerEJBClient..

Usage: java bank_Client.TellerEJBClient
com.ibm.websphere.naming.WsnInitialContextFactory
protocol://hostname:port
Use the defaulf value for initialContextFactoryClassName =
com.ibm.websphere.naming.WsnInitialContextFactory
Use the defaulf value for providerURL = iiop://localhost:900
Lookup home interface (TellerHome) successfully.
Creating a TellerRemote
Create EJB (Remote interface) successfully
Calling createAccount
error occurs when calling remote method createAccount.
java.rmi.ServerException: RemoteException occurred in server thread;
nested exception is:
com.ibm.ejs.container.CreateFailureException:
java.lang.reflect.InvocationTargetException; nested exception is:
java.lang.reflect.InvocationTargetException
com.ibm.ejs.container.CreateFailureException:
java.lang.reflect.InvocationTargetException; nested exception is:
java.lang.reflect.InvocationTargetException
java.lang.reflect.InvocationTargetException: javax.ejb.CreateException:
Failed to find environment value Name not found in context "java:".
Removing the TellerRemote
There was an exception while creating and using the TellerRemote.
This indicates that there was a problem communicating with the server:
java.rmi.ServerException: RemoteException occurred in server thread;
nested exception is:
com.ibm.ejs.container.CreateFailureException:
java.lang.reflect.InvocationTargetException; nested exception is:
java.lang.reflect.InvocationTargetException

End of bank_Client.TellerEJBClient...

=====================================================================================================

Why can the EJBHome object be lookuped in the naming context and not
complained about the "java:" environment name
but it failed when the client actually invoked the EJB's remote method?

Does anyone have meet the similar problem when you run the EJB client?
I am attaching the this application's ear file and you look at the
source code and DD files.
Anything wrong there or missing something to defined? I should solve
this ASAP and your helps will be very appreciated.
Thanks in advance.

James You


=============== Attached Files
================================================================================================================

1) application.xml
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE application PUBLIC
'-//Sun Microsystems, Inc.//DTD J2EE Application 1.2//EN'
'http://java.sun.com/j2ee/dtds/application_1_2.dtd'>

<application id="Application_ID">

<display-name>TellerRemote Stateless Session EJB</display-name>

<description>PEJ Session Facade</description>

<module id="EjbModule_1">

<ejb>bank_TellerEJB.jar</ejb>

</module>

<module id="JavaClientModule_1">
<java>bank_Client_TellerEJBClient.jar</java>
</module>

</application>

------------------------------
2) ibm-application-bnd.xmi

<applicationbnd:ApplicationBinding xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI"
xmlns:applicationbnd="applicationbnd.xmi"
xmlns:application="application.xmi"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmi:id="Application_ID_Bnd">
<appName xsi:nil="true"/>
<application href="META-INF/application.xml#Application_ID"/>
<authorizationTable xmi:id="AuthorizationTable_1"/>
<runAsMap xmi:id="RunAsMap_1"/>
</applicationbnd:ApplicationBinding>


------------------------------
3) ibm-application-ext.xmi
<applicationext:ApplicationExtension xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI"
xmlns:applicationext="applicationext.xmi"
xmlns:application="application.xmi"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmi:id="Application_ID_Ext">
<reloadInterval xsi:nil="true"/>
<application href="META-INF/application.xml#Application_ID"/>
</applicationext:ApplicationExtension>


------------------------------
3) Manifest.MF (for application .ear file)

Manifest-Version: 1.0


---------------------------------------
4) ejb-jar.xml

<?xml version="1.0" encoding='UTF-8'?>

<!DOCTYPE ejb-jar PUBLIC
'-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN'
'http://java.sun.com/j2ee/dtds/ejb-jar_1_1.dtd'>

<ejb-jar>
<enterprise-beans>
<session>
<description>Facade Session EJB TellerEJB</description>
<display-name>TellerEJB</display-name>
<ejb-name>TellerEJB</ejb-name>
<home>bank.TellerHome</home>
<remote>bank.TellerRemote</remote>
<ejb-class>bank.TellerEJB</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>

<env-entry>
<env-entry-name>maximum_amount</env-entry-name>
<env-entry-type>java.lang.Double</env-entry-type>
<env-entry-value>10000.0</env-entry-value>
</env-entry>
<env-entry>
<env-entry-name>default_amount</env-entry-name>
<env-entry-type>java.lang.Long</env-entry-type>
<env-entry-value>1000</env-entry-value>
</env-entry>
</session>
</enterprise-beans>
<assembly-descriptor>
<container-transaction>
<method>
<ejb-name>TellerEJB</ejb-name>
<method-name>createAccount</method-name>
</method>
<trans-attribute>Supports</trans-attribute>
</container-transaction>
</assembly-descriptor>
</ejb-jar>

-------------------------------------
5) ibm-ejb-jar-bnd.xmi

<ejbbnd:EJBJarBinding xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI"
xmlns:ejbbnd="ejbbnd.xmi"
xmlns:commonbnd="commonbnd.xmi" xmlns:ejb="ejb.xmi"
xmi:id="ejb-jar_ID_Bnd">

<ejbJar href="META-INF/ejb-jar.xml#ejb-jar_ID"/>

<ejbBindings xmi:id="Session_1_Bnd" jndiName="Teller">

<enterpriseBean xsi:type="ejb:Session"
href="META-INF/ejb-jar.xml#Session_1"/>

</ejbBindings>

</ejbbnd:EJBJarBinding>

-------------------------------------
6) ibm-ejb-jar-ext.xmi

<ejbext:EJBJarExtension xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI" xmlns:ejbext="ejbext.xmi"
xmlns:ejb="ejb.xmi" xmi:id="ejb-jar_ID_Ext">
<ejbJar href="META-INF/ejb-jar.xml#ejb-jar_ID"/>


<ejbExtensions xsi:type="ejbext:SessionExtension"
xmi:id="SessionExtension_1" timeout="600">
<structure xmi:id="BeanStructure_1" inheritenceRoot="false"/>
<internationalization xmi:id="BeanInternationalization_1"
invocationLocale="CALLER"/>
<localTran xmi:id="LocalTran_1" boundary="ACTIVITY_SESSION"
resolver="BEAN" unresolvedAction="ROLLBACK"/>
</ejbExtensions>
</ejbext:EJBJarExtension>

------------------------------------
7) MANIFEST.MF for ejb jar file
Manifest-Version: 1.0
Class-Path: facade.jar


--------------------------------------
8) TellerHome.java


package bank;


import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.ejb.EJBHome;

/**
* This interface is the home interface for the real EJB class
TellerEJB.java
*
* A home interface may support one or more create
* methods, which must correspond to methods named "ejbCreate" in the
EJBean.
*
* @author: jyou
* @created date: Sep 20, 2002
* @last modified date: Sep 20, 2002
* @version: 1.0
*/
public interface TellerHome extends EJBHome {


/**
* This method corresponds to the ejbCreate method in the bean
"TellerEJB.java".
* The parameter sets of the two methods are identical. When the
client calls
* <code>TellerHome.create()</code>, the container
* allocates an instance of the EJBean and calls
<code>ejbCreate()</code>.
*
* @return TellerRemote
*
* @exception RemoteException if there is a communications or
systems failure
*
* @exception CreateException if there is a problem creating the
bean
*
* @see EJB Bean class: bank.TellerEJB.java
*/
TellerRemote create() throws CreateException, RemoteException;

}


-----------------------------------------
9) TellerRemote.java

package bank;

import java.rmi.RemoteException;
import javax.ejb.EJBObject;

/**
* The methods in this interface are the public face of EJB Bean class
(TellerEJB).
* The signatures of the methods are identical to those of the EJBean,
except
* that these methods throw a java.rmi.RemoteException.
* Note that the EJBean does not implement this interface. The
corresponding
* code-generated EJBObject, TellerEJB , implements this interface and
* delegates to the bean.
*
* @author: jyou
* @created date: Sep 20, 2002
* @last modified date: Sep 20, 2002
* @version: 1.0
*/
public interface TellerRemote extends EJBObject {

/** createAccount method comments */
public void createAccount( String customerNames , int
startingBalance , boolean isCheckingAccount ) throws RemoteException;


}

----------------------------------------
10) TellerEJB.java EJB Bean implementation classes


package bank;

import com.hywy.samples.bank.Teller;

import javax.ejb.CreateException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import javax.naming.InitialContext;
import javax.naming.NamingException;

/**
* TellerEJB is a stateless Session Bean.
*
* @author: jyou
* @created date: Sep 20, 2002
* @last modified date: Sep 20, 2002
* @version: 1.0
*/
public class TellerEJB implements SessionBean {
/** Debug message switch. true -> print */
private static final boolean VERBOSE_ = true;

private SessionContext context_;

/** The Teller reference */
private Teller teller_;

/** Env-entry variable defined in the ejb-jar.xml file */
private java.lang.Double maximum_amount;

/** Env-entry variable defined in the ejb-jar.xml file */
private java.lang.Long default_amount;

/** You might also consider using the real application server's log
service */
private void log(String string) {
if (VERBOSE_) System.out.println(string);
}

/**
* This method is required by the EJB Specification.
*
*/
public void ejbActivate() {
log("ejbActivate called");
}

/**
* This method is required by the EJB Specification.
*
*/
public void ejbRemove() {
log("ejbRemove called");
}

/**
* This method is required by the EJB Specification.
*
*/
public void ejbPassivate() {
log("ejbPassivate called");
}

/**
* Sets the session context_.
*
* @param context_ SessionContext Context for session
*/
public void setSessionContext(SessionContext context_) {
log("setSessionContext called");
this.context_ = context_;
}

/**
* This method corresponds to the create method in the home
interface
* "TellerHome.java".
* The parameter sets of the two methods are identical. When the
client calls
* <code>TellerHome.create()</code>, the containamingExceptionr
allocates an instance of
* the EJBean and calls <code>ejbCreate()</code>.
*
* @exception javax.ejb.CreateException if there is a communications
or systems failure
*
* @see bank.TellerRemote.java
*/
public void ejbCreate () throws CreateException{
log("ejbCreate called");
Throwable th = null;

try {
InitialContext initialContext = new InitialContext();

maximum_amount = (java.lang.Double )
initialContext.lookup("java:/comp/env/maximum_amount");
default_amount = (java.lang.Long )
initialContext.lookup("java:/comp/env/default_amount");
} catch (NamingException namingException) {
th = namingException;
}finally{
if(th != null){
throw new CreateException("Failed to find
environment value "+ th.getMessage());
}
}

this.teller_ = new Teller();

}


/** createAccount method comments */
public void createAccount( String customerNames , int
startingBalance , boolean isCheckingAccount )
{
final String THIS = "TellerEJB::createAccount(...) :";
Throwable th = null;

try {
this.teller_.createAccount( customerNames , startingBalance
, isCheckingAccount );
}
catch(Exception exception) {
th = exception;
}finally{
if( th != null){
log(THIS + " " + th.getMessage());
}
}
}


}


---------------------------------------------------------------
11) application-client.xml

<?xml version="1.0" encoding="UTF-8"?>


<!DOCTYPE application-client PUBLIC "-//Sun Microsystems, Inc.//DTD J2EE
Application Client 1.2//EN"
"http://java.sun.com/j2ee/dtds/application-client_1_2.dtd">


<application-client id="Application-client_ID">
<display-name>TellerEJB Standalone Client</display-name>
<ejb-ref id="EjbRef_1">
<ejb-ref-name>Teller</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<home>bank.TellerHome</home>
<remote>bank.TellerRemote</remote>
</ejb-ref>
</application-client>

-----------------------------------------
12) ibm-application-client-bnd.xmi

<clientbnd:ApplicationClientBinding xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI" xmlns:clientbnd="clientbnd.xmi"
xmlns:commonbnd="commonbnd.xmi" xmlns:common="common.xmi"
xmlns:client="client.xmi" xmi:id="Application-client_ID_Bnd">
<ejbRefs xmi:id="EjbRefBinding_1" jndiName="Teller">
<bindingEjbRef href="META-INF/application-client.xml#EjbRef_1"/>
</ejbRefs>
<applicationClient
href="META-INF/application-client.xml#Application-client_ID"/>
</clientbnd:ApplicationClientBinding>

-----------------------------------------
13) MANIFEST.MF for EJB client jar file

Manifest-Version: 1.0
Main-Class: bank_Client.TellerEJBClient
Class-Path: bank_TellerEJB.jar bank_Client_TellerEJBClient.jar

-----------------------------------------
14) TellerEJBClient.java

package bank_Client;

import bank.TellerHome;
import bank.TellerRemote;

import java.util.Properties;

import java.rmi.RemoteException;

import javax.ejb.CreateException;
import javax.ejb.RemoveException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;


/**
* This EJB client class (bank_Client.TellerEJBClient) illustrates
* calling a Stateless Session Bean (bank.TellerEJB)
* and performing the following remote method calls:
*
* <ul>
* <li> createAccount( customerNames , startingBalance ,
isCheckingAccount );
*
* </ul>
*
* @author: jyou
* @created date: Sep 20, 2002
* @last modified date: Sep 20, 2002
* @version: 1.0
*
*/
public class TellerEJBClient {

// JNDI name for EJB instance
private static final String JNDI_NAME_ = "Teller";

// Initial Context Factory Class name
private String initialContextFactoryClassName_;

// JNDI Context Provider URL
private String contextProviderURL_;

// EJB Home interface
private TellerHome home_;


/**
* TellerEJBClient class Constructor
*
* @param String contextFactoryClassName
*
* @param String provider url
*/
public TellerEJBClient(String contextFactoryClassName,String
providerURL ) throws NamingException {

this.initialContextFactoryClassName_ = contextFactoryClassName;

this.contextProviderURL_ = providerURL;

home_ = lookupHome();
}

/**
*
* Runs this example from the command line, Example:
* <p>
* <tt>java bank_Client.TellerEJBClient "iiop://localhost:900"</tt>
* <p>
* The parameters are optional, but if any are supplied,
* they are interpreted in this order:
* <p>
* @param url URL such as "iiop://localhost:900" of application
server's JNDI_CONTEXT_PROVIDER_URL
*/
public static void main(String[] args) throws Exception {

log("\nBeginning of bank_Client.TellerEJBClient..\n");

/*
* "Weblogic.jndi.WLInitialContextFactory" is the default initial
context factory class name
* for BEA Weblogic application server
* if the current application server is IBM WebSphere application
server,
* then the default initial context factory class name should be
changed to
* com.ibm.websphere.naming.WsnInitialContextFactory"
*/
String initialContextFactoryClassName =
"com.ibm.websphere.naming.WsnInitialContextFactory";

/*
* "t3://localhost:7001" is the default provider URL name for for
BEA Weblogic application server
* if the current application server is IBM WebSphere application
server,
* then the default provider URL name should be changed to
* "iiop://localhost:900"
*/
String providerURL = "iiop://localhost:900";

Throwable th = null;

String errorMsg = null;

// Parse the argument list
if (args.length == 2) {

initialContextFactoryClassName = args[0];

providerURL = args[1];


} else if (args.length != 2 ) {


log("Usage: java bank_Client.TellerEJBClient
com.ibm.websphere.naming.WsnInitialContextFactory
protocol://hostname:port");
log("Use the defaulf value for initialContextFactoryClassName =
com.ibm.websphere.naming.WsnInitialContextFactory");
log("Use the defaulf value for providerURL =
iiop://localhost:900");

}

TellerEJBClient tellerejbclient = null;

try {
tellerejbclient = new
TellerEJBClient(initialContextFactoryClassName, providerURL);
}catch (NamingException namingException) {
th = namingException;
}finally{
if(th != null){
errorMsg = " error occurs when looking session EJB's Home
interface. ";
log(errorMsg + " --> " + th.getMessage());
}
}

try {
tellerejbclient.callingRemoteMethodExample();
} catch (Exception exception) {
log("There was an exception while creating and using the
TellerRemote.");
log("This indicates that there was a problem communicating with
the server: "+exception);
}

log("\nEnd of bank_Client.TellerEJBClient...\n");
}

/**
* This method is used to call all of the session EJB's remote method
*
* @throws CreateException
* @throws RemoteException
* @throws RemoveException
*/
public void callingRemoteMethodExample() throws CreateException,
RemoteException, RemoveException {

// create and lookup a Remote interface
log("Creating a TellerRemote");

Throwable th = null;

String errorMsg = null;

TellerRemote tellerremote = (TellerRemote) home_.create();
log("Create EJB (Remote interface) successfully");

//////////////////////////////////////
// Invoke the Servant's Remote Method
/////////////////////////////////////

// Calling createAccount
try {
log("Calling createAccount");

tellerremote.createAccount( "ABC" , 0 , true );
log("EJB client ran successfully.");
}
catch (Exception exception) {
th = exception;
}finally{
if(th != null){
errorMsg = " error occurs when calling remote method
createAccount.";
log(errorMsg);
th.printStackTrace();
}
}

// remove the TellerRemote
log("Removing the TellerRemote");
tellerremote .remove();

}

/**
* RMI/IIOP clients should use this narrow function
*/
private Object narrow(Object reference, Class classReference) {
return PortableRemoteObject.narrow(reference, classReference);
}

/**
* Lookup the EJBs home_ in the JNDI tree
*/
private TellerHome lookupHome() throws NamingException {
// Lookup the beans home_ using JNDI
Context context = getInitialContext();
Object home = null;
TellerHome homeObject = null;
Throwable th = null;
try {

// If the <ejb-ref-name> is defined in the
application-client.xml,
// the default <ejb-ref-name> value is the same as the ejb's
JNDI name
// defined in the ibm-ejb-jar-bnd.xmi
// the EJB client is launched from the jar file,
// the following code is used.

home = context.lookup("java:comp/env/"+JNDI_NAME_);

homeObject = (TellerHome) narrow(home, TellerHome.class);
} catch (NamingException namingException) {
th = namingException;

}finally{
if(th != null){
if(home == null){
try{
home = context.lookup(JNDI_NAME_);
homeObject = (TellerHome) narrow(home,
TellerHome.class);

}catch (NamingException namingException) {

log("The client was unable to lookup the EJBHome. Please make
sure ");
log("that you have deployed the ejb with the JNDI name
"+JNDI_NAME_+" on the application server at "+contextProviderURL_);
throw namingException;

}

}
}

}

log("Lookup home interface (TellerHome) successfully.");

return homeObject;
}

/**
* Using a Properties object will work on JDK 1.1.x and Java2
* clients
*/
private Context getInitialContext() throws NamingException {

try {
// Get an InitialContext
Properties properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY,
initialContextFactoryClassName_);
properties.put(Context.PROVIDER_URL, contextProviderURL_);
return new InitialContext(properties);
} catch (NamingException namingException) {
log("We were unable to get a connection to the Application
server at "+contextProviderURL_);
log("Please make sure that the server is running.");
log(namingException.toString());
throw namingException;
}
}

/**
* This is the Java2 version to get an InitialContext.
* This version relies on the existence of a jndi.properties file in
* the application's classpath.
*
*/
// private static Context getInitialContext()
// throws NamingException
// {
// return new InitialContext();
// }

private static void log(String string) {
System.out.println(string);
}

}

-----------------------------------------------------------
15) Teller.java used by EJB bean class

/**
* To Run the Application
* java -classpath
*
.;C:\PEJ\lib\jdo.jar;C:\PEJ\lib\j2ee.jar;C:\PEJ\lib\pej.jar;C:\PEJ\lib\tools.jar
* com.hywy.samples.bank.Teller
*/

package com.hywy.samples.bank;


public class Teller {

public Teller() {
super();
}

/**
* Create Checking or Savings Account
*/
public void createAccount(String customerNames,
int startingBalance,
boolean isCheckingAccount)
throws Exception {

final String THIS =
"com.hywy.samples.bank.Teller::createAccount(..): ";

System.out.println(" calling " + THIS );

if(isCheckingAccount == true) {
System.out.println(THIS + " It is checking account..");
}
else {
System.out.println(THIS + " It is Saving account..");
}

System.out.println(THIS + " CustomerName ->" + customerNames + "
startingBalance -> " + startingBalance);


}

/**
* Say "Hello" to you
*/
public String sayHello(String person) throws Exception {
final String THIS = "com.hywy.samples.bank.Teller::sayHello(..): ";
System.out.println(" calling " + THIS );
String message = "Hello To (" + person + ") From facade Teller
Class";
return message;

}
}

0 new messages