Simple WS endpoint deployment with JAXWS 2.2 HTTP container abstraction

Recently I’ve been playing with the JAXWS Endpoint.publish(..) API. For those not really involved in WS development, JAXWS includes an API for easily deploying an endpoint in JSE environment while starting a http server just for serving calls to the specified endpoint.

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

While from a user point of view this API is of few interest on a JavaEE environment, this is still quite interesting in JSE env as well as whenever having the need for a quick/easy testing of basic endpoints.
Moreover, JAXWS 2.2 added a HTTP SPI for establishing / fixing the layer between http server containers and JAXWS stack implementations. This basically allows any jaxws 2.2 compliant implementation to be used on top of any “compatible” http server.
Jitendra Kotamraju (current JSR-224 spec lead) recently provided a bridge project for making Grizzly compatible with the JAXWS 2.2 HTTP SPI. I’ve done the same for the httpserver included in the JDK6 com.sun.net.httpserver.HttpServer. There’s also a similar project for Jetty. So, with the additions of spec 2.2 and the required vendor implementations to comply on that, users can finally do the following with any JAXWS compliant implementation:

import javax.xml.ws.spi.http.HttpContext;
..
HttpContext context = ..;
Endpoint endpoint = Endpoint.create(new EndpointBean());
endpoint.publish(context);
//invoke endpoint
endpoint.stop();

where the context is obtained according to the selected containers, for instance (using my bridge to the JDK6 httpserver):

import com.sun.net.httpserver.HttpServer;
..
HttpServer server = HttpServer.create(new InetSocketAddress(currentPort), 0);
HttpContext context = HttpServerContextFactory.createHttpContext(server, contextPath, path);
server.start();
..
//here comes the endpoint publish and usage as shown above
..
server.stop(0);

Quite handy, isn’t it? ;-)

One Response to “Simple WS endpoint deployment with JAXWS 2.2 HTTP container abstraction”

  1. jaxwsfan says:

    Exception in thread “main” java.lang.IllegalArgumentException: class HttpContextDelegate is not a supported context.

    I get the following error when i execute the code.
    shouldn’t HttpContextDelegate be of type com.sun.net.httpserver.HttpContext ?

    I get the following stackTrace:
    java.lang.IllegalArgumentException: class org.jboss.ws.httpserver_httpspi.HttpContextDelegate is not a supported context.
    at com.sun.xml.ws.transport.http.server.EndpointImpl.publish(EndpointImpl.java:192)
    at org.jboss.ws.httpserver_httpspi.EndpointAPITest.testSingleEndpoint(EndpointAPITest.java:101)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
    at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>