3

I have created SOAP client in pure java. Also I have implemented SOAPHandler to trace the SOAP requests and responses. But when I see the sysouts the header part is missing in the request. Note that I am calling an enterprise service and that requires a mandatory security header for the service to be called. I am getting proper response with my security header back in the response and also is being sysout. What could be the issue for blank header trace from SOAPHandler ? Below is my handler code:

public class SOAPLoggingHandler implements SOAPHandler<SOAPMessageContext> {

    private static final Logger log = LoggerFactory.getLogger(SOAPLoggingHandler.class);

    public boolean handleMessage(SOAPMessageContext context) {
        log.info("handleMessage");
        logToSystemOut(context);
        return true;
    }

    public boolean handleFault(SOAPMessageContext context) {
        log.info("SOAP Fault Occur");
        logToSystemOut(context);
        return true;
    }

    public void close(MessageContext context) {
        log.info("close");
    }

    public Set<QName> getHeaders() {
        log.info("getHeaders");
        return null;
    }

    protected void logToSystemOut(SOAPMessageContext smc) {
        final Boolean outboundProperty = (Boolean) smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
        final String message = !outboundProperty.booleanValue() ? "Web Service Response\n" : "Web Service Request\n";
        logMessage(smc, message);
    }

    protected void logToSystemOut(SOAPMessageContext smc, String message) {
        logMessage(smc, message);
    }

    private void logMessage(SOAPMessageContext smc, String message) {

        try {
            final ByteArrayOutputStream oStream = new ByteArrayOutputStream();
            final Transformer transformer = TransformerFactory.newInstance().newTransformer();
            transformer.setOutputProperty(OutputKeys.INDENT, "yes");
            transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
            transformer.transform(new DOMSource(smc.getMessage().getSOAPPart()), new StreamResult(oStream));
            oStream.close();
            log.info(message + new String(oStream.toByteArray()));
        } catch (final Exception e) {
            log.warn("Failed to log web service message", e);
        }
        //some custom logging going on below - could be ignored
        SomeLogger someLoggerObj = SomeLogger.getInstance();
        try {
            someLoggerObj.logSomeMessage(smc, message);
        } catch (SOAPException e) {
            log.error("SOAP Exception occurred :", e);
        } catch (TransformerException e) {
            log.error("TransformerException Exception occurred :", e);
        }
    }

}

My Header is seen as:

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
    <SOAP-ENV:Header/>
N Patil
  • 71
  • 1
  • 5

1 Answers1

0

I've experienced this week exactly the same issue, I have a chain of 5 SOAP calls with also TLS and SAML, and a mix of services implemented with AXIS and CXF, running aunder the same Tomcat 9 on OpenJDK 11. The issue happened only on production server (RedHat server) and I was not able to reproduce it on my development machine, the header was completely dropped by the java client and it was not possible to debug on the server.

I ended up installing on the target server a dedicated Tomcat 8.5 on JDK 1.8 to run CXF service separated from AXIS ones. Hope this helps if someone has such a complex configuration, it's not a solution but a workaround.

itomainu
  • 45
  • 1
  • 7