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:se.curity.examples.oauth.opaque.OpaqueTokenValidator.java

protected String introspect(String token) throws IOException {
    HttpPost post = new HttpPost(_introspectionUri);
    post.setHeader(HttpHeaders.ACCEPT, ContentType.APPLICATION_JSON.getMimeType());

    List<NameValuePair> params = new ArrayList<>();
    params.add(new BasicNameValuePair("token", token));
    params.add(new BasicNameValuePair("client_id", _clientId));
    params.add(new BasicNameValuePair("client_secret", _clientSecret));

    post.setEntity(new UrlEncodedFormEntity(params));

    HttpResponse response = _httpClient.execute(post);

    if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
        _logger.error("Got error from introspection server: " + response.getStatusLine().getStatusCode());
        throw new IOException(
                "Got error from introspection server: " + response.getStatusLine().getStatusCode());
    }/*from www.  ja  v a2s .  c o  m*/
    return EntityUtils.toString(response.getEntity(), Charsets.UTF_8);
}

From source file:org.jclouds.openstack.keystone.v2_0.internal.KeystoneFixture.java

public HttpRequest initialAuthWithAccessKeyAndSecretKeyAndTenantId(String accessKey, String secretKey) {
    return HttpRequest.builder().method("POST")

            .endpoint("http://localhost:5000/v2.0/tokens").addHeader(HttpHeaders.ACCEPT, "application/json")
            .payload(payloadFromStringWithContentType(format(
                    "{\"auth\":{\"apiAccessKeyCredentials\":{\"accessKey\":\"%s\",\"secretKey\":\"%s\"},\"tenantId\":\"%s\"}}",
                    accessKey, secretKey, getTenantId()), "application/json"))
            .build();//from w  ww .j  a va  2s.  c o m
}

From source file:se.curity.examples.oauth.jwt.JwkManager.java

protected String fetchKeys() throws IOException {
    HttpGet get = new HttpGet(_jwksUri);
    get.setHeader(HttpHeaders.ACCEPT, ContentType.APPLICATION_JSON.getMimeType());

    HttpResponse response = _httpClient.execute(get);

    if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
        _logger.error("Got error from Jwks server: " + response.getStatusLine().getStatusCode());
        throw new IOException("Got error from Jwks server: " + response.getStatusLine().getStatusCode());
    }/*from  ww  w .  j a  v a2 s  .c o m*/

    return EntityUtils.toString(response.getEntity(), Charsets.UTF_8);
}

From source file:clocker.mesos.entity.MesosUtils.java

public static final Optional<String> httpDelete(Entity framework, String subUrl) {
    String targetUrl = Urls.mergePaths(framework.sensors().get(MesosFramework.FRAMEWORK_URL), subUrl);
    LOG.debug("Deleting {}", targetUrl);
    URI deleteUri = URI.create(targetUrl);
    HttpToolResponse response = HttpTool.httpDelete(buildClient(framework), deleteUri,
            MutableMap.of(HttpHeaders.ACCEPT, "application/json"));
    LOG.debug("Response: " + response.getContentAsString());
    if (!HttpTool.isStatusCodeHealthy(response.getResponseCode())) {
        LOG.warn("Invalid response code {}: {}", response.getResponseCode(), response.getReasonPhrase());
        return Optional.absent();
    } else {//from w w w  .j  a  va2s .c  o  m
        LOG.debug("Successfull call to {}: {}", targetUrl);
        return Optional.of(response.getContentAsString());
    }
}

From source file:org.sonar.server.ws.ServletRequest.java

@CheckForNull
private String acceptedContentTypeInResponse() {
    return source.getHeader(HttpHeaders.ACCEPT);
}

From source file:org.ldp4j.server.IntegrationTestHelper.java

public void executeCommand(Object command) throws Exception {
    HttpPost post = new HttpPost(resolve("ldp4j/action/"));
    post.setHeader(HttpHeaders.ACCEPT, MediaType.TEXT_PLAIN);
    post.setEntity(new StringEntity(commandUtil.toString(CommandDescription.newInstance(command)),
            ContentType.create(Command.MIME, "UTF-8")));
    httpRequest(post);/*from www . j a  v a  2s.  com*/
}

From source file:org.opennms.smoketest.RequisitionUtils.java

public OnmsNodeList getNodesInDatabase(final String foreignSource) {
    try (HttpClientWrapper httpClient = HttpClientWrapper.create()) {
        httpClient.addBasicCredentials(OpenNMSSeleniumTestCase.BASIC_AUTH_USERNAME,
                OpenNMSSeleniumTestCase.BASIC_AUTH_PASSWORD);
        httpClient.usePreemptiveAuth();/*from   ww  w . j a  v  a 2  s  .  com*/
        HttpGet request = new HttpGet(OpenNMSSeleniumTestCase.BASE_URL + "/opennms/rest/nodes");
        request.setHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_XML_UTF_8.toString());

        try (CloseableHttpResponse response = httpClient.execute(request)) {
            try (Reader reader = new InputStreamReader(response.getEntity().getContent())) {
                return JaxbUtils.unmarshal(OnmsNodeList.class, reader);
            }
        }
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}

From source file:org.apache.marmotta.platform.core.webservices.triplestore.ContextWebService.java

/**
 * Indirect context identification, listing in case 'graph' is missing
 *
 * @param context uri/*from w  w w  .j  a v a  2s  .  c  o  m*/
 * @param accept Accept HTTP header
 * @param format format requested (overwrites accept header)
 *
 * @return response
 * @throws URISyntaxException
 * @see <a href="http://www.w3.org/TR/sparql11-http-rdf-update/#indirect-graph-identification">Indirect Graph Identification</a>
 */
@GET
public Response get(@QueryParam("graph") String context, @HeaderParam("Accept") String accept,
        @QueryParam("format") String format) throws URISyntaxException {
    if (StringUtils.isBlank(context)) {
        return Response
                .seeOther(new URI(
                        configurationService.getServerUri() + ConfigurationService.CONTEXT_PATH + "/list"))
                .header(HttpHeaders.ACCEPT, accept).build();
    } else {
        URI uri = buildExportUri(context, accept, format);
        return Response.seeOther(uri).build();
    }
}

From source file:org.hashes.CollisionInjector.java

protected void addRequestHeaders(final int contentLength, final StringBuilder payloadBuilder) {

    // http://www.ietf.org/rfc/rfc2616.txt
    // Each header field consists of a name followed by a colon (":") and the field value. Field names are
    // case-insensitive.
    final Locale locale = Locale.ENGLISH;
    final Map<String, String> defaultHeaders = new LinkedHashMap<String, String>();
    defaultHeaders.put(HttpHeaders.HOST.toLowerCase(locale), this.configuration.getTarget().getHost());
    defaultHeaders.put(HttpHeaders.CONTENT_TYPE.toLowerCase(locale), "application/x-www-form-urlencoded");
    defaultHeaders.put(HttpHeaders.ACCEPT_CHARSET.toLowerCase(locale), this.configuration.getCharset().name());
    defaultHeaders.put(HttpHeaders.CONTENT_LENGTH.toLowerCase(locale), String.valueOf(contentLength));
    defaultHeaders.put(HttpHeaders.USER_AGENT.toLowerCase(locale), "hashes");
    defaultHeaders.put(HttpHeaders.ACCEPT.toLowerCase(locale), "*/*");

    for (final Entry<String, String> externalHeaders : this.configuration.getHeaders().entrySet()) {
        defaultHeaders.put(externalHeaders.getKey().toLowerCase(locale), externalHeaders.getValue());
    }/*from www  . j  a  v a 2  s.c  o  m*/

    for (final Entry<String, String> header : defaultHeaders.entrySet()) {
        payloadBuilder.append(header.getKey());
        payloadBuilder.append(": ");
        payloadBuilder.append(header.getValue());
        payloadBuilder.append("\r\n");
    }

    payloadBuilder.append("\r\n");
}

From source file:org.glassfish.jersey.server.RequestContextBuilder.java

public RequestContextBuilder accept(String... acceptHeader) {
    putHeaders(HttpHeaders.ACCEPT, acceptHeader);
    return this;
}