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

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

Introduction

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

Prototype

public int executeMethod(HttpMethod paramHttpMethod) throws IOException, HttpException 

Source Link

Usage

From source file:exception.handler.configuration.ExceptionHandlerRedirectConfigTest.java

@Test
public void notHandlerConfiguration() {
    HttpClient client = new HttpClient();
    GetMethod method = new GetMethod(deploymentUrl + "/index.jsf");

    try {//from   w  w  w.j a  va  2  s  . com
        client.executeMethod(method);
        String message = method.getResponseBodyAsString();
        assertTrue(message.contains("Called the page /error_page"));

    } catch (HttpException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.mikenimer.familydam.web.jobs.FacebookCheckinsJob.java

@Override
protected JobResult queryFacebook(Node facebookData, String username, String userPath, String nextUrl)
        throws RepositoryException, IOException, JSONException {
    String accessToken = facebookData.getProperty("accessToken").getString();
    String expiresIn = facebookData.getProperty("expiresIn").getString();
    String signedRequest = facebookData.getProperty("signedRequest").getString();

    String userId = "me";
    if (facebookData.hasProperty("userId")) {
        userId = facebookData.getProperty("userId").getString();
    }/*from   w  w  w .j av  a  2s  .  c o  m*/

    String _url = nextUrl;
    if (nextUrl == null) {
        _url = "https://graph.facebook.com/" + userId + "/checkins?access_token=" + accessToken;
    }
    URL url = new URL(_url);

    HttpClient client = new HttpClient();
    GetMethod method = new GetMethod(_url);
    int statusCode = client.executeMethod(method);

    if (statusCode != HttpStatus.SC_OK) {
        return JobResult.FAILED;
    }

    // Read the response body.
    String jsonStr = method.getResponseBodyAsString();
    return saveData(username, jsonStr, FACEBOOKPATH, "checkin");
}

From source file:com.mikenimer.familydam.web.jobs.FacebookLikesJob.java

@Override
protected JobResult queryFacebook(Node facebookData, String username, String userPath, String nextUrl)
        throws RepositoryException, IOException, JSONException {
    String accessToken = facebookData.getProperty("accessToken").getString();
    String expiresIn = facebookData.getProperty("expiresIn").getString();
    String signedRequest = facebookData.getProperty("signedRequest").getString();

    String userId = "me";
    if (facebookData.hasProperty("userId")) {
        userId = facebookData.getProperty("userId").getString();
    }/*w  w w.jav  a 2s.co  m*/

    String _url = nextUrl;
    if (nextUrl == null) {
        _url = "https://graph.facebook.com/" + userId + "/likes?access_token=" + accessToken;
    }
    URL url = new URL(_url);

    HttpClient client = new HttpClient();
    GetMethod method = new GetMethod(_url);
    int statusCode = client.executeMethod(method);

    if (statusCode != HttpStatus.SC_OK) {
        return JobResult.FAILED;
    }

    // Read the response body.
    String jsonStr = method.getResponseBodyAsString();
    return saveData(username, jsonStr, FACEBOOKPATH, "like");
}

From source file:com.mikenimer.familydam.web.jobs.FacebookPhotosJob.java

@Override
protected JobResult queryFacebook(Node facebookData, String username, String userPath, String nextUrl)
        throws RepositoryException, IOException, JSONException {
    String accessToken = facebookData.getProperty("accessToken").getString();
    String expiresIn = facebookData.getProperty("expiresIn").getString();
    String signedRequest = facebookData.getProperty("signedRequest").getString();

    String userId = "me";
    if (facebookData.hasProperty("userId")) {
        userId = facebookData.getProperty("userId").getString();
    }/* w ww.j  av a  2 s  . c om*/

    String _url = nextUrl;
    if (nextUrl == null) {
        _url = "https://graph.facebook.com/" + userId + "/photos?access_token=" + accessToken;
    }
    URL url = new URL(_url);

    HttpClient client = new HttpClient();
    GetMethod method = new GetMethod(_url);
    int statusCode = client.executeMethod(method);

    if (statusCode != HttpStatus.SC_OK) {
        return JobResult.FAILED;
    }

    // Read the response body.
    String jsonStr = method.getResponseBodyAsString();
    return saveData(username, jsonStr, FACEBOOKPATH, "photo");
}

From source file:com.mikenimer.familydam.web.jobs.FacebookStatusJob.java

@Override
protected JobResult queryFacebook(Node facebookData, String username, String userPath, String nextUrl)
        throws RepositoryException, IOException, JSONException {
    String accessToken = facebookData.getProperty("accessToken").getString();
    String expiresIn = facebookData.getProperty("expiresIn").getString();
    String signedRequest = facebookData.getProperty("signedRequest").getString();

    String userId = "me";
    if (facebookData.hasProperty("userId")) {
        userId = facebookData.getProperty("userId").getString();
    }//from www  .j av  a  2  s  .c  om

    String _url = nextUrl;
    if (nextUrl == null) {
        _url = "https://graph.facebook.com/" + userId + "/statuses?access_token=" + accessToken;
    }
    URL url = new URL(_url);

    HttpClient client = new HttpClient();
    GetMethod method = new GetMethod(_url);
    int statusCode = client.executeMethod(method);

    if (statusCode != HttpStatus.SC_OK) {
        return JobResult.FAILED;
    }

    // Read the response body.
    String jsonStr = method.getResponseBodyAsString();
    return saveData(username, jsonStr, FACEBOOKPATH, "status");
}

From source file:net.jadler.JadlerDeprecatedDefaultsConfigurationTest.java

@Test
@SuppressWarnings("deprecation")
public void ongoingConfiguration() throws IOException {
    initJadler().that().respondsWithDefaultStatus(EXPECTED_STATUS)
            .respondsWithDefaultContentType(EXPECTED_CONTENT_TYPE)
            .respondsWithDefaultEncoding(EXPECTED_ENCODING)
            .respondsWithDefaultHeader(EXPECTED_HEADER_NAME, EXPECTED_HEADER_VALUE);

    try {//  w w  w  .  j  ava2s.c  o  m
        onRequest().respond().withBody(STRING_WITH_DIACRITICS);

        final HttpClient client = new HttpClient();
        final GetMethod method = new GetMethod("http://localhost:" + port() + "/");
        client.executeMethod(method);

        assertThat(method.getStatusCode(), is(EXPECTED_STATUS));
        assertThat(method.getResponseHeader("Content-Type").getValue(), is(EXPECTED_CONTENT_TYPE));
        assertThat(method.getResponseHeader(EXPECTED_HEADER_NAME).getValue(), is(EXPECTED_HEADER_VALUE));
        assertThat(method.getResponseBody(), is(ISO_8859_2_REPRESENTATION));

        method.releaseConnection();
    } finally {
        closeJadler();
    }
}

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();/* ww w.  j a v  a 2 s . c o  m*/
}

From source file:eu.impact_project.resultsrepository.DavHandlerTest.java

@Test
public void testRetrieveTextFile() throws HttpException, IOException {
    DavHandler dav = new DavHandler(folders);

    InputStream stream = new ByteArrayInputStream("some text".getBytes());
    PutMethod putMethod = new PutMethod("http://localhost:9002/parent/child/textToRetrieve.txt");
    putMethod.setRequestEntity(new InputStreamRequestEntity(stream));
    HttpClient client = new HttpClient();
    client.executeMethod(putMethod);
    stream.close();//from  ww w . j  av  a 2 s .  c o  m
    putMethod.releaseConnection();

    String retrieved = dav.retrieveTextFile("http://localhost:9002/parent/child/textToRetrieve.txt");
    assertEquals("some text", retrieved);
}

From source file:gov.nih.nci.cabio.portal.portlet.RESTProxyServletController.java

@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
        throws Exception {

    try {/*from  ww  w. ja  v  a  2 s  .c  o m*/
        String relativeURL = request.getParameter("relativeURL");
        if (relativeURL == null) {
            log.error("Null relativeURL parameter");
            return null;
        }

        String qs = request.getQueryString();
        if (qs == null) {
            qs = "";
        }

        qs = qs.replaceFirst("relativeURL=(.*?)&", "");
        qs = URLDecoder.decode(qs, "UTF-8");

        String url = caBIORestURL + relativeURL + "?" + qs;
        log.info("Proxying URL: " + url);

        URI uri = new URI(url, false);
        HttpClient client = new HttpClient();
        HttpMethod method = new GetMethod();
        method.setURI(uri);
        client.executeMethod(method);

        response.setContentType(method.getResponseHeader("Content-Type").getValue());

        CopyUtils.copy(method.getResponseBodyAsStream(), response.getOutputStream());
    } catch (Exception e) {
        throw new ServletException("Unable to connect to caBIO", e);
    }

    return null;
}

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);
    AssertUtils.assertContains("<html", post.getResponseBodyAsString());

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