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.cordys.cm.uiunit.framework.internal.selenium.GetActiveRCs.java

public String[] execute() {
    HttpClient client = new HttpClient();
    GetMethod getMethod = new GetMethod(this.pathToServlet);
    try {/*from www.  ja v  a2 s  .c o m*/
        try {
            if (client.executeMethod(getMethod) == HttpStatus.SC_OK) {
                InputStream responseBody = getMethod.getResponseBodyAsStream();
                String response = convertStreamToString(responseBody);
                if (!response.equals("")) {
                    //response= response.substring(1, response.length()-1);
                    String[] activeRcs = response.split("\\,");
                    System.out.println(response + " " + activeRcs.length);
                    return activeRcs;
                }
            }
        } catch (HttpException e) {
            throw new UIUnitRuntimeException(e);
        } catch (IOException e) {
            throw new UIUnitRuntimeException(e);
        }
    } finally {
        getMethod.releaseConnection();
    }
    return null;
}

From source file:net.sf.sail.webapp.domain.webservice.http.HttpGetCurnitMapRequestTest.java

protected void setUp() throws Exception {
    super.setUp();
    method = EasyMock.createMock(HttpMethod.class);
    request = new HttpGetCurnitMapRequest(AbstractHttpRestCommand.REQUEST_HEADERS_ACCEPT,
            AbstractHttpRestCommand.EMPTY_STRING_MAP, URL, HttpStatus.SC_OK);
}

From source file:eu.alefzero.owncloud.authenticator.AuthenticationRunnable.java

@Override
public void run() {
    Uri uri;//  www .  j  a  v  a2  s  .c  o  m
    uri = Uri.parse(mUrl.toString());
    int login_result = WebdavClient.tryToLogin(uri, mUsername, mPassword);
    switch (login_result) {
    case HttpStatus.SC_OK:
        postResult(true, uri.toString());
        break;
    case HttpStatus.SC_UNAUTHORIZED:
        postResult(false, "Invalid login or/and password");
        break;
    case HttpStatus.SC_NOT_FOUND:
        postResult(false, "Wrong path given");
        break;
    default:
        postResult(false, "Internal server error, code: " + login_result);
    }
}

From source file:edu.uci.ics.external.connector.asterixdb.ConnectorUtils.java

public static DatasetInfo retrieveDatasetInfo(StorageParameter storageParameter) throws Exception {
    HttpClient client = new HttpClient();
    String requestStr = storageParameter.getServiceURL() + "/connector" + "?dataverseName="
            + storageParameter.getDataverseName() + "&datasetName=" + storageParameter.getDatasetName();
    // Create a method instance.
    GetMethod method = new GetMethod(requestStr);

    // Provide custom retry handler is necessary
    method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
            new DefaultHttpMethodRetryHandler(3, false));

    // Deals with the response.
    // Executes the method.
    try {//from   w w  w  .j a v a2  s. c  o m
        int statusCode = client.executeMethod(method);
        if (statusCode != HttpStatus.SC_OK) {
            System.err.println("Method failed: " + method.getStatusLine());
        }

        // Deals with the response.
        JSONTokener tokener = new JSONTokener(new InputStreamReader(method.getResponseBodyAsStream()));
        JSONObject response = new JSONObject(tokener);

        // Checks if there are errors.
        String error = "error";
        if (response.has(error)) {
            throw new IllegalStateException("AsterixDB returned errors: " + response.getString(error));
        }

        // Extracts record type and file partitions.
        boolean temp = extractTempInfo(response);
        ARecordType recordType = extractRecordType(response);
        List<FilePartition> filePartitions = extractFilePartitions(response);
        IFileSplitProvider fileSplitProvider = createFileSplitProvider(storageParameter, filePartitions);
        String[] locations = getScanLocationConstraints(filePartitions, storageParameter.getIpToNcNames());
        String[] primaryKeys = response.getString("keys").split(",");
        DatasetInfo datasetInfo = new DatasetInfo(locations, fileSplitProvider, recordType, primaryKeys, temp);
        return datasetInfo;
    } catch (Exception e) {
        throw e;
    } finally {
        method.releaseConnection();
    }
}

From source file:com.android.volley.NetworkResponse.java

public NetworkResponse(byte[] data) {
    this(HttpStatus.SC_OK, data, Collections.<String, String>emptyMap(), false, 0);
}

From source file:com.intellij.internal.statistic.connect.StatisticsHttpClientSender.java

@Override
public void send(@NotNull String url, @NotNull String content) throws StatServiceException {
    PostMethod post = null;//from  w  w  w  .  j a va  2s  . c o m

    try {
        //HttpConfigurable.getInstance().prepareURL(url);

        HttpClient httpclient = new HttpClient();
        post = new PostMethod(url);

        post.setRequestBody(
                new NameValuePair[] { new NameValuePair("content", content), new NameValuePair("uuid",
                        UpdateChecker.getInstallationUID(PropertiesComponent.getInstance())) });

        httpclient.executeMethod(post);

        if (post.getStatusCode() != HttpStatus.SC_OK) {
            throw new StatServiceException("Error during data sending... Code: " + post.getStatusCode());
        }

        final Header errors = post.getResponseHeader("errors");
        if (errors != null) {
            final String value = errors.getValue();

            throw new StatServiceException("Error during updating statistics "
                    + (!StringUtil.isEmptyOrSpaces(value) ? " : " + value : ""));
        }
    } catch (StatServiceException e) {
        throw e;
    } catch (Exception e) {
        throw new StatServiceException("Error during data sending...", e);
    } finally {
        if (post != null) {
            post.releaseConnection();
        }
    }
}

