Connecting a Java EE Application to an External System

We have a Java EE application running on Glassfish 3.1 that should receive notifications from an inherited system written in Java. This legacy system provides a JAR file that should be used by any external application that wants to subscribe to system notifications.

When used in a Java SE application, the library works as follows:

  • The library is initialized with parameters for connecting to an outdated system.
  • The library connects to the system and listens for notifications.
  • Our applications register for notifications, implementing the interface
  • Whenever a notification arrives, the method in the implementation class is called

We would like to reproduce the same in Java EE in such a way that the EJB method is called whenever a notification is sent by the system.

Is there a JCA way? How about a single EJB initializing the library and registering yourself as a listener?

Good examples on this topic are hard to find, so if you have any recommendations, I would be grateful.

+4
source share
1 answer

Theoretically, the JCA will indeed be a specialized API to use for this.

If the application is an EAR and the EJB classes live in a pure EJB module, there are quite certain restrictions on what EJBs are allowed to do. JCA can do exactly those things that EJB does not allow to do (reflection, static fields, create threads, load own libraries, etc.).

The downside is that the JCA is a "thoroughly" documented API that is more intended to be used by vendors of the legacy systems you describe than the "regular" application programmers. If you want to follow the JCA path, one of the sources of information is perhaps the Quartz source code, which contains the incoming JCA resource adapter for Quartz .

Registering Singleton directly as a listener must be done carefully. The inherited library should receive a reference to the Singleton proxy class, and not to the actual implementation (i.e., Do not pass this to an obsolete library).

Another option would be to provide a regular class that implements the required interface and registers with an inherited library. After receiving the notification, he can find the factory and Queue JMS connection from the JNDI, and then sends a JMS message that is listening to the Message Driven Bean.

+6
source

Source: https://habr.com/ru/post/1385684/


All Articles