简体   繁体   中英

Spring Boot Server did not recognize the value of HTTP Header SOAPAction

I'm trying to consume this web-service but I'm getting SoapExeption .

Below is my method for sending the request. How can I fix this issue in Spring boot?

public class CalcClient extends WebServiceGatewaySupport {

    private static final Logger LOGGER = LoggerFactory.getLogger(CalcClient.class);
    private ObjectFactory objectFactory;

    @Autowired
    public void setObjectFactory(ObjectFactory objectFactory) {
        this.objectFactory = objectFactory;
    }

    public JAXBElement<AddResponse> sendAndReceive() {
        Add request = objectFactory.createAdd();
        request.setIntA(12);
        request.setIntB(12);
        LOGGER.info("Sending request");
        JAXBElement<AddResponse> response = (JAXBElement<AddResponse>) getWebServiceTemplate().marshalSendAndReceive("http://www.dneonline.com/calculator.asmx", request);
        return response;
    }
}

I had the same issue accessing this service, You'll get an error for trying to bind AddResponse to JAXBElement . You need to set your soapAction in your code, like below using WebServiceMessageCallback

public AddResponse sendAndReceive() {
    Add request = objectFactory.createAdd();
    request.setIntA(12);
    request.setIntB(12);
    LOGGER.info("Sending request");
    AddResponse response = (AddResponse) getWebServiceTemplate().marshalSendAndReceive("http://www.dneonline.com/calculator.asmx", request, new WebServiceMessageCallback() {
        @Override
        public void doWithMessage(WebServiceMessage webServiceMessage) throws IOException, TransformerException {
            ((SoapMessage)webServiceMessage).setSoapAction("http://tempuri.org/Add");
        }
    });
    return response;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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