On Tuesday, October 25, 2011 4:23:39 PM sdoca sdoca wrote:
> Hi,
>
> Here's a snippet of the code I'm testing:
>
> WebClient webClient = WebClient.create(this.serviceURL,
> this.username,
> this.password,
> null); // Spring config file - we don't use this
>
> if (trustAllCerts)
> {
> HTTPConduit conduit = WebClient.getConfig(webClient)
> .getHttpConduit();
>
> TLSClientParameters params = conduit.getTlsClientParameters();
>
> params.setTrustManagers(new TrustManager[] { new
> DumbX509TrustManager() }); params.setDisableCNCheck(true);
> }
>
> Unfortunately, the params retreived from the conduit is null. What creates
> the TLSClientParameters? Maybe I'm calling this method too soon?
If there isn't any configuration that would specify it, it would be null.
Just do:
TLSClientParameters params = conduit.getTlsClientParameters();
if (params == null) {
params = new TLSClientParameters();
conduit.setTlsClientParameters(params);
}
.....
Dan
>
> Thanks!
>
> ----- Original Message -----
> From: Sergey Beryozkin <[email protected]>
> Date: Tuesday, October 25, 2011 5:23 am
> Subject: Re: CXF RESTful Client - How to do trust all certs?
> To: [email protected]
>
> > Hi
> >
> > I haven't tried configurinh HTTPS from the code yet, but given [1]
> >
> > it will probably look something like this:
> >
> > WebClient wc = WebClient.create(address);
> > HttpConduit conduit =
> > WebClient.getClient(wc).getConfig().getHttpConduit();TLSClientParameters
> > params = conduit.getTlsClientParameters();
> >
> > and then set relevant properties as per [1].
> > I will add a test later on, can't do today
> >
> > Cheers, Sergey
> >
> > [1]
> > http://cxf.apache.org/javadoc/latest/org/apache/cxf/configuration/jsse/T
> > LSClientParameters.html>
> > On 24/10/11 22:43, sdoca sdoca wrote:
> > >Hi,
> > >
> > >I have written Jersey RESTful clients that made use of a Dumb
> >
> > X509TrustManager and a HostnameVerifier to trust all SSL certs
> > on our lab systems to make it easier to deal with certs that are
> > self-signed.
> >
> > > ClientConfig
> >
> > config = new DefaultClientConfig();
> >
> > > SSLContext
> >
> > context = null;
> >
> > > try
> > > {
> > > context = SSLContext.getInstance("SSL");
> > > context.init(null,
> > > new TrustManager[] { new DumbX509TrustManager()
> > >},
> > > null);
> > > config.getProperties()
> > > .put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES,
> > > new
> > >HTTPSProperties(this.getHostnameVerifier(), context));
> > > webClient = Client.create(config);
> > > }
> > > ....
> > >
> > >Is there a way for me to do something similar using CXF?
> > >
> > >Thanks!
> >
> > >(please note that I have also posted this on StackOverflow:
> > http://stackoverflow.com/questions/7881122/cxf-restful-client-
> > how-to-do-trust-all-certs)
--
Daniel Kulp
[email protected]
http://dankulp.com/blog
Talend - http://www.talend.com