简体   繁体   English

com.sun.xml.ws.client.ClientTransportException:请求需要HTTP身份验证:未经授权

[英]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.

相关问题 com.sun.xml.ws.client.ClientTransportException:HTTP传输错误:java.lang.ClassCastException - com.sun.xml.ws.client.ClientTransportException: HTTP transport error: java.lang.ClassCastException Glassfish抛出com.sun.xml.ws.client.ClientTransportException:服务器发送了HTTP状态代码500:内部服务器错误 - Glassfish throws com.sun.xml.ws.client.ClientTransportException: The server sent HTTP status code 500: Internal Server Error 使用CXF从Java消耗Web服务会导致com.sun.xml.ws.client.ClientTransportException:服务器发送了HTTP状态代码200:确定 - Consuming webservice from java using CXF results in com.sun.xml.ws.client.ClientTransportException: The server sent HTTP status code 200: OK JAX WS com.sun.xml.internal.ws.client.ClientTransportException:HTTP 传输错误:java.net.ConnectException:连接被拒绝 - JAX WS com.sun.xml.internal.ws.client.ClientTransportException: HTTP transport error: java.net.ConnectException: Connection refused 线程“ main” com.sun.xml.internal.ws.client.ClientTransportException中的异常:服务器发送了HTTP状态代码502:代理错误 - Exception in thread “main” com.sun.xml.internal.ws.client.ClientTransportException: The server sent HTTP status code 502: Proxy Error com.sun.xml.internal.ws.client.ClientTransportException:HTTP传输错误:java.net.SocketException:连接重置 - com.sun.xml.internal.ws.client.ClientTransportException: HTTP transport error: java.net.SocketException: Connection reset 连接到 web 服务导致 com.sun.xml.internal.ws.client.ClientTransportException:服务器发送 HTTP 状态码 200 - Connecting to webservice results in com.sun.xml.internal.ws.client.ClientTransportException: The server sent HTTP status code 200: OK 导入com.sun.xml.internal.ws.client.ClientTransportException,无法读取此导入 - import com.sun.xml.internal.ws.client.ClientTransportException, can't read this import com.sun.xml.internal.ws.client 不存在 - com.sun.xml.internal.ws.client does not exist java.lang.NoSuchMethodError:com.sun.xml.ws.api.pipe.ClientTubeAssemblerContext.getPortInfo()Lcom / sun / xml / ws / api / client / WSPortInfo; - java.lang.NoSuchMethodError : com.sun.xml.ws.api.pipe.ClientTubeAssemblerContext.getPortInfo()Lcom/sun/xml/ws/api/client/WSPortInfo;
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM