Thursday, August 26, 2010

com.sun.net.httpserver transport using JAXWS 2.2 HTTP SPI

In the previous post I've written about Apache CXF and JBossWS-CXF implementation of JAXWS 2.2 HTTP SPI. From a container point of view, a bit of additional coding is required for making an existing http server compliant too.

Similarly to what Jitendra Kotamraju did for Grizzly, I've just created a small project for using the JDK6 httpserver with this HTTP SPI, basically allowing any JAXWS 2.2 stack implementation to be used on top of it (not just the JAXWS RI as mentioned here). The project only runtime dependency is the JAXWS 2.2 API, so it's completely vendor agnostic (the project testsuite uses Apache CXF just for the sake of testing with a JAXWS 2.2 impl).
So, the following is now possible using any JAXWS 2.2 compliant implementation:

import com.sun.net.httpserver.HttpServer;
import javax.xml.ws.spi.http.HttpContext;
import org.jboss.ws.httpserver_httpspi.
HttpServerContextFactory;
..

HttpServer server = HttpServer.create(new InetSocketAddress(8080), 0);
HttpContext context = HttpServerContextFactory.createHttpContext(server, "/ctx", "/echo");

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

The binaries for the project are on JBoss' Maven repository.

4 comments:

Glen Mazza said...

Hi Alessio, the code snippet in your blog doesn't seem to have any dependencies on the small project you created (unless I'm missing something), so I'm not sure how the project you created plays a role in this. Can you explain further? Thanks!

Alessio Soldano said...

Hi Glen,
sorry, I simply copied the snippet from a test I have in the same package of the HttpServerContextFactory... hence no import for that. I've just modified the snippet to make the dependency more clear. Thanks for pointing this out :-)
Cheers
Alessio

Alessio Soldano said...

btw, the source code of the mentioned test is at http://anonsvn.jboss.org/repos/jbossws/projects/jaxws-httpserver-httpspi/trunk/src/test/java/org/jboss/ws/httpserver_httpspi/EndpointAPITest.java

Alessio Soldano said...

For the records, the project has been released in its first final version:

Sources

Maven artifacts

JBossWS 5.4.0.FInal is released !

I am pleased to annouce JBossWS 5.4.0 Final is out. In this release we upgraded many components as usual and brings Elytron client configur...