Example usage for com.google.common.net HttpHeaders ACCEPT

List of usage examples for com.google.common.net HttpHeaders ACCEPT

Introduction

In this page you can find the example usage for com.google.common.net HttpHeaders ACCEPT.

Prototype

String ACCEPT

To view the source code for com.google.common.net HttpHeaders ACCEPT.

Click Source Link

Document

The HTTP Accept header field name.

Usage

From source file:com.abiquo.apiclient.RestClient.java

public void put(final String uri, final String accept, final String contentType,
        final SingleResourceTransportDto body) {
    try {/*from  w w  w .j  a  v a 2  s . com*/
        String rawBody = json.write(body);
        RequestBody requestBody = RequestBody.create(MediaType.parse(withVersion(contentType)), rawBody);
        Request request = new Request.Builder().url(absolute(uri))
                .addHeader(HttpHeaders.ACCEPT, withVersion(accept)).put(requestBody).build();

        execute(request, (Class<?>) null);
    } catch (IOException ex) {
        throw Throwables.propagate(ex);
    }
}

From source file:de.iteratec.iteraplan.presentation.rest.resource.AResource.java

private boolean isBrowserRequest(HttpRequest request) {
    String[] formatStrings = request.getHeaders().getValuesArray(HttpHeaders.ACCEPT, true);
    for (String formatString : formatStrings) {
        if (formatString.toLowerCase().contains("html")) {
            return true;
        }/* w  w  w  .j  av a 2  s  .  com*/
    }
    return false;
}

From source file:eu.seaclouds.policy.SeaCloudsManagementPolicy.java

private HttpToolResponse delete(String url, String mediaType, String username, String password) {
    URI apiEndpoint = URI.create(url);
    // the uri is required by the HttpClientBuilder in order to set the AuthScope of the credentials

    if (username == null || password == null) {
        return HttpTool.httpDelete(HttpTool.httpClientBuilder().build(), apiEndpoint,
                MutableMap.of(HttpHeaders.CONTENT_TYPE, mediaType, HttpHeaders.ACCEPT, mediaType));
    } else {/*from  ww w .j a  va2s  .  c  o m*/
        UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(username, password);

        // the uri is required by the HttpClientBuilder in order to set the AuthScope of the credentials
        return HttpTool.httpDelete(
                HttpTool.httpClientBuilder().uri(apiEndpoint).credentials(credentials).build(), apiEndpoint,
                MutableMap.of(HttpHeaders.CONTENT_TYPE, mediaType, HttpHeaders.ACCEPT, mediaType,
                        HttpHeaders.AUTHORIZATION, HttpTool.toBasicAuthorizationValue(credentials)));
    }
}

From source file:eu.seaclouds.policy.SeaCloudsManagementPolicy.java

private HttpToolResponse post(String url, String mediaType, String username, String password, byte[] payload) {
    URI apiEndpoint = URI.create(url);
    // the uri is required by the HttpClientBuilder in order to set the AuthScope of the credentials

    if (username == null || password == null) {
        return HttpTool.httpPost(HttpTool.httpClientBuilder().build(), apiEndpoint,
                MutableMap.of(HttpHeaders.CONTENT_TYPE, mediaType, HttpHeaders.ACCEPT, mediaType), payload);
    } else {//from w  ww .  jav  a 2 s.  com
        UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(username, password);

        // the uri is required by the HttpClientBuilder in order to set the AuthScope of the credentials
        return HttpTool.httpPost(HttpTool.httpClientBuilder().uri(apiEndpoint).credentials(credentials).build(),
                apiEndpoint, MutableMap.of(HttpHeaders.CONTENT_TYPE, mediaType, HttpHeaders.ACCEPT, mediaType,
                        HttpHeaders.AUTHORIZATION, HttpTool.toBasicAuthorizationValue(credentials)),
                payload);
    }
}

From source file:com.google.gerrit.httpd.restapi.RestApiServlet.java

private static boolean acceptsJson(HttpServletRequest req) {
    return req != null && isType(JSON_TYPE, req.getHeader(HttpHeaders.ACCEPT));
}

From source file:brooklyn.entity.mesos.task.marathon.MarathonTaskImpl.java

public Optional<JsonElement> getApplicationJson() {
    MesosFramework framework = getFramework();
    String uri = Urls.mergePaths(framework.sensors().get(MarathonFramework.FRAMEWORK_URL), "/v2/apps",
            sensors().get(APPLICATION_ID));
    HttpToolResponse response = HttpTool.httpGet(MesosUtils.buildClient(framework), URI.create(uri),
            MutableMap.of(HttpHeaders.ACCEPT, "application/json"));
    if (!HttpTool.isStatusCodeHealthy(response.getResponseCode())) {
        return Optional.absent();
    } else {//from  w w w .java2 s  .c o  m
        JsonElement app = HttpValueFunctions.jsonContents().apply(response);
        if (app.isJsonNull()) {
            return Optional.absent();
        } else {
            LOG.debug("Application JSON: {}", response.getContentAsString());
            return Optional.of(app);
        }
    }
}