Skip to main content

Grizzly transport using JAX-WS 2.2 HTTP SPI

Posted by jitu on July 9, 2010 at 5:55 PM PDT

Created a new jax-ws-commons project at the familiar jax-ws-commons. JAX-WS 2.2 has defined HTTP SPI that allows to plugin a http transport with any JAX-WS runtime. This project implements the HTTP SPI using Grizzly HTTP implementation. That means ANY JAX-WS 2.2 runtime can be used with this grizzly transport portably(zero dependency on RI code). The following example shows on how to use this transport to host endpoints:

public void startApp() {    
    String contextPath = "/ctxt";
    String path = "/echo";
    int port = 12345;

    String address = "http://localhost:"+port+contextPath+path;

    GrizzlyWebServer server = new GrizzlyWebServer(port);
    HttpContext context = GrizzlyHttpContextFactory.createHttpContext(server, contextPath, path);

    Endpoint endpoint = Endpoint.create(new EchoService());
    endpoint.publish(context);      // Use grizzly HTTP context for publishing

    server.start();

    ...
    endpoint.stop();

    server.stop();
}

The binaries are pushed to maven. Let me know if you have any feedback.

Comments

Grizzly transport using

Hi Jitendra,
hope I am not offtopic, but looks like u are the right guy for WS in JDK 6. I have a big issue on implementing custom HTTP transport in jdk 6, for JAX-WS.
Reasons I need to implement:

  • http proxy usage without overwriting DefaultProxy (multiple web services clients in same JVM are accessing direct or via proxy, same time)
  • connect timeout not working in JAX-WS from JDK
  • I MUST catch the HTTP response body (for logging reasons) even if due to an unexpected event, the response is not in SOAP format (maybe a 404 response)

I followed your advice and also http://blogs.sun.com/oleksiys/entry/how_to_create_custom_network and created own transport,
everything works fine under Eclipse, using JDK and my own transport, but when compiling (mvn), I get errors like
package com.sun.istack.internal does not exist
package com.sun.xml.internal.ws.api does not exist
...
probably due to
http://java.sun.com/products/jdk/faq/faq-sun-packages.html

Here comes my Q: do you see a solution for implementing custom HTTP transport, and be able to compile ??

Thanks in advance,
Tavi Giurgiu

This looks very usefull for

This looks very usefull for me. But is there a way I can runb this in Eclipse using JDK6 withouth receiving: Exception in thread "main" java.lang.IllegalArgumentException: class org.jvnet.jax_ws_commons.transport.grizzly_httpspi.GrizzlyHttpContext is not a supported context.

 You need to use JAX-WS 2.2

 You need to use JAX-WS 2.2 jaxws-api.jar and jaxb-api.jar using endorsed mechanism. JDK 6 has only JAX-WS 2.1 API 

<p>Hi Jitu,</p> <p>Is there a way we can use the Grizzly to ...

Hi Jitu,
Is there a way we can use the Grizzly to support a HTTPS endpoint?
I checked the code of EndpointImpl where the HttpServer is loaded,is there a way we can instead load a user define HTTPSserver so that i can support webservices over https?
Thanks
JaxwsFan