我试图编写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)
有人可以帮忙吗?
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。