Search in sources :

Example 16 with HttpHostConnectException

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

the class RestClient method executePostRequest.

private int executePostRequest(String apiURI, UrlEncodedFormEntity entity) {
    try {
        HttpPost postRequest = new HttpPost(bonitaURI + apiURI);
        postRequest.setEntity(entity);
        HttpResponse response = httpClient.execute(postRequest, httpContext);
        return consumeResponse(response, true);
    } catch (HttpHostConnectException e) {
        throw new RuntimeException("Bonita bundle may not have been started, or the URL is invalid. Please verify hostname and port number. URL used is: " + BONITA_URI, e);
    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) HttpHostConnectException(org.apache.http.conn.HttpHostConnectException) HttpResponse(org.apache.http.HttpResponse) ClientProtocolException(org.apache.http.client.ClientProtocolException) HttpHostConnectException(org.apache.http.conn.HttpHostConnectException) IOException(java.io.IOException)

Example 17 with HttpHostConnectException

use of org.apache.http.conn.HttpHostConnectException in project sling by apache.

the class SimpleHttpDistributionTransport method retrievePackage.

@Nullable
public RemoteDistributionPackage retrievePackage(@Nonnull ResourceResolver resourceResolver, @Nonnull DistributionRequest distributionRequest, @Nonnull DistributionTransportContext distributionContext) throws DistributionException {
    log.debug("pulling from {}", distributionEndpoint.getUri());
    try {
        URI distributionURI = RequestUtils.appendDistributionRequest(distributionEndpoint.getUri(), distributionRequest);
        Executor executor = getExecutor(distributionContext);
        // TODO : add queue parameter
        InputStream inputStream = HttpTransportUtils.fetchNextPackage(executor, distributionURI, httpConfiguration);
        if (inputStream == null) {
            return null;
        }
        try {
            final DistributionPackage responsePackage = packageBuilder.readPackage(resourceResolver, inputStream);
            responsePackage.getInfo().put(PACKAGE_INFO_PROPERTY_ORIGIN_URI, distributionURI);
            log.debug("pulled package with info {}", responsePackage.getInfo());
            return new DefaultRemoteDistributionPackage(responsePackage, executor, distributionURI);
        } finally {
            IOUtils.closeQuietly(inputStream);
        }
    } catch (HttpHostConnectException e) {
        log.debug("could not connect to {} - skipping", distributionEndpoint.getUri());
    } catch (Exception ex) {
        log.error("cannot retrieve packages", ex);
    }
    return null;
}
Also used : DistributionPackage(org.apache.sling.distribution.packaging.DistributionPackage) AbstractDistributionPackage(org.apache.sling.distribution.packaging.impl.AbstractDistributionPackage) Executor(org.apache.http.client.fluent.Executor) InputStream(java.io.InputStream) HttpHostConnectException(org.apache.http.conn.HttpHostConnectException) URI(java.net.URI) DistributionException(org.apache.sling.distribution.common.DistributionException) HttpHostConnectException(org.apache.http.conn.HttpHostConnectException) RecoverableDistributionException(org.apache.sling.distribution.common.RecoverableDistributionException) HttpResponseException(org.apache.http.client.HttpResponseException) Nullable(javax.annotation.Nullable)

Aggregations

HttpHostConnectException (org.apache.http.conn.HttpHostConnectException)17 ConnectException (java.net.ConnectException)6 Socket (java.net.Socket)6 LayeredSocketFactory (org.apache.http.conn.scheme.LayeredSocketFactory)6 Scheme (org.apache.http.conn.scheme.Scheme)6 HttpResponse (org.apache.http.HttpResponse)4 ConnectTimeoutException (org.apache.http.conn.ConnectTimeoutException)4 InputStream (java.io.InputStream)3 InetAddress (java.net.InetAddress)3 SocketException (java.net.SocketException)3 HttpGet (org.apache.http.client.methods.HttpGet)3 PlainSocketFactory (org.apache.http.conn.scheme.PlainSocketFactory)3 SocketFactory (org.apache.http.conn.scheme.SocketFactory)3 IOException (java.io.IOException)2 URI (java.net.URI)2 HttpEntity (org.apache.http.HttpEntity)2 ClientProtocolException (org.apache.http.client.ClientProtocolException)2 HttpResponseException (org.apache.http.client.HttpResponseException)2 Executor (org.apache.http.client.fluent.Executor)2 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)2