سؤال

What options are there to achieve low-latency communication between two wars running in the same jetty-container?

I basically need to call a service in one war from the other, but can't afford the overhead of calling it as a web service.

Since they are running in the same JVM, I'm hoping to avoid using RMI/JMS etc., but I don't know what other options I have?

I've looked at inter-servlet communication, but since direct method invocation is deprecated that doesn't seem to be the right choice?

I also found kyronet, but are there better solutions since this is in the same JVM?

What I'm looking for is something like Apache Camel's VM Component (seda between web-applications), but since only one of the applications is using Camel for this is not an option.

I know I might have to share some DTO's between the wars, but please don't suggest pulling the service into a shared library, if that was an option I wouldn't be asking this question:)

Edit:

Embedding an EJB-container is probably not an option either.

هل كانت مفيدة؟

المحلول

Register interfaces with JNDI and make them global so that the 'other' servlet can retrieve them from the repository.

Check this

(note: we gave up JNDI in favor of our own registry implementation but we start the registry and Jetty programmatically in the same JVM)

نصائح أخرى

It is possible to "communicate" between two co-located web applications by using ServletContext.getContext(String uriPath) and RequestDispatchers (or even ServletContext listeners).

Following is the working code. Suggested by Peer Reynders (http://www.coderanch.com/t/222608/Web-Services/java/communicate-war-files)

public void doGet(HttpServletRequest Prequest, HttpServletResponse Presponse)
  throws IOException, ServletException {

  ServletContext    sc = getServletContext().getContext("/war2");
  RequestDispatcher rd = sc.getRequestDispatcher("/LoginHandler?UserId=DummyUser");
  rd.forward(Prequest, Presponse);
} /* End of doGet */

Exposing the service as an EJB with local interface would be one option. The standard does not guarantee that this will be implemented as a direct call when done across apllications, but apparently most app servers implement it that way. For running in Jetty, you'd have to use an embeddable EJB container such as OpenEJB, JBoss embeddable or Spring's Pitchfork.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top