gpt4 book ai didi

web-services - 使用 CXF 的 Java 抢占式身份验证 Web 服务消耗

转载 作者:行者123 更新时间:2023-12-01 06:38:48 24 4
gpt4 key购买 nike

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

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();
}

异常(exception):
 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 选项卡下,我提供了以下详细信息并且它正在工作。
授权类型:抢占式
用户名:用户名
密码:密码

最佳答案

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

这可能会更有用。

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

干杯。

关于web-services - 使用 CXF 的 Java 抢占式身份验证 Web 服务消耗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12805427/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com