@Override
    public HttpResponse execute(HttpRequest request) throws BaasException {
        try {
            HttpURLConnection connection = openConnection(request.url);

            for (String name : request.headers.keySet()) {
                connection.addRequestProperty(name, request.headers.get(name));
            }
            setupConnectionForRequest(connection, request);
            connection.connect();

            int responseCode = -1;
            try {
                responseCode = connection.getResponseCode();
            } catch (IOException e) {
                responseCode = connection.getResponseCode();
            }
            Logger.info("Connection response received");
            if (responseCode == -1) {
                throw new IOException("Connection failed");
            }


            HttpResponse response = new HttpResponse(HttpResponse.HttpVersion.HTTP_1_1,responseCode,connection.getResponseMessage());

            response.setEntity(asEntity(connection));
            for (Map.Entry<String, List<String>> header : connection.getHeaderFields().entrySet()) {
                if (header.getKey() != null) {
//                    Header h = new BasicHeader(header.getKey(), header.getValue().get(0));
                    response.addHeader(header.getKey(),header.getValue().get(0));
                }
            }
            return response;
        } catch (IOException e) {
            throw new BaasIOException(e);
        }
    }
@ Override public HttpResponse execute ( HttpRequest request ) throws BaasException { try { HttpURLConnection connection = openConnection ( request . url ) ; for ( String name : request . headers . keySet ( ) ) { connection . addRequestProperty ( name , request . headers . get ( name ) ) ; } setupConnectionForRequest ( connection , request ) ; connection . connect ( ) ; int responseCode = - 1 ; try { responseCode = connection . getResponseCode ( ) ; } catch ( IOException e ) { responseCode = connection . getResponseCode ( ) ; } Logger . info ( "Connection response received" ) ; if ( responseCode == - 1 ) { throw new IOException ( "Connection failed" ) ; } HttpResponse response = new HttpResponse ( HttpResponse . HttpVersion . HTTP_1_1 , responseCode , connection . getResponseMessage ( ) ) ; response . setEntity ( asEntity ( connection ) ) ; for ( Map . Entry < String , List < String > > header : connection . getHeaderFields ( ) . entrySet ( ) ) { if ( header . getKey ( ) != null ) { response . addHeader ( header . getKey ( ) , header . getValue ( ) . get ( 0 ) ) ; } } return response ; } catch ( IOException e ) { throw new BaasIOException ( e ) ; } }
--------------------- Interface RestClient ---------------------