0

I have a jax-ws service published in a standalone server application. This service uses mtom to receive documents

As advised in the answer to this question:

Tracing XML request/responses with JAX-WS

I use a handler for soap message logging for the service as below:

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

The logger method is as below:

 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);
    }

}

When client sends a valid request, there is no problem in logging. Everything is logged as expected.

However, if I send an invalid content id in request via SOAP UI, the logging fails in line SOAPMessage message = smc.getMessage(); and I have the below error:

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)

The problem is, when this occurs, the message does not propogate to service level and the service responds to the client with below fault:

<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>

When I disable soap logging and send a fault request, the message is propagated to service level, to the @WebService annotated class, and I receive a similar expection when trying to read the mtom content. However, in that case the error is reflected in the response as fault string:

 <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>

I would expect the same fault regardless of the existence of the logging handler.

As you can see, I am catching all exceptions in logging handler but the service response changes according to the existence of the logging handler.

I am doing something wrong? My requirement is getting the same fault with and without logging handler.

Regards

EDIT : Entire stack trace of the error added:

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)
simpleusr
  • 354
  • 4
  • 23

1 Answers1

0

Could you please paste the entire stack trace and the code in your SOAP handler? Is this line getting printed in your logs?
logger.error(String.format("Error in logSoapMessage! Error: %s ", e.getMessage()), e);

Gautam
  • 564
  • 2
  • 12
  • I have added the entire stack trace . As you can see the line you mentione d is printed . The exception occurs from line SOAPMessage message = smc.getMessage(); – simpleusr Aug 28 '17 at 06:16
  • Just add `throw e` to your catch block and see. That should throw back the original exception to the client. – Gautam Aug 28 '17 at 06:22
  • Hi, I already thought that option but public boolean handleMessage(C context) method in javax.xml.ws.handler.Handler interface does not allow exceptions to be thrown... – simpleusr Aug 28 '17 at 06:29
  • Ah! Yes, it does not. But still this stacktrace doesn't really tell what is eating up that original exception. You're not printing this stakctrace so what is? Is there a caused by clause in the stack trace? Please look at that to see what is. If possible, please paste that part of stack trace too. It might be going into your Sysout/Syserr files, if not in your log file. – Gautam Aug 28 '17 at 06:42
  • Oh wait! Just remembered, you should return false from handler when Exception occurs. And you can throw SOAPFaultException, that's a runtime exception.. – Gautam Aug 28 '17 at 06:47
  • Returning false from handler later results in http 200 ok without reachişng implementation class. Below error is written to log java.lang.IllegalStateException: The current event is not START_ELEMENT but 4 at com.sun.xml.internal.ws.util.xml.XMLStreamReaderToXMLStreamWriter.bridge(XMLStreamReaderToXMLStreamWriter.java:96) at com.sun.xml.internal.ws.message.stream.StreamMessage.writePayloadTo(StreamMessage.java:311) at com.sun.xml.internal.ws.message.stream.StreamMessage.writeEnvelope(StreamMessage.java:341) at – simpleusr Aug 29 '17 at 13:27
  • Throw SOAPFaultException from handler instead of returning false, successfully. I should have edited that comment earlier, but got stuck in work. Sorry for that. – Gautam Aug 30 '17 at 04:09