How to create custom network transport for JAX-WS
By oleksiys on Jun 01, 2006
In this entry I will try to describe how to implement custom JAX-WS transport from some experience I got with JMS and TCP implementations.
1) Implement your own transport pipe, which implements Pipe interface. Mainly you have to implement interface's method process(Packet), which should do actual work on serializing Packet and send it, then wait(or not) for reply packet, deserialize it and pass back it as return param.
2) To plug your transport pipe, you need to create own transport factory. It means its required to write a factory, which extends TransportPipeFactory and actually plugs transport pipe to ws pipeline. Probably it makes sence to check it current service requires exactly this transport to be plugged by checking ws address schema. If return null as pipe - then default (http) transport pipe will be tried to be pluged.
3) And last: to say JAX-WS client framework to use just created TransportPipeFactory - its required to supply configuration file, which should be located at classpath META-INF\\services\\com.sun.xml.ws.api.pipe.TransportPipeFactory this text file have to contain a line with full classname of custom transport pipe factory.
1) For server side first its required to build adapters for provided webservices. Transport Adapter class should do all transport specific work to deserialize and serialize Packet and make it ready for processing by jax-ws service-side pipeline. Its useful to use Adapter.Toolkit for processing packets, as common transport resources, packet encoder, decoder could be stored to pool and reused. Basically Adapter should deserialize Packet from underlying transport, pass it to pipeline head, get reply packet from it and serialize it back to underlying transport. Transport specific Adapter could be constructed manually, with self written code, or as it is in JMSTransport example - DeploymentDescriptorParser was used, which originally located in http specific package, but obviously could be reused for other transports. This parser uses webservice description file (sun-jaxws.xml) to create adapters, its just required to provide some artifacts for that including DeploymentDescriptorParser.AdapterFactory implementation class, which is responsible to create Adapter instances.
2) Actually it could be 1st step:) Its required to implement incoming message listener. If its tcp - listen on tcp port, jms - listen on some queue or topic and based on some transport specific header or some other agreement decide, what is the correspondent adapter for that request and pass transport specific artifacts to adapter for feature processing, including sending actual reply.
Looking at client and server side custom transport implementation, it seems to me, that client side is easier and more clear in implementation, server's is not perfect and requires more work, also don't like too much my solution to use http specific util like DeploymentDescriptorParser. So hope soon with help of jax-ws team I will be able to come with better solution :)