4

我想使用一个使用 CXF 保护的网络服务。(http://host:port/test/ws?wsdl)。下面是我的代码。但它给出了下面给出的例外。在 SoapUI 中,我测试了 web 服务。我在“aut”选项卡下的 SoapUI 中提供了凭据。它正在工作。您能告诉我如何使用 CXF 使用安全的 Web 服务吗?

ProcessService proxy = new ProcessService(wsdlURL, SERVICE_NAME);       
try {       
  IProcessService port = proxy.getBinding1IProcessService();
  Client client = ClientProxy.getClient(port);
  HTTPConduit http = (HTTPConduit) client.getConduit();
  http.getAuthorization().setUserName("username");
  http.getAuthorization().setPassword("password");


  System.out.println("Result=" + port.startReturnDDCStatusForAC(""));
} catch (Exception e) {
 e.printStackTrace();
}

例外:

 Okt 09, 2012 7:23:50 PM org.apache.cxf.service.factory.ReflectionServiceFactoryBean buildServiceFromWSDL
    INFO: Creating Service {http://tempuri.org/}ProcessService from WSDL: http://sn000333.tauri.ch:61527/WS/Process?wsdl
    Okt 09, 2012 7:24:02 PM org.apache.cxf.ws.policy.AssertionBuilderRegistryImpl handleNoRegisteredBuilder
    WARNING: No assertion builder for type {http://schemas.microsoft.com/ws/06/2004/policy/http}BasicAuthentication registered.
    org.apache.cxf.ws.policy.PolicyException: None of the policy alternatives can be satisfied.
        at org.apache.cxf.ws.policy.EndpointPolicyImpl.chooseAlternative(EndpointPolicyImpl.java:165)
        at org.apache.cxf.ws.policy.EndpointPolicyImpl.finalizeConfig(EndpointPolicyImpl.java:145)
        at org.apache.cxf.ws.policy.EndpointPolicyImpl.initialize(EndpointPolicyImpl.java:141)
        at org.apache.cxf.ws.policy.PolicyEngineImpl.createEndpointPolicyInfo(PolicyEngineImpl.java:549)
        at org.apache.cxf.ws.policy.PolicyEngineImpl.getEndpointPolicy(PolicyEngineImpl.java:295)
        at org.apache.cxf.ws.policy.PolicyEngineImpl.getClientEndpointPolicy(PolicyEngineImpl.java:278)
        at org.apache.cxf.ws.policy.PolicyDataEngineImpl.getClientEndpointPolicy(PolicyDataEngineImpl.java:61)
        at org.apache.cxf.transport.http.HTTPConduit.updateClientPolicy(HTTPConduit.java:318)
        at org.apache.cxf.transport.http.HTTPConduit.<init>(HTTPConduit.java:303)
        at org.apache.cxf.transport.http.HTTPTransportFactory.getConduit(HTTPTransportFactory.java:250)
        at org.apache.cxf.binding.soap.SoapTransportFactory.getConduit(SoapTransportFactory.java:228)
        at org.apache.cxf.binding.soap.SoapTransportFactory.getConduit(SoapTransportFactory.java:235)
        at org.apache.cxf.endpoint.AbstractConduitSelector.getSelectedConduit(AbstractConduitSelector.java:103)
        at org.apache.cxf.endpoint.UpfrontConduitSelector.selectConduit(UpfrontConduitSelector.java:77)
        at org.apache.cxf.endpoint.ClientImpl.getConduit(ClientImpl.java:842)
        at com.test.TestWS.main(TestWS.java:66)

SOAPUI 测试:

在 aut tab 下,我在下面给出了详细信息,它正在工作。授权类型:抢占用户名:用户名密码:密码

4

1 回答 1

0

也许您可以尝试通过扩展HttpBasicAuthSupplier并覆盖getPreemptiveUserPass来制作自己的MyBasicAuthSupplier。然后,您可以使用setAuthSupplier方法将新类的实例设置为HTTPConduit

这可能会更有用。

http://alvinalexander.com/java/jwarehouse/apache-cxf/rt/transports/http/src/test/java/org/apache/cxf/transport/http/HTTPConduitTest.java.shtml

干杯。

于 2012-10-10T08:08:18.407 回答