• 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

purpose of InitialContext?

 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello all,

What 'InitialContext' can do?

With Jboss, The code like,


InitialContext context = new InitialContext();

context.lookup("look/into/jboss.xml");

The last statement looks into jboss.xml file and returns the ejb-name?

Thank You!
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does this help https://coderanch.com/t/507616/java-EJB-SCBCD/certification/Remote-client-EJB#2293049
 
yuvaraj KumarAmudhan
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank You Jaikiran!

But we need to set properties to the context object?
then what is the purpose of jboss.xml?

Either define the properties or define jboss.xml or we have to define both?

Thank you again for your kind reply!

 
Jaikiran Pai
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

yuvaraj Mbr wrote:

But we need to set properties to the context object?


If you don't pass the properties to the constructor of InitialContext, then a file named jndi.properties is scanned for, in the classpath. The contents of the jndi.properties are expected to contain the context properties.

yuvaraj Mbr wrote:
then what is the purpose of jboss.xml?


jboss.xml is JBoss specific EJB deployment descriptor used to configure EJBs.
 
yuvaraj KumarAmudhan
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank You jaikiran!

I have created the properties like,

Properties props = new Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY,"org.apache.openejb.client.RemoteInitialContextFactory");
props.put(Context.PROVIDER_URL,"http://164.10.10.10:8080");
Context ctx = new InitialContext(props);

My jboss AS is running on "http://164.10.10.10:8080", and made a lookup with this statement,

Object objref = ctx.lookup("java:comp/env/ejb/testbean/MyAdvice");

The things here are correct? If so, it is not working!


Note: I am using ejb 2.0 and jboss AS 6.0!
 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes,
For creating Initial Context in Jboss you have to use jnp and not http.
And the port has to be 1099 by default if you have not changed your settings.

So,
Try and use jnp://164.10.10.10:1099 and you should get the Initial context.

Too add to IC explanation :
Initial context is basically used to get a handle on the Application Servers JNDI tree. It provides the base from where you can look up your resources.

Hope it helps
 
yuvaraj KumarAmudhan
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank You Vikram!

I have tried with jnp also. Jboss is running on remote system (164.10.10.10) with port 8080.

properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
properties.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
properties.put(Context.PROVIDER_URL, "jnp://164.10.10.10:8080");

It shows some exception like,

