aspose file tools*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes how to connect EJB without using runclient Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "how to connect EJB without using runclient" Watch "how to connect EJB without using runclient" New topic
Author

how to connect EJB without using runclient

Yothin Phorn
Greenhorn

Joined: Oct 18, 2001
Posts: 15
Now I'm studying EJB using j2eesdk ri and when I test java application client to connect ejb, I will use "runclient" command of j2eesdk/bin. I want to know that I can use basically "java" command to connect ejb or not and How should I do?


Yothin Pohn<br />SCJP, SCWCD, SCBCD
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/GettingStarted5.html#87369


Groovy
Weerawit Maneepongsawat
Ranch Hand

Joined: Apr 11, 2002
Posts: 203
Originally posted by Yothin Pohn:
Now I'm studying EJB using j2eesdk ri and when I test java application client to connect ejb, I will use "runclient" command of j2eesdk/bin. I want to know that I can use basically "java" command to connect ejb or not and How should I do?


try this.
Holp this help.
Fix me.


Weerawit<br />SCJP 1.4, SCWCD 1.2, SCWCD 1.4, SCBCD 1.3, SCBCD 5.0, SCMAD 1.0, SCJA 1.0, SCDJWS, SCJD, SCEA, SCDJWS 1.5
somkiat puisungnoen
Ranch Hand

Joined: Jul 04, 2003
Posts: 1312
Please, see this :
This is code in %J2EE_HOME%\bin\runclient.bat, you can apply this code which use in java commamd.
@echo off
REM
REM Copyright 2002 Sun Microsystems, Inc. All rights reserved.
REM SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
REM
rem
rem Set JAVA_HOME and J2EE_HOME before running this script.
rem
rem set JAVA_HOME to the path where you have Java 2 (JDK1.2) installed.
rem
rem set J2EE_HOME to the path where you have installed this package (EJB server).
rem
if not "%J2EE_HOME%" == "" goto CONT0
echo ERROR: Set J2EE_HOME before running this script.
goto END
:CONT0
if EXIST "%J2EE_HOME%\bin\setenv.bat" goto CONT1
echo ERROR: Set J2EE_HOME to the path of a valid j2sdkee.
goto END
:CONT1
call %J2EE_HOME%\bin\setenv.bat
if not "%JAVA_HOME%" == "" goto CONT2
echo ERROR: Set JAVA_HOME before running this script.
goto END
:CONT2
if EXIST "%JAVA_HOME%\bin\java.exe" goto CONT3
echo ERROR: Set JAVA_HOME to the path of a valid jdk.
goto END
:CONT3

rem @echo on
%JAVA_COMMAND% %VMARGS% -Djms.home=%JMS_HOME% -Djms.properties=%J2EE_HOME%\config\jms_client.properties -Djava.security.policy==%J2EE_HOME%\lib\security\client.policy -Djava.security.auth.login.config=%J2EE_HOME%\lib\security\clientlogin.config -Dcom.sun.enterprise.home=%J2EE_HOME% -classpath %CPATH%;%APPCPATH% com.sun.enterprise.appclient.Main %*

:END


SCJA,SCJP,SCWCD,SCBCD,SCEA I
Java Developer, Thailand
Ko Ko Naing
Ranch Hand

Joined: Jun 08, 2002
Posts: 3178
Originally posted by somkiat puisungnoen:
Please, see this :
This is code in %J2EE_HOME%\bin\runclient.bat, you can apply this code which use in java commamd.

That's a great investigation... I just found out some commands that are unfamiliar to me... Thanx, Pui...


Co-author of SCMAD Exam Guide, Author of JMADPlus
SCJP1.2, CCNA, SCWCD1.4, SCBCD1.3, SCMAD1.0, SCJA1.0, SCJP6.0
Yothin Phorn
Greenhorn

Joined: Oct 18, 2001
Posts: 15
Thanks for Mr. Weerawit. I think your suggest that is good approach but I think it still lack of something that is "Context.INITIAL_CONTEXT_FACTORY" and I don't know what is its value?.
Pradeep Bhat, your link or j2ee tutorial I have already read it and I don't find any sentence tell me about my question because j2ee tutorial use runclient command not java.
Somkiat, thanks for your comment but I have already read it too but I have not found anything helping me. It doesn't tell me what is value of Context.INITIAL_CONTEXT_FACTORY and Context.PROVIDER_URL and why?.
Oh I think there are a lot Thai Java Developer here (notice from name).
It's great.
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

Thanks for Mr. Weerawit. I think your suggest that is good approach but I think it still lack of something that is "Context.INITIAL_CONTEXT_FACTORY" and I don't know what is its value?.

