有没有办法手动或基于每个请求处理 SOAP 请求?由于现有系统中一些非常愚蠢的技术原因,我无法将 JAX-WS 服务发布到通过标准端点工厂创建的端点。我的情况有点困惑,因为我基本上从 ServerSocket 获得了一个原始的 InputStream 并被告知处理它。
流中的数据是从发出 SOAP 请求的客户端发送的。客户端的开发人员提供了一堆 WSDL 和 XSD,用于使用 wsimport 和 xjc 生成必要的服务器端类。所有这些都是 JAX-WS,我希望尽可能多地利用 JAX-WS 来最大限度地减少我必须做的工作。
有谁知道从哪里开始寻找如何做到这一点?有可能吗?目前我最好的猜测是我必须手动实现客户端点或提供商。
谢谢!
最佳答案
您可以通过以下步骤处理原始输入。只需像解析任何 XML 流一样解析传入消息
try{ //throws a bunch of XML parsing related exceptions
XMLInputFactory xFactory = XMLInputFactory.newFactory();
XMLStreamReader xStream = xFactory.createXMLStreamReader(req.getInputStream());
//Start skipping tags til you get to the message payload
for(int nodeCount=0; nodeCount < 3; nodeCount++){
xStream.nextTag(); //Jump <Envelope/>,<Body/>,<theMessageNode/>
}
//You're now at the level of the actual class; Now unmarshal the payload
JAXBContext ctxt = JAXBContext.newInstance(YourResponseClass.class);
Unmarshaller um = ctxt.createUnmarshaller();
JAXBElement<YourResponseClass.class> elem = um.unmarshal(xStream, YourResponseClass.class);
YourResponseClass theObj = elem.getValue();
}
catch(Exception ex) {
}
关于java - 手动处理 SOAP/JAX-WS 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15014080/