• Post Reply Bookmark Topic Watch Topic
  • New Topic

hello world problem with local interface and stateless session bean.

 
prashant gandhi
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi, I am trying to write first hello world program. I have written below code, and it does not work. what is wrong with it? I am using eclipse indigo, ejb3, jboss 7.1.1. I am able to deploy the ejb to jboss without any errors.

HelloWorldLocal.java



HelloWorldLocalBean.java



EJBApplicationClientLocal.java



ClientUtilityLocal.java


When I run the EJBApplicationClientLocal.java file, I get below error message:

javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.lookup(Unknown Source)
at com.ibytecode.client.EJBApplicationClientLocal.doLookup(EJBApplicationClientLocal.java:26)
at com.ibytecode.client.EJBApplicationClientLocal.main(EJBApplicationClientLocal.java:13)
Exception in thread "main" java.lang.NullPointerException
at com.ibytecode.client.EJBApplicationClientLocal.main(EJBApplicationClientLocal.java:14)


Looks like some JNDI stuff is missing, that i am not able to figure out. I read through the NoInitialContextException stuff, but dont know what is missing.

I wrote another program looking up on web, with remote session bean, and that worked fine. It used: jboss-ejb-client.properties file with below info. I dont know what is equivalent to that for local session bean (interface) so i did not include that file for local.



Also, I observed 1 key difference when both the ejbs are deployed into jboss server.
For remote session bean where things worked, 1 extra line is generated.

java:global/HelloWorldSessionBean/HelloWorldBean!com.ibytecode.business.HelloWorld
java:app/HelloWorldSessionBean/HelloWorldBean!com.ibytecode.business.HelloWorld
java:module/HelloWorldBean!com.ibytecode.business.HelloWorld
java:jboss/exported/HelloWorldSessionBean/HelloWorldBean!com.ibytecode.business.HelloWorld
java:global/HelloWorldSessionBean/HelloWorldBean
java:app/HelloWorldSessionBean/HelloWorldBean
java:module/HelloWorldBean


for local session bean, this line is not generated.

java:global/HelloWorldLocalSessionBean/HelloWorldLocalBean!com.ibytecode.business.HelloWorldLocal
java:app/HelloWorldLocalSessionBean/HelloWorldLocalBean!com.ibytecode.business.HelloWorldLocal
java:module/HelloWorldLocalBean!com.ibytecode.business.HelloWorldLocal
java:global/HelloWorldLocalSessionBean/HelloWorldLocalBean
java:app/HelloWorldLocalSessionBean/HelloWorldLocalBean
java:module/HelloWorldLocalBean

Any help is appreciated. Entire code is on my PC.
 
Jaikiran Pai
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Like Anayonkar already replied here http://www.coderanch.com/t/614108/EJB-JEE/java/include-local-session-bean-existing#2806465, you can't use local interfaces from a remote client. Your EJBApplicationClientLocal (that name is misleading) is a standalone Java application which runs in its own Java runtime and thus is a remote client. You cannot lookup/use local interfaces from that client.
 
prashant gandhi
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jaikiran, Thanks for your reply.

So how can I test the local interface? I think for this I will need a local client (meaning client and EJB both on same JVM).

Can you elaborate anayonkar's response on that thread:
3) Same as above. Examples of client and EJB being in same JVM might be: a) Client to the EJB being another EJB (which is in same container); b) Client to the EJB being a servlet (which is in same container)

-- how can i do this? I am very new to java world so please bare with me.

is there any working code sample that i can look through? as i mentioned, the @remote interface worked, so my understanding was that if i make it @local, it will make the interface local and since i am running application from my pc only from eclipse, the client and interface both are local, that is why i named the client: EJBApplicationClientLocal - but from your (and anyonkar's) post i understand : this is a remote client. Thanks again.
 
Jaikiran Pai
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
prashant gandhi wrote:Hi Jaikiran, Thanks for your reply.

So how can I test the local interface? I think for this I will need a local client (meaning client and EJB both on same JVM).

You'll need a local client like a servlet which is part of the same application as the EJB. See this chapter for an extensive explanation about remote and local views of a EJB http://docs.oracle.com/javaee/6/tutorial/doc/gipjf.html#gipiz. Pay special attention to the part where it says a local client has to be part of the same application as the EJB.
prashant gandhi wrote:
Can you elaborate anayonkar's response on that thread:
3) Same as above. Examples of client and EJB being in same JVM might be: a) Client to the EJB being another EJB (which is in same container); b) Client to the EJB being a servlet (which is in same container)


-- how can i do this? I am very new to java world so please bare with me.

Please ask this question in that other thread so that it can be answered in the right context.

prashant gandhi wrote:
is there any working code sample that i can look through? as i mentioned, the @remote interface worked, so my understanding was that if i make it @local, it will make the interface local and since i am running application from my pc only from eclipse, the client and interface both are local, that is why i named the client: EJBApplicationClientLocal - but from your (and anyonkar's) post i understand : this is a remote client. Thanks again.


The link I posted in this reply should help with understanding the difference between local and remote clients. If you have follow up questions, feel free to ask. As for examples, take a look at the quickstarts here http://www.jboss.org/jdf/quickstarts/get-started/
 
prashant gandhi
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Jaikiran again for pointing out the java EE tutorial. I think this would help me understand the EJB and its working to a greater detail. I will scan it quickly and try it out myself. Thanks.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!