From source file:com.pari.nm.modules.imgmgmt.ImagePropertyCCOHelper.java

private static void populateImagePropertiesFromCCOInternal(SoftwareImage image, String imageName, String url,
        boolean populateVersion, boolean populatePforms) throws PariException {
    HttpClient httpClient = new HttpClient();
    GetMethod method = new GetMethod(url);
    method.setFollowRedirects(true);/*from w  ww  . ja v  a 2  s.c  o m*/
    try {
        httpClient.executeMethod(method);

        int statuscode = method.getStatusCode();
        if (statuscode != HttpStatus.SC_OK) {
            throw new PariException(-1, "Unable to connect to cisco.com to get image properites for image: "
                    + imageName + " Status: " + method.getStatusText());
        }
        populateImagePropertiesFromHTTPOutput(method.getResponseBodyAsStream(), image, imageName,
                populateVersion, populatePforms);
    } catch (PariException pex) {
        logger.error("Pari Exception while getting image properties for image: " + imageName, pex);
        throw pex;
    } catch (Exception ex) {
        logger.error("Exception while getting image properties for image: " + imageName, ex);
        throw new PariException(-1,
                "Error while getting image properties from www.cisco.com for image: " + imageName);
    }
}

From source file:com.glaf.core.util.http.CommonsHttpClientUtils.java

/**
 * ??GET/*  w ww  .ja  va  2s. c om*/
 * 
 * @param url
 *            ??
 * @param encoding
 *            
 * @param dataMap
 *            ?
 * 
 * @return
 */
public static String doGet(String url, String encoding, Map<String, String> dataMap) {
    GetMethod method = null;
    String content = null;
    try {
        method = new GetMethod(url);
        method.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, encoding);
        method.addRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=" + encoding);
        if (dataMap != null && !dataMap.isEmpty()) {
            NameValuePair[] nameValues = new NameValuePair[dataMap.size()];
            int i = 0;
            for (Map.Entry<String, String> entry : dataMap.entrySet()) {
                String name = entry.getKey().toString();
                String value = entry.getValue();
                nameValues[i] = new NameValuePair(name, value);
                i++;
            }
            method.setQueryString(nameValues);
        }
        HttpClient client = new HttpClient();
        int status = client.executeMethod(method);
        if (status == HttpStatus.SC_OK) {
            content = method.getResponseBodyAsString();
        }
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    } finally {
        if (method != null) {
            method.releaseConnection();
            method = null;
        }
    }
    return content;
}

From source file:com.tw.go.plugin.material.artifactrepository.yum.exec.HttpConnectionChecker.java

public void checkConnection(String url, Credentials credentials) {
    HttpClient client = getHttpClient();
    if (credentials.isComplete()) {
        org.apache.commons.httpclient.Credentials usernamePasswordCredentials = new UsernamePasswordCredentials(
                credentials.getUser(), credentials.getPassword());
        client.getState().setCredentials(AuthScope.ANY, usernamePasswordCredentials);
    }//from w w  w .ja  v  a 2s.c  om
    GetMethod method = getGetMethod(url);
    method.setFollowRedirects(false);
    try {
        int returnCode = client.executeMethod(method);
        if (returnCode != HttpStatus.SC_OK) {
            throw new RuntimeException(method.getStatusLine().toString());
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:es.carebear.rightmanagement.client.user.ChangeAttributeUser.java

public void ChangeAttribute(String userName, String authName, String[] attribute, String[] value)
        throws BadRequestException, InternalServerErrorException, IOException, UnknownResponseException {
    Gson gson = new Gson();
    String attr = gson.toJson(attribute, attribute.getClass());
    String val = gson.toJson(value, value.getClass());

    PostMethod postMethod = new PostMethod(baseUri + "/client/users/change/" + userName);
    postMethod.addParameter("authName", authName);
    postMethod.addParameter("attribute", attr);
    postMethod.addParameter("value", val);

    int responseCode = httpClient.executeMethod(postMethod);

    switch (responseCode) {
    case HttpStatus.SC_OK:
        break;//w ww  .j  av  a2  s.c om
    case HttpStatus.SC_BAD_REQUEST:
        throw new BadRequestException();
    case HttpStatus.SC_INTERNAL_SERVER_ERROR:
        throw new InternalServerErrorException();
    case HttpStatus.SC_FORBIDDEN:
        throw new ForbiddenException();
    default:
        throw new UnknownResponseException((new Integer(responseCode)).toString());
    }
}