Search in sources :

Example 36 with HttpHostConnectException

use of org.apache.http.conn.HttpHostConnectException in project lavaplayer by sedmelluq.

the class ExtendedConnectionOperator method connectWithDestination.

private boolean connectWithDestination(ConnectionSocketFactory socketFactory, HttpContext context, SocketConfig socketConfig, HttpHost host, InetSocketAddress localAddress, int connectTimeout, ManagedHttpClientConnection connection, InetSocketAddress remoteAddress, InetAddress[] addresses, boolean last) throws IOException {
    Socket socket = socketFactory.createSocket(context);
    configureSocket(socket, socketConfig);
    try {
        socket = socketFactory.connectSocket(connectTimeout, socket, host, remoteAddress, localAddress, context);
        connection.bind(socket);
        return true;
    } catch (final SocketTimeoutException ex) {
        if (last) {
            throw new ConnectTimeoutException(ex, host, addresses);
        }
    } catch (final ConnectException ex) {
        if (last) {
            final String msg = ex.getMessage();
            throw "Connection timed out".equals(msg) ? new ConnectTimeoutException(ex, host, addresses) : new HttpHostConnectException(ex, host, addresses);
        }
    } catch (final NoRouteToHostException ex) {
        if (last) {
            throw ex;
        }
    }
    return false;
}
Also used : SocketTimeoutException(java.net.SocketTimeoutException) HttpHostConnectException(org.apache.http.conn.HttpHostConnectException) NoRouteToHostException(java.net.NoRouteToHostException) Socket(java.net.Socket) ConnectTimeoutException(org.apache.http.conn.ConnectTimeoutException) HttpHostConnectException(org.apache.http.conn.HttpHostConnectException) ConnectException(java.net.ConnectException)

Example 37 with HttpHostConnectException

use of org.apache.http.conn.HttpHostConnectException in project tmdm-studio-se by Talend.

the class MDMServerMessageConsole method doMonitor.

private void doMonitor() {
    String monitorURL = buildMonitorURL(position);
    MessageConsoleStream errorMsgStream = newErrorMessageStream();
    InputStream is = null;
    BufferedReader br = null;
    MessageConsoleStream msgStream = null;
    InputStreamReader isr = null;
    try {
        HttpResponse response = executeByHttpget(monitorURL, serverDef.getUser(), serverDef.getPasswd());
        int code = response.getStatusLine().getStatusCode();
        if (HTTP_STATUS_OK == code) {
            modifyChunkedPosition(response);
            if (isEndOfChunk(response)) {
                return;
            }
            is = response.getEntity().getContent();
            msgStream = newMessageStream();
            isr = new InputStreamReader(is);
            br = new BufferedReader(isr);
            String line = null;
            while ((line = br.readLine()) != null) {
                msgStream.println(line);
            }
        } else {
            if (HTTP_STATUS_NO_ACCESS == code) {
                errorMsgStream.println(Messages.MDMServerMessageConsole_No_Acess_Message);
                disposeTimer();
            } else if (HTTP_STSTUS_FORBIDDEN == code) {
                errorMsgStream.println(Messages.MDMServerMessageConsole_Forbidden_Message);
                disposeTimer();
            } else if (HTTP_STATUS_NOT_FOUND == code) {
                errorMsgStream.println(Messages.MDMServerMessageConsole_NotConnected_Message);
                disposeTimer();
            }
        }
    } catch (HttpHostConnectException ex) {
        errorMsgStream.println(ex.getMessage());
        disposeTimer();
    } catch (IOException e) {
        LOG.error(e.getMessage(), e);
        errorMsgStream.println(e.getMessage());
        disposeTimer();
    } catch (SecurityException e) {
        errorMsgStream.println(e.getMessage());
    } finally {
        if (br != null) {
            try {
                br.close();
            } catch (IOException e) {
                LOG.error(e.getMessage(), e);
            }
        }
        if (isr != null) {
            try {
                isr.close();
            } catch (IOException e) {
                LOG.error(e.getMessage(), e);
            }
        }
        if (is != null) {
            try {
                is.close();
            } catch (IOException e) {
                LOG.error(e.getMessage(), e);
            }
        }
        if (msgStream != null) {
            try {
                msgStream.close();
            } catch (IOException e) {
                LOG.error(e.getMessage(), e);
            }
        }
        if (errorMsgStream != null) {
            try {
                errorMsgStream.close();
            } catch (IOException e) {
                LOG.error(e.getMessage(), e);
            }
        }
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) HttpHostConnectException(org.apache.http.conn.HttpHostConnectException) MessageConsoleStream(org.eclipse.ui.console.MessageConsoleStream) HttpResponse(org.apache.http.HttpResponse) IOException(java.io.IOException)

Aggregations

HttpHostConnectException (org.apache.http.conn.HttpHostConnectException)37 ConnectTimeoutException (org.apache.http.conn.ConnectTimeoutException)11 IOException (java.io.IOException)10 ConnectException (java.net.ConnectException)10 SocketTimeoutException (java.net.SocketTimeoutException)10 Socket (java.net.Socket)7 HttpResponse (org.apache.http.HttpResponse)6 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)6 LayeredSocketFactory (org.apache.http.conn.scheme.LayeredSocketFactory)6 Scheme (org.apache.http.conn.scheme.Scheme)6 Test (org.junit.Test)5 InputStream (java.io.InputStream)4 GenericUrl (com.google.api.client.http.GenericUrl)3 InetAddress (java.net.InetAddress)3 NoRouteToHostException (java.net.NoRouteToHostException)3 SocketException (java.net.SocketException)3 UnknownHostException (java.net.UnknownHostException)3 HttpEntity (org.apache.http.HttpEntity)3 HttpHost (org.apache.http.HttpHost)3 ClientProtocolException (org.apache.http.client.ClientProtocolException)3