我使用Java7和JAX-WS开发了一个SOAP Web服务。这是界面的摘录:
@WebService(name = "MyWebService",
targetNamespace = "http://www.something.com")
@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
public interface MyWebServiceInterface
{
@WebMethod(operationName = "handleMsg",
action = "handleMsg")
@Oneway
void handleMsg(@WebParam(name = "MessageHeader",
targetNamespace = "http://www.something.com",
header = true,
partName = "header")
MessageHeader header,
@WebParam(name = "MessageBody",
targetNamespace = "http://www.soemthing.com",
partName = "body")
MessageType body);
}
我已经为这个Web服务实现了一个自定义SOAP处理程序(它工作正常)来做一些额外的事情。在方法handleFault(..)
中,我需要访问Web方法的原始MessageHeader
(请参阅上面的界面)。怎么办呢?
public class MyHandler implements SOAPHandler<SOAPMessageContext>
{
// ...
@Override
public boolean handleFault(final SOAPMessageContext context)
{
final Boolean outbound =
( Boolean ) context.get( MessageContext.MESSAGE_OUTBOUND_PROPERTY );
// handle only incoming message which do have a message set
if ( outbound != null && !outbound.booleanValue() && context.getMessage() != null )
{
MessageHeader header =
getOriginalHeaderOfFautlyMessage(); // <-- how can this be done?
}
}
}
答案 0 :(得分:1)
SOAPMessage soapMsg = context.getMessage();
SOAPEnvelope soapEnv = soapMsg.getSOAPPart().getEnvelope();
SOAPHeader soapHeader = soapEnv.getHeader();
然后你必须提取你的标题节点并取消编组。