I am trying to setup a "slim" client for an existing, CXF-based web service.

While I see that using spring here is well documented and pretty
straight-forward, this does not seem to be the case for a spring-less
configuration.

Using what I found in an existing spring configuration for a working
example I have got this far:

URL wsdlLocation =
DCommand_Service.class.getClassLoader().getResource("XXX.wsdl");

QName serviceName = new QName("...", "...");

DCommand_Service svc = new XXX_Service(wsdlLocation, serviceName);

XXX xxx = svc.getWSHttpBindindXXX();

Client client = ClientProxy.getClient(xxx);
client.getRequestContext().put(Message.ENDPOINT_ADDRESS,
"http://myService/soap";) ;

HTTPConduit http = (HTTPConduit) client.getConduit();
HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
httpClientPolicy.setConnectionTimeout(3000000);
httpClientPolicy.setReceiveTimeout(3000000);
http.setClient(httpClientPolicy);

TLSClientParameters tlsClientParameters = new TLSClientParameters();
tlsClientParameters.setDisableCNCheck(true);
tlsClientParameters.setUseHttpsURLConnectionDefaultHostnameVerifier(true);
tlsClientParameters.setUseHttpsURLConnectionDefaultSslSocketFactory(true);
http.setTlsClientParameters(tlsClientParameters);

AuthorizationPolicy authorization = new AuthorizationPolicy();
authorization.setUserName("");
authorization.setPassword("");
http.setAuthorization(authorization);


Using the above code I've setup a TestNG integration test against the
server code running on a jetty in background.
When I use this code in my TestNG's beforeClass() method, I am now
getting this kind of error:

org.apache.cxf.ws.policy.PolicyException: Assertion of type
{http://schemas.xmlsoap.org/ws/2005/07/securitypolicy}HttpsToken could
not be asserted: Not an HTTPs connection
        at 
org.apache.cxf.ws.security.policy.interceptors.HttpsTokenInterceptorProvider$HttpsTokenOutInterceptor.assertHttps(HttpsTokenInterceptorProvider.java:198)
~[cxf-rt-ws-security-3.0.4.jar:3.0.4]
        at 
org.apache.cxf.ws.security.policy.interceptors.HttpsTokenInterceptorProvider$HttpsTokenOutInterceptor.handleMessage(HttpsTokenInterceptorProvider.java:135)
~[cxf-rt-ws-security-3.0.4.jar:3.0.4]
        at 
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307)
~[cxf-core-3.0.4.jar:3.0.4]
        at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:516)
[cxf-core-3.0.4.jar:3.0.4]
        at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:425)
[cxf-core-3.0.4.jar:3.0.4]
        at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:326)
[cxf-core-3.0.4.jar:3.0.4]
        at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:279)
[cxf-core-3.0.4.jar:3.0.4]
        at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:96)
[cxf-rt-frontend-simple-3.0.4.jar:3.0.4]
        at 
org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:138)
[cxf-rt-frontend-jaxws-3.0.4.jar:3.0.4]
        at com.sun.proxy.$Proxy51.executeCommand(Unknown Source) [na:na]
[...]

Having gone through the CXF code (I forgot to mention that this is
pretty much the first time I deal with CXF) I found that for a
requester the default policy is "HttpsToken:true", which is pretty
easy to reconfigure in XML code, but I have found no clue how to do
that in Java code.

The point is that I need to create a client library in which I should
ideally be able to provide a simple API for configuring this kind of
thing (while now I simply don't get my code running because I just
don't know at all how to change the default without spring). In the
end one should be able to configure the client for both use with http
and https (that's why I have played around with the
TLSClientParameters above).

Could anybody provide me a simple piece of Java code showing what to
do to override the default for HttpsToken here?

I'd greatly appreciate any help here, since this has really got
frustrating after several hours of searching the web and debugging...

Cheers,

Martin

-- 
---------- [email protected] --/-- [email protected] ----
------------- / http://herbert.the-little-red-haired-girl.org / -------------

Reply via email to