aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes JBoss Remote Lookup Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "JBoss Remote Lookup" Watch "JBoss Remote Lookup" New topic
Author

JBoss Remote Lookup

Jetendra Ivaturi
Ranch Hand

Joined: Feb 08, 2007
Posts: 159
Hi Friends,

I would like to know about remote lookup in JBoss application server.

If its weblogic, we pass a Properties object to the initial context, with

the provider URL and context factory. In the same way what am I supposed to do it for JBoss.

This is how the code goes in weblogic:

Properties p=new Properties();
p.put(Context.PROVIDER_URL,"t3://127.0.0.1:7001/");
p.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
Context ctx=new InitialContext(p);

How to write the same in JBoss?

Thanks


SCJP 1.4 & 1.5, SCWCD 1.5. Learn and Let Learn.
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3775

If your question is about the context parameters for JBOSS then Check this......


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Jetendra Ivaturi
Ranch Hand

Joined: Feb 08, 2007
Posts: 159
Thanks
Jetendra Ivaturi
Ranch Hand

Joined: Feb 08, 2007
Posts: 159
Am not successful using the link which you have sent.

Says unable to find the context. Do I have to add any .jars in the classpath.

Could you please suggest.
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3775

please post some code you used for others to see where the problem (if any in the code)
Jetendra Ivaturi
Ranch Hand

Joined: Feb 08, 2007
Posts: 159
This is my Code:

Properties p=new Properties();
p.put(Context.PROVIDER_URL,"127.0.0.1:8080");
p.put(Context.INITIAL_CONTEXT_FACTORY,"org.jboss.naming rg.jnp.interfaces");
Context ctx=new InitialContext(p);
Object obj=ctx.lookup("HelloBean");

Error:

Exception in thread "main" javax.naming.NoInitialContextException: Cannot instatiate class: org.jboss.naming rg.jnp.interfaces [Root exception is java.lang.ClassNotFoundException: org.jboss.naming rg.jnp.interfaces]
at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.init(Unknown Source)
at javax.naming.InitialContext.<init>(Unknown Source)
at mypack2.Client.main(Client.java:19)
Caused by: java.lang.ClassNotFoundException: org.jboss.naming rg.jnp.interface

at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at com.sun.naming.internal.VersionHelper12.loadClass(Unknown Source)

To which .jar do I have to set the classpath.

thanks
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

JBoss has a jbossall-client.jar (in the client directory of your server). It should be in there.
[ July 31, 2008: Message edited by: Paul Sturrock ]

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Jetendra Ivaturi
Ranch Hand

Joined: Feb 08, 2007
Posts: 159
Its there in the classpath paul.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


That doesn't look right. Sure it shouldn't be org.jnp.interfaces.NamingContextFactory?
Jetendra Ivaturi
Ranch Hand

Joined: Feb 08, 2007
Posts: 159
Neither its working paul.
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3775

Did you check the port for the JBOSS ?


I'm not sure 8080 is the right one.
Jetendra Ivaturi
Ranch Hand

Joined: Feb 08, 2007
Posts: 159
No its 8080. Am able to access the console.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Originally posted by Jetendra Ivaturi:
Neither its working paul.


I've just successfully checked a lookup against JBoss 4.2.2 using the initial context factory I mention above. The only thing I added to my claspath to get it to work is jbossall-client.jar. A quick jar -tf jbossall-client.jar shows org.jnp.interfaces.NamingContextFactory is in there. I'd double check your classpath.
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3775

8080 is HTTP port. Try 3528 for the port number
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Originally posted by Vijitha Kumara:
8080 is HTTP port. Try 3528 for the port number


If you run jboss and look at the jmx-console you will be able to find out for sure, but normally the provider URL and defauklt port is jnp://localhost:1099
Jetendra Ivaturi
Ranch Hand

Joined: Feb 08, 2007
Posts: 159
Same error even with 3528.

I have written all the classes required and the .xml files. compiled them.

And copied the folder into the deploy folder of EJB. Is the process correct.

Even its not getting deployed says an error while deploying.

That might be the reason am unable to lookup.
Jetendra Ivaturi
Ranch Hand

Joined: Feb 08, 2007
Posts: 159
ejb-jar.xml
------------

<?xml version="1.0"?>

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

<ejb-jar>
<enterprise-beans>
<session>
<ejb-name>HelloBean</ejb-name>
<home>mypack2.HelloHome</home>
<remote>mypack2.Hello</remote>
<ejb-class>mypack2.HelloBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
</enterprise-beans>
</ejb-jar>


jboss-jar.xml
-------------

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jboss PUBLIC "-//JBoss//DTD JBOSS 3.2//EN" "http://www.jboss.org/j2ee/dtd/jboss_3_2.dtd">
<jboss>
<enterprise-beans>
<session>
<ejb-name>HelloBean</ejb-name>
<jndi-name>HelloBean</jndi-name>
</session>

</jboss>

Are they correct.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


Even its not getting deployed says an error while deploying.

Well, its definately a problem. I'd fix the deployment issue before trying to look anything up.

