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.sina.stock.SinaStockClient.java

private Bitmap getBitmapFromUrl(String url) throws HttpException, IOException {

    HttpMethod method = new GetMethod(url);
    int statusCode = mHttpClient.executeMethod(method);
    if (statusCode != HttpStatus.SC_OK) {
        method.releaseConnection();// w  w w. j  a  v a  2 s. c  om
        return null;
    }

    InputStream in = method.getResponseBodyAsStream();
    BufferedInputStream bis = new BufferedInputStream(in);

    Bitmap bm = BitmapFactory.decodeStream(bis);

    bis.close();
    method.releaseConnection();

    return bm;
}

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

@GET
@Path("/ontology")
@ApiOperation(value = "Produces a Json object containing meta-ontology types instances.", notes = "The built Json object will contain ontology nodes divided in roles, entities, relations and resources.", response = Json.class)
@ApiImplicitParam(name = "keyspace", value = "Name of graph to use", dataType = "string", paramType = "query")
private String ontology(Request request, Response response) {
    String keyspace = mandatoryQueryParameter(request, KEYSPACE);
    validateRequest(request, APPLICATION_ALL, APPLICATION_JSON);
    try (GraknGraph graph = factory.getGraph(keyspace, READ); Context context = ontologyGetTimer.time()) {
        Json responseObj = Json.object();
        responseObj.set(ROLES_JSON_FIELD, subLabels(graph.admin().getMetaRole()));
        responseObj.set(ENTITIES_JSON_FIELD, subLabels(graph.admin().getMetaEntityType()));
        responseObj.set(RELATIONS_JSON_FIELD, subLabels(graph.admin().getMetaRelationType()));
        responseObj.set(RESOURCES_JSON_FIELD, subLabels(graph.admin().getMetaResourceType()));

        response.type(APPLICATION_JSON);
        response.status(HttpStatus.SC_OK);
        return responseObj.toString();
    } catch (Exception e) {
        throw GraknServerException.serverException(500, e);
    }/*w  w  w  .j  a va 2s .com*/
}

From source file:davmail.exchange.dav.ExchangeDavMethod.java

protected void handlePropstat(XMLStreamReader reader, MultiStatusResponse multiStatusResponse)
        throws XMLStreamException {
    int propstatStatus = 0;
    while (reader.hasNext() && !XMLStreamUtil.isEndTag(reader, "propstat")) {
        reader.next();//  w w w.ja  va 2  s  . c om
        if (XMLStreamUtil.isStartTag(reader)) {
            String tagLocalName = reader.getLocalName();
            if ("status".equals(tagLocalName)) {
                if ("HTTP/1.1 200 OK".equals(reader.getElementText())) {
                    propstatStatus = HttpStatus.SC_OK;
                } else {
                    propstatStatus = 0;
                }
            } else if ("prop".equals(tagLocalName) && propstatStatus == HttpStatus.SC_OK) {
                handleProperty(reader, multiStatusResponse);
            }
        }
    }

}

From source file:net.sf.sail.webapp.junit.AbstractSpringHttpUnitTests.java

/**
 * Uses HttpUnit functionality to retreive a singe sds curnit from the sds.
 * /*  w ww . j a  va2 s  . c  o m*/
 * @param sdsCurnitId
 *            The id of the curnit you want to retrieve
 * @return The SdsCurnit with name, url and id set
 * @throws IOException
 * @throws JDOMException
 * @throws SAXException
 */
protected SdsCurnit getCurnitInSds(Long sdsCurnitId) throws IOException, JDOMException, SAXException {
    WebResponse webResponse = this.makeHttpRestGetRequest("/curnit/" + sdsCurnitId);
    assertEquals(HttpStatus.SC_OK, webResponse.getResponseCode());

    Document doc = createDocumentFromResponse(webResponse);
    SdsCurnit sdsCurnit = (SdsCurnit) this.applicationContext.getBean("sdsCurnit");
    Element curnitElement = doc.getRootElement();
    sdsCurnit.setName(curnitElement.getChild("name").getValue());
    sdsCurnit.setUrl(curnitElement.getChild("url").getValue());
    sdsCurnit.setSdsObjectId(new Long(curnitElement.getChild("id").getValue()));
    return sdsCurnit;
}

From source file:com.ephesoft.dcma.core.service.ServerHeartBeatMonitor.java

/**
 * This method will return true if the server is active other wise false.
 * /*from  ww w . ja v a  2 s. c  om*/
 * @param url {@link String} URL of the Heart beat service.
 * @return true if the serve is active other wise false.
 */
private boolean checkHealth(final String serviceURL) {
    boolean isActive = false;
    LOGGER.info(serviceURL);
    if (!EphesoftStringUtil.isNullOrEmpty(serviceURL)) {

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

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

        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 httpException) {
            LOGGER.error("Fatal protocol violation: " + httpException.getMessage());
        } catch (IOException ioException) {
            LOGGER.error("Fatal transport error: " + ioException.getMessage());
        } finally {
            // Release the connection.
            if (method != null) {
                method.releaseConnection();
            }
        }

        return isActive;
    }
    return isActive;
}

From source file:ch.cyberduck.core.dav.DAVResource.java