Have you checked samples that come with the server ?
Yothin Phorn
Greenhorn

Joined: Oct 18, 2001
Posts: 15
Originally posted by Pradeep Bhat:

Have you checked samples that come with the server ?

It have no example coming with j2ee server that use Context.INITIAL_CONTEXT_FACTORY declaration since it use only runclientcommand.
So I don't know yet how to connect ejb without using runclient command.
Anyone can help me?
somkiat puisungnoen
Ranch Hand

Joined: Jul 04, 2003
Posts: 1312
Solution :
Create JSP File or Servlet File for connect/use EJB component.
Ex: Servlet File


I think, it will help you.
Vishwa Kumba
Ranch Hand

Joined: Aug 27, 2003
Posts: 1064
I am also curious to know the answer for this. Do all clients for the beans deployed in the Sun's Reference Implementation be J2EE Application clients?
I get the foll. exception if I try to run the program without using runclient utility.
C:\Learn\potato>java PotClient
javax.naming.NamingException: java:comp/env namespace is only available from within a J2EE component
at com.sun.enterprise.naming.java.javaURLContext.getComponentContext(javaURLContext.java:395)
at com.sun.enterprise.naming.java.javaURLContext.lookup(javaURLContext.java:51)
at javax.naming.InitialContext.lookup(Unknown Source)
at PotClient.main(PotClient.java:32)
Kathy Sierra
Cowgirl and Author
Ranch Hand

Joined: Oct 10, 2002
Posts: 1572
Howdy,
You CAN make stand-alone Java clients to use with the Reference Implementation (RI), and you do NOT need to use runclient (which means running the clients as "J2EE clients"), unless you want a simple way to test your security roles and access control.
If you have installed J2EE and set-up your environment variables correctly, then the default InitialContext will work just fine, because properties for the J2EE server's JNDI settings are already set-up.
Here's a simple client:

To run it at the command-line, use:

java -cp {$CLASSPATH}:adviceappClient.jar AdviceClient
Where we've added "adviceAppClient.jar" to the current classpath, and "AdviceClient" is of course the name of the client class. This client is NOT in a package, so the current working directory for this command-line is the directory that holds both the AdviceClient and the client jar.
Cheers,
Kathy
Yothin Phorn
Greenhorn

Joined: Oct 18, 2001
Posts: 15
Hi Kathy,
Thank for your help and I try following your comment.
This is my sourcecode:

and I got a result as follow:
obj = com.sun.corba.ee.internal.iiop.CDRInputStream_1_0$1:IOR:0000000000000023524d493a436f6e766572746572486f6d653a30303030303030303
0303030303030300000000000010000000000000160000102000000000e3139322e3136382e3
12e31303800085d0000003eafabcb0000000024abb28bd800000001000000000000000100000
00d5472616e7369656e74504f41000000000000000d7c76ca900000000000000001ff0a00000
0000005000000010000002000000000000100010000000205010001000100200001010900000
00100010100000000210000007c00000000000000010040000000000024000000200000
006600000000000000010000000e3139322e3136382e312e31303800085e0040004000000008
0606678102010101000000170401000806066781020101010000000764656661756c74000400
000000000000000000010000000806066781020101010000000f000000190000003200000000
0000002a687474703a2f2f796f7468696e3a393139312f436f6e766572746572417070436c69
656e742e6a61720000000000001f0000000400000003000000200000000400000001
Caught an unexpected exception!
java.lang.ClassCastException
at com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:293)
at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:134)
at ConverterClient.main(ConverterClient.java:14)

That mean after looking up the jndi name, MyConverter, It doesn't get
ConverterHome object so the ClassCastException occurs.
Anyone can explain this?
[ November 05, 2003: Message edited by: Yothin Pohn ]
[ November 05, 2003: Message edited by: Yothin Pohn ]
Dani Mazzuca
Ranch Hand

Joined: May 21, 2003
Posts: 70
OK Kathy,
but what if you want to run the client from another machine, a one that has no J2EE installed. Is it possible to access the Naming server inside the J2EE RI from outside? Is it documented somewhere? I mean, which URL, etc should we use for the JNDI initial context?
Dani Mazzuca
Kathy Sierra
Cowgirl and Author
Ranch Hand

Joined: Oct 10, 2002
Posts: 1572
Howdy Yothin,
If you are getting a ClassCastException on the client, that might mean that the Home stub class is not in your classpath. You must be sure that the client JAR is in your current classpath. So, look at your command-line script for running the client, and re-check your directories to be certain that JAR is indeed being seen by the JVM. Remember, you will not get any kind of error if you specify a JAR in your -classpath setting, and that JAR is not present. You won't know until you get a ClassCastException or a ClassNotFoundException.
Re-check all of that and we'll see what else we can come up with... also, did you do a VERIFY from the J2EE deploytool?
cheers,
Kathy
Kathy Sierra
Cowgirl and Author
Ranch Hand

