Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
711 views
in Technique[技术] by (71.8m points)

java - Apache CXF - None of the policy alternatives can be satisfied

I'm trying to create client of 3rd party WS. My app is running on JBoss AS 6 (with its Apache CXF 2.3.1 stack). I generated client code by wsconsume (wsdl2java). When I tried to connect to WS a got exception:

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.

Auth part of WSDL looks like:

<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>

Client code:

@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;
}

Exception is thrown whe I try get Conduit:

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

I suspect that is because of non-standard MS policy and I need proper Intercerptor to handle this policy, but can somebody show me a way how to do it?

I dont even no, where I should put my HTTPS credentials to auth (I can't get conduit)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The problem gone when I used this code:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...