[英]com.sun.xml.ws.client.ClientTransportException: request requires HTTP authentication: Unauthorized
I am trying to access a remote web service. 我正在尝试访问远程Web服务。 Am able to get good response from curl like this: 能够从如下所示的curl获得良好的响应:
curl -X POST -H "Content-Type: text/xml" -k -H "SOAPAction:getUserActivity" --data @testFile.dat https://esp-int.my.company.com:443/UsageService/13.11
But from java get error: 但是从java得到错误:
com.sun.xml.ws.client.ClientTransportException: request requires HTTP authentication: Unauthorized
Java sets up the security part of the request like this: Java这样设置请求的安全性部分:
String SECURITY_NAMESPACE = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";
QName securityQName = new QName(SECURITY_NAMESPACE, "Security");
SOAPElement security = soapFactory.createElement(securityQName);
QName usernameTokenQName = new QName(SECURITY_NAMESPACE, "UsernameToken");
SOAPElement usernameToken = soapFactory.createElement(usernameTokenQName);
QName usernameQName = new QName(SECURITY_NAMESPACE, "Username");
SOAPElement theUsername = soapFactory.createElement(usernameQName);
theUsername.addTextNode(username);
QName passwordQName = new QName(SECURITY_NAMESPACE, "Password");
SOAPElement thePassword = soapFactory.createElement(passwordQName);
thePassword.addTextNode(password);
usernameToken.addChildElement(theUsername);
usernameToken.addChildElement(thePassword);
security.addChildElement(usernameToken);
where username and password are the same as what's in testFile.dat. 用户名和密码与testFile.dat中的相同。
security part of testFile.dat request is: testFile.dat请求的安全性部分是:
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsu:Timestamp>
<wsu:Created>2016-02-19T16:36:21Z</wsu:Created>
<wsu:Expires>2016-02-19T16:41:21Z</wsu:Expires>
</wsu:Timestamp>
<wsse:UsernameToken>
<wsse:Username>username</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">password</wsse:Password>
<wsu:Created>2016-02-19T16:36:21Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
Any suggestions? 有什么建议么?
I had to add the following 2 lines when they changed the endpoint of their web service 当他们更改Web服务的端点时,我必须添加以下两行
QName pwdTypeQName = new QName("Type");
thePassword.addAttribute(pwdTypeQName, "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.