File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and other Java EE Technologies and the fly likes EJB 3.0 client issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "EJB 3.0 client issue" Watch "EJB 3.0 client issue" New topic
Author

EJB 3.0 client issue

Zenikko Sugiarto
Ranch Hand

Joined: Jan 09, 2005
Posts: 58
Guys,

I deployed a stateless session bean into JBOSS 4.2 as .jar, but my client couldn't seem to get a hold of this bean!

Currently my bean jar contains simply the binaries as such:



the interface has got the @Remote annotation
The session bean, has got the @Stateless annotation

I think I don't need to put any other file because of the new EJB3 @Annotations

upon deploying this app, I got this msg in JBOSS:



At which point, I deployed a separate .war containing a simple webapp, where the servlet attempts to access the bean like so:



However, I couldn't get it because I got a ClassCastException. Basically the object retrieved by the ctx.lookup is not castable to ProcessHello.

However I checked a bunch of tutorials, and they seems to be accessing them this way.
So my guess is that I must have prepared the bean .jar file incorrectly, but I couldn't work out what is wrong with it or what is missing.

Any pointer/help is much appreciated!

[ October 18, 2007: Message edited by: Zenikko Sugiarto ]
[ October 18, 2007: Message edited by: Zenikko Sugiarto ]
Zenikko Sugiarto
Ranch Hand

Joined: Jan 09, 2005
Posts: 58
Hmm, I suspected that this might be related to the way the container handled the JNDI naming. I tried this on the latest SJSAS 9.1 and it worked as I expected it to.

However shouldn't this be a standard? Anyone have used JBOSS extensively here and able to shed some light ?
Anand Kumar Singh
Greenhorn

Joined: Oct 18, 2007
Posts: 22
Try to write your code Like This.

Bean CODE:
-----------------
@Stateless
@RemoteBinding(jndiBinding = "MeterInfoDAORemote")
@LocalBinding(jndiBinding = "MeterInfoDAOLocal")
public class MeterInfoDAOEJB implements MeterInfoDAORemote, MeterInfoDAOLocal {
------
---
-
}

Client CODE:
-------------------

public class MeterInfoEJBTest{

public MeterInfoDAOLocal meterInfoLocal;

public static void main(String[] args) {
try {
Properties properties = new Properties();
properties.put("java.naming.factory.initial",
"org.jnp.interfaces.NamingContextFactory");
properties.put("java.naming.factory.url.pkgs",
"=org.jboss.naming rg.jnp.interfaces");
properties.put("java.naming.provider.url", "jnp://localhost:1099");

Context ctx = new InitialContext(properties);
meterInfoLocal= (MeterInfoDAOLocal) ctx.lookup("MeterInfoDAOLocal");

// call business method using meterInfoLocal object

} catch (NamingException ne) {
// log.error("Naming Exception Encountered : "+ne);
}

}


SCJP 5, SCWCD 5, SCBCD 5,
SCEA 5,
OCUP Fundamental,
OCUP Intermediate,
OCUP Advanced,
IBM Certified Solution Designer - Object Oriented Analysis and Design, vUML 2
Zenikko Sugiarto
Ranch Hand

Joined: Jan 09, 2005
Posts: 58
Thanks Kumar, I'm trying it right now, will post update.

I'm guessing the code you gave for the client is meant for a standalone client running outside the server (as you put those settings int the Properties).

Anyway I'll give it a go, as I have installed both server I want to write code that can deploy for both...
Anand Kumar Singh
Greenhorn

Joined: Oct 18, 2007
Posts: 22
You can use the same code for remote call in your server, if any problam please let me know.
Zenikko Sugiarto
Ranch Hand

Joined: Jan 09, 2005
Posts: 58
Kumar, the code works, but only with JBOSS. It won't work with Glassfish due to library dependency?

Anyway I made the switch to Glassfish as I found that it is easier to work with. Thanks a lot for your help anyway I am trying something else now...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: EJB 3.0 client issue
 
Similar Threads
Database changes vanish after jboss closed
Session bean not bound
using EJB annotation
Problem with EJB 3. Name not bound error
Websphere Community Edition 2.0 - EJB lookup ISSUE