• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

java application accessing the ejb

 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How to access the EJB (session beans) from a swing application keeping code reuse in mind? EJBs are created as the same functionality needs to be web enabled also. I do not want to access the EJB as a web service from client / swing application. Any thoughts or any useful links?
 
Ranch Hand
Posts: 536
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your web application / swing application needs to talk to the EJB via a delegate.

The delegate needs to use the Service Locator to locate the home inteface of the session facade.

Ok let me give you a small example. Lets say that you have three entity beans (a) user (stores login details) (b) employee (c) department. Each of the above bean has its own home and component interface. You want to expose few methods in these three interfaces to the client. Rather than the client perform a lookup and identifying which interface he needs to use to call a business method, we hide all the complexity in a single business component that that contains and centralizes complex interactions between lower-level business components.

ie., in this case I would create a single stateless session bean and expose the component methods in it.

Example:

The above class (SessionFacde) is a stateless session which means that you still need to create a home and component interface. You have now consolidated all the business functions into one big class but still clients have to do all the lookup to get to it. Do you want your clients to know that you are using EJB? No, ofcourse not.

So we need one more level of abstraction. We need a delegate. The delegate will be the contact point for the client. The delegate will perform all the JNDI lookup and call the appropriate business function.

So, your delegate class (remember, its not a session / entity bean) - its a plain old java class will look something like:



Sounds better. But wait!! Whats with all the duplicate code in the DummyDelegate. Wouldn't it be great if all the jndi lookup is handled in one place? Yeah, probably. So here is a better Delegate class



and the servicelocator will be responsible for all the JNDI lookup. How good is that?

So, to reiterate:- The delegate needs to use the Service Locator to locate the home inteface of the session facade.
 
Richard Green
Ranch Hand
Posts: 536
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
p.s: no time to proof read. kindly adjust with all grammatical and spelling mistakes.
 
veena madhukar
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much. Very beautifully explained. Helped me a lot.
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nice job Lynette
 
veena madhukar
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a question regarding the data from web tier.

Let us say the search is done and the result is fetched by making a series of calls like

User --> JSP --> Servlet Controller --> Action --> Business Delegate --> Service Locator --> Stateless Session Bean --> DAO.

Next time when details are asked, i would like to do search within the earlier fetched result. Then will the following be OK?

User --> JSP --> Servlet Controller --> Action --> Business Delegate Detail JSP.

Kindly tell me where the search result which was retrieved earlier will be available in the web tier? Will it be in the servlet controller class or Action Or Business Delegate?

I do not want to use stateful session bean for storing the ealrier fetched result. It is something like showing the order details from order list. Order list is not a very big list.
 
Richard Green
Ranch Hand
Posts: 536
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you can store the search results in the delegate.
 
veena madhukar
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I store it in Business Delegate ---> will it be in HTTP Session. Can you pls. point me to an example on how are they stored in HTTP Session?
 
Ranch Hand
Posts: 1847
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
EJBs have nothing to do with HTTP sessions, you are responsible for handling what you put into those yourself.
 
Richard Green
Ranch Hand
Posts: 536
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by veena madhukar:
If I store it in Business Delegate ---> will it be in HTTP Session. Can you pls. point me to an example on how are they stored in HTTP Session?


no. whatever function you call on the delegate that returns the results, needs to do something like this:



Alternatively you can put the results in your HTTPsession. The choice is yours.
 
The moustache of a titan! The ad of a flea:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic