【问题标题】:JAX-WS Authentication SoapUI vs. Client applicationJAX-WS 身份验证 SoapUI 与客户端应用程序
【发布时间】:2018-01-24 06:52:21
【问题描述】:

我需要在 JBoss 上使用 JAX-WS 创建一个 SOAP 客户端。 问题是我无法通过身份验证。

我在 SoapUI 中实现了一个测试,当我设置请求属性用户名和密码 时,该测试有效

使用以下代码

        URL kbaURL = new URL("http://...");
        IkfzService ikfzService = new IkfzService(kbaURL);
        IkfzPortType ikfzPortType = ikfzService.getIkfzSOAP();
        Map<String, Object> requestContext = ((BindingProvider)ikfzPortType).getRequestContext();
        requestContext.put(BindingProvider.USERNAME_PROPERTY, "...");
        requestContext.put(BindingProvider.PASSWORD_PROPERTY, "...");

URL、用户名和密码与我得到的 SOAPUI 中的相同

javax.xml.ws.WebServiceException: org.apache.cxf.service.factory.ServiceConstructionException:
Failed to create service.
...
Caused by: javax.wsdl.WSDLException: WSDLException: faultCode=PARSER_ERROR: 
Problem parsing 'http://..'.: java.io.IOException: Server returned HTTP response code: 
401 for URL: http://..

我错过了什么?

【问题讨论】:

  • 您真的想使用URL kbaURL = new URL("http://..."); 作为您的 SOAP Web 服务端点吗?我认为Problem parsing 'http://.. 有点表明你是。 SOAP 端点“WSDL”应该设置为您在 SOAP-UI 中使用的那个

标签: security authentication soap jax-ws soapui


【解决方案1】:

这应该是您尝试完成的基本示例 - 如果您需要更多帮助或说明,请告诉我

//the WSDL/webservice endpoint
private static final String WSDL_URL = "http://localhost:8080/MyWebService/MyWebService?wsdl";

URL url = new URL(WSDL_URL);
QName qname = new QName("http://ws.mycompany.com/", MyWebServiceImpl");

Service theWSService = Service.create(url, qname);

//returns the interface for MyWebServiceImpl
TheWSServiceIF port = theWSService.getPort(TheWSServiceIF.class);

//Setup Security
Map<String, Object> requestContext = ((BindingProvider)port).getRequestContext();
requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, WS_URL);

Map<String, List<String>> requestHeaders = new HashMap<String, List<String>>();
requestHeaders.put("Username", Collections.singletonList("myUserName"));
requestHeaders.put("Password", Collections.singletonList("myPasword"));
requestContext.put(MessageContext.HTTP_REQUEST_HEADERS, headers);
/**********************************************************************/

//actually call the web service method, print results
System.out.println(port.getMyWebServiceData());

【讨论】:

  • 这个答案对汉斯有帮助吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-29
  • 2017-03-02
相关资源
最近更新 更多