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:ch.cyberduck.core.dropbox.client.DropboxClient.java

/**
 * Get metadata about directories and files, such as file listings and such.
 *//*from  w  ww .j  a va  2s.  c  o m*/
public ListEntryResponse metadata(String path, int file_limit, String hash, boolean list,
        boolean status_in_response, String callback) throws IOException {
    String[] params = { "file_limit", "" + file_limit, "hash", hash, "list", "" + list, "status_in_response",
            "" + status_in_response, "callback", callback };

    HttpResponse response = request(this.buildRequest(HttpGet.METHOD_NAME, "/files/" + ROOT + path, params));
    return new ListEntryResponse(this.parse(response));
}

From source file:com.uploader.Vimeo.java

public VimeoResponse searchVideos(String query, String pageNumber, String itemsPerPage) throws IOException {
    String apiRequestEndpoint = "/me/videos?page=" + pageNumber + "&per_page=" + itemsPerPage + "&query="
            + query;//w  ww  .j  a v  a2s  .com
    return apiRequest(apiRequestEndpoint, HttpGet.METHOD_NAME, null, null);
}

From source file:com.seleritycorp.common.base.http.client.HttpRequest.java

private org.apache.http.HttpResponse getHttpResponse() throws HttpException {
    final HttpRequestBase request;

    switch (method) {
    case HttpGet.METHOD_NAME:
        request = new HttpGet();
        break;//from w ww .java  2 s .c o m
    case HttpPost.METHOD_NAME:
        request = new HttpPost();
        break;
    default:
        throw new HttpException("Unknown HTTP method '" + method + "'");
    }

    try {
        request.setURI(URI.create(uri));
    } catch (IllegalArgumentException e) {
        throw new HttpException("Failed to create URI '" + uri + "'", e);
    }

    if (userAgent != null) {
        request.setHeader(HTTP.USER_AGENT, userAgent);
    }

    if (readTimeoutMillis >= 0) {
        request.setConfig(RequestConfig.custom().setSocketTimeout(readTimeoutMillis)
                .setConnectTimeout(readTimeoutMillis).setConnectionRequestTimeout(readTimeoutMillis).build());
    }

    if (!data.isEmpty()) {
        if (request instanceof HttpEntityEnclosingRequestBase) {
            final HttpEntity entity;
            ContentType localContentType = contentType;
            if (localContentType == null) {
                localContentType = ContentType.create("text/plain", StandardCharsets.UTF_8);
            }
            entity = new StringEntity(data, localContentType);
            HttpEntityEnclosingRequestBase entityRequest = (HttpEntityEnclosingRequestBase) request;
            entityRequest.setEntity(entity);
        } else {
            throw new HttpException(
                    "Request " + request.getMethod() + " does not allow to send data " + "with the request");
        }
    }

    final HttpClient httpClient;
    if (uri.startsWith("file://")) {
        httpClient = this.fileHttpClient;
    } else {
        httpClient = this.netHttpClient;
    }
    final org.apache.http.HttpResponse response;
    try {
        response = httpClient.execute(request);
    } catch (IOException e) {
        throw new HttpException("Failed to execute request to '" + uri + "'", e);
    }
    return response;
}

From source file:code.google.restclient.core.Hitter.java

/**
 * Method to make POST or PUT request by sending http entity (as body)
 *//*from   ww w.  j a  v a2 s . c o m*/
public void hit(String url, String methodName, HttpHandler handler, Map<String, String> requestHeaders)
        throws Exception {

    if (DEBUG_ENABLED)
        LOG.debug("hit() - method => " + methodName + ", url => " + url);

    if (HttpGet.METHOD_NAME.equals(methodName)) {
        if (DEBUG_ENABLED)
            LOG.debug("hit() - ===> GET " + url);
        hit(url, new HttpGet(url), handler, requestHeaders);
    } else if (HttpHead.METHOD_NAME.equals(methodName)) {
        if (DEBUG_ENABLED)
            LOG.debug("hit() - ===> HEAD " + url);
        hit(url, new HttpHead(url), handler, requestHeaders);
    } else if (HttpDelete.METHOD_NAME.equals(methodName)) {
        if (DEBUG_ENABLED)
            LOG.debug("hit() - ===> DELETE " + url);
        hit(url, new HttpDelete(url), handler, requestHeaders);
    } else if (HttpOptions.METHOD_NAME.equals(methodName)) {
        if (DEBUG_ENABLED)
            LOG.debug("hit() - ===> OPTIONS " + url);
        hit(url, new HttpOptions(url), handler, requestHeaders);
    } else if (HttpTrace.METHOD_NAME.equals(methodName)) {
        if (DEBUG_ENABLED)
            LOG.debug("hit() - ===> TRACE " + url);
        hit(url, new HttpTrace(url), handler, requestHeaders);
    } else if (HttpPost.METHOD_NAME.equals(methodName)) { // POST
        if (DEBUG_ENABLED)
            LOG.debug("hit() - ===> POST " + url);
        HttpPost httpPost = new HttpPost(url);
        httpPost.setEntity(handler.getReqBodyEntity());
        hit(url, httpPost, handler, requestHeaders);
    } else if (HttpPut.METHOD_NAME.equals(methodName)) { // PUT
        if (DEBUG_ENABLED)
            LOG.debug("hit() - ===> PUT " + url);
        HttpPut httpPut = new HttpPut(url);
        httpPut.setEntity(handler.getReqBodyEntity());
        hit(url, httpPut, handler, requestHeaders);
    } else {
        throw new IllegalArgumentException("hit(): Unsupported method => " + methodName);
    }
}

