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.cloud.agent.direct.download.HttpDirectTemplateDownloader.java

@Override
public boolean downloadTemplate() {
    try {//from w w  w. j  a v  a 2 s.com
        int status = client.executeMethod(request);
        if (status != HttpStatus.SC_OK) {
            s_logger.warn("Not able to download template, status code: " + status);
            return false;
        }
        return performDownload();
    } catch (IOException e) {
        throw new CloudRuntimeException("Error on HTTP request: " + e.getMessage());
    } finally {
        request.releaseConnection();
    }
}

From source file:com.uber.jenkins.phabricator.conduit.ConduitAPIClientTest.java

@Test
public void testWithUTF8() throws Exception {
    server.register("/api/utf8", TestUtils.makeHttpHandler(HttpStatus.SC_OK, "{}"));

    client = new ConduitAPIClient(getTestServerAddress(), TestUtils.TEST_CONDUIT_TOKEN);
    JSONObject utf8Params = new JSONObject().element("message", "????");
    client.perform("utf8", utf8Params);
}

From source file:com.bbva.arq.devops.ae.mirrorgate.jenkins.plugin.service.DefaultMirrorGateServiceTest.java

@Test
public void testSuccessConnectionTest() throws IOException {
    when(htppClient.executeMethod(any(GetMethod.class))).thenReturn(HttpStatus.SC_OK);

    assertEquals(service.testConnection().getResponseCode(), HttpStatus.SC_OK);
}

From source file:it.geosolutions.geonetwork.op.GNMetadataGetInfo.java

protected static MetadataInfo getAux(HTTPUtils connection, String gnServiceURL, String queryId,
        boolean forUpdate) throws GNLibException, GNServerException {
    try {/*  w w  w .java 2s . c o m*/
        if (LOGGER.isDebugEnabled())
            LOGGER.debug("Retrieve metadata info for " + queryId);

        String serviceName = forUpdate ? "getForUpdate" : "get";
        String serviceURL = gnServiceURL + "/srv/en/xml.metadata.info." + serviceName + "?" + queryId;

        connection.setIgnoreResponseContentOnSuccess(false);
        String response = connection.get(serviceURL);

        if (LOGGER.isDebugEnabled()) {
            if (response != null)
                LOGGER.debug("Response is " + response.length() + " chars long");
            else
                LOGGER.debug("Response is null");
        }

        if (connection.getLastHttpStatus() != HttpStatus.SC_OK)
            throw new GNServerException("Error retrieving data in GeoNetwork", connection.getLastHttpStatus());

        MetadataInfo ret = parseMetadataInfo(response);

        if (LOGGER.isDebugEnabled())
            LOGGER.debug("Metadata " + queryId + " has info " + ret);

        return ret;
    } catch (MalformedURLException ex) {
        throw new GNLibException("Bad URL", ex);
    }
}

From source file:com.owncloud.android.lib.resources.files.ToggleEncryptionOperation.java

/**
 * @param client Client object//from www  . j  a  v  a2  s  . c  o m
 */
@Override
protected RemoteOperationResult run(OwnCloudClient client) {
    RemoteOperationResult result;
    HttpMethodBase method = null;

    ReadRemoteFolderOperation remoteFolderOperation = new ReadRemoteFolderOperation(remotePath);
    RemoteOperationResult remoteFolderOperationResult = remoteFolderOperation.execute(client);

    // Abort if not empty
    // Result has always the folder and maybe children, so size == 1 is ok
    if (remoteFolderOperationResult.isSuccess() && remoteFolderOperationResult.getData().size() > 1) {
        return new RemoteOperationResult(false, "Non empty", HttpStatus.SC_FORBIDDEN);
    }

    try {
        String url = client.getBaseUri() + ENCRYPTED_URL + localId;
        if (encryption) {
            method = new PutMethod(url);
        } else {
            method = new DeleteMethod(url);
        }

        // remote request
        method.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE);
        method.addRequestHeader(CONTENT_TYPE, FORM_URLENCODED);

        int status = client.executeMethod(method, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT);

        if (status == HttpStatus.SC_OK) {
            result = new RemoteOperationResult(true, method);
        } else {
            result = new RemoteOperationResult(false, method);
            client.exhaustResponse(method.getResponseBodyAsStream());
        }
    } catch (Exception e) {
        result = new RemoteOperationResult(e);
        Log_OC.e(TAG, "Setting encryption status of " + localId + " failed: " + result.getLogMessage(),
                result.getException());
    } finally {
        if (method != null)
            method.releaseConnection();
    }
    return result;
}

From source file:it.geosolutions.geonetwork.op.GNMetadataGetStatus.java

protected static MetadataInfo getAux(HTTPUtils connection, String gnServiceURL, String queryId,
        boolean forUpdate) throws GNLibException, GNServerException {
    try {/*from w w  w  .j av  a  2  s  .com*/
        if (LOGGER.isDebugEnabled())
            LOGGER.debug("Retrieve metadata info for " + queryId);

        String serviceName = forUpdate ? "getForUpdate" : "get";
        String serviceURL = gnServiceURL + "/srv/eng/xml.metadata.info." + serviceName + "?" + queryId;

        connection.setIgnoreResponseContentOnSuccess(false);
        String response = connection.get(serviceURL);

        if (LOGGER.isDebugEnabled()) {
            if (response != null)
                LOGGER.debug("Response is " + response.length() + " chars long");
            else
                LOGGER.debug("Response is null");
        }

        if (connection.getLastHttpStatus() != HttpStatus.SC_OK)
            throw new GNServerException("Error retrieving data in GeoNetwork", connection.getLastHttpStatus());

        MetadataInfo ret = parseMetadataInfo(response);

        if (LOGGER.isDebugEnabled())
            LOGGER.debug("Metadata " + queryId + " has info " + ret);

        return ret;
    } catch (MalformedURLException ex) {
        throw new GNLibException("Bad URL", ex);
    }
}

From source file:com.zimbra.qa.unittest.TestWsdlServlet.java

public void testWsdlServletZimbraServicesWsdl() throws Exception {
    String body = doWsdlServletRequest(wsdlUrlBase + "ZimbraService.wsdl", false, HttpStatus.SC_OK);
    assertTrue("Body contains expected string", body.contains("wsdl:service name="));
}

From source file:com.ifeng.vdn.ip.repository.service.impl.AliIPAddressChecker.java

public IPAddress ipCheckByGet(String ip) {
    AliIPBean ipaddress = null;//from   www.jav a  2s. c o m

    String url = "http://ip.taobao.com/service/getIpInfo.php?ip=" + ip;

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

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

    // Execute the method.
    // Read the response body.
    try {

        int resultCode = clinet.executeMethod(getMethod);

        if (resultCode == HttpStatus.SC_OK) {
            InputStream responseBody = getMethod.getResponseBodyAsStream();

            ObjectMapper mapper = new ObjectMapper();
            ipaddress = mapper.readValue(responseBody, AliIPBean.class);

            log.info(responseBody.toString());
        } else {
            log.error("Method failedd: [{}] , IP: [{}]", getMethod.getStatusCode(), ip);
        }

    } catch (JsonParseException | JsonMappingException | HttpException e) {
        log.error(e.getMessage(), e);
    } catch (IOException e) {
        log.error(e.getMessage(), e);
    }

    return ipaddress;
}

From source file:com.cerema.cloud2.lib.resources.files.ReadRemoteFileOperation.java

/**
 * Performs the read operation./* w ww.ja v a  2 s  . c  o m*/
 * 
 * @param client      Client object to communicate with the remote ownCloud server.
 */
@Override
protected RemoteOperationResult run(OwnCloudClient client) {
    PropFindMethod propfind = null;
    RemoteOperationResult result = null;

    /// take the duty of check the server for the current state of the file there
    try {
        // remote request
        propfind = new PropFindMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath),
                WebdavUtils.getFilePropSet(), // PropFind Properties
                DavConstants.DEPTH_0);
        int status;
        status = client.executeMethod(propfind, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT);

        boolean isSuccess = (status == HttpStatus.SC_MULTI_STATUS || status == HttpStatus.SC_OK);
        if (isSuccess) {
            // Parse response
            MultiStatus resp = propfind.getResponseBodyAsMultiStatus();
            WebdavEntry we = new WebdavEntry(resp.getResponses()[0], client.getWebdavUri().getPath());
            RemoteFile remoteFile = new RemoteFile(we);
            ArrayList<Object> files = new ArrayList<Object>();
            files.add(remoteFile);

            // Result of the operation
            result = new RemoteOperationResult(true, status, propfind.getResponseHeaders());
            result.setData(files);

        } else {
            client.exhaustResponse(propfind.getResponseBodyAsStream());
            result = new RemoteOperationResult(false, status, propfind.getResponseHeaders());
        }

    } catch (Exception e) {
        result = new RemoteOperationResult(e);
        e.printStackTrace();
        Log_OC.e(TAG, "Synchronizing  file " + mRemotePath + ": " + result.getLogMessage(),
                result.getException());
    } finally {
        if (propfind != null)
            propfind.releaseConnection();
    }
    return result;
}

From source file:net.bryansaunders.jee6divelog.service.rest.SecurityApiIT.java

/**
 * Test Identify.//from   w  w  w  .java  2 s .c  om
 */
@Test
public void ifLoggedInThenIdentify() {
    // given
    final String requestUrl = RestApiTest.URL_ROOT + "/security/identify";
    final UserAccount loggedInUser = this.doLogin(SecurityApiIT.VALID_EMAIL, SecurityApiIT.VALID_PASSWORD);
    final String privateApiKey = loggedInUser.getPrivateApiKey();
    final String publicApiKey = loggedInUser.getPublicApiKey();

    final Map<String, String> headers = this.generateLoginHeaders(HttpMethod.GET, requestUrl, null,
            privateApiKey, publicApiKey);

    // when
    final UserAccount foundUser = given().headers(headers).expect().statusCode(HttpStatus.SC_OK).when()
            .get(requestUrl).as(UserAccount.class);

    // then
    assertNotNull(foundUser);
    assertEquals(SecurityApiIT.VALID_EMAIL, foundUser.getEmail());
}