You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Michael Hoffman <mi...@hotmail.com> on 2014/02/12 21:45:25 UTC

How to resolve PolicyException HttpURLConnection is not a HttpsURLConnection

A brief background of what I am trying to do. My company acts as a centralized mediator. I need to consume a WSDL from a third-party provider that uses aliasing for determining the correct endpoint: (https://company1....?wsdl, https://company2...?wsdl). I've created a dynamic client through CXF to support consumption. The code is below:
 
JaxWsDynamicClientFactory factory = JaxWsDynamicClientFactory.newInstance();
Client client = factory.createClient(wsdlURL, SERVICE_NAME);
ClientImpl clientImpl = (ClientImpl) client;
Endpoint endpoint = clientImpl.getEndpoint();
ServiceInfo serviceInfo = endpoint.getService().getServiceInfos().get(0);
BindingInfo bindingInfo = serviceInfo.getBinding(BINDING_NAME);
BindingOperationInfo bindingOperationInfo = bindingInfo
    .getOperation(GET_USER_OP_NAME);
BindingMessageInfo inputMessageInfo = bindingOperationInfo.getInput();
List<MessagePartInfo> parts = inputMessageInfo.getMessageParts();
MessagePartInfo partInfo = parts.get(0);
Class<?> partClass = partInfo.getTypeClass();
Object inputObject = partClass.newInstance();
// Add the objects to the inputObject
Map<String, Object> requestContext = client.getRequestContext();
requestContext.put("ws-security.username", "test@test.com");
requestContext.put("ws-security.password", "testPassword");
Object[] result = client.invoke(bindingOperationInfo, inputObject);

I am running a jUnit test case as well as running the client in a web container. In both cases, I get through to the client invoke, but fail out with a policy exception. 
 
2014-02-12 14:23:03,372 6797 [main] ERROR com.mycompany.ServiceClientExecutor - Assertion of type {http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702}HttpsToken could not be asserted: HttpURLConnection is not a HttpsURLConnection
org.apache.cxf.ws.policy.PolicyException: Assertion of type {http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702}HttpsToken could not be asserted: HttpURLConnection is not a HttpsURLConnection
 at org.apache.cxf.ws.security.policy.interceptors.HttpsTokenInterceptorProvider$HttpsTokenOutInterceptor.assertHttps(HttpsTokenInterceptorProvider.java:150)
 at org.apache.cxf.ws.security.policy.interceptors.HttpsTokenInterceptorProvider$HttpsTokenOutInterceptor.handleMessage(HttpsTokenInterceptorProvider.java:90)
 at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:262)
 at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:530)
 at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:463)
 at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:366)
 at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:319)
 
Looking through the trace, I assume I need to setup an HTTP conduit, but wanted to check to assure this was my issue. Any help is greatly appreciated.
 
Regards,
 
Michael Hoffman
 
 		 	   		  

RE: How to resolve PolicyException HttpURLConnection is not a HttpsURLConnection

Posted by Michael Hoffman <mi...@hotmail.com>.
A quick note to this. I added an HTTP conduit; however, the WSDL that I am using is based on an HTTPS URL; however, it then imports a WSDL for the definition parts, but that WSDL is HTTP. I think it may be confusing CXF to switch to HTTP. Anyone come across this type of scenario? 
 
From: mikevoxcap@hotmail.com
To: users@cxf.apache.org
Subject: How to resolve PolicyException HttpURLConnection is not a HttpsURLConnection
Date: Wed, 12 Feb 2014 14:45:25 -0600




A brief background of what I am trying to do. My company acts as a centralized mediator. I need to consume a WSDL from a third-party provider that uses aliasing for determining the correct endpoint: (https://company1....?wsdl, https://company2...?wsdl). I've created a dynamic client through CXF to support consumption. The code is below:
 
JaxWsDynamicClientFactory factory = JaxWsDynamicClientFactory.newInstance();
Client client = factory.createClient(wsdlURL, SERVICE_NAME);
ClientImpl clientImpl = (ClientImpl) client;
Endpoint endpoint = clientImpl.getEndpoint();
ServiceInfo serviceInfo = endpoint.getService().getServiceInfos().get(0);
BindingInfo bindingInfo = serviceInfo.getBinding(BINDING_NAME);
BindingOperationInfo bindingOperationInfo = bindingInfo
    .getOperation(GET_USER_OP_NAME);
BindingMessageInfo inputMessageInfo = bindingOperationInfo.getInput();
List<MessagePartInfo> parts = inputMessageInfo.getMessageParts();
MessagePartInfo partInfo = parts.get(0);
Class<?> partClass = partInfo.getTypeClass();
Object inputObject = partClass.newInstance();
// Add the objects to the inputObject
Map<String, Object> requestContext = client.getRequestContext();
requestContext.put("ws-security.username", "test@test.com");
requestContext.put("ws-security.password", "testPassword");
Object[] result = client.invoke(bindingOperationInfo, inputObject);

I am running a jUnit test case as well as running the client in a web container. In both cases, I get through to the client invoke, but fail out with a policy exception. 
 
2014-02-12 14:23:03,372 6797 [main] ERROR com.mycompany.ServiceClientExecutor - Assertion of type {http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702}HttpsToken could not be asserted: HttpURLConnection is not a HttpsURLConnection
org.apache.cxf.ws.policy.PolicyException: Assertion of type {http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702}HttpsToken could not be asserted: HttpURLConnection is not a HttpsURLConnection
 at org.apache.cxf.ws.security.policy.interceptors.HttpsTokenInterceptorProvider$HttpsTokenOutInterceptor.assertHttps(HttpsTokenInterceptorProvider.java:150)
 at org.apache.cxf.ws.security.policy.interceptors.HttpsTokenInterceptorProvider$HttpsTokenOutInterceptor.handleMessage(HttpsTokenInterceptorProvider.java:90)
 at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:262)
 at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:530)
 at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:463)
 at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:366)
 at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:319)
 
Looking through the trace, I assume I need to setup an HTTP conduit, but wanted to check to assure this was my issue. Any help is greatly appreciated.
 
Regards,
 
Michael Hoffman