Thursday, August 26, 2010

Implementing JAXWS 2.2 HTTP SPI on Apache CXF

JAXWS 2.2 specification introduced a compact HTTP SPI; that defines the minimal set of required information a http server container and a JAXWS stack implementation need to share for allowing an endpoint deployment and invocation.

Previous JAXWS specification already included API for simplified endpoint deployment in a JSE environment:

Endpoint endpoint = Endpoint.create(new EndpointBean());
endpoint.publish("http://localhost:8080/jaxws-endpoint1");
//invoke endpoint...
endpoint.stop();

.. as well as a Endpoint publish(Object obj) method for allowing the JAXWS RI (only) to deploy an endpoint on top of JDK6 httpserver. However, this was not portable and different JAXWS implementation could actually support different and vendor specific http context implementations passed in that object instance in publish(Object obj). For instance, Apache CXF - despite being JAXWS 2.1 compliant - didn't have a specific implementation for the publish(Object obj) method, but just of the publish(String s) one.

With JAXWS 2.2 the specification added a Endpoint publish(HttpContext ctx) method and the other classes/interfaces defining the HTTP SPI together with the HttpContext. A JAXWS 2.2 implementation is supposed to be able to deploy an endpoint on top of any http container that also supports the JAXWS 2.2 HTTP SPI.

Thanks to a joint work of Daniel Kulp and me, the current trunk for Apache CXF now supports this JAXWS 2.2 HTTP SPI. This means you'll soon be able to perform a quick deployment and test of your endpoint using Apache CXF (or JBossWS-CXF, of course ;-)) on top of the JAXWS 2.2 compatible http server you prefer.

As a proof of that, I've added a testcase leveraging Jitendra Kotamraju's Grizzly transport bridge project for deploying on top of Grizzly http server, while still having the whole ws invocation being handled by CXF:

import javax.xml.ws.spi.http.HttpContext;
import com.sun.grizzly.http.embed.GrizzlyWebServer;
import org.jvnet.jax_ws_commons.transport.grizzly_httpspi.GrizzlyHttpContextFactory;

..

GrizzlyWebServer server = new GrizzlyWebServer(8080);
HttpContext context = GrizzlyHttpContextFactory.createHttpContext(server, "/ctx", "/echo");

Endpoint endpoint = Endpoint.create(new EndpointBean());
endpoint.publish(context); // Use grizzly HTTP context for publishing
server.start();
//invoke endpoint
endpoint.stop();
server.stop();

.. but the same would have worked with other compatible containers (just to mention one, there's a project for making Jetty compatible with the jaxws 2.2 http spi).

The whole JAXWS 2.2 support is being included in Apache CXF 2.3 and JBossWS-CXF 3.4.0 which should come out soon... in the mean time you can give the latest snapshots a try! Feedback is welcome :-)

No comments:

JBossWS 5.2.0.Final is available

After some micro bug fix releases on the 5.1 stream, JBossWS 5.2.0.Final has eventually been released . The latest versions brings a lot o...