Example usage for org.apache.http.client.methods HttpGet METHOD_NAME

List of usage examples for org.apache.http.client.methods HttpGet METHOD_NAME

Introduction

In this page you can find the example usage for org.apache.http.client.methods HttpGet METHOD_NAME.

Prototype

String METHOD_NAME

To view the source code for org.apache.http.client.methods HttpGet METHOD_NAME.

Click Source Link

Usage

From source file:org.robolectric.shadows.httpclient.HttpRedirect.java

public HttpRedirect(final String method, final URI uri) {
    super();/*from   ww  w . j  a  v  a2  s. co  m*/
    if (method.equalsIgnoreCase(HttpHead.METHOD_NAME)) {
        this.method = HttpHead.METHOD_NAME;
    } else {
        this.method = HttpGet.METHOD_NAME;
    }
    setURI(uri);
}

From source file:com.openx.oauth.redirect.OpenXRedirectStrategy.java

/**
 * Custom redirect logic// w  w  w .  java  2 s.c  om
 * @param request
 * @param response
 * @param context
 * @return if the handler should redirect or not
 */
@Override
public boolean isRedirected(final HttpRequest request, final HttpResponse response, final HttpContext context) {
    if (response == null) {
        throw new IllegalArgumentException("HTTP response may not be null");
    }

    int statusCode = response.getStatusLine().getStatusCode();
    String method = request.getRequestLine().getMethod();
    Header locationHeader = response.getFirstHeader("location");
    switch (statusCode) {
    case HttpStatus.SC_MOVED_TEMPORARILY:
        if (method.equalsIgnoreCase(HttpPost.METHOD_NAME)) {
            return locationHeader != null;
        } else {
            return (method.equalsIgnoreCase(HttpGet.METHOD_NAME)
                    || method.equalsIgnoreCase(HttpHead.METHOD_NAME)) && locationHeader != null;
        }
    case HttpStatus.SC_MOVED_PERMANENTLY:
    case HttpStatus.SC_TEMPORARY_REDIRECT:
        return method.equalsIgnoreCase(HttpGet.METHOD_NAME) || method.equalsIgnoreCase(HttpHead.METHOD_NAME);
    case HttpStatus.SC_SEE_OTHER:
        return true;
    default:
        return false;
    }
}

From source file:org.camunda.connect.httpclient.HttpRequestTest.java

@Test
public void setHttpMethod() {
    HttpRequest request = connector.createRequest().get();
    assertThat(request.getMethod()).isEqualTo(HttpGet.METHOD_NAME);

    request = connector.createRequest().post();
    assertThat(request.getMethod()).isEqualTo(HttpPost.METHOD_NAME);

    request = connector.createRequest().put();
    assertThat(request.getMethod()).isEqualTo(HttpPut.METHOD_NAME);

    request = connector.createRequest().delete();
    assertThat(request.getMethod()).isEqualTo(HttpDelete.METHOD_NAME);

    request = connector.createRequest().patch();
    assertThat(request.getMethod()).isEqualTo(HttpPatch.METHOD_NAME);

    request = connector.createRequest().head();
    assertThat(request.getMethod()).isEqualTo(HttpHead.METHOD_NAME);

    request = connector.createRequest().options();
    assertThat(request.getMethod()).isEqualTo(HttpOptions.METHOD_NAME);

    request = connector.createRequest().trace();
    assertThat(request.getMethod()).isEqualTo(HttpTrace.METHOD_NAME);
}

From source file:com.uploader.Vimeo.java

public VimeoResponse getVideoInfo(String videoEndpoint) throws IOException {
    return apiRequest(videoEndpoint, HttpGet.METHOD_NAME, null, null);
}

From source file:quarks.connectors.http.runtime.HttpRequester.java

