File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

returning a class from an session ejb

 
Sergio Barreros
Greenhorn
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • 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!
 
Anthony Watson
Ranch Hand
Posts: 327
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
David Harkness
Ranch Hand
Posts: 1646
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic