通过SOAPHandler

时间:2017-08-28 05:26:19

标签: java web-services jax-ws mtom

我在独立服务器应用程序中发布了jax-ws服务。此服务使用mtom接收文档

正如在回答这个问题时所建议的那样:

Tracing XML request/responses with JAX-WS

我使用处理程序为服务进行肥皂消息记录,如下所示:

public boolean handleMessage(SOAPMessageContext smc){
    performLoggingActions(smc);
    return true;
}

记录器方法如下:

 private void performLoggingActions(SOAPMessageContext smc) {
   ByteArrayOutputStream bout = null;
   try {
       Boolean isOutBound = (Boolean) smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
       SOAPMessage message = smc.getMessage();
       //More stuff
    } catch (Exception e) {
        logger.error(String.format("Error in logSoapMessage! Error: %s ", e.getMessage()), e);
    } finally {
        IOUtils.closeQuietly(bout);
    }

}

当客户端发送有效请求时,日志记录没有问题。一切都按预期记录。

但是,如果我通过SOAP UI在请求中发送了无效的内容id,则日志记录在SOAPMessage message = smc.getMessage();我有以下错误:

Error in logSoapMessage! Error: No such MIME Part: Part=5 
java.lang.IllegalStateException: No such MIME Part: Part=5
    at com.sun.xml.internal.org.jvnet.mimepull.DataHead.read(DataHead.java:138)
    at com.sun.xml.internal.org.jvnet.mimepull.MIMEPart.read(MIMEPart.java:85)

问题是,当发生这种情况时,消息不会传播到服务级别,并且服务以低于以下的错误响应客户端:

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
   <S:Body>
      <S:Fault xmlns:ns4="http://www.w3.org/2003/05/soap-envelope">
         <faultcode>S:Server</faultcode>
         <faultstring>unexpected XML tag. expected: somenamespace but found: {http://www.w3.org/2004/08/xop/include}Include</faultstring>
      </S:Fault>
   </S:Body>
</S:Envelope>

当我禁用soap日志并发送错误请求时,消息将传播到服务级别,传播到@WebService注释类,并且在尝试读取mtom内容时会收到类似的信息。 但是,在这种情况下,错误会在响应中反映为错误字符串:

 <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
   <S:Body>
      <S:Fault xmlns:ns4="http://www.w3.org/2003/05/soap-envelope">
         <faultcode>S:Server</faultcode>
         <faultstring>No such MIME Part: Part=5</faultstring>
      </S:Fault>
   </S:Body>
</S:Envelope>

无论是否存在日志处理程序,我都会期待同样的错误。

正如您所看到的,我正在捕获日志记录处理程序中的所有异常,但服务响应会根据日志记录处理程序的存在而更改。

我做错了什么?我的要求是使用和不使用日志处理程序来获得相同的错误。

此致

编辑:添加了错误的整个堆栈跟踪:

Error in logSoapMessage! Error: No such MIME Part: Part=5 
java.lang.IllegalStateException: No such MIME Part: Part=5
    at com.sun.xml.internal.org.jvnet.mimepull.DataHead.read(DataHead.java:138)
    at com.sun.xml.internal.org.jvnet.mimepull.MIMEPart.read(MIMEPart.java:85)
    at com.sun.xml.internal.ws.encoding.MIMEPartStreamingDataHandler$StreamingDataSource.getInputStream(MIMEPartStreamingDataHandler.java:98)
    at com.sun.xml.internal.org.jvnet.staxex.Base64Data.get(Base64Data.java:315)
    at com.sun.xml.internal.org.jvnet.staxex.Base64Data.length(Base64Data.java:357)
    at com.sun.xml.internal.ws.encoding.MtomCodec$MtomXMLStreamReaderEx.getTextCharacters(MtomCodec.java:533)
    at com.sun.istack.internal.XMLStreamReaderToContentHandler.handleCharacters(XMLStreamReaderToContentHandler.java:244)
    at com.sun.istack.internal.XMLStreamReaderToContentHandler.bridge(XMLStreamReaderToContentHandler.java:155)
    at com.sun.xml.internal.ws.message.stream.StreamMessage.writePayloadTo(StreamMessage.java:375)
    at com.sun.xml.internal.ws.message.stream.StreamMessage.writeTo(StreamMessage.java:460)
    at com.sun.xml.internal.ws.message.AbstractMessageImpl.readAsSOAPMessage(AbstractMessageImpl.java:196)
    at com.sun.xml.internal.ws.handler.SOAPMessageContextImpl.getMessage(SOAPMessageContextImpl.java:82)
    at com.ibtech.smg.esb.jaxws.handler.JAXWSSOAPLoggingHandler.performLoggingActions(JAXWSSOAPLoggingHandler.java:54)
    at com.ibtech.smg.esb.jaxws.handler.JAXWSSOAPLoggingHandler.handleMessage(JAXWSSOAPLoggingHandler.java:36)
    at com.ibtech.smg.esb.jaxws.handler.JAXWSSOAPLoggingHandler.handleMessage(JAXWSSOAPLoggingHandler.java:1)
    at com.sun.xml.internal.ws.handler.HandlerProcessor.callHandleMessage(HandlerProcessor.java:295)
    at com.sun.xml.internal.ws.handler.HandlerProcessor.callHandlersRequest(HandlerProcessor.java:138)
    at com.sun.xml.internal.ws.handler.ServerSOAPHandlerTube.callHandlersOnRequest(ServerSOAPHandlerTube.java:136)
    at com.sun.xml.internal.ws.handler.HandlerTube.processRequest(HandlerTube.java:118)
    at com.sun.xml.internal.ws.api.pipe.Fiber.__doRun(Fiber.java:639)
    at com.sun.xml.internal.ws.api.pipe.Fiber._doRun(Fiber.java:598)
    at com.sun.xml.internal.ws.api.pipe.Fiber.doRun(Fiber.java:583)
    at com.sun.xml.internal.ws.api.pipe.Fiber.runSync(Fiber.java:480)
    at com.sun.xml.internal.ws.server.WSEndpointImpl$2.process(WSEndpointImpl.java:312)
    at com.sun.xml.internal.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:606)
    at com.sun.xml.internal.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:257)
    at com.sun.xml.internal.ws.transport.http.server.WSHttpHandler.handleExchange(WSHttpHandler.java:108)
    at com.sun.xml.internal.ws.transport.http.server.WSHttpHandler.handle(WSHttpHandler.java:93)
    at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:90)
    at sun.net.httpserver.AuthFilter.doFilter(AuthFilter.java:96)
    at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:93)
    at sun.net.httpserver.ServerImpl$Exchange$LinkHandler.handle(ServerImpl.java:690)
    at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:90)
    at sun.net.httpserver.ServerImpl$Exchange.run(ServerImpl.java:662)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1157)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:627)
    at java.lang.Thread.run(Thread.java:809)

1 个答案:

答案 0 :(得分:0)

您能否将整个堆栈跟踪和代码粘贴到SOAP处理程序中?这条线是否会在您的日志中打印出来?
logger.error(String.format("Error in logSoapMessage! Error: %s ", e.getMessage()), e);