简体   繁体   English

缺少soap请求java中的标头

[英]missing header in soap request java

I have created SOAP client in pure java.我已经用纯 Java 创建了 SOAP 客户端。 Also I have implemented SOAPHandler to trace the SOAP requests and responses.我还实现了 SOAPHandler 来跟踪 SOAP 请求和响应。 But when I see the sysouts the header part is missing in the request.但是当我看到 sysouts 时,请求中缺少标头部分。 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.我在响应中得到了安全标头的正确响应,并且正在被 sysout。 What could be the issue for blank header trace from SOAPHandler ?来自 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/>

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.本周我遇到了完全相同的问题,我有 5 个带有 TLS 和 SAML 的 SOAP 调用链,以及使用 AXIS 和 CXF 实现的混合服务,在 OpenJDK 11 上的相同 Tomcat 9 下运行。该问题仅发生在生产服务器(RedHat 服务器)上,我无法在我的开发机器上重现它,头文件完全被 java 客户端删除,无法在服务器上调试。

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.我最终在目标服务器上安装了 JDK 1.8 上的专用 Tomcat 8.5,以运行与 AXIS 服务分离的 CXF 服务。 Hope this helps if someone has such a complex configuration, it's not a solution but a workaround.如果有人有如此复杂的配置,希望这会有所帮助,这不是解决方案,而是一种解决方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM