CXF throws None of the policy alternatives can be satisfied

蹲街弑〆低调 提交于 2019-12-23 03:52:14

问题


I am trying to write Java client for .NET web service using CXF but when calling "client.getConduit()", it throws Exception - org.apache.cxf.ws.policy.PolicyException: None of the policy alternatives can be satisfied. Please help!

Here is the code snippet-

    ServiceClass service = new ServiceClass();
    PortClass port = service.getPort(ServiceClass.class);
            Client client = ClientProxy.getClient(port); 
    HTTPConduit httpConduit = (HTTPConduit) client.getConduit(); 

    final HTTPClientPolicy httpClientPolicy = httpConduit.getClient();
    httpClientPolicy.setAllowChunking(false);
    httpClientPolicy.setAutoRedirect(true);

    final BindingProvider bindingProvider = (BindingProvider) port;
    final Map<String, Object> requestContext = bindingProvider.getRequestContext();

    final Credentials credentials = new NTCredentials(USERNAME, PASSWORD, "", DOMAIN);
    requestContext.put(Credentials.class.getName(), credentials);
            requestContext.put(AsyncHTTPConduit.USE_ASYNC, Boolean.TRUE);

Here is the ws policy snippet from wsdl -

    <wsp:Policy wsu:Id="httpsendpoint_policy">
    <wsp:ExactlyOne>
      <wsp:All>
        <http:NegotiateAuthentication 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>
        <wsaw:UsingAddressing />
      </wsp:All>
    </wsp:ExactlyOne>
  </wsp:Policy>

来源:https://stackoverflow.com/questions/36630212/cxf-throws-none-of-the-policy-alternatives-can-be-satisfied

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!