• 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

EJB 3.0 client issue

 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Z Sugiarto
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ?
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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);
}

}
 
Z Sugiarto
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can use the same code for remote call in your server, if any problam please let me know.
 
Z Sugiarto
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic