public RBrokerEngine()

in src/main/java/com/revo/deployr/client/broker/engine/RBrokerEngine.java [113:198]


    public RBrokerEngine(RBrokerConfig brokerConfig) throws RBrokerException {

        this.brokerConfig = brokerConfig;

        /*
         * Validate DeployR server endpoint passed to RBroker.
         */
        try {
            /*
             * Test the /r/server/info endpoint, expect HTTP 200.
             */
            String serverInfoEndpoint = brokerConfig.deployrEndpoint +
                                        "/r/server/info?format=json";
            URLConnection urlConn =
                (new URL(serverInfoEndpoint)).openConnection();
            HttpsURLConnection trustedConn = null;

            if(brokerConfig.allowSelfSignedSSLCert &&
                    urlConn instanceof HttpsURLConnection) {

                /*
                 * Build a temporary TrustManager for this
                 * /r/server/info call that accepts self-signed SSL
                 * certificates for the purposes of this endpoint
                 * validation call.
                 */

                TrustManager[] selfTrustManager = new TrustManager[] {
                    new X509TrustManager() {
                        public java.security.cert.X509Certificate[] getAcceptedIssuers() { 
                            return null;
                        } 
                        public void checkClientTrusted( 
                            java.security.cert.X509Certificate[] certs, String authType) {
                        } 
                        public void checkServerTrusted( 
                            java.security.cert.X509Certificate[] certs, String authType) {
                        }
                    }
                };

                /*
                 * Install the custom TrustManager.
                 */
                SSLContext sc = SSLContext.getInstance("SSL");
                sc.init(null, selfTrustManager, new SecureRandom());
                SSLSocketFactory selfTrustSocketFactory = sc.getSocketFactory();
                HostnameVerifier selfTrustHostnameVerifier = new HostnameVerifier() {
                    public boolean verify(String hostname, SSLSession session) {
                        return true;
                    }
                };

                trustedConn = (HttpsURLConnection) urlConn;
                trustedConn.setSSLSocketFactory(selfTrustSocketFactory);
                trustedConn.setHostnameVerifier(selfTrustHostnameVerifier);

            }

            /*
             * Make endpoint connection, catch handles failure.
             */

            InputStream is = null;
            try {
                if(trustedConn != null)
                    is = trustedConn.getInputStream();
                else
                    is = urlConn.getInputStream();
            } finally {
                if(is != null) {
                    try {
                       is.close();
                    } catch(java.io.IOException ioex) {}
                }
            }

        } catch(Exception ex) {
            /*
             * Halt RBroker instance initialization,
             * report invalid DeployR server endpoint.
             */
           throw new RBrokerException("DeployR endpoint invalid=" +
                                                ex.getMessage(), ex);
        }
    }