• 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

Passing parameters between Session beans

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello folks - working on my first J2EE project now.

I am trying to implement exception-handling with a facility to show detailed and informative error message to the user. We are using Struts. I am instantiating a simple Java bean (public class, implementing Serializable) from the ActionClass. I am passing this object on to the business delegate (stateless session) bean.

The delegate, in turn, passes this to a session facade (stateless session) bean.

The facade, in trun, passes this error bean to a DAO object, where lots of action takes place.

The idea is, at any point, when a exception is thrown, I will set a code into this error bean, and continue to normally propogate the exception using throw. I expect this to happen till I reach the ActionClass, where I will examine the bean, get the code, and fetch a nice message from a property file.

An error is simulated in DAO code; this causes the error object to be filled with a error code; this code is also visible to the Session facade bean (because objects are passed by reference). However, the business delegate is unable to get this code, in fact, if I preset the error object with some junk code in the business delegate before passing the object to the facade, it continues to hold this value even after returning from the facade!

Does this mean, between two session beans, we do not have reference passing of objects? Between session beans, is the mechanism always pass-by-value even for entire objects?

Else, what could be wrong? Please suggest. Thanks for reading this longish post, and thanks for any help.

Also pls suggest how this approach can be further improved.

Regards/Harish
[ March 17, 2006: Message edited by: Harish Vaishnav ]
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Instead of passing on error code related information as arguments to methods, a better approach would be to throw an application exception from the session beans on encountering an error. This application exception would contain the error code. One question to you, do you expect the transaction to be rolled back when an error occurs? If yes, then in the approach that you have stated, i dont see a way this can be done.
 
Harish Vaishnav
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
jaikiran pai:

Thanks for the response.

- How would the application exception contain the error code?

- Since I am using a custom error object, which contains the error code, I can afford to only fill up this object and then always throw new EJBException(e), which I believe causes the container to rollback.

So, by using a simple error object, I plan to give a better user response without losing container tran management. But I am facing the problem I described earlier.
 
Jaikiran Pai
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Since I am using a custom error object, which contains the error code, I can afford to only fill up this object and then always throw new EJBException(e)



This means that you dont need the pass the error object as part of method parameters. Whenever an error occurs and the EJBException is thrown, you then retrieve your custom error object(that you wrapped inside the EJBException, as EJBException(e)) from this EJBException instance by invoking the getCause() method on the same.
 
Jaikiran Pai
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Something like:

 
Harish Vaishnav
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
jaikiran pai:

My situation is like this: there is a need to present detailed message to the user. We have decided that instead of defining custom exceptions extending java.lang.Exception, we will create a small class instead:

public class CustomError {
int eCode;
String eMsg;
String userAction;
...
...
}

We will pass this class's object along all the way from ActionClass to the DAO layer where, potentially, this object will be filled with a error code. (If this object were to be filled, we will also have come out of any trans due to "throw new EJBException();")

So, we are not subclassing Exception at all in this approach, relying entirely on java's default "pass-by-reference" behavior for objects to retrieve it back in the ActionClass for further action.

This expected java "pass-by-reference" behavior is failing at the business delegate, and I cannot get back the same object I set into circulation from the ActionClass. Instead, I am stuck with the object originally sent into the delegate from the ActionClass.

Hope you understand my problem.
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


I am passing this object on to the business delegate (stateless session) bean.

The delegate, in turn, passes this to a session facade (stateless session) bean.



You shouldn't need to go through two EJB Session Beans here. In the Struts best practice architecture the Business Delegate would not be a Stateless Session bean but just a POJO.

Mark
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic