Hi all, I have an application which used jsps ans servlets as web layer and POJO as business layer and DAO s as data base layer.
Now the question is, if I want to redesign this using EJBs how ll I do? I will retain the JSP pages as such and populate a DTO from the JSP inputs, call a session bean in the servlet for performing all business logics, and an entity bean will be used for doing the data base updates.
Is this design Ok? I have a doubt whether I can use servlet to call a session bean. Any better design or suggestions?
Technically, there is no problem in calling an EJB from a servlet (or JSP, Struts Action, Swing, etc). But you can certainly argue that the client should not know how the business logic is implemented. My preference is to use a business delegate between the servlet and EJB. The client invokes business methods on the BD and the BD invokes the required methods in the business logic layer. This layer might consist of just POJOs today, tomorrow it might consist of EJBs and POJOs.
I suggest you implement the BD first, then add EJBs.
Use of Business Delegate is a j2ee design patterns that have a lot of advantages. Most important patterns to implement if you decide to use EJB : Service Locator (use to look up your ejb) and Proxy(use to make separation and abstraction between your presentation layer and the ressource one).
I use a vendor framework with proprietary a BD architecture. Inside it does its own marshalling and then uses strategies to make the service call via native Java methods, EJB, raw sockets, XML/HTTP, JMS, etc. So the BD methods are the business methods on the remote object and the strategy methods are about making remote calls to any service with any set of parameters. Cool stuff.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi