• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Accessing a java class in a web application through EJB

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm trying to implement the observer pattern using EJBs. Subject and Object interfaces are inside the EJB module. Concrete subject is a statefull session bean. The problem is with the concrete observer. Observer class (Which implements the observer interface inside the EJB module)resides in a separate web application.

There are many web applications which share the common EJB module which should act as the set of observers.

In order to do this, subject(EJB) need to access the concrete observer class inside the web app to perform registerObservers and updateObservers.
Is there a way to access classes in the web app through EJB? Are those classes visible to the EJB module?

I'm using GlassFish V2 with netbeans 6.1.
 
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Most "web" applications are designed to respond to human interaction via web browser.

You are attempting to call a set of objects (concrete observers) that have their class files stored in multiple web applications.

Are all of the web applications deployed on the same machine as the EJB module?

Describe the requirement(s) associated with what you are attempting to do.

It is very strange and as far as I remember, there is no way to instantiate an arbitrary class in a web application from EJB code.

In web applications, processing goes down and data is sent up. Processing instructions are not sent up, only downward.

Presentation

Business

Integration

[ November 10, 2008: Message edited by: James Clark ]
 
Sandareka Fernando
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the info James... Overview if my requirement is as follows:

- There are multiple web applications (deployed in the same machine as EJB module) which share the functionality given by single EJB module.

- I need to broadcast a particular message (from an session bean) to all the above mentioned web modules.

- Then those web apps can process the message and reply to the EJB module accordingly.

I need a way to implement this behavior.(I thought of using Observer pattern since it seems provide the same functionality as i want.Any other way is acceptable)

The main problem is sending some kind of a message from a EJB to the client web app.
Thanks in advance..
[ November 10, 2008: Message edited by: Sandareka Fernando ]
 
Jimmy Clark
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks.

- I need to broadcast a particular message (from an session bean) to all the above mentioned web modules.



What initiates this message? At what point in time, does the Session EJB do processing that includes the "message sending" to multiple web modules.

- Then those web apps can process the message and reply to the EJB module accordingly.



It sounds like you have business logic contained within the class that is deployed with the web modules. This is not really a good place for business logic. Describe the "processing" that is executed by this object in the web module.

The main problem is sending some kind of a message from a EJB to the client web app.



Well, let's see what we can come up with. Your response to my first question above is important.

If the processing in the Session EJB is not started by some activity within the web module, e.g. user clicks button or hyperlink, then you need to add something in the web modules to keep checking for a message from the Session EJB. Here the web modules will not be checking the Session EJB but rather a message table in a database. The Session EJB will post a message (intended for reading by the web module) to the database. Processing goes down, not up

Keep in mind that a Session EJB is a temporary object. After the Session EJB posts its message to the database, it must then have code that keeps reading the message table for the responses from the web module.

Sounds like there will be two Session EJB, one to do the processing and posting of the message to the database. And the other Session EJB will be used by the web modules for reading the message table and posting the responses to the message table.

Sounds like a queer design, however. Robin's suggestion below is another option. However, business logic should not be coded in Message EJB either. So, the best option it to keep the business logic in Session EJB.
Whatever processing you currently have in the class in the web module, should be reengineered into another Session EJB.
[ November 10, 2008: Message edited by: James Clark ]
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The best way to implement this type of functionality is to use Message Driven Beans in what is currently your Web applications. They won't be simple web applications afterwords, but that makes sense since the listener type functionality is not user driven anyway. The MDB and Servlets would be installed in the same EAR.

The session bean does not need to know about the listeners, just post the events in question to a topic, and have all the MDB's as listeners for these events.
 
Sandareka Fernando
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Seems that the approach I have taken to solve this problem is wrong. I'll explain the message flow I need to have in my app.

- Message I mentioned above is actually a request comes from a web client. Request is for one of a several available services. (Which I try to implement as different web applications)

- Communication between the client and available services is handled by the common EJB module.

- When EJB module gets a request from client it broadcast it for available services. Specific one service should reply back (send the response) to the EJB module which in turn sent back to the initial user.

- Logic of generating the response to a particular request is up to the specific service module. Only the communication between user and service modules is handled by the common EJB module. (So it is not possible to implement all the logic inside EJB module)

I'll try it using a message driven bean as Robin suggested. If you have any thoughts of implementing the above requirement please help me.. Thanks.
 
Jimmy Clark
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. A human being goes to a web browser and clicks on a link or clicks on a button of a web module.

2. The server code of the web module gets a reference to an Session EJB.

* You mentioned that you are trying to implement "web services" with web applications. This does not sound right. It looks like you are getting the "web services" part of the design wrong.

** A Java servlet can be the implementation of a web service, but, you need to expose the web service for clients to call on it. This is typically done with a WSDL file. The client in this case is the Session EJB.

*** A Session EJB can be the implementation of a web service, but you need to expose the web service for clients to call on it. This is also done with a WSDL. The client in this case is the Session EJB.

**** There is no known way in implement a "web service" with an entire web application. This does not make any sense.

3. The Session EJB should call a web service that executes some business logic or it should call another Session EJB executes some business logic.

A Message EJB implementation will not help you do what you want to do, if the flow I mention above is correct.

If you have WSDL files for the web services, you could easily call the web services from the Session EJB with no problem. (See Service Locator design pattern).
[ November 11, 2008: Message edited by: James Clark ]
 
Sandareka Fernando
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got the idea now Thanks for showing the path. I can continue with this info.
 
what if we put solar panels on top of the semi truck trailer? That could power this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic