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

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

Introduction

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

Prototype

int SC_OK

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

Click Source Link

Document

<tt>200 OK</tt> (HTTP/1.0 - RFC 1945)

Usage

From source file:com.eviware.soapui.impl.support.AbstractMockResponse.java

public int getResponseHttpStatus() {

    if (getConfig().getHttpResponseStatus() != null) {
        return Integer.valueOf(getConfig().getHttpResponseStatus());

    } else {/*from  www.j a v a  2  s . com*/
        return HttpStatus.SC_OK;
    }
}

From source file:com.honnix.yaacs.adapter.http.ACHttpClient.java

private Map<String, String> sendAndReceive(String url, String request) throws ACException {
    Map<String, String> responseMap = null;

    PostMethod postMethod = buildPostMethod(url, request);

    if (postMethod == null) {
        throw new ACException(ACHttpError.INTERNAL_ERROR_MSG, ACHttpError.INTERNAL_ERROR);
    }/*from   ww w  .  j  ava2s.  c  om*/

    int statusCode = -1;

    try {
        statusCode = httpClient.executeMethod(postMethod);
    } catch (Exception e) {
        throw new ACException(ACHttpError.INTERNAL_ERROR_MSG, ACHttpError.INTERNAL_ERROR, e);
    }

    if (statusCode == HttpStatus.SC_OK) {
        try {
            responseMap = ACHttpBodyUtil.buildParameterMap(postMethod.getResponseBodyAsStream(),
                    postMethod.getResponseCharSet());
        } catch (IOException e) {
            throw new ACException(ACHttpError.INTERNAL_ERROR_MSG, ACHttpError.INTERNAL_ERROR, e);
        } finally {
            postMethod.releaseConnection();
        }
    } else {
        throw new ACException(ACHttpError.BAD_STATUS_CODE_MSG, ACHttpError.BAD_STATUS_CODE);
    }

    checkResponse(responseMap);

    return responseMap;
}

From source file:JiraWebSession.java

private boolean isAuthenticated(HttpClient httpClient, HostConfiguration hostConfiguration,
        IProgressMonitor monitor) throws JiraException {
    String url = baseUrl + "/secure/UpdateUserPreferences!default.jspa"; //$NON-NLS-1$
    GetMethod method = new GetMethod(url);
    method.setFollowRedirects(false);// w w  w  . j ava2s .c o m

    try {
        int statusCode = WebUtil.execute(httpClient, hostConfiguration, method, monitor);

        if (statusCode == HttpStatus.SC_OK) {
            return !method.getResponseBodyAsString().contains("/login.jsp?os_destination"); //$NON-NLS-1$
        }
    } catch (IOException e) {
        throw new JiraException(e);
    }
    return false;
}

From source file:net.sf.xmm.moviemanager.http.HttpUtil.java

public HTTPResult readData2(URL url) throws Exception {

    if (!isSetup())
        setup();/*from   www  .j a v  a  2  s.c o m*/

    GetMethod method = new GetMethod(url.toString());
    int statusCode = client.executeMethod(method);

    if (statusCode != HttpStatus.SC_OK) {
        log.debug("HTTP StatusCode not HttpStatus.SC_OK:(" + statusCode + "):" + method.getStatusLine());
    }

    java.io.BufferedReader stream = new java.io.BufferedReader(
            new java.io.InputStreamReader(method.getResponseBodyAsStream(), "ISO-8859-1"));

    StringBuffer data = new StringBuffer();

    // Saves the page data in a string buffer... 
    int buffer;

    while ((buffer = stream.read()) != -1) {
        data.append((char) buffer);
    }

    stream.close();

    return new HTTPResult(url, statusCode == HttpStatus.SC_OK ? data : null, method.getStatusLine());
}

From source file:muki.tool.JavaCompilationDeploymentTestCase.java

@Test
public void testGetOperation1() throws Exception {
    String url = URL_RESOURCE1 + "/pathGetOperation1";
    GetMethod method = new GetMethod(url);

    int statusCode = this.getHttpClient().executeMethod(method);
    assertTrue("Method failed: " + method.getStatusLine(), statusCode == HttpStatus.SC_OK);
    byte[] responseBody = method.getResponseBody();
    String actualResponse = new String(responseBody);
    String expectedResponse = "getOperation1";
    assertEquals(expectedResponse, actualResponse);
}

From source file:com.gisgraphy.rest.RestClient.java

private int executeAndCheckStatusCode(HttpMethod httpMethod)
        throws IOException, HttpException, RestClientException {
    int statusCode = httpClient.executeMethod(httpMethod);
    if (statusCode != HttpStatus.SC_OK && statusCode != HttpStatus.SC_CREATED
            && statusCode != HttpStatus.SC_NO_CONTENT) {
        throw new RestClientException(statusCode, "restclient exception for " + httpMethod.getURI() + " : "
                + statusCode + ", " + HttpStatus.getStatusText(statusCode));
    }/* ww  w.ja  va  2s  .  c  o  m*/
    return statusCode;
}

From source file:com.ephesoft.dcma.heartbeat.HeartBeat.java

/**
 * This method will return true if the server is active other wise false.
 * /*from w  w w . ja  v a2 s. c om*/
 * @param url {@link String}
 * @return boolean true if the serve is active other wise false.
 */
private boolean checkHealth(final String url) {

    boolean isActive = false;

    // Create an instance of HttpClient.
    HttpClient client = new HttpClient();

    // Create a method instance.
    GetMethod method = new GetMethod(url);

    try {
        // Execute the method.
        int statusCode = client.executeMethod(method);

        if (statusCode == HttpStatus.SC_OK) {
            isActive = true;
        } else {
            LOGGER.info("Method failed: " + method.getStatusLine());
        }

    } catch (HttpException e) {
        LOGGER.error("Fatal protocol violation: " + e.getMessage());
    } catch (IOException e) {
        LOGGER.error("Fatal transport error: " + e.getMessage());
    } finally {
        // Release the connection.
        if (method != null) {
            method.releaseConnection();
        }
    }

    return isActive;
}

From source file:com.jackbe.mapreduce.EMMLRestRunner.java

protected String executeRESTCall(String scriptName, String encodedValue) {

    // "http://localhost:8080/presto/edge/api/rest/StockQuoteMapper/runMashup?x-presto-resultFormat=xml&value=<encodedValue>"
    HttpMethod httpMethod = null;/*from   ww w .java  2 s. c o  m*/
    String result = null;

    if (encodedValue != null) {
        httpMethod = new GetMethod(protocol + host + ":" + port + path + scriptName + "/" + operation + "?"
                + format + "&value=" + encodedValue);
        log.debug("Invoking REST service: " + protocol + host + ":" + port + path + scriptName + "/" + operation
                + "?" + format + "&value=" + encodedValue);
    } else {
        httpMethod = new GetMethod(
                protocol + host + ":" + port + path + scriptName + "/" + operation + "?" + format);
        log.debug("Invoking REST service: " + protocol + host + ":" + port + path + scriptName + "/" + operation
                + "?" + format);
    }

    try {
        client.executeMethod(httpMethod);

        if (httpMethod.getStatusCode() != HttpStatus.SC_OK) {
            log.error("HTTP Error status connecting to Presto: " + httpMethod.getStatusCode());
            log.error("HTTP Error message connecting to Presto: " + httpMethod.getStatusText());
            return null;
        } else {
            if (log.isDebugEnabled()) {
                log.debug("Status code: " + httpMethod.getStatusCode());
                Header contentTypeHeader = httpMethod.getResponseHeader("content-type");
                log.debug("Mimetype: " + contentTypeHeader.getValue());
            }
        }

        result = httpMethod.getResponseBodyAsString();
        // log.debug(httpMethod.getStatusText());
        if (log.isDebugEnabled())
            log.debug("Response: " + result);
    } catch (Exception e) {
        log.error("Exception executing REST call: " + e, e);
    } finally {
        httpMethod.releaseConnection();
    }

    return result;

}

From source file:ai.grakn.engine.controller.TasksController.java

@GET
@Path("/")
@ApiOperation(value = "Get tasks matching a specific TaskStatus.")
@ApiImplicitParams({//w w w.  j  a  v a  2  s  .c o m
        @ApiImplicitParam(name = REST.Request.TASK_STATUS_PARAMETER, value = "TaskStatus as string.", dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = REST.Request.TASK_CLASS_NAME_PARAMETER, value = "Class name of BackgroundTask Object.", dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = REST.Request.TASK_CREATOR_PARAMETER, value = "Who instantiated these tasks.", dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = REST.Request.LIMIT_PARAM, value = "Limit the number of entries in the returned result.", dataType = "integer", paramType = "query"),
        @ApiImplicitParam(name = REST.Request.OFFSET_PARAM, value = "Use in conjunction with limit for pagination.", dataType = "integer", paramType = "query") })
private Json getTasks(Request request, Response response) {
    TaskStatus status = null;
    String className = request.queryParams(REST.Request.TASK_CLASS_NAME_PARAMETER);
    String creator = request.queryParams(REST.Request.TASK_CREATOR_PARAMETER);
    int limit = 0;
    int offset = 0;

    if (request.queryParams(REST.Request.LIMIT_PARAM) != null) {
        limit = Integer.parseInt(request.queryParams(REST.Request.LIMIT_PARAM));
    }

    if (request.queryParams(REST.Request.OFFSET_PARAM) != null) {
        offset = Integer.parseInt(request.queryParams(REST.Request.OFFSET_PARAM));
    }

    if (request.queryParams(REST.Request.TASK_STATUS_PARAMETER) != null) {
        status = TaskStatus.valueOf(request.queryParams(REST.Request.TASK_STATUS_PARAMETER));
    }

    Context context = getTasksTimer.time();
    try {
        Json result = Json.array();
        manager.storage().getTasks(status, className, creator, null, limit, offset).stream()
                .map(this::serialiseStateSubset).forEach(result::add);

        response.status(HttpStatus.SC_OK);
        response.type(APPLICATION_JSON);
        return result;
    } finally {
        context.stop();
    }
}

From source file:ke.go.moh.oec.adt.Daemon.java

private static boolean sendMessage(String url, String filename) {
    int returnStatus = HttpStatus.SC_CREATED;
    HttpClient httpclient = new HttpClient();
    HttpConnectionManager connectionManager = httpclient.getHttpConnectionManager();
    connectionManager.getParams().setSoTimeout(120000);

    PostMethod httpPost = new PostMethod(url);

    RequestEntity requestEntity;/*from w  w w  .ja v a 2s .  c o  m*/
    try {
        FileInputStream message = new FileInputStream(filename);
        Base64InputStream message64 = new Base64InputStream(message, true, -1, null);
        requestEntity = new InputStreamRequestEntity(message64, "application/octet-stream");
    } catch (FileNotFoundException e) {
        Logger.getLogger(Daemon.class.getName()).log(Level.SEVERE, "File not found.", e);
        return false;
    }
    httpPost.setRequestEntity(requestEntity);
    try {
        httpclient.executeMethod(httpPost);
        returnStatus = httpPost.getStatusCode();
    } catch (SocketTimeoutException e) {
        returnStatus = HttpStatus.SC_REQUEST_TIMEOUT;
        Logger.getLogger(Daemon.class.getName()).log(Level.SEVERE, "Request timed out.  Not retrying.", e);
    } catch (HttpException e) {
        returnStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR;
        Logger.getLogger(Daemon.class.getName()).log(Level.SEVERE, "HTTP exception.  Not retrying.", e);
    } catch (ConnectException e) {
        returnStatus = HttpStatus.SC_SERVICE_UNAVAILABLE;
        Logger.getLogger(Daemon.class.getName()).log(Level.SEVERE, "Service unavailable.  Not retrying.", e);
    } catch (UnknownHostException e) {
        returnStatus = HttpStatus.SC_NOT_FOUND;
        Logger.getLogger(Daemon.class.getName()).log(Level.SEVERE, "Not found.  Not retrying.", e);
    } catch (IOException e) {
        returnStatus = HttpStatus.SC_GATEWAY_TIMEOUT;
        Logger.getLogger(Daemon.class.getName()).log(Level.SEVERE, "IO exception.  Not retrying.", e);
    } finally {
        httpPost.releaseConnection();
    }
    return returnStatus == HttpStatus.SC_OK;
}