Joined: Oct 10, 2002
Posts: 1572
Originally posted by Dani Mazzuca:
OK Kathy,
but what if you want to run the client from another machine, a one that has no J2EE installed. Is it possible to access the Naming server inside the J2EE RI from outside? Is it documented somewhere? I mean, which URL, etc should we use for the JNDI initial context?
Dani Mazzuca

Howdy -- you can access a J2EE server's JNDI context running on a *different* machine using this command-line:
java -classpath [whatever] -Dorg.omg.CORBA.ORBInitialHost=theRemoteHostNameGoesHere MyClientClassName
Now, this might not work if you don't have J2EE installed on the client, so that doesn't fully answer your question. I'm going to have to look that up, I think. Unless someone else here knows the answer. I think you still have to specify the InitialContextFactory. (basically the Driver class) and I believe that for the RI it is one of the following:
-Djava.naming.factory.initial=com.sun.enterprise.naming.SerialInitContextFactory
or maybe...
-Djava.naming.factory.initial=java.naming.jndi.cosnaming.CNCtxFactory
(I can't remember which one)
And of course you will NEED this particular factory class in your classpath as well in order to make it work.
Here's a little overview of how the whole JNDI process works:
1) In order to get an InitialContext, you need to have TWO properties specified:
-- the TYPE of the Service Provider (the factory class)
-- the URL for where the service is (or some way of specifying the host of the JNDI service)
2) These properties can be set in several ways:
A) In the overloaded IniitalContext constructor that takes a HashTable
B) As a System property set at the command-line when you run the client (that's how I've been showing it above)
C) in a jndi.properties file in your classpath, or in one of several directories
When you install J2EE, a jndi.properties file is contained within the j2ee.jar, which is why when the client is on a machine with J2EE installed, you can simply use the no-arg constructor for the InitialContext, and it pulls its info from the properties file.
So, to connect to a J2EE server on a different machine, when J2EE is installed on the client, you need to override the host using the command-line for -Dorg.omg.CORBA.ORBInitialHost=SomeOtherHostName and that's it.
BUT... if J2EE is NOT installed on the client, I'm not entirely sure how to specify the InitialContext factory. I'd suggest trying the other command-line properties...
I'm hoping someone else has tried this. I have J2EE on every machine we work with, so I can't easily test it. Sorry, let us know what you come up with!
cheers,
Kathy
Dani Mazzuca
Ranch Hand

Joined: May 21, 2003
Posts: 70
OK,
the following code worked for me, using J2EE RI
as a JNDI naming server(of course better if you use
a -D to pass properties). The client used the j2ee.jar
in the classpath, because it needs many classes besides
the SerialInitContextFactory class.

