Example usage for org.apache.commons.httpclient HttpClient HttpClient

List of usage examples for org.apache.commons.httpclient HttpClient HttpClient

Introduction

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

Prototype

public HttpClient() 

Source Link

Usage

From source file:com.cisco.tbd.stec.client.ServerConnection.java

public static JSONArray pullNewRules(String timeStamp) throws IOException, ParseException {

    String request = "http://10.154.244.56/stec/get_threats.php?token=weiuyrwerywiuery&exchange=1&from="
            + timeStamp;//from  w ww  .  j a  v  a  2  s  . c o m

    HttpClient client = new HttpClient();

    GetMethod method = new GetMethod(request);

    int statusCode = client.executeMethod(method);

    InputStream rstream = null;

    rstream = method.getResponseBodyAsStream();

    BufferedReader br = new BufferedReader(new InputStreamReader(rstream));

    JSONObject json = (JSONObject) new JSONParser().parse(br.readLine());
    //System.out.println(json.toString());
    String newTimeStamp = json.get("timestamp").toString();
    JSONArray rules = (JSONArray) json.get("data");

    br.close();

    if (FileUtils.removeFile(Runner.PATH_TO_TIME_STAMP_FILE)) {
        FileUtils.createFileWithText(Runner.PATH_TO_TIME_STAMP_FILE, newTimeStamp);
    }

    return rules;
}

From source file:net.jadler.JadlerMockerResetIntegrationTest.java

private void assertStatus(int expected) throws IOException {
    final HttpClient client = new HttpClient();
    final GetMethod method = new GetMethod("http://localhost:" + mocker.getStubHttpServerPort() + "/");
    assertThat(client.executeMethod(method), is(expected));
    method.releaseConnection();//from   w  ww  .ja  va  2 s  .c  o m
}

From source file:net.duckling.ddl.service.version.impl.VersionService.java

@Override
public Version get(String project, String type) {
    HttpClient dClient = new HttpClient();
    PostMethod method = new PostMethod(getDupdateUrl());
    method.setParameter("type", type);
    method.setParameter("project", project);
    try {/*  w  ww .j a  v a  2s. c o m*/
        dClient.executeMethod(method);
        String response = method.getResponseBodyAsString();
        Map<String, String> map = parseResponse(response);

        Version v = new Version();
        if (map.get("success").equals("true")) {
            v.setVersion(map.get("version"));
            v.setDownloadUrl(map.get("downloadUrl"));
            v.setForcedUpdate(Boolean.valueOf(map.get("forcedUpdate")));
            v.setDescription(map.get("description"));
            v.setCreateTime(map.get("createTime"));
        }
        v.setSuccess(Boolean.valueOf(map.get("success")));
        return v;
    } catch (HttpException e) {
        LOG.error("", e);
    } catch (IOException e) {
        LOG.error("", e);
    } catch (ParseException e) {
        LOG.error("", e);
    }
    return null;
}

From source file:edu.utk.gsda.CalaisHttpClient.java

public String getAnnotatedResult(String originString) {
    try {/*  w ww  . j  ava2  s .c  om*/
        client = new HttpClient();
        client.getParams().setParameter("http.useragent", "Calais Rest Client");

        initMethod();

        method.setRequestEntity(new StringRequestEntity(originString, null, null));
        int returnCode = client.executeMethod(method);

        if (returnCode == HttpStatus.SC_OK) {
            BufferedReader reader = new BufferedReader(
                    new InputStreamReader(method.getResponseBodyAsStream(), "UTF-8"));

            StringBuffer stringBuffer = new StringBuffer();
            String line;
            while ((line = reader.readLine()) != null) {
                stringBuffer.append(line);
            }

            reader.close();
            return stringBuffer.toString();
        } else {
            System.err.println("request failed: ");
            System.err.println("Got code: " + returnCode);
            return null;
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

    return null;

}

From source file:com.infosupport.service.LPRServiceCaller.java

public static void postData(String urlString, File file) {
    try {/*from   w  ww . java 2  s .com*/
        PostMethod postMessage = new PostMethod(urlString);
        Part[] parts = { new FilePart("lpimage", file), new StringPart("country", "eu"),
                new StringPart("nonce", "123456789") };
        postMessage.setRequestEntity(new MultipartRequestEntity(parts, postMessage.getParams()));
        HttpClient client = new HttpClient();
        client.executeMethod(postMessage);
    } catch (IOException e) {
        Log.w(TAG, "IOException, waarschijnlijk geen internet connectie aanwezig...");
    }
}

From source file:mesquite.tol.lib.BaseHttpRequestMaker.java

public static boolean contactServer(String s, String URI, StringBuffer response) {
    HttpClient client = new HttpClient();
    GetMethod method = new GetMethod(URI);
    NameValuePair[] pairs = new NameValuePair[1];
    pairs[0] = new NameValuePair("build",
            StringEscapeUtils.escapeHtml("\t" + s + "\tOS =\t" + System.getProperty("os.name") + "\t"
                    + System.getProperty("os.version") + "\tjava =\t" + System.getProperty("java.version")
                    + "\t" + System.getProperty("java.vendor")));
    method.setQueryString(pairs);//w ww .  j av a 2 s .c o  m

    method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
            new DefaultHttpMethodRetryHandler(3, false));

    return executeMethod(client, method, response);
}

From source file:com.predic8.membrane.integration.ProxySSLConnectionMethodTest.java

@Test
public void testSSLConnectionMethod() throws Exception {
    HttpClient client = new HttpClient();
    client.getHostConfiguration().setProxy("localhost", 3129);

    GetMethod post = new GetMethod("https://www.google.com/");
    client.executeMethod(post);/*from  ww w  . j a va2  s. c o m*/
    AssertUtils.assertContains("<html", post.getResponseBodyAsString());

    client.getHttpConnectionManager().closeIdleConnections(0);
}

From source file:eu.learnpad.rest.utils.RestResource.java

public HttpClient getClient(String userName, String password) {
    HttpClient httpClient = new HttpClient();
    httpClient.getParams().setAuthenticationPreemptive(true);
    Credentials credentials = new UsernamePasswordCredentials(userName, password);
    AuthScope authentication = new AuthScope(this.HOSTNAME, this.PORT, AuthScope.ANY_REALM);
    httpClient.getState().setCredentials(authentication, credentials);
    return httpClient;
}

From source file:guru.nidi.atlassian.remote.script.RemoteConfluence.java

public RemoteConfluence(String serverUrl, String username, String password) {
    client = new HttpClient();
    this.serverUrl = serverUrl;
    this.username = username;
    this.password = password;
}

From source file:com.epam.wilma.gepard.test.operation.OperationModeSwitch.java

/**
 * Set Wilma operation mode (Wilma/stub/proxy).
 * @param tc is the caller Test Case/*from  w ww .j  a v  a 2 s .  c om*/
 * @param url to Wilma
 * @return with the response code
 * @throws Exception in case error happens
 */
public String switchOperationMode(final WilmaTestLogDecorator tc, final String url) throws Exception {
    tc.logStep("Switching operation mode in Wilma to: " + url.split("switch/")[1]);
    tc.logGetRequestEvent(url);

    HttpClient httpClient = new HttpClient();
    GetMethod httpGet = new GetMethod(url);
    int statusCode = httpClient.executeMethod(httpGet);
    String responseCode = "status code: " + statusCode + "\n";
    if (statusCode != STATUS_OK) {
        tc.naTestCase("Operation mode switch failed.");
    }
    tc.logComment("Operation mode is: " + url.split("switch/")[1]);
    return responseCode;
}