Could not obtain connection to any of these urls: 164.10.10.10:8080 and discovery failed with error: javax.naming.CommunicationException: Receive timed out [Root exception is java.net.SocketTimeoutException;


Any idea about this vikram?

Thank You again!



 
Vikram Saxena
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes,

8080 is the web port. You have to use the JNDI bind port which is mentioned in the jboss-service.xml in the
server\<server-name>\conf directly.

By default its 1099.

So if you have not hanged it the correct PROVIDER_URL would be :
jnp://164.10.10.10:1099

Also, please post the version of the Jboss App Server you are using.

 
yuvaraj KumarAmudhan
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JBOSS 6 vikram!

Ejb 2x.
 
Jaikiran Pai
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you try using 1099 port, as suggested by Vikram?
 
yuvaraj KumarAmudhan
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes! i tried! If i use 1099, then it shows "ejb not bound".

If i use 8080, then it shows

"Could not obtain connection to any of these urls: 164.10.10.10:8080 and discovery failed with error: javax.naming.CommunicationException: Receive timed out [Root exception is java.net.SocketTimeoutException;"

Thank You!
 
Jaikiran Pai
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

yuvaraj Mbr wrote:yes! i tried! If i use 1099, then it shows "ejb not bound".


That indicates you are using a wrong JNDI name. Check the jndi name of your bean using the JNDIView MBean in the jmx-console and then use it as your lookup string.

yuvaraj Mbr wrote:
If i use 8080, then it shows


Don't use that. As has already been mentioned, that port is not the naming port.
 
yuvaraj KumarAmudhan
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank You for your kind reply!

And sorry for asking questions again and again!


My jboss.xml contains,

<session>
<ejb-name>AdviceBean</ejb-name>
<jndi-name>testbean/MyAdvice</jndi-name>
</session>


and ejb-jar.xml has something like,

<session id="test_MyTestSession">

<display-name> AdviceBean </display-name>

<ejb-name>AdviceBean</ejb-name>

<home>com.testbean.beans.AdviceHome</home>
<remote>com.testbean.beans.Advice</remote>
<ejb-class>com.testbean.beans.AdviceBean</ejb-class>

<session-type>Stateless</session-type>

<transaction-type>Container</transaction-type>
</session>


And i call them from a servlet with these foloowing statements,

Properties properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
properties.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
properties.put(Context.PROVIDER_URL, "jnp://localhost:1099");
Context context = new InitialContext(properties);

Object objref = context.lookup("testbean/MyAdvice");




then why it shows "testbean not bound". It has anything wrong? If so, let me know please!

Thank you!
 
Jaikiran Pai
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

yuvaraj Mbr wrote:

then why it shows "testbean not bound". It has anything wrong? If so, let me know please!



What's the output of the JNDIView MBean? Can you post that? Also, while posting code, xml or logs, make sure that you wrap them in a Code block (you can use the Code button in the message editor window).
 
yuvaraj KumarAmudhan
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry for this!

this is the JNDI tree i have!


 
Jaikiran Pai
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It doesn't look like your bean is deployed. How are you packaging and deploying the bean? What does the console log show when you deploy your application?

P.S: By the way, is there any specific reason you are using EJB2.x? The latest supported version in AS6 is EJB3.1 and is much more simpler than EJB2.x
 
yuvaraj KumarAmudhan
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank You fro your reply kiran!

sorry to paste this long content. but need to know the problem in this!

This indicates? It s not a deployed structure?



servler.log has something like the following,




Note: No special reasons to use ejb2x. But now only started learning ejb. my senior said that "first try ejb 2x"
 
Jaikiran Pai
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

yuvaraj Mbr wrote:Thank You fro your reply kiran!

sorry to paste this long content. but need to know the problem in this!

This indicates? It s not a deployed structure?



That part from java: namespace indicates that your application has been deployed and the JavaEE6 spec mandated names have been initialized. However that does not indicate that the deployment was picked up as a EJB2.x deployment. The global jndi namespace should have contained the bean references, if it was considered as a EJB2.x deployment.


servler.log has something like the following,
2010-10-07 18:59:28,375 INFO [org.jboss.ejb3.deployers.Ejb3DependenciesDeployer] (HDScanner) Encountered deployment AbstractVFSDeploymentContext@15716912{vfs:///D:/servers/jboss-6/server/default/deploy/testbean.ear/testbean.jar/}
2010-10-07 18:59:28,375 INFO [org.jboss.ejb3.deployers.Ejb3DependenciesDeployer] (HDScanner) Encountered deployment AbstractVFSDeploymentContext@15716912{vfs:///D:/servers/jboss-6/server/default/deploy/testbean.ear/testbean.jar/}
2010-10-07 18:59:28,375 INFO [org.jboss.ejb3.deployers.Ejb3DependenciesDeployer] (HDScanner) Encountered deployment AbstractVFSDeploymentContext@15716912{vfs:///D:/servers/jboss-6/server/default/deploy/testbean.ear/testbean.jar/}


For some reason, the deployment is being considered as EJB3.x instead of EJB2.x. Just re-read your previous post in this thread about ejb-jar.xml. Is that the exact XML file you have in the testbean.jar/META-INF? It's missing the xsd/dtd declaration.


Note: No special reasons to use ejb2x. But now only started learning ejb. my senior said that "first try ejb 2x"


I personally would recommend you start with EJB3.x instead of EJB2. That way you'll save a lot of trouble trying to get past issues. Also, for JBoss AS, we have the EJB3 tutorials (including the source code) here
 
yuvaraj KumarAmudhan
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank You for your kind reply kiran!

this is the entire content of ejb-jar.xml, But now its not even ready to deploy.

just now i have pasted the dtd element!

 
yuvaraj KumarAmudhan
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks to All!

problem resolved!

Especially to Jaikiran and Vikram!

EJB 2.1 could be deployed with jboss 6.0. And its working good.

Thank You again!



 
Jaikiran Pai
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Glad to know, you got it working!
 
reply
    Bookmark Topic Watch Topic
  • New Topic