开发者社区> 问答> 正文

Spring-WS Client-WebServiceTransportException:Spri

我试图编写SOAP Web服务客户端,并org.springframework.ws.client.WebServiceTransportException: Internal Server Error [500]在SpringBoot中调用SOAP WS客户端时出现错误。

请找到以下SOAP WS客户端:

SOAPConnector.java
@Service
public class SOAPConnector extends WebServiceGatewaySupport {

    @Value("${soap.mw.url}")
    String soapMwUrl;

    @Value("${soap.mw.username}")
    private String username;

    @Value("${soap.mw.password}")
    private String password;

    private static final String SCHEMA_PREFIX = "oas";

    public Object callWebService(Object request) {

        getWebServiceTemplate().setCheckConnectionForFault(false);

        return getWebServiceTemplate().marshalSendAndReceive(soapMwUrl, request, new WebServiceMessageCallback() {

            @Override
            public void doWithMessage(WebServiceMessage message) throws IOException, TransformerException {

                try {

                    SaajSoapMessage saajSoapMessage = (SaajSoapMessage) message;

                    saajSoapMessage.setSoapAction("/updateData");

                    SOAPMessage soapMessage = saajSoapMessage.getSaajMessage();
                    SOAPPart soapPart = soapMessage.getSOAPPart();
                    SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
                    SOAPHeader soapHeader = soapEnvelope.getHeader();

                    SOAPHeaderElement securityHeader = soapHeader
                            .addHeaderElement(new QName(Constants.SECURITY_NS, "Security", SCHEMA_PREFIX));
                    SOAPElement usernameToken = securityHeader.addChildElement("UsernameToken", SCHEMA_PREFIX);
                    SOAPElement usernameElement = usernameToken.addChildElement("Username", SCHEMA_PREFIX);
                    SOAPElement passwordElement = usernameToken.addChildElement("Password", SCHEMA_PREFIX);

                    usernameElement.setTextContent(username);
                    passwordElement.setTextContent(password);

                    securityHeader.setMustUnderstand(true);



                } catch (Exception e) {
                    throw new IOException("Error while adding authentication.");
                }
            }
        });
    }
}

错误:

org.springframework.ws.client.WebServiceTransportException: Internal Server Error [500]
        at org.springframework.ws.client.core.WebServiceTemplate.handleError(WebServiceTemplate.java:699)
        at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:609)
        at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:555)
        at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:390)
        ......SOAPConnector.callWebService(SOAPConnector.java:41)

有人可以帮忙吗?

展开
收起
垚tutu 2019-12-26 18:21:45 1337 0
0 条回答
写回答
取消 提交回答
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
Java Spring Boot开发实战系列课程【第15讲】:Spring Boot 2.0 API与Spring REST Docs实战 立即下载
Apache Dubbo3 源码深入解读 立即下载
Spring Cloud Alibaba - 重新定义 Java Cloud-Native 立即下载