我需要编写一个消息处理程序。我正在学习本教程https://www.mkyong.com/webservices/jax-ws/jax-ws-soap-handler-in-server-side/。
我创建了我的处理程序并将其用作我的服务实现类,如
@Component(value = "AccountValidationsoapImpl")
@WebService(endpointInterface = "com.abc.validation.api.IAccountValidationService")
@HandlerChain(file = "./handler/handler.xml")
public class AccountValidationSOAPImpl implements IAccountValidationService
我的handler.xml是
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<javaee:handler-chains
xmlns:javaee="http://java.sun.com/xml/ns/javaee"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<javaee:handler-chain>
<javaee:handler>
<javaee:handler-class>com.abc.validation.api.handler.WSHandler</javaee:handler-class>
</javaee:handler>
</javaee:handler-chain>
</javaee:handler-chains>
我运行我的应用程序并发送SOAP请求,但我从未看到我的处理程序被调用。
我的handler.xml和WSHandler都存在于com.abc.validation.api.handler中 而web服务类存在于com.abc.validation.api包中。我错过了什么?
我的WSHandler
public class WSHandler implements SOAPHandler<SOAPMessageContext>{
@Override
public boolean handleMessage(SOAPMessageContext context) {
System.out.println("Server : handleMessage()......");
return true;
}
@Override
public boolean handleFault(SOAPMessageContext context) {
System.out.println("Server : handleFault()......");
return true;
}
@Override
public void close(MessageContext context) {
System.out.println("Server : close()......");
}
@Override
public Set<QName> getHeaders() {
System.out.println("Server : getHeaders()......");
return null;
}
private void generateSOAPErrMessage(SOAPMessage msg, String reason) {
try {
SOAPBody soapBody = msg.getSOAPPart().getEnvelope().getBody();
SOAPFault soapFault = soapBody.addFault();
soapFault.setFaultString(reason);
throw new SOAPFaultException(soapFault);
}
catch(SOAPException e) { }
}
}