首页 > 解决方案 > SOAP 请求消息头无法记录

问题描述

我有一个工作肥皂客户端代码发送请求并获得响应。但是当我尝试使用soap处理程序将我的请求记录到数据库时,标题部分没有出现,并且我收到以下消息。

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
    <SOAP-ENV:Header/> //missing part
    <S:Body>
        "bla bla bla"
    </S:Body>
</S:Envelope>

我的消息处理程序是,

@Override
    public boolean handleMessage(SOAPMessageContext context) {
        Boolean isRequest = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
        SOAPMessage message = context.getMessage();     
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        try {
            message.writeTo(out);
        } catch (SOAPException | IOException e) {
            e.printStackTrace();
        }
        if (isRequest) {
            MyLogService.saveResponse(logRefNo, "", "", "", "", "", "", "", out.toByteArray());
        } else {
            MyLogService.saveResponse(logRefNo, "", "", out.toByteArray());
        }
        return true;
    }

我期待在 DB 中看到完整的请求标头,例如;

<s:Header>
     <o:Security s:mustUnderstand=1 xmlns:o=http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd>
            <o:UsernameToken u:Id=uuid-0df61a7941-1436-41157-8368-d1c85c01d6cac31-1>
                <o:Username>?</o:Username>
                <o:Password Type=http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText>?</o:Password>
            </o:UsernameToken>
        </o:Security>
</s:Header>

标签: xmlspring-bootsoapsoapheadersoaphandler

解决方案


推荐阅读