• 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

returning a class from an session ejb

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have an session ejb(MyEJB) that calls a class(skuObj.class) with a bunch of getters and setters, I retrieve a record from the database and set the row to the class like this skuObj.setSKU(the value from db).. and so on.
after that I return the class object.So my ejb Method looks like this;
NOT ALL THE CODE IS HERE IS JUST TO GIVE AN IDEA OF WHAT I AM TRYING TO DO.
public skuObj getSku(String _sku_cd) throws EJBException {
skuObj sku = new skuObj();
sql = "select * from sku where sku_cd = '" + _sku_cd + "'";
sku.setSku_cd(rs.getString("sku_cd"));
sku.setSku_desc(rs.getString("sku_desc"));
sku.setSku_class(rs.getString("sku_class"));

return sku;
}
The EJB resides in a Jboss server, so If I call the EJB from the local server, I have no problem. The problem is tha I need to call the EJB from a remote server running tomcat, I get a java.io.Exception error. I know I need to serialize the skuObj.class object in order to pass it to the remote server, and I have been looking for an example on this, but can't find any.
Is this even possible? I am quite sure it is possible, but I can not find an kind of reference to this and that is making me think otherwise.
Thanks for any help provided!
 
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Firstly, there's no reason to declare that your getSku method throws an EJBException because EJBExceptions are runtime exceptions and are not checked.
Secondly, you don't have to do much to get your SkuObj to be Serializable. You just need two things: 1) make the SkuObj class implements java.io.Serializable 2) Make sure that your client has the SkuObj class available to it because it will need this class to reconstruct the skuObj once it receives it.
You don't explicitly write code to serialize any parameters or return values. This is done for you by the rmi implementation.
 
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And to clarify your post, you are not returning the *class*. You are returning an instance of the SkuObj class -- an object in simple terms. AFAIK, RMI will not pass along classes with serialized objects. Instead, you must ensure that the client has access to the SkuObj class in its classpath.
 
Sergio Barreros
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks guys, reading about serializing other objects and looking at examples that you had to write code to serialze them and then reconstruct them was making me think I had to write some code to achieve this.
I got it to work, thanks!
 
Don't destroy the earth! That's where I keep all my stuff! Including this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic