Java 修改SOAP信封以包含名称空间
我有类似这样的SOAP响应Java 修改SOAP信封以包含名称空间,java,soap,jaxb,cxf,jax-ws,Java,Soap,Jaxb,Cxf,Jax Ws,我有类似这样的SOAP响应 <?xml version='1.0' encoding='UTF-8'?> <soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> <soapenv:Body> <calculate_response> <tid>33433</tid>
<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope
xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'>
<soapenv:Body>
<calculate_response>
<tid>33433</tid>
<status>0</status>
<reason>0</reason>
</calculate_response>
</soapenv:Body>
</soapenv:Envelope>
<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
xmlns:def="http://com.sample.xyz/Messages">
<soapenv:Body>
<def:calculate_response>
<tid>33433</tid>
<status>0</status>
<reason>0</reason>
</def:calculate_response>
</soapenv:Body>
</soapenv:Envelope>
33433
0
0
我需要向它添加名称空间,它应该是这样的
<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope
xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'>
<soapenv:Body>
<calculate_response>
<tid>33433</tid>
<status>0</status>
<reason>0</reason>
</calculate_response>
</soapenv:Body>
</soapenv:Envelope>
<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
xmlns:def="http://com.sample.xyz/Messages">
<soapenv:Body>
<def:calculate_response>
<tid>33433</tid>
<status>0</status>
<reason>0</reason>
</def:calculate_response>
</soapenv:Body>
</soapenv:Envelope>
xmlns:def=”http://com.sample.xyz/Messages">
33433
0
0
我已经使用wsimport
创建了存根,我需要在进一步处理之前修改此响应
实际上,正如我所理解的,这是一个两步的过程,第一步是向soap信封添加名称空间,然后向其添加前缀。
关于我找到的前缀部分。我不清楚如何做第一步
注意:我需要在客户端修改响应,而不能在服务器端更改SOAP。我是在
SOAP消息处理程序的帮助下实现的
我已经编写了handler
,它实现了SOAPHandler
并使用以下实现重写其handleMessage(SOAPMessageContext上下文){}
//Get soapElement from your soap request.
if (soapElement.getTagName().equalsIgnoreCase("calculate_response")) {
soapElement.setElementQName(
new QName("http://com.sample.xyz/Messages",
"calculate_response",
"def"));
为什么需要更改客户端的响应?您试图通过添加该名称空间来实现什么?实际上,soap客户端希望响应类型为{http://com.sample.xyz/Messages}计算\u响应
,因为它不是由服务器返回的,它恰好缺少名称空间。为什么不重新生成Soap客户端类,以便它们与服务器发送的响应相匹配?我确实使用了,我使用了来自服务器的wsdl、xsd来生成客户端类,但它期望的响应与服务器不返回的响应类似。