@Override
public R apply(T t) {

    if (client == null)
        client = clientCreator.get();//from   ww w .  ja  v  a 2s.co  m

    String m = method.apply(t);
    String uri = url.apply(t);
    HttpUriRequest request;
    switch (m) {
    case HttpGet.METHOD_NAME:
        request = new HttpGet(uri);
        break;
    case HttpDelete.METHOD_NAME:
        request = new HttpDelete(uri);
        break;

    default:
        throw new IllegalArgumentException();
    }

    try {
        try (CloseableHttpResponse response = client.execute(request)) {
            return responseProcessor.apply(t, response);
        }

    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:io.wcm.caravan.io.http.impl.RequestUtilTest.java

@Test
public void testBuildHttpRequest_Get() {
    RequestTemplate template = new RequestTemplate().method("get").append("/path").header("header1", "value1")
            .header("header2", "value2", "value3");
    HttpUriRequest request = RequestUtil.buildHttpRequest("http://host", template.request());

    assertEquals("http://host/path", request.getURI().toString());
    assertEquals(HttpGet.METHOD_NAME, request.getMethod());

    Map<String, Collection<String>> expected = ImmutableMap.<String, Collection<String>>of("header1",
            ImmutableList.of("value1"), "header2", ImmutableList.of("value2", "value3"));
    assertEquals(expected, RequestUtil.toHeadersMap(request.getAllHeaders()));
}

From source file:org.apache.edgent.connectors.http.HttpStreams.java

/**
 * Make an HTTP GET request with JsonObject. <br>
 * //from  w w w  .  j  a v  a 2  s . c  o  m
 * Method specifically works with JsonObjects. For each JsonObject in the stream, 
 * HTTP GET request is executed on provided uri. As a result, Response is added to
 * the response TStream.
 * <br>
 * 
 * Sample usage:<br>
 * 
 * <pre>
 * {@code
 *     DirectProvider ep = new DirectProvider();
 *     Topology topology = ep.newTopology();
 *     final String url = "http://httpbin.org/get?";
 * 
 *     JsonObject request1 = new JsonObject();
 *     request1.addProperty("a", "abc");
 *     request1.addProperty("b", "42");
 * 
 *     TStream<JsonObject> stream = topology.collection(Arrays.asList(request1));
 *     TStream<JsonObject> rc = HttpStreams.getJson(stream,
 *             HttpClients::noAuthentication,
 *             t -> url + "a=" + t.get("a").getAsString() + "&b="
 *                     + t.get("b").getAsString());
 * }
 * </pre>
 * 
 * <br>
 * See <i>HttpTest</i> for example. <br>
 * 
 * @param stream - JsonObject TStream.
 * @param clientCreator - CloseableHttpClient supplier preferably created using {@link HttpClients}
 * @param uri - URI function which returns URI string
 * @return TStream of JsonObject which contains responses of GET requests
 * 
 * @see HttpStreams#requests(TStream, Supplier, Function, Function, BiFunction)
 */
public static TStream<JsonObject> getJson(TStream<JsonObject> stream,
        Supplier<CloseableHttpClient> clientCreator, Function<JsonObject, String> uri) {

    return HttpStreams.<JsonObject, JsonObject>requests(stream, clientCreator, t -> HttpGet.METHOD_NAME, uri,
            HttpResponders.json());
}

From source file:com.cloud.utils.rest.HttpUriRequestBuilderTest.java

@Test
public void testBuildSimpleRequest() throws Exception {
    final HttpUriRequest request = HttpUriRequestBuilder.create().method(HttpMethods.GET).path("/path").build();

    assertThat(request, notNullValue());
    assertThat(request.getURI().getPath(), equalTo("/path"));
    assertThat(request.getURI().getScheme(), nullValue());
    assertThat(request.getURI().getQuery(), nullValue());
    assertThat(request.getURI().getHost(), nullValue());
    assertThat(request.getMethod(), equalTo(HttpGet.METHOD_NAME));
}

From source file:org.apache.brooklyn.entity.brooklynnode.CallbackEntityHttpClient.java

@Override
public HttpToolResponse get(String path) {
    String result = callback/*from w ww  .jav a2 s .c o  m*/
            .apply(new Request(entity, HttpGet.METHOD_NAME, path, Collections.<String, String>emptyMap()));
    return new HttpToolResponse(HttpStatus.SC_OK, null, result.getBytes(), 0, 0, 0);
}

From source file:org.apache.edgent.test.connectors.http.HttpTest.java

@Test
public void testGet() throws Exception {

    DirectProvider ep = new DirectProvider();

    Topology topology = ep.newTopology();

    String url = "http://httpbin.org/get";

    TStream<String> rc = HttpStreams.<String, String>requests(topology.strings(url),
            HttpClients::noAuthentication, t -> HttpGet.METHOD_NAME, t -> t, HttpResponders.inputOn200());

    Tester tester = topology.getTester();

    Condition<List<String>> endCondition = tester.streamContents(rc, url);

    tester.complete(ep, new JsonObject(), endCondition, 10, TimeUnit.SECONDS);

    assertTrue(endCondition.valid());//from www  .  ja v  a2 s  .c  o  m
}