Example usage for org.apache.commons.httpclient HttpStatus SC_REQUEST_TIMEOUT

List of usage examples for org.apache.commons.httpclient HttpStatus SC_REQUEST_TIMEOUT

Introduction

In this page you can find the example usage for org.apache.commons.httpclient HttpStatus SC_REQUEST_TIMEOUT.

Prototype

int SC_REQUEST_TIMEOUT

To view the source code for org.apache.commons.httpclient HttpStatus SC_REQUEST_TIMEOUT.

Click Source Link

Document

<tt>408 Request Timeout</tt> (HTTP/1.1 - RFC 2616)

Usage

From source file:org.colombbus.tangara.net.TConnection.java

private String executeMethod(HttpMethod method) throws CommandException {
    int statusCode = 0;
    try {/*from w  w w .  j  ava  2s . c  o  m*/
        statusCode = getClient().executeMethod(method);
        if (statusCode == HttpStatus.SC_REQUEST_TIMEOUT) {
            LOG.warn("Request timeout");
        }
        if (statusCode != HttpStatus.SC_OK) {
            String msg = "Method failed: " + method.getStatusLine(); //$NON-NLS-1$
            LOG.error(msg);
            throw new IOException(msg);
        }

        InputStream in = method.getResponseBodyAsStream();
        byte[] buffer = IOUtils.toByteArray(in);

        String response = new String(buffer, encodingCharset);
        if (LOG.isDebugEnabled()) {
            LOG.debug("Response content:\n" + response);
        }
        return response;
    } catch (HttpException httpEx) {
        String msg = String.format("An HTTP error occurs during the " + //$NON-NLS-1$
                "execution of the method %s. The returned HTTP code is %d", //$NON-NLS-1$
                method.getPath(), statusCode);
        LOG.error(msg, httpEx);
        throw CommandExceptionFactory.createCommunicationException(method, CommandException.HTTP_ERR, msg,
                httpEx);
    } catch (IOException ioEx) {
        String msg = String.format("An IO communication error occurs during the execution of the method %s.",
                method.getPath());
        LOG.error(msg, ioEx);
        throw CommandExceptionFactory.createCommunicationException(method, CommandException.HTTP_ERR, msg,
                ioEx);
    } catch (Throwable th) {
        String msg = String.format("An unknown error occurs during the execution of the method %s",
                method.getPath());
        LOG.error(msg, th);
        throw CommandExceptionFactory.createCommunicationException(method, CommandException.HTTP_ERR, msg, th);

    }
}

From source file:org.opens.tanaguru.util.http.HttpRequestHandler.java

