/**
 * Copyright 2014 Telefonica Investigación y Desarrollo, S.A.U <br>
 * This file is part of FI-WARE project.
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
 * the License.
 * </p>
 * <p>
 * You may obtain a copy of the License at:<br>
 * <br>
 * http://www.apache.org/licenses/LICENSE-2.0
 * </p>
 * <p>
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * </p>
 * <p>
 * See the License for the specific language governing permissions and limitations under the License.
 * </p>
 * <p>
 * For those usages not covered by the Apache version 2.0 License please contact with opensource@tid.es
 * </p>
 */

package com.telefonica.euro_iaas.sdc.client.services.impl;

import java.security.SecureRandom;
import java.security.cert.X509Certificate;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;

import com.telefonica.euro_iaas.sdc.client.services.SdcClientConfig;

/**
 * SDC client configuration.
 */
public class SdcClientConfigImp implements SdcClientConfig {

    private HostnameVerifier hostnameVerifier;
    private SSLContext stx;

    /**
     * constructor.
     */
    public SdcClientConfigImp() {

        hostnameVerifier = new HostnameVerifier() {

            public boolean verify(String arg0, SSLSession arg1) {
                return true;
            }
        };

        javax.net.ssl.TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
            public X509Certificate[] getAcceptedIssuers() {
                return null;
            }

            public void checkClientTrusted(X509Certificate[] certs, String authType) {
            }

            public void checkServerTrusted(X509Certificate[] certs, String authType) {
            }
        } };

        try {
            stx = SSLContext.getInstance("TLS");
            stx.init(null, trustAllCerts, new SecureRandom());


            HttpsURLConnection.setDefaultSSLSocketFactory(stx.getSocketFactory());
        } catch (Exception e) {
            System.out.println("SdcClientConfigImp:" + e);
        }

    }

    /**
     * Build a valid client with ssl configured.
     * 
     * @return Rest Client
     */
    public Client getClient() {



        return ClientBuilder.newBuilder().sslContext(getStx()).hostnameVerifier(getHostnameVerifier()).build();
    }

    public HostnameVerifier getHostnameVerifier() {
        return hostnameVerifier;
    }

    public SSLContext getStx() {
        return stx;
    }

}

@@ -1277,16 +1277,74 @@
 ilder;%0A%0A
+import org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A%0A
 import c
@@ -1580,16 +1580,100 @@
 t stx;%0A%0A
+    private static Logger log = LoggerFactory.getLogger(SdcClientConfigImp.class);%0A%0A
     /**%0A
@@ -2456,17 +2456,16 @@
 om());%0A%0A
-%0A
         
@@ -2587,46 +2587,40 @@
     
-System.out.println(%22SdcClientConfigImp
+log.error(%22Error configuring SSL
 :%22 +
@@ -2734,32 +2734,32 @@
  Client%0A     */%0A
+
     public Clien
@@ -2775,18 +2775,16 @@
 nt() %7B%0A%0A
-%0A%0A
         

remove system.out