Is it possible to use jax-ws to generate xml, but NOT send it out

心不动则不痛 提交于 2019-11-29 07:27:36

There is a systematic way of doing so in Java web services, JAX-WS. Just apply interceptor pattern using SOAP Handler. The handler class will intercept the message in handleMessage(SOAPMessageContext mc) method, do whatever you want to do with XML body of SOAP Envelope. and stop SOAPMessage further processing.

Then, you can treat the XML as you like (e.g. sending via peoplesoft mechanism). And when response come back from peoplesoft, bypass the outbound handler chain ... (I really have to look how to by pass a chain). I am just rolling the idea, you have to make POC. I never did so, otherwise I would have share code. But this is absolutely doable.

One of the solutions might be to replace the SocketFatory of JAX-WS. Roughly it will look like this:

javax.net.SocketFactory socketFactory = new MySocketFactory();
Service service = Service.create(new URL(wsdl), new QName(namespace, servicename));
Dispatch<SOAPMessage> dispatch = service.createDispatch(methodToBeCalled, SOAPMessage.class, Service.Mode.MESSAGE);
dispatch.getRequestContext().put(com.sun.xml.ws.developer.JAXWSProperties.SSL_SOCKET_FACTORY, socketFactory);
// or ((BindingProvider) Service.getPort(SEIInterface.class)).getRequestContext().put(...);

And in MySocketFactory you are free to create sockets that will pipe the message to another channel.

When you say that you only need the XML, are you talking about the SOAP message or just the request/response types? I'm not sure if your are talking about the second case, but if you only wanted the XML, why not using JAXB directly?

If that's the case, you could extract the schemas from the WSDL, generate your types (let's say you have RequestA and ResponseA for an operation "A" in the WSDL) and use JAXB's marshaller/unmarshaller to serialize/parse the XML. Then send it through the protocol that you want.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!