But ...
What king of naming server is that? I mean, it is
not an LDAP, not a COS naming (isn't it?) not a
file system. What kind of objects can we bind?
Could we bind and RMI remote object? Is it also
a directory server?
Dani Mazzuca
[ November 05, 2003: Message edited by: Dani Mazzuca ]
[ November 05, 2003: Message edited by: Dani Mazzuca ]
[ November 05, 2003: Message edited by: Dani Mazzuca ]
Kathy Sierra
Cowgirl and Author
Ranch Hand

Joined: Oct 10, 2002
Posts: 1572
Originally posted by Dani Mazzuca:
OK,
...
What king of naming server is that? I mean, it is
not an LDAP, not a COS naming (isn't it?) not a
file system. What kind of objects can we bind?
Could we bind and RMI remote object? Is it also
a directory server?

Howdy -- I don't know what the RI is using internally, but all we're *supposed* to know from the perspective of the spec is that it is a service that can support *some* aspects of JNDI.
The only thing that is guaranteed is that anything looked up by the bean using the bean's JNDI environment (administered objects, resource manager factory references, environment entries, etc.) and a bean's home interface, must be configurable into the server when a bean is deployed. (Oh, and it must be COS naming-compliant). So, you *might* have other parts of the JNDI API exposed, or you might not, depending on the server.
You aren't *supposed* to ever make the Remote object available, so it's doubtful that you would be allowed to bind it anyway, and that would almost certainly NOT be supported by deployment tools. The deploy tools should restrict you from binding anything but the types of things that can be looked up in a bean's special environment context, or a bean's home interface.
In other words, you aren't getting a full-on naming and directory service bundled with the RI (and you might not with other J2EE servers, it just depends), although it can vary greatly from server to server. You could, for example, have a server that lets you hook into your company's directory services (like an LDAP server) and represent everything as one giant virtual tree, or you might have one that does not tie into existing services, but is still more functional -- supporting more of the JNDI API (allowing you to programmatically bind things to it, for example).
I haven't tried using the RI naming service for anything else...
But I'm not an expert on JNDI, so this is probably about all I can say about it. Thanks so much for posting what you used on the client that worked!!
cheers,
Kathy
Vishwa Kumba
Ranch Hand

Joined: Aug 27, 2003
Posts: 1064
I tried with the same code as Kathy's in my sample.
I am getting java.rmi.AccessException! Can somebody help?
I tried the foll. ways :
1. set VMARGS=-Dj2eelogin.name=guest -Dj2eelogin.password=guest123
java MyClient
2.java -Dj2eelogin.name=guest -Dj2eelogin.password=guest123 MyClient
3. Also tried setting j2eelogin and password as environment variables, but didn't work.
My client.jar is in the classpath.
How to specify the username and password for the client program with Sun's RI? (without using runclient)
Caught an unexpected exception!
java.rmi.AccessException: CORBA NO_PERMISSION 0 No; nested exception is:
org.omg.CORBA.NO_PERMISSION: minor code: 0 completed: No
org.omg.CORBA.NO_PERMISSION: minor code: 0 completed: No
at java.lang.Class.newInstance0(Native Method)
at java.lang.Class.newInstance(Unknown Source)
at com.sun.corba.ee.internal.iiop.messages.ReplyMessage_1_2.getSystemException(ReplyMessage_1_2.java:93)
at com.sun.corba.ee.internal.iiop.ClientResponseImpl.getSystemException(ClientResponseImpl.java:108)
at com.sun.corba.ee.internal.POA.GenericPOAClientSC.invoke(GenericPOAClientSC.java:136)
at org.omg.CORBA.portable.ObjectImpl._invoke(Unknown Source)
at _ConverterHome_Stub.create(Unknown Source)
at MyClient.main(MyClient.java:19)
[ November 12, 2003: Message edited by: Vish Kumar ]
Yothin Phorn
Greenhorn

Joined: Oct 18, 2001
Posts: 15
Yes Vish. I have found the same problem like you.
I have already set ConverterAppClient.jar generated from j2ee's deploytool in my classpath and run ConverterClient.class using basically "java" command and I get the following output:
java.rmi.AccessException: CORBA NO_PERMISSION 0 No; nested exception is:
org.omg.CORBA.NO_PERMISSION: vmcid: 0x0 minor code: 0 completed: No
at com.sun.corba.ee.internal.iiop.ShutdownUtilDelegate.mapSystemException(ShutdownUtilDelegate.java:98)
at javax.rmi.CORBA.Util.mapSystemException(Util.java:65)
at _ConverterHome_Stub.create(Unknown Source)
at ConverterClient.main(ConverterClient.java:18)
Caused by: org.omg.CORBA.NO_PERMISSION: vmcid: 0x0 minor code: 0 completed: No
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:274)
at java.lang.Class.newInstance0(Class.java:306)
at java.lang.Class.newInstance(Class.java:259)
at com.sun.corba.ee.internal.iiop.messages.ReplyMessage_1_2.getSystemException(ReplyMessage_1_2.java:93)
at com.sun.corba.ee.internal.iiop.ClientResponseImpl.getSystemException(ClientResponseImpl.java:108)
at com.sun.corba.ee.internal.POA.GenericPOAClientSC.invoke(GenericPOAClientSC.java:132)
at org.omg.CORBA.portable.ObjectImpl._invoke(ObjectImpl.java:457)
at _ConverterHome_Stub.create(Unknown Source)
Anyone know how to fix this problem?
[ November 14, 2003: Message edited by: Yothin Pohn ]
Vishwa Kumba
Ranch Hand

Joined: Aug 27, 2003
Posts: 1064
Yothin,
I downloaded the latest JDK/J2EE for windows and tried, it works now.
Also I placed all my classes in a package. Please see Kathy's explanation
regarding the bug in the Sun's RI.


http://www.coderanch.com/t/158262/java-EJB-SCBCD/certification/CORBA-bad-operation-error-RI
Yothin Phorn
Greenhorn

Joined: Oct 18, 2001
Posts: 15
Thanks Kumar,
Now it already work. I followed all from http://www.coderanch.com/t/158274/java-EJB-SCBCD/certification/Help-AdviceClient-Error
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to connect EJB without using runclient