Spring-WS client not setting SOAPAction header

后端 未结 3 1191
迷失自我
迷失自我 2020-12-08 08:08

I\'m sending a SOAP request and the server is complaining that the SOAPAction header is empty. I think I\'m setting it right, but obviously I\'m not. Wireshark shows it\'s

3条回答
  •  情书的邮戳
    2020-12-08 08:55

    Another walk-around is to add an interceptor and set the soapAction within the handleRequest() method that inbound receives the MessageContext from which the SoapMessage can be derived;

    after that you can easily set the soapAction invoking the setSoapAction() method.

    here is the code of the interceptor class:

    public class SecurityInterceptor implements ClientInterceptor {
    
        @Override
        public boolean handleRequest(MessageContext messageContext) throws WebServiceClientException {
    
            SoapMessage soapMessage = (SoapMessage) messageContext.getRequest();
            soapMessage.setSoapAction("mySoapAction");    
    
            return true;
        }
    
        //TODO:: other methods and constructor..
    }
    

    and of course add the interceptor to the WebTemplate:

    WebServiceTemplate webServiceTemplate = new WebServiceTemplate(marshaller);
    ClientInterceptor[] interceptors = new ClientInterceptor[]{new SecurityInterceptor(parameters)};
    webServiceTemplate.setInterceptors();
    webServiceTemplate.marshalSendAndReceive(uriWebService, request)
    

提交回复
热议问题