如何在Java中向我的soap请求添加标头?

时间:2019-10-16 12:29:16

标签: java soap

我试图将两个标头添加到我的soap请求中,但是在调用该SOAP WS时遇到错误。

com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl:com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl:消息发送失败。

下面是我要添加标头的代码和SOAP请求。
有人可以让我知道我要去哪里了吗?

我曾尝试从SOAP UI调用WS,以提供标头及其正常工作。

private SOAPMessage createSOAPRequest(String request) throws Exception {

        MessageFactory messageFactory = MessageFactory.newInstance();
        InputStream stream = new 
        ByteArrayInputStream(request.getBytes(StandardCharsets.UTF_8));

        SOAPMessage soapMessage = messageFactory.createMessage(new MimeHeaders(), stream);
        soapMessage.getMimeHeaders().addHeader("Authorization", "Auth_value");
        soapMessage.getMimeHeaders().addHeader("Header1", "header_value1");

        }
        soapMessage.saveChanges();
        return soapMessage;
    }   

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:prov="http://abc/ProvisioningServiceMessages">
   <soapenv:Header/>
   <soapenv:Body>
     <prov:RetrieveRequest>
     <prov:KeyPropertyLookup>
        <prov1:NodeType xmlns:prov1="http://abc/ProvisioningServiceMessages">ABC</prov1:NodeType>
        <prov1:PropertyName xmlns:prov1="http://abc/ProvisioningServiceMessages">DEF</prov1:PropertyName>
        <prov1:PropertyValue xmlns:prov1="http://abc/ProvisioningServiceMessages">12345</prov1:PropertyValue>
     </prov:KeyPropertyLookup>
     <prov:Projections>
        <prov:IncludeChildren>true</prov:IncludeChildren>
     </prov:Projections>
     </prov:RetrieveRequest>
   </soapenv:Body>
</soapenv:Envelope>

0 个答案:

没有答案