WebServiceTemplate SOAP client 500 issue

荒凉一梦 提交于 2021-01-29 05:29:48

问题


I have wsdl on this address: https://this.url.address/ws/soap/nameOfWSDLFileWithoutWSDLExtension.wsdl

And I create WebServiceTemplate to call one method. If I do it standard way, with generated classes it works fine. But I have 'Internal Server Error 500 ' when I try with WebServiceTemplate.

WebServiceTemplate webServiceTemplate = new WebServiceTemplate();
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setPackagesToScan("package.with.generated.classes");
webServiceTemplate.setMarshaller(marshaller);
webServiceTemplate.setUnmarshaller(marshaller);
webServiceTemplate.setDefaultUri(<soap:address location="https://this.url.address/ws/soap/nameOfWSDLFileWithoutWSDLExtension"/>);
MyRequest request = new MyRequest();
request.setRequest("someValue");
MyResponse response = (MyResponse ) webServiceTemplate.marshalSendAndReceive(request,new WebServiceMessageCallback() {

    @Override
    public void doWithMessage(WebServiceMessage message) {
        try {
            SoapHeader soapHeader = ((SoapMessage) message).getSoapHeader();
            DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
            Document doc = dBuilder.newDocument();

            Element rootElement = doc.createElementNS( "", "header");
            Element childElement = doc.createElementNS("", "myElement");
            childElement.setTextContent("myValue");
            rootElement.appendChild(childElement);
            doc.appendChild(rootElement);
            TransformerFactory tf = TransformerFactory.newInstance();
            Transformer t = tf.newTransformer();
            DOMSource source = new DOMSource(doc.getDocumentElement());
            t.transform(source, soapHeader.getResult());
        } catch (Exception e) {
            System.out.println("error during marshalling of the SOAP headers"+ e);
        }
    }
});

I printed what I have and the message seems fine.

message = SaajSoapMessage {http://some.page.com/some/thing}MyRequest

The header also seems fine.

header = <?xml version="1.0" encoding="UTF-8"?><header><myElement>myValue</myElement></header>

It works when I go standard way, with generated classes and soap port object and calling method 'myMethod' which is here in WSDL file:

<wsdl:portType name="MyServicePort">
<wsdl:operation name="MyMethod">
<wsdl:input message="tns:MyRequest" name="MyRequest"/>
<wsdl:output message="tns:MyResponse" name="MyResponse"/>
<wsdl:fault message="tns:MyFault" name="MyFault"/>
</wsdl:operation>
</wsdl:portType>

And the exception is:

org.springframework.ws.client.WebServiceTransportException: Internal Server Error [500]

I tried with, like here: SOAP web service call using WebServiceTemplate in SpringBoot client

webServiceTemplate.setCheckConnectionForFault(true);

But the same.

来源:https://stackoverflow.com/questions/62524093/webservicetemplate-soap-client-500-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!