gpt4 book ai didi

java - Apache CXF - 无法满足任何策略选择

转载 作者:搜寻专家 更新时间:2023-10-30 21:07:01 25 4
gpt4 key购买 nike

我正在尝试创建第 3 方 WS 的客户端。我的应用程序在 JBoss AS 6 上运行(带有 Apache CXF 2.3.1 堆栈)。我通过 wsconsume (wsdl2java) 生成了客户端代码。当我尝试连接到 WS 时出现异常:

No assertion builder for type http://schemas.microsoft.com/ws/06/2004/policy/http}BasicAuthentication registered. 
Exception in thread "main" org.apache.cxf.ws.policy.PolicyException: None of the policy alternatives can be satisfied.

WSDL 的授权部分如下所示:

<wsp:Policy wsu:Id="abc_ssl_policy">
<wsp:ExactlyOne>
<wsp:All>
<http:BasicAuthentication
xmlns:http="http://schemas.microsoft.com/ws/06/2004/policy/http" />
<sp:TransportBinding
xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
<wsp:Policy>
<sp:TransportToken>
<wsp:Policy>
<sp:HttpsToken RequireClientCertificate="false" />
</wsp:Policy>
</sp:TransportToken>
<sp:AlgorithmSuite>
<wsp:Policy>
<sp:Basic256 />
</wsp:Policy>
</sp:AlgorithmSuite>
<sp:Layout>
<wsp:Policy>
<sp:Strict />
</wsp:Policy>
</sp:Layout>
</wsp:Policy>
</sp:TransportBinding>
</wsp:All>
</wsp:ExactlyOne>
</wsp:Policy>

客户端代码:

@WebServiceClient(name = "Abc", 
wsdlLocation = "https://hiddendomain.com/abc/abc.svc?wsdl",
targetNamespace = "http://tempuri.org/")
public class Abc extends Service {

public final static URL WSDL_LOCATION;

public final static QName SERVICE = new QName("http://tempuri.org/", "Abc");
public final static QName AbcSsl = new QName("http://tempuri.org/", "abc_ssl");
static {

Authenticator.setDefault(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("user", "pas".toCharArray());
}

});

URL url = null;
try {
url = new URL("https://hiddendomain.com/abc/abc.svc?wsdl");

} catch (MalformedURLException e) {
java.util.logging.Logger.getLogger(DistrInfo.class.getName())
.log(java.util.logging.Level.INFO,
"Can not initialize the default wsdl from {0}", "...");
}
WSDL_LOCATION = url;
}

当我尝试获取管道时抛出异常:

    Client client = ClientProxy.getClient(port);
HTTPConduit con = (HTTPConduit) client.getConduit(); <- exception

我怀疑这是因为非标准的 MS 政策,我需要适当的拦截器来处理这个政策,但有人可以告诉我如何做吗?

我什至不知道,我应该把我的 HTTPS 凭据放在哪里进行身份验证(我无法获得管道)

最佳答案

当我使用这段代码时问题消失了:

import org.apache.cxf.endpoint.Client;
import org.apache.cxf.frontend.ClientProxy;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.apache.cxf.transport.http.HTTPConduit;

...

JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();

//factory.getInInterceptors().add(new LoggingInInterceptor());
//factory.getOutInterceptors().add(new LoggingOutInterceptor());

factory.setServiceClass(IAbc.class);
factory.setAddress("https://hiddendomain.com/abc/abc.svc/soap"); <- must be /soap there, otherwise 404

IAbc info = (IAbc) factory.create();

Client client = ClientProxy.getClient(info);
HTTPConduit http = (HTTPConduit) client.getConduit();

http.getAuthorization().setUserName("user");
http.getAuthorization().setPassword("pass");

String abc = info.abc();

关于java - Apache CXF - 无法满足任何策略选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12072500/

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