But its not the cause of your lookup issue. That is a ClassNotFoundException, which means your classpath is wrong, or your initial context factory property contains an invalid value. Once you have fixed your deployment issue you will need to double check your classpath and the value you use for this property.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


Are they correct.

What does the deployment error say?
Jetendra Ivaturi
Ranch Hand

Joined: Feb 08, 2007
Posts: 159
This is the deployement error:
Incompletely deployed packages:
org.jboss.deployment.DeploymentInfo@33eb170 { url=file:/C:/jboss-3.2.6/server/default/deploy/stateless.jar/ }
deployer: org.jboss.ejb.EJBDeployer@6295eb
status: null
state: FAILED
watch: file:/C:/jboss-3.2.6/server/default/deploy/stateless.jar/META-INF/ejb-jar.xml
lastDeployed: 1217499161571
lastModified: 1217488956532
mbeans:

15:42:42,461 INFO [Http11Protocol] Starting Coyote HTTP/1.1 on http-0.0.0-8080
15:42:42,555 INFO [ChannelSocket] JK2: ajp13 listening on /0.0.0.0:8009
15:42:42,555 INFO [JkMain] Jk running ID=0 time=0/31 config=null
15:42:42,555 INFO [Server] JBoss (MX MicroKernel) [3.2.6 (build: CVSTag=JBoss_3
_2_6 date=200410140106)] Started in 9s:921ms
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Look back in the log. That is the message that a deployment has failed, somewhere else there will be a stacktrace or error message telling you why it failed.
Jetendra Ivaturi
Ranch Hand

Joined: Feb 08, 2007
Posts: 159
Could not exactly get the error from logs.
Jetendra Ivaturi
Ranch Hand

Joined: Feb 08, 2007
Posts: 159
Could deploy the application successfully.

Still getting the same error stating. Cann't instantiate the class, jnp.interfaces.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


jnp.interfaces

This not a valid class. Re-read my post above. And check your classpath.
[ July 31, 2008: Message edited by: Paul Sturrock ]
Jetendra Ivaturi
Ranch Hand

Joined: Feb 08, 2007
Posts: 159
This is what I have in my classpath:

C:\jboss-4.2.3.GA-jdk6\jboss-4.2.3.GA\bin>echo %classpath%
.;D:\Work2008\OTCEIH\build;.;C:\jboss-4.2.3.GA-jdk6\jboss-4.2.3.GA\client;C:\jboss-4.2.3.GA-jdk6\jboss-4.2.3.GA\lib;;C:\jboss-4.2.3.GA-jdk6\jboss-4.2.3.GA\client\jbossall-client.jar

Here is the error:

Exception in thread "main" javax.naming.NoInitialContextException: Cannot instantiate class: org.jboss.naming rg.jnp.interfaces [Root exception is java.lang.ClassNotFoundException: org.jboss.naming rg.jnp.interfaces]
at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.init(Unknown Source)
at javax.naming.InitialContext.<init>(Unknown Source)
at mypack2.Client.main(Client.java:19)
Caused by: java.lang.ClassNotFoundException: org.jboss.naming rg.jnp.interfaces
Jetendra Ivaturi
Ranch Hand

Joined: Feb 08, 2007
Posts: 159
Could resolve the previous error.

Now am getting the exception stating:

Exception in thread "main" javax.naming.NameNotFoundException: HelloBean not bound

Where HelloBean is the JNDI name. Where I might be wrong.
Jetendra Ivaturi
Ranch Hand

Joined: Feb 08, 2007
Posts: 159
Paul what you said was right, properties which I am passing were wrong.

Could resolve it.

Properties p=new Properties();
p.put(Context.PROVIDER_URL,"localhost:1099");
p.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
p.put(Context.URL_PKG_PREFIXES, "org.jboss.naming rg.jnp.interfaces");

Class path which I have set:

C:\jboss-4.2.3.GA-jdk6\jboss-4.2.3.GA\client\jbossall-client.jar;C:\jboss-4.2.3.GA-jdk6\jboss-4.2.3.GA\client\jnp-client.jar

Still do I have to add any other .jar files.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


C:\jboss-4.2.3.GA-jdk6\jboss-4.2.3.GA\client\jbossall-client.jar;C:\jboss-4.2.3.GA-jdk6\jboss-4.2.3.GA\client\jnp-client.jar

I would be surprised if you needed both jbossall-client.jar and jnp-client.jar in your classpath. jbossall-client.jar should include everything you need.

In my test (see my earlier post) my classpath only included jbossall-client.jar.
Jetendra Ivaturi
Ranch Hand

Joined: Feb 08, 2007
Posts: 159
Thanks for all you support Pual and Vijitha... I could do it.

Thanks. I am good at using weblogic. But JBoss is new to me so sturggled a lot.

But could get it atlast only with your support and cooperation.

Thanks for being patient.

Cheers.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

You are more than welcome. Glad you got it working.
Jetendra Ivaturi
Ranch Hand

Joined: Feb 08, 2007
Posts: 159
Thank You.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JBoss Remote Lookup
 
Similar Threads
ServiceUnavailable Exception
EJB lookups from different physical boxes
HF-EJB - initial context in chapter 1
jdbc not bound
Communication between two EJB container