/**
 * Check if the http status code passed as argument is a success
 *
 * @param statusCode/*from   w ww.  j a  v  a2 s . c om*/
 * @return true if code represents a HTTP success
 */
private boolean isHttpSuccess(int statusCode) {
    return (statusCode >= HttpStatus.SC_OK && statusCode < HttpStatus.SC_MULTIPLE_CHOICES);
}

From source file:com.intellij.openapi.paths.WebReferencesAnnotatorBase.java

private static MyFetchResult doCheckUrl(String url) {
    final HttpClient client = new HttpClient();
    client.setTimeout(3000);/*from ww w  .  j  ava 2  s.  c om*/
    client.setConnectionTimeout(3000);
    // see http://hc.apache.org/httpclient-3.x/cookies.html
    client.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
    try {
        final GetMethod method = new GetMethod(url);
        final int code = client.executeMethod(method);

        return code == HttpStatus.SC_OK || code == HttpStatus.SC_REQUEST_TIMEOUT ? MyFetchResult.OK
                : MyFetchResult.NONEXISTENCE;
    } catch (UnknownHostException e) {
        LOG.info(e);
        return MyFetchResult.UNKNOWN_HOST;
    } catch (IOException e) {
        LOG.info(e);
        return MyFetchResult.OK;
    } catch (IllegalArgumentException e) {
        LOG.debug(e);
        return MyFetchResult.OK;
    }
}

From source file:com.comcast.cats.service.util.HttpClientUtil.java

public static synchronized Object postForObject(String requestUrl, byte[] payload) {
    Object responseObject = new Object();

    PostMethod httpMethod = new PostMethod(requestUrl);

    InputStream responseStream = null;
    Reader inputStreamReader = null;

    httpMethod.addRequestHeader(VideoRecorderServiceConstants.CONTENT_TYPE,
            VideoRecorderServiceConstants.APPLICATION_XML);

    RequestEntity requestEntity = new ByteArrayRequestEntity(payload, VideoRecorderServiceConstants.UTF);
    httpMethod.setRequestEntity(requestEntity);

    try {//from   ww  w.ja  v a  2 s  . c  om
        int responseCode = new HttpClient().executeMethod(httpMethod);

        if (HttpStatus.SC_OK != responseCode) {
            logger.error("[ REQUEST  ] " + httpMethod.getURI().toString());
            logger.error("[ METHOD   ] " + httpMethod.getName());
            logger.error("[ STATUS   ] " + responseCode);
        } else {
            logger.trace("[ REQUEST  ] " + httpMethod.getURI().toString());
            logger.trace("[ METHOD   ] " + httpMethod.getName());
            logger.trace("[ STATUS   ] " + responseCode);
        }

        responseStream = httpMethod.getResponseBodyAsStream();
        inputStreamReader = new InputStreamReader(responseStream, VideoRecorderServiceConstants.UTF);
        responseObject = new Yaml().load(inputStreamReader);
    } catch (IOException ioException) {
        ioException.printStackTrace();
    } finally {
        cleanUp(inputStreamReader, responseStream, httpMethod);
    }

    return responseObject;
}

From source file:davmail.exchange.dav.TestDavExchangeSession.java

/**
 * Get main category list/*from   w  w  w .  j av a2s . c  om*/
 *
 * @throws IOException on error
 */
public void testGetCategoryList() throws IOException {
    Set<String> attributes = new HashSet<String>();
    attributes.add("permanenturl");
    attributes.add("roamingxmlstream");
    MultiStatusResponse[] responses = davSession.searchItems("/users/" + davSession.getEmail() + "/calendar",
            attributes,
            davSession.and(davSession.isFalse("isfolder"),
                    davSession.isEqualTo("messageclass", "IPM.Configuration.CategoryList")),
            DavExchangeSession.FolderQueryTraversal.Shallow, 0);
    String value = (String) responses[0].getProperties(HttpStatus.SC_OK)
            .get(Field.getPropertyName("roamingxmlstream")).getValue();
    String propertyList = new String(Base64.decodeBase64(value.getBytes()), "UTF-8");
    System.out.println(propertyList);
}

From source file:edu.si.services.fits.itest.UCT_FITS_IT.java

@Test
public void fitsOutputTest() throws IOException, XpathException, SAXException {
    log.debug("FITS_URI = {}", FITS_URI);

    log.info("fits test URL = {}", FITS_URI + "/examine?file=" + testFile.getAbsolutePath());
    HttpGet request = new HttpGet(FITS_URI + "/examine?file=" + testFile.getAbsolutePath());
    final String fitsOutput;
    try (CloseableHttpResponse response = httpClient.execute(request)) {
        assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
        fitsOutput = EntityUtils.toString(response.getEntity());
    }//from   w  ww.j  a v  a  2s .c o m
    logger.info("FITS Response: {}", fitsOutput);

    Map nsMap = new HashMap();
    nsMap.put("fits", "http://hul.harvard.edu/ois/xml/ns/fits/fits_output");

    XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(nsMap));

    assertXpathEvaluatesTo("image/x-nikon-nef", "/fits:fits/fits:identification/fits:identity[1]/@mimetype",
            fitsOutput.trim());
}