Example usage for org.apache.http.client.fluent Request Head

List of usage examples for org.apache.http.client.fluent Request Head

Introduction

In this page you can find the example usage for org.apache.http.client.fluent Request Head.

Prototype

public static Request Head(final String uri) 

Source Link

Usage

From source file:org.ow2.proactive.addons.webhook.service.ApacheHttpClientRequestGetter.java

public Request getHttpRequestByString(String method, String url) {
    switch (method) {
    case "GET":
        return Request.Get(url);
    case "POST":
        return Request.Post(url);
    case "HEAD":
        return Request.Head(url);
    case "PUT":
        return Request.Put(url);
    case "DELETE":
        return Request.Delete(url);
    case "OPTIONS":
        return Request.Options(url);
    case "TRACE":
        return Request.Trace(url);
    default:/*from  www  . ja v a 2s  .  c  o m*/
        throw new IllegalArgumentException(method + " is not supported as a rest method");
    }
}

From source file:com.github.arnabk.BlockingChecker.java

public void execute(int frequencyInMins, String... hostsToCheck) {

    while (true) {

        for (int index = 1; index < hostsToCheck.length; index++) {
            StringBuilder sb = new StringBuilder();
            sb.append("Timestamp : ").append(new Date()).append(", ").append("Server : ")
                    .append(hostsToCheck[index]).append(", ").append("Status code : ");
            try {
                sb.append(Request.Head(prepareURL(StringUtils.trimToEmpty(hostsToCheck[index]))).execute()
                        .returnResponse().getStatusLine().getStatusCode());
            } catch (Exception e) {
                sb.append(" Request failed!");
            }/*from   w  w  w. j  av a  2 s.  c o  m*/
            System.out.println(sb);
        }

        try {
            synchronized (this) {
                wait(frequencyInMins * 60 * 1000);
            }
        } catch (InterruptedException ex) {
            Logger.getLogger(App.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

}

From source file:org.debux.webmotion.server.tools.RequestBuilder.java

/**
 * @return a head request
 */
public Request Head() throws URISyntaxException {
    return Request.Head(this.build());
}

From source file:io.coala.capability.online.FluentHCOnlineCapability.java

/**
 * @param method//www . j  a v  a2s. c om
 * @param uri
 * @return
 */
@SuppressWarnings("rawtypes")
public static Request getFluentRequest(final HttpMethod method, final URI uri, final Map.Entry... formData) {
    final Request request;
    switch (method) {
    case GET:
        request = Request.Get(toFormDataURI(uri, formData));
        break;
    case HEAD:
        request = Request.Head(toFormDataURI(uri, formData));
        break;
    case POST:
        request = Request.Post(uri);
        break;
    case PUT:
        request = Request.Put(uri);
        break;
    case DELETE:
        request = Request.Delete(toFormDataURI(uri, formData));
        break;
    case OPTIONS:
        request = Request.Options(toFormDataURI(uri, formData));
        break;
    case TRACE:
        request = Request.Trace(toFormDataURI(uri, formData));
        break;
    default:
        throw new IllegalStateException("UNSUPPORTED: " + method);
    }
    return request.useExpectContinue().version(HttpVersion.HTTP_1_1);
}

From source file:org.schedulesdirect.api.json.DefaultJsonRequest.java

private Request initRequest() {
    Request r = null;//from  www  .j a  v a2  s  . c om
    switch (action) {
    case GET:
        r = Request.Get(baseUrl);
        break;
    case PUT:
        r = Request.Put(baseUrl);
        break;
    case POST:
        r = Request.Post(baseUrl);
        break;
    case DELETE:
        r = Request.Delete(baseUrl);
        break;
    case OPTIONS:
        r = Request.Options(baseUrl);
        break;
    case HEAD:
        r = Request.Head(baseUrl);
        break;
    }
    return r.userAgent(userAgent);
}

From source file:org.n52.youngs.test.ElasticsearchSinkTestmappingIT.java

@Test
public void insertSchema() throws Exception {
    sink.prepare(mapping);/*from  w  w w .  j  a v a 2s .c  om*/

    IndicesAdminClient indicesClient = sink.getClient().admin().indices();
    GetMappingsRequestBuilder builder = new GetMappingsRequestBuilder(indicesClient, GetMappingsAction.INSTANCE,
            mapping.getIndex()).addTypes(mapping.getType());
    GetMappingsResponse response = indicesClient.getMappings(builder.request()).actionGet();
    ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappings = response.getMappings();

    Map<String, Object> recordTypeMap = mappings.get(mapping.getIndex()).get(mapping.getType())
            .getSourceAsMap();
    assertThat("dynamic value is correct", Boolean.valueOf(recordTypeMap.get("dynamic").toString()),
            is(mapping.isDynamicMappingEnabled()));

    Thread.sleep(1000);

    // https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-mapping.html
    String allMappingsResponse = Request.Get("http://localhost:9200/_mapping/_all?pretty").execute()
            .returnContent().asString();
    assertThat("record type is provided (checking id property type", allMappingsResponse, hasJsonPath(
            mapping.getIndex() + ".mappings." + mapping.getType() + ".properties.id.type", is("string")));
    assertThat("metadata type is provided (checking mt_update-time property type)", allMappingsResponse,
            hasJsonPath(mapping.getIndex() + ".mappings.mt.properties.mt-update-time.type", is("date")));

    // https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-types-exists.html
    StatusLine recordsStatus = Request
            .Head("http://localhost:9200/" + mapping.getIndex() + "/" + mapping.getType()).execute()
            .returnResponse().getStatusLine();
    assertThat("records type is available", recordsStatus.getStatusCode(), is(200));
    StatusLine mtStatus = Request.Head("http://localhost:9200/" + mapping.getIndex() + "/mt").execute()
            .returnResponse().getStatusLine();
    assertThat("metadata type is available", mtStatus.getStatusCode(), is(200));
}

From source file:org.n52.youngs.test.ElasticsearchSinkTestmappingIT.java

private void assertEmptyNode() throws IOException {
    String allMappingsResponse = Request.Get("http://localhost:9200/_mapping/_all?pretty").execute()
            .returnContent().asString();
    assertThat("response is empty", allMappingsResponse, not(containsString("mappings")));

    StatusLine recordsStatus = Request
            .Head("http://localhost:9200/" + mapping.getIndex() + "/" + mapping.getType()).execute()
            .returnResponse().getStatusLine();
    assertThat("records type is not available", recordsStatus.getStatusCode(), is(404));
    StatusLine mtStatus = Request.Head("http://localhost:9200/" + mapping.getIndex() + "/mt").execute()
            .returnResponse().getStatusLine();
    assertThat("metadata type is not available", mtStatus.getStatusCode(), is(404));
}

From source file:be.fedict.dcat.datagovbe.Drupal.java

/**
 * Check if dataset with ID already exists on drupal site.
 * //from  w ww .jav  a2  s .co  m
 * @param id
 * @param lang
 * @return 
 */
private String checkExists(String id, String lang) {
    String node = "";

    String u = this.url.toString() + "/" + lang + "/" + Drupal.TYPE_DATA + "/" + id;

    Request r = Request.Head(u);
    if (proxy != null) {
        r.viaProxy(proxy);
    }

    try {
        HttpResponse resp = exec.execute(r).returnResponse();
        Header header = resp.getFirstHeader("Link");
        if (header != null) {
            Matcher m = SHORTLINK.matcher(header.getValue());
            if (m.find()) {
                node = m.group(1);
                logger.info("Dataset {} exists, node {}", id, node);
            }
        }
    } catch (IOException ex) {
        logger.error("Exception getting dataset {}", id);
    }

    return node;
}

From source file:de.elomagic.maven.http.HTTPMojo.java

private Request createRequestMethod() throws Exception {
    switch (method) {
    case DELETE:/*from ww  w  .j av a 2  s.  co m*/
        return Request.Delete(url.toURI());
    case GET:
        return Request.Get(url.toURI());
    case HEAD:
        return Request.Head(url.toURI());
    case POST:
        return Request.Post(url.toURI());
    case PUT:
        return Request.Put(url.toURI());
    }

    throw new Exception("Unsupported HTTP method \"" + method + "\".");
}