我已经使用处理程序解决了它。可以将处理程序添加到 webservices.xml 文件中,如下所示
<webservice-description>
<webservice-description-name>XXXXXXXXXXXX</webservice-description-name>
<wsdl-file>WEB-INF/wsdl/XXXXXXXXXXXXX.wsdl</wsdl-file>
<jaxrpc-mapping-file>WEB-INF/XXXXXXXXXXX.xml</jaxrpc-mapping-file>
<port-component>
<port-component-name>XXXXXXXXXX</port-component-name>
<wsdl-port xmlns:pfx="http://XXXXX">pfx:XXXXX</wsdl-port>
<service-endpoint-interface>XXXXXXXXX</service-endpoint-interface>
<service-impl-bean>
<servlet-link>XXXXXXXXXXXX</servlet-link>
</service-impl-bean>
**<handler id="Handler_1066493401322">
<handler-name>com.a.b.ResponseHandler</handler-name>
<handler-class>com.a.b.ResponseHandler</handler-class>
</handler>**
</port-component>
</webservice-description>
Handler 类应该重写 handleResponse() 方法来拦截响应
import java.util.Date;
import java.util.Iterator;
import javax.xml.namespace.QName;
import javax.xml.rpc.handler.GenericHandler;
import javax.xml.rpc.handler.HandlerInfo;
import javax.xml.rpc.handler.MessageContext;
import javax.xml.rpc.handler.soap.SOAPMessageContext;
import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPHeader;
import javax.xml.soap.SOAPMessage;
import org.w3c.dom.NodeList;
import com.ibm.ws.webcontainer.srt.SRTServletResponse;
public class ResponseHandler extends GenericHandler {
protected HandlerInfo info = null;
public boolean handleResponse(MessageContext context) {
try {
SOAPMessageContext smc = (SOAPMessageContext) context;
SOAPMessage message = smc.getMessage();
SOAPBody sb = message.getSOAPBody();
NodeList nl = sb.getChildNodes();
nl= sb.getChildNodes().item(0).getChildNodes().item(0).getChildNodes();
String responseValue = nl.item(0).getNodeValue();
System.out.println("Received response value is"+ responseValue);
if("1".equals(responseValue))
{
System.out.println(" Setting the response value to true");
nl.item(0).setNodeValue("true");
}
else
{
System.out.println(" Setting the response value to false");
nl.item(0).setNodeValue("false");
}
} catch (Exception x) {
// insert error handling here
x.printStackTrace();
}
return true;
}
/* (non-Javadoc)
* @see javax.xml.rpc.handler.Handler#getHeaders()
*/
public QName[] getHeaders() {
return info.getHeaders();
}
public void init(HandlerInfo arg) {
info = arg;
}
public void destroy() {
}
}