From source file:io.wcm.caravan.pipeline.extensions.hal.client.action.LoadLink.java

/**
 * Adds a cache point to the given JSON pipeline if provided and the http request method is GET.
 * @param pipeline JSON pipeline/* w ww .  j  a v a2s .  com*/
 * @return JSON pipeline with or without cache point
 */
private JsonPipeline setCacheStrategyIfExists(JsonPipeline pipeline) {
    if (!HttpGet.METHOD_NAME.equals(httpMethod)) {
        return pipeline;
    } else {
        CacheStrategy cacheStrategy = getCacheStrategy();
        return cacheStrategy == null ? pipeline : pipeline.addCachePoint(cacheStrategy);
    }
}

From source file:org.apache.zeppelin.notebook.repo.zeppelinhub.rest.HttpProxyClient.java

private HttpAsyncClientBuilder setRedirects(HttpAsyncClientBuilder clientBuilder) {
    clientBuilder.setRedirectStrategy(new DefaultRedirectStrategy() {
        /** Redirectable methods. */
        private String[] REDIRECT_METHODS = new String[] { HttpGet.METHOD_NAME, HttpPost.METHOD_NAME,
                HttpPut.METHOD_NAME, HttpDelete.METHOD_NAME, HttpHead.METHOD_NAME };

        @Override// w  ww .  ja  v  a  2 s  .  c  o m
        protected boolean isRedirectable(String method) {
            for (String m : REDIRECT_METHODS) {
                if (m.equalsIgnoreCase(method)) {
                    return true;
                }
            }
            return false;
        }
    });
    return clientBuilder;
}

From source file:com.mywork.framework.util.RemoteHttpUtil.java

/**
 * ?getpost????/*from   w w w . j av  a2  s . c o  m*/
 */
public static String fetchSimpleHttpResponse(String method, String contentUrl, Map<String, String> headerMap,
        Map<String, String> bodyMap) throws IOException {
    Executor executor = Executor.newInstance(httpClient);
    if (HttpGet.METHOD_NAME.equalsIgnoreCase(method)) {
        String result = contentUrl;
        StringBuilder sb = new StringBuilder();
        sb.append(contentUrl);
        if (bodyMap != null && !bodyMap.isEmpty()) {
            if (contentUrl.indexOf("?") > 0) {
                sb.append("&");
            } else {
                sb.append("?");
            }
            result = Joiner.on("&").appendTo(sb, bodyMap.entrySet()).toString();
        }

        return executor.execute(Request.Get(result)).returnContent().asString();
    }
    if (HttpPost.METHOD_NAME.equalsIgnoreCase(method)) {
        Request request = Request.Post(contentUrl);
        if (headerMap != null && !headerMap.isEmpty()) {
            for (Map.Entry<String, String> m : headerMap.entrySet()) {
                request.addHeader(m.getKey(), m.getValue());
            }
        }
        if (bodyMap != null && !bodyMap.isEmpty()) {
            Form form = Form.form();
            for (Map.Entry<String, String> m : bodyMap.entrySet()) {
                form.add(m.getKey(), m.getValue());
            }
            request.bodyForm(form.build());
        }
        return executor.execute(request).returnContent().asString();
    }
    return null;

}

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

@Test
public void testStatusCode() throws Exception {

    DirectProvider ep = new DirectProvider();

    Topology topology = ep.newTopology();

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

    TStream<Integer> rc = HttpStreams.<Integer, Integer>requests(
            topology.collection(Arrays.asList(200, 404, 202)), HttpClients::noAuthentication,
            t -> HttpGet.METHOD_NAME, t -> url + Integer.toString(t),
            (t, resp) -> resp.getStatusLine().getStatusCode());

    Tester tester = topology.getTester();

    Condition<List<Integer>> endCondition = tester.streamContents(rc, 200, 404, 202);

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

    assertTrue(endCondition.valid());// w  w w  .  jav a 2  s  .c o m
}

From source file:ch.cyberduck.core.dropbox.client.DropboxClient.java

/**
 * @param path//  ww w . ja  va2 s . co m
 * @return
 * @throws IOException
 */
public ListEntryResponse list(String path) throws IOException {
    String[] params = { "list", String.valueOf(true) };
    HttpResponse response = request(this.buildRequest(HttpGet.METHOD_NAME, "/metadata/" + ROOT + path, params));
    return new ListEntryResponse(this.parse(response));
}

From source file:eu.over9000.cathode.Dispatcher.java

public Result<String> getResponseRaw(final String url) {
    try {//from w  w  w . j a va 2s .  c  o m
        return new Result<>(getResponseString(HttpGet.METHOD_NAME, url, null));

    } catch (final Exception e) {
        return new Result<>(e);
    }
}