Reputation:
The challenge here is that I need to implement a highly concurrent and dynamic system that is based on SOAP communication - in Java. It can be viewed as a multi-agent system where an agent is a software process (like a daemon) that responds to SOAP requests. At runtime my system may comprise more than a thousand of such agents - each of which bound to its own dedicated port, offering the exact same service/interface. Thus, implementing it as a Tomcat servlet or similar is a way to heavy.
For my first try I built a simple HTTP-Server and tried to implement SOAP message handling on top. But I didn't want to re-invent the wheel, especially since that Simple Object Access Protocol is actually not that simple. Unfortunately, most solutions for Java are based on Jax-WS and require a tomcat or other server environment to run (as far as I understood).
Then I had a look at the axis library (awesome). It even comes with a SimpleAxisServer module which does exactly what I want. It runs as a very light-weight standalone SOAP server, and deploying a SOAP service is done very easily. But... here comes the problem: The SimpleAxisServer is meant for development and debugging purposes only and it is highly discouraged to use it otherwise. Of course, me ignoring those hints started prototyping the system using that module, and ran right into trouble after a few days...
My actual question now is: Isn't there a ready-made solution for this problem? Which libraries/classes should I have a look at?
Upvotes: 4
Views: 2699
Reputation: 7779
I personally would use Apache CXF. The standalone mode is based on Jetty which is light enough according to my book and Jetty itself is stable and performs well.
import java.util.logging.LogManager;
import javax.xml.ws.Endpoint;
public class MySoapServer {
public static void main(String[] args) {
String serviceAddress = "http://localhost:9099/mysoap";
MyService implementor = new MyServiceImpl();
Endpoint ep = Endpoint.publish(serviceAddress, implementor);
}
}
If you are using Maven (which you really should), add the following to pom.xml:
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>2.4.2</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>2.4.2</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
<version>2.4.2</version>
</dependency>
The service itself will be built with standard JAX-WS annotations.
First create the interface.
import javax.jws.WebService;
@WebService
public interface MyService {
public String hello();
}
And then the implementing class.
import javax.jws.WebService;
@WebService(serviceName="HelloWorld")
public class MyServiceImpl implements MyService {
public String hello() {
return "Hello World!";
}
}
Or you may also use WSDL-first approach if you want to.
Upvotes: 7