我想用 SOAPHandler 处理 SOAP 标头,即我已经创建了 SOAPHandler,但是如何将其插入指定的服务?换句话说,这个处理程序应该处理这个服务的消息。可能我需要使用一些注释或xml配置......?..
问问题
1627 次
1 回答
0
这可以通过以下步骤来完成。
1.定义处理程序
public class CalculatorSOAPHandlerOne implements SOAPHandler<SOAPMessageContext> {
private static final Logger logger = LoggerFactory.getLogger(CalculatorSOAPHandlerOne.class);
@Override
public Set<QName> getHeaders() {
return null;
}
@Override
public boolean handleMessage(SOAPMessageContext context) {
if(!(Boolean)context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY)){
logger.info(" soap message passed through CalculatorSOAPHandlerOne (only for request)");
}
return true;
}
@Override
public boolean handleFault(SOAPMessageContext context) {
return true;
}
@Override
public void close(MessageContext context) {
}
}
2.在XML中声明处理程序链声明(handler-chain.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.chathurangaonline.jaxws.samples.handler.CalculatorSOAPHandlerOne</javaee:handler-class>
</javaee:handler>
<javaee:handler>
</javaee:handler-chain>
</javaee:handler-chains>
3. 为 JAX-WS 服务实现添加处理程序链
@WebService
@HandlerChain(file = "handler-chain.xml")
public class CalculatorService{
private static final Logger logger = LoggerFactory.getLogger(CalculatorServiceImpl.class);
@Override
public double add(double num1, double num2) {
logger.info("== calling add method ==");
return num1 + num2;
}
@Override
public double multiply(double num1, double num2) {
return num1 * num2;
}
}
于 2015-02-08T15:52:59.757 回答