private int computeStatus(int status) {
    switch (status) {
    case HttpStatus.SC_FORBIDDEN:
    case HttpStatus.SC_METHOD_NOT_ALLOWED:
    case HttpStatus.SC_BAD_REQUEST:
    case HttpStatus.SC_UNAUTHORIZED:
    case HttpStatus.SC_PAYMENT_REQUIRED:
    case HttpStatus.SC_NOT_FOUND:
    case HttpStatus.SC_NOT_ACCEPTABLE:
    case HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED:
    case HttpStatus.SC_REQUEST_TIMEOUT:
    case HttpStatus.SC_CONFLICT:
    case HttpStatus.SC_GONE:
    case HttpStatus.SC_LENGTH_REQUIRED:
    case HttpStatus.SC_PRECONDITION_FAILED:
    case HttpStatus.SC_REQUEST_TOO_LONG:
    case HttpStatus.SC_REQUEST_URI_TOO_LONG:
    case HttpStatus.SC_UNSUPPORTED_MEDIA_TYPE:
    case HttpStatus.SC_REQUESTED_RANGE_NOT_SATISFIABLE:
    case HttpStatus.SC_EXPECTATION_FAILED:
    case HttpStatus.SC_INSUFFICIENT_SPACE_ON_RESOURCE:
    case HttpStatus.SC_METHOD_FAILURE:
    case HttpStatus.SC_UNPROCESSABLE_ENTITY:
    case HttpStatus.SC_LOCKED:
    case HttpStatus.SC_FAILED_DEPENDENCY:
    case HttpStatus.SC_INTERNAL_SERVER_ERROR:
    case HttpStatus.SC_NOT_IMPLEMENTED:
    case HttpStatus.SC_BAD_GATEWAY:
    case HttpStatus.SC_SERVICE_UNAVAILABLE:
    case HttpStatus.SC_GATEWAY_TIMEOUT:
    case HttpStatus.SC_HTTP_VERSION_NOT_SUPPORTED:
    case HttpStatus.SC_INSUFFICIENT_STORAGE:
        return 0;
    case HttpStatus.SC_CONTINUE:
    case HttpStatus.SC_SWITCHING_PROTOCOLS:
    case HttpStatus.SC_PROCESSING:
    case HttpStatus.SC_OK:
    case HttpStatus.SC_CREATED:
    case HttpStatus.SC_ACCEPTED:
    case HttpStatus.SC_NON_AUTHORITATIVE_INFORMATION:
    case HttpStatus.SC_NO_CONTENT:
    case HttpStatus.SC_RESET_CONTENT:
    case HttpStatus.SC_PARTIAL_CONTENT:
    case HttpStatus.SC_MULTI_STATUS:
    case HttpStatus.SC_MULTIPLE_CHOICES:
    case HttpStatus.SC_MOVED_PERMANENTLY:
    case HttpStatus.SC_MOVED_TEMPORARILY:
    case HttpStatus.SC_SEE_OTHER:
    case HttpStatus.SC_NOT_MODIFIED:
    case HttpStatus.SC_USE_PROXY:
    case HttpStatus.SC_TEMPORARY_REDIRECT:
        return 1;
    default:/*from w  ww  .  jav  a2 s .  c o  m*/
        return 1;
    }
}

From source file:org.wso2.appcloud.integration.test.utils.clients.ApplicationClient.java

public void stopApplicationRevision(String applicationName, String applicationRevision, String versionHash)
        throws Exception {
    List<NameValuePair> nameValuePairs = new ArrayList<>();
    nameValuePairs.add(new BasicNameValuePair(PARAM_NAME_ACTION, STOP_APPLICATION_ACTION));
    nameValuePairs.add(new BasicNameValuePair(PARAM_NAME_APPLICATION_NAME, applicationName));
    nameValuePairs.add(new BasicNameValuePair(PARAM_NAME_APPLICATION_REVISION, applicationRevision));
    nameValuePairs.add(new BasicNameValuePair(PARAM_NAME_VERSION_KEY, versionHash));
    HttpResponse response = doPostRequest(this.endpoint, nameValuePairs);

    if (response.getResponseCode() != HttpStatus.SC_OK
            && response.getResponseCode() != HttpStatus.SC_REQUEST_TIMEOUT) {
        throw new AppCloudIntegrationTestException("Application stop failed " + response.getData());
    }/*ww  w .java2 s  .c o m*/
}

From source file:org.wso2.appcloud.integration.test.utils.clients.ApplicationClient.java

public void startApplicationRevision(String applicationName, String applicationRevision, String versionHash)
        throws Exception {
    List<NameValuePair> nameValuePairs = new ArrayList<>();
    nameValuePairs.add(new BasicNameValuePair(PARAM_NAME_ACTION, START_APPLICATION_ACTION));
    nameValuePairs.add(new BasicNameValuePair(PARAM_NAME_APPLICATION_NAME, applicationName));
    nameValuePairs.add(new BasicNameValuePair(PARAM_NAME_APPLICATION_REVISION, applicationRevision));
    nameValuePairs.add(new BasicNameValuePair(PARAM_NAME_VERSION_KEY, versionHash));
    HttpResponse response = doPostRequest(this.endpoint, nameValuePairs);

    if (response.getResponseCode() != HttpStatus.SC_OK
            && response.getResponseCode() != HttpStatus.SC_REQUEST_TIMEOUT) {
        throw new AppCloudIntegrationTestException("Application start failed " + response.getData());
    }/*from   w  w  w.  j a va  2  s  .c om*/
}

