• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to connect EJB without using runclient

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/GettingStarted5.html#87369
 
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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...
 
Yothin Phorn
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 1312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Solution :
Create JSP File or Servlet File for connect/use EJB component.
Ex: Servlet File


I think, it will help you.
 
Ranch Hand
Posts: 1066
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)
 
Cowgirl and Author
Posts: 1589
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1589
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1589
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1589
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 1066
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1066
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.


https://coderanch.com/t/158262/java-EJB-SCBCD/certification/CORBA-bad-operation-error-RI
 
Yothin Phorn
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Kumar,
Now it already work. I followed all from https://coderanch.com/t/158274/java-EJB-SCBCD/certification/Help-AdviceClient-Error
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic