<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Java Automation Client over SSL in Nuxeo Forum</title>
    <link>https://connect.hyland.com/t5/nuxeo-forum/java-automation-client-over-ssl/m-p/322221#M9222</link>
    <description>&lt;P&gt;Thank you Antoine!&lt;/P&gt;</description>
    <pubDate>Mon, 14 Jan 2013 15:03:42 GMT</pubDate>
    <dc:creator>Laurent_Doguin</dc:creator>
    <dc:date>2013-01-14T15:03:42Z</dc:date>
    <item>
      <title>Java Automation Client over SSL</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/java-automation-client-over-ssl/m-p/322220#M9221</link>
      <description>&lt;P&gt;This post is kind of a copy paste from this &lt;A href="http://javaskeleton.blogspot.fr/2010/07/avoiding-peer-not-authenticated-with.html"&gt;resource&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;If you're running nuxeo platform over https, you may face this exception the first time you try HttpAutomationClient, following the example provided in REST API documentation :&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;javax.net.ssl.SSLPeerUnverifiedException:
peer not authenticated&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Here is how i went through it and finally could have fun with AutomationClient :&lt;/P&gt;
&lt;P&gt;First, you need a wrapper class to update the HttpClient reference of your HttpAutomationClient :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.X509Certificate;

import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;

import org.apache.http.client.HttpClient;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.impl.client.DefaultHttpClient;

public class SSLClientWrapper {

    @SuppressWarnings("deprecation")
    public static HttpClient wrapClient(HttpClient client) {

        DefaultHttpClient clientReference = null;

        try {
            SSLContext context = SSLContext.getInstance("TLS");
            X509TrustManager trustManager = new X509TrustManager() {

                public void checkClientTrusted(X509Certificate[] xcs, String string) {
                }

                public void checkServerTrusted(X509Certificate[] xcs, String string) {
                }

                public X509Certificate[] getAcceptedIssuers() {
                    return null;
                }
            };
            context.init(null, new TrustManager[]{trustManager}, null);
            SSLSocketFactory socketFactory = new SSLSocketFactory(context);
            socketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
            ClientConnectionManager connectionManager = client.getConnectionManager();
            SchemeRegistry schemeRegistry = connectionManager.getSchemeRegistry();
            schemeRegistry.register(new Scheme("https", socketFactory, 443));
            clientReference = new DefaultHttpClient(connectionManager,client.getParams());
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();

        } catch (KeyManagementException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return clientReference;
    }
}
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then you just need to use the static method to update Nuxeo HttpAutomationClient HttpClient reference :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;        HttpAutomationClient client = new HttpAutomationClient("https://my-server.com/nuxeo/site/automation"); 
        SSLClientWrapper.wrapClient(client.http()); 
        Session session = client.getSession("user", "pass");
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(Of course you will need to update authentication with a correct user and password)&lt;/P&gt;
&lt;P&gt;Hope this helps,&lt;/P&gt;
&lt;P&gt;Antoine&lt;/P&gt;</description>
      <pubDate>Fri, 11 Jan 2013 12:28:38 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/java-automation-client-over-ssl/m-p/322220#M9221</guid>
      <dc:creator>Antoine_Cordier</dc:creator>
      <dc:date>2013-01-11T12:28:38Z</dc:date>
    </item>
    <item>
      <title>Re: Java Automation Client over SSL</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/java-automation-client-over-ssl/m-p/322221#M9222</link>
      <description>&lt;P&gt;Thank you Antoine!&lt;/P&gt;</description>
      <pubDate>Mon, 14 Jan 2013 15:03:42 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/java-automation-client-over-ssl/m-p/322221#M9222</guid>
      <dc:creator>Laurent_Doguin</dc:creator>
      <dc:date>2013-01-14T15:03:42Z</dc:date>
    </item>
    <item>
      <title>Re: Java Automation Client over SSL</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/java-automation-client-over-ssl/m-p/322222#M9223</link>
      <description>&lt;P&gt;Niceeeeeeee, got a badge&lt;/P&gt;</description>
      <pubDate>Fri, 18 Jan 2013 22:50:19 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/java-automation-client-over-ssl/m-p/322222#M9223</guid>
      <dc:creator>Antoine_Cordier</dc:creator>
      <dc:date>2013-01-18T22:50:19Z</dc:date>
    </item>
  </channel>
</rss>

