Web Services 表示消息寻址属性的必需标头不存在

jecbmhm3  于 2022-11-15  发布在  其他
关注(0)|答案(3)|浏览(116)

我在SOAPUI中遇到此错误:

<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsa="http://www.w3.org/2005/08/addressing">
   <env:Header>
      <wsa:Action>http://www.w3.org/2005/08/addressing/fault</wsa:Action>
   </env:Header>
   <env:Body>
      <env:Fault>
         <faultcode>wsa:MessageAddressingHeaderRequired</faultcode>
         <faultstring>A required header representing a Message Addressing Property is not present</faultstring>
      </env:Fault>
   </env:Body>
</env:Envelope>

我在Java代码中使用了SoapHeader和SoapElement,因此代码的XML输出:

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
   <S:Header>
      <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
         <wsse:UsernameToken wsu:Id="UsernameToken">
            <wsse:Username>Username</wsse:Username>
            <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">Password</wsse:Password>
            <wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">...</wsse:Nonce>
            <wsu:Created>2016-05-07T11:57:03.821Z</wsu:Created>
         </wsse:UsernameToken>
      </wsse:Security>
   </S:Header>
   <S:Body>
      <ns2:getRequestDetail xmlns:ns2="http://xmlns.oracle.com/scheduler" xmlns:ns3="http://xmlns.oracle.com/scheduler/types">
         <ns2:requestId>37</ns2:requestId>
      </ns2:getRequestDetail>
   </S:Body>
</S:Envelope>

通常在SOAPUI中:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sch="http://xmlns.oracle.com/scheduler">
      <soapenv:Header>
      <wsse:Security soapenv:mustUnderstand="1"  xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
         <wsse:UsernameToken wsu:Id="UsernameToken">
            <wsse:Username>Username</wsse:Username>
            <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">Password</wsse:Password>
            <wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">...</wsse:Nonce>
            <wsu:Created>2016-05-07T11:57:03.821Z</wsu:Created>
         </wsse:UsernameToken>
      </wsse:Security>
   </soapenv:Header>
   <soapenv:Body>
      <sch:getRequestDetail>
         <sch:requestId>37</sch:requestId>
      </sch:getRequestDetail>
   </soapenv:Body>
</soapenv:Envelope>

我在java单元测试中遇到错误:

java.lang.ExceptionInInitializerError
    at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:107)
    at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:78)
    at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:135)
    at com.sun.proxy.$Proxy80.getRequestDetail(Unknown Source)
    at tr.com.basarimobile.common.test.EnterpriseSchedulerClientTest.getRequestDetailTest(EnterpriseSchedulerClientTest.java:34)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
    at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
    at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:254)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:89)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:193)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.lang.ClassCastException: com.sun.xml.bind.v2.runtime.JAXBContextImpl cannot be cast to com.sun.xml.internal.bind.api.JAXBRIContext
    at com.sun.xml.internal.ws.fault.SOAPFaultBuilder$1.run(SOAPFaultBuilder.java:570)
    at com.sun.xml.internal.ws.fault.SOAPFaultBuilder$1.run(SOAPFaultBuilder.java:566)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.xml.internal.ws.fault.SOAPFaultBuilder.createJAXBContext(SOAPFaultBuilder.java:565)
    at com.sun.xml.internal.ws.fault.SOAPFaultBuilder.<clinit>(SOAPFaultBuilder.java:555)
    ... 34 more

也许,XML代码之间的差异导致这个错误?
谢谢你们,

qq24tv8q

qq24tv8q1#

看来这是一个迟来的回应。我相信在标题中添加下面的内容应该会对你有所帮助。

<wsa:Action>http://....../{operationName}</wsa:Action>
    <wsa:To>http(s)://.../serviceName</wsa:To>
vcudknz3

vcudknz32#

我遇到了同样的异常,并添加(创建)了以下类,

public class SoapRequestHeaderModifier implements WebServiceMessageCallback {

    String action ="http://xxx.xxx.xx.x/PlayerServices/PlayerIntelligence/PlayerManagementService";
    String uri = "http://xxx.xxx.xx.x/PlayerServices/PlayerIntelligence/PlayerManagementService/SetCode";

    @Override
    public void doWithMessage(WebServiceMessage message) {
        SaajSoapMessage soapMessage = (SaajSoapMessage) message;
        SoapHeader soapHeader = soapMessage.getSoapHeader();

        QName wsaToQName = new QName("http://www.w3.org/2005/08/addressing", "To", "wsa");
        SoapHeaderElement wsaTo =  soapHeader.addHeaderElement(wsaToQName);
        wsaTo.setText(uri);

        QName wsaActionQName = new QName("http://www.w3.org/2005/08/addressing", "Action", "wsa");
        SoapHeaderElement wsaAction =  soapHeader.addHeaderElement(wsaActionQName);
    wsaAction.setText(action);
    }

}

并将其作为webServiceTemplate.marshalSendAndReceive()方法中的回调函数参数提供,帮助我解决了这个问题。

JAXBElement<T> response = (JAXBElement<BatchResponse>) webServiceTemplate
            .marshalSendAndReceive("url?wsdl", batchRequest,new 
SoapRequestHeaderModifier());

指的是Use SOAP 1.2 with WebServiceGatewaySupport in Spring

f0brbegy

f0brbegy3#

希望下面的回答可以帮助其他人面对主题行中的错误。通过将此元素添加到标题列表中解决了问题

<wsa:MessageID>uuid:d077a3a6-e63d-462f-a06f-db9e55a28350</wsa:MessageID>

uuid是一个随机的唯一数字,在SoapUI中,它是通过选中Randomly generate messageID选项来设置的,如所附的代码片段所示:

相关问题