From source file:org.wso2.appcloud.integration.test.utils.clients.ApplicationClient.java

public boolean deleteApplication(String applicationHashId) throws Exception {
    List<NameValuePair> nameValuePairs = new ArrayList<>();
    nameValuePairs.add(new BasicNameValuePair(PARAM_NAME_ACTION, DELETE_APPLICATION_ACTION));
    nameValuePairs.add(new BasicNameValuePair(PARAM_NAME_APPLICATION_HASH_ID, applicationHashId));
    HttpResponse response = doPostRequest(this.endpoint, nameValuePairs);

    if (response.getResponseCode() == HttpStatus.SC_OK && response.getData().equals("true")) {
        return true;
    } else if (response.getResponseCode() == HttpStatus.SC_REQUEST_TIMEOUT) {
        //todo: check if application is there yet
        return true;
    } else {//w  ww  . java2 s .  c  o  m
        throw new AppCloudIntegrationTestException("Application deletion failed " + response.getData());
    }
}

From source file:org.wso2.appcloud.integration.test.utils.clients.ApplicationClient.java

public void deleteVersion(String versionKey) throws Exception {
    List<NameValuePair> nameValuePairs = new ArrayList<>();
    nameValuePairs.add(new BasicNameValuePair(PARAM_NAME_ACTION, DELETE_REVISION_ACTION));
    nameValuePairs.add(new BasicNameValuePair(PARAM_NAME_VERSION_KEY, versionKey));
    HttpResponse response = doPostRequest(this.endpoint, nameValuePairs);

    if (response.getResponseCode() != HttpStatus.SC_OK
            && response.getResponseCode() != HttpStatus.SC_REQUEST_TIMEOUT) {
        throw new AppCloudIntegrationTestException("Delete Application Version failed " + response.getData());
    }//w  w  w .  j  av  a 2  s  . c  o m
}

From source file:org.wso2.appcloud.integration.test.utils.clients.BaseClient.java

public HttpResponse doPostRequest(String endpoint, List<NameValuePair> nameValuePairs)
        throws AppCloudIntegrationTestException {
    HttpClient httpclient = null;//from  w ww  .  j  a  v  a2 s .c  o m
    int timeout = (int) AppCloudIntegrationTestUtils.getTimeOutPeriod();
    try {
        httpclient = HttpClients.custom().setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE).build();
        RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(timeout)
                .setConnectTimeout(timeout).build();
        HttpPost httppost = new HttpPost(endpoint);
        httppost.setConfig(requestConfig);

        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        httppost.setHeader(HEADER_COOKIE, getRequestHeaders().get(HEADER_COOKIE));
        org.apache.http.HttpResponse httpResponse = (httpclient.execute(httppost));
        return new HttpResponse(EntityUtils.toString(httpResponse.getEntity(), "UTF-8").replaceAll("\\s+", ""),
                httpResponse.getStatusLine().getStatusCode());
    } catch (ConnectTimeoutException | java.net.SocketTimeoutException e1) {
        // In most of the cases, even though connection is timed out, actual activity is completed.
        log.warn("Failed to get 200 ok response from endpoint:" + endpoint, e1);
        return new HttpResponse(e1.getMessage(), HttpStatus.SC_REQUEST_TIMEOUT);
    } catch (IOException e) {
        log.error("Failed to invoke API endpoint:" + endpoint, e);
        throw new AppCloudIntegrationTestException("Failed to invoke API endpoint:" + endpoint, e);
    } finally {
        HttpClientUtils.closeQuietly(httpclient);
    }
}