Can The ServletRequest object be passed to SLSB method?


EJB programming & troubleshooting: Can The ServletRequest object be passed to SLSB method?

  1. I'm wondering if doing this is possible or if it's a bad idea. The Stateless Session Bean would need to get parameters from the Request Object and then setAttributes on it.

  2. Hi!

    ServletRequest does not implement Serializable, so from what I can see it is not a lega parameter to a (non-local) EJB method.

    My recommendation is to create a value object class passing parameters from the Servlet to the SLSB.

  3. Is this also a violation of the standard MVC architecture? Should we not use DTOs etc. to transfer data into a EJB?
  4. I am aware of these concepts but my problem is because
    depending on certain form data submitted the method must set attributes of different types in response so i would have to make a different EJB method for each possible result. Thanks for thnbe advice anyhow.
  5. If you don't want to create various DTOs use HashMap as a generic DTO instead, some of this is outlined in the EJB Pattern book. It is not as cohesive, but in cases where you do not want keep changing the interfaces to you app it is effective.

  6. Won't work anyway[ Go to top ]

    Even if you passed the HttpServletRequest into the EJB, you'd be passing by value and not by reference, so changing the request's state in the EJB does not guarantee that the state is called in the request object in your web container. If you're not passing the request by reference (local EJB), then it just won't work.

    If you are passing the request by reference (local EJB), then I suggest using a generic collecting parameter and passing *that* into the EJB instead. Implement some narrow interface that includes an "attribute setter" of some kind, then wrap the request in an implementation of that interface and delegate. The goal here is to maximize the substitutability of another implementation for testing or refactoring.

    If you need an example, let me know; otherwise, good luck.