users@jersey.java.net

Re: [Jersey] Jersey Client with https

From: Julio Faerman <jfaerman_at_gmail.com>
Date: Thu, 27 Nov 2008 08:48:33 -0200

Yes, but i think you have to hande hostname and certificate verification.
For now, i am skipping this. Code pasted.


                HostnameVerifier hv = new HostnameVerifier() {
                        @Override
                        public boolean verify(String hostname, SSLSession session) {
                                System.out.println("Warning: URL Host: " + hostname + " vs. "
                                                + session.getPeerHost());
                                return true;
                        }
                };
                HttpsURLConnection.setDefaultHostnameVerifier(hv);
                try {
                        // Create a trust manager that does not validate certificate chains
                        TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
                                public void checkClientTrusted(
                                                java.security.cert.X509Certificate[] certs,
                                                String authType) {
                                }

                                public void checkServerTrusted(
                                                java.security.cert.X509Certificate[] certs,
                                                String authType) {
                                }

                                public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                                        return null;
                                }
                        } };

                        // Install the all-trusting trust manager
                        SSLContext sc = SSLContext.getInstance("SSL");

                        sc.init(null, trustAllCerts, new java.security.SecureRandom());
                        
                        HttpsURLConnection
                                        .setDefaultSSLSocketFactory(sc.getSocketFactory());

                } catch (Exception ex) {
                        throw new RuntimeException(ex);
                }


On Wed, Nov 26, 2008 at 2:52 PM, Paul Sandoz <Paul.Sandoz_at_sun.com> wrote:
>
> On Nov 26, 2008, at 5:49 PM, Paul Sandoz wrote:
>
>>
>> On Nov 26, 2008, at 5:14 PM, Robert Naczinski wrote:
>>
>>> Hi,
>>>
>>> can I use jersey client with SSL ( URL starts with 'http')?
>>>
>>
>> The URL scheme has to be "https" for HTTP-based secured by SSL.
>>
>> So if you use a URL say "https://host/path" it should work, since the
>> Jersey client API defers to HttpURLConnection that supports the https
>> scheme.
>>
>
> That should read:
>
> since the Jersey client API defers to HttpsURLConnection that supports the
> https scheme.
>
> via:
>
> URL.openConnection()
>
> Paul.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
>