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.b2international.snowowl.snomed.api.rest.SnomedConceptRestService.java

@ApiOperation(value = "Alternate search endpoint. Retrieve Concepts from a branch", notes = "This is an alternative to the standard {path}/concepts search endpoint.<br/>"
        + "Returns a list with all/filtered Concepts from a branch."
        + "<p>The following properties can be expanded:" + "<p>"
        + "&bull; pt() &ndash; the description representing the concept's preferred term in the given locale<br>"
        + "&bull; fsn() &ndash; the description representing the concept's fully specified name in the given locale<br>"
        + "&bull; descriptions() &ndash; the list of descriptions for the concept<br>")
@ApiResponses({ @ApiResponse(code = 200, message = "OK", response = PageableCollectionResource.class),
        @ApiResponse(code = 400, message = "Invalid filter config", response = RestApiError.class),
        @ApiResponse(code = 404, message = "Branch not found", response = RestApiError.class) })
@RequestMapping(value = "/{path:**}/concepts/search", method = RequestMethod.POST, produces = {
        AbstractRestService.SO_MEDIA_TYPE, AbstractRestService.TEXT_CSV_MEDIA_TYPE })
public @ResponseBody DeferredResult<SnomedConcepts> searchViaPost(

        @ApiParam(value = "The branch path") @PathVariable(value = "path") final String branch,

        @RequestBody final SnomedConceptRestSearch body,

        @ApiParam(value = "Accepted language tags, in order of preference") @RequestHeader(value = HttpHeaders.ACCEPT_LANGUAGE, defaultValue = "en-US;q=0.8,en-GB;q=0.6", required = false) final String acceptLanguage,

        @ApiIgnore @RequestHeader(value = HttpHeaders.ACCEPT, defaultValue = AbstractRestService.SO_MEDIA_TYPE, required = false) final String contentType) {

    return doSearch(branch, body.getActiveFilter(), body.getModuleFilter(), body.getNamespaceFilter(),
            body.getEffectiveTimeFilter(), body.getDefinitionStatusFilter(), body.getTermFilter(),
            body.getDescriptionActiveFilter(), body.getEclFilter(), body.getStatedEclFilter(),
            body.getConceptIds(), body.getScrollKeepAlive(), body.getScrollId(), body.getSearchAfter(),
            body.getLimit(), body.getExpand(), acceptLanguage, contentType);
}

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

public <T extends SingleResourceTransportDto> T post(final String uri, final String accept,
        final String contentType, final SingleResourceTransportDto body, final TypeToken<T> returnType) {
    try {/*from ww w.j  av  a2 s. c o  m*/
        RequestBody requestBody = RequestBody.create(MediaType.parse(withVersion(contentType)),
                json.write(body));
        Request request = new Request.Builder().url(absolute(uri))
                .addHeader(HttpHeaders.ACCEPT, withVersion(accept)).post(requestBody).build();

        return execute(request, returnType);
    } catch (IOException ex) {
        throw Throwables.propagate(ex);
    }
}

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

public <T extends SingleResourceTransportDto> T post(final String uri, final String accept,
        final Class<T> returnClass) {
    try {/*from   w w w. j  ava  2 s.c  om*/
        Request request = new Request.Builder().url(absolute(uri))
                .addHeader(HttpHeaders.ACCEPT, withVersion(accept)).post(null).build();

        return execute(request, returnClass);
    } catch (IOException ex) {
        throw Throwables.propagate(ex);
    }
}

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

public <T extends SingleResourceTransportDto> T post(final String uri, final String accept,
        final String contentType, final String body, final Class<T> returnClass) {
    try {/*from   w  ww  .ja  v  a 2  s. c  o  m*/
        RequestBody requestBody = RequestBody.create(MediaType.parse(withVersion(contentType)), body);
        Request request = new Request.Builder().url(absolute(uri))
                .addHeader(HttpHeaders.ACCEPT, withVersion(accept)).post(requestBody).build();

        return execute(request, returnClass);
    } catch (IOException ex) {
        throw Throwables.propagate(ex);
    }
}

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

public <T extends SingleResourceTransportDto> T post(final String uri, final String accept,
        final TypeToken<T> returnType) {
    try {//from  www  .j  a  v  a2 s.  c  o  m
        Request request = new Request.Builder().url(absolute(uri))
                .addHeader(HttpHeaders.ACCEPT, withVersion(accept)).post(null).build();

        return execute(request, returnType);
    } catch (IOException ex) {
        throw Throwables.propagate(ex);
    }
}

From source file:net.myrrix.web.servlets.AbstractMyrrixServlet.java

/**
 * Determines the appropriate content type for the response based on request headers. At the moment these
 * are chosen from the values in {@link ResponseContentType}.
 *//*from w w  w .j a v  a  2 s .  c o  m*/
final ResponseContentType determineResponseType(HttpServletRequest request) {

    String acceptHeader = request.getHeader(HttpHeaders.ACCEPT);
    if (acceptHeader == null) {
        return ResponseContentType.JSON;
    }
    ResponseContentType cached = responseTypeCache.get(acceptHeader);
    if (cached != null) {
        return cached;
    }

    SortedMap<Double, ResponseContentType> types = Maps.newTreeMap();
    for (String accept : COMMA.split(acceptHeader)) {
        double preference;
        String type;
        int semiColon = accept.indexOf(';');
        if (semiColon < 0) {
            preference = 1.0;
            type = accept;
        } else {
            String valueString = accept.substring(semiColon + 1).trim();
            if (valueString.startsWith("q=")) {
                valueString = valueString.substring(2);
            }
            try {
                preference = LangUtils.parseDouble(valueString);
            } catch (IllegalArgumentException ignored) {
                preference = 1.0;
            }
            type = accept.substring(semiColon);
        }
        ResponseContentType parsedType = null;
        if ("text/csv".equals(type) || "text/plain".equals(type)) {
            parsedType = ResponseContentType.CSV;
        } else if ("application/json".equals(type)) {
            parsedType = ResponseContentType.JSON;
        }
        if (parsedType != null) {
            types.put(preference, parsedType);
        }
    }

    ResponseContentType finalType;
    if (types.isEmpty()) {
        finalType = ResponseContentType.JSON;
    } else {
        finalType = types.values().iterator().next();
    }

    responseTypeCache.putIfAbsent(acceptHeader, finalType);
    return finalType;
}

From source file:net.myrrix.client.ClientRecommender.java

/**
 * @param replica host and port of replica to connect to
 * @param path URL to access (relative to context root)
 * @param method HTTP method to use/*ww  w .ja  va2s  .com*/
 * @param doOutput if true, will need to write data into the request body
 * @param chunkedStreaming if true, use chunked streaming to accommodate a large upload, if possible
 * @param requestProperties additional request key/value pairs or {@code null} for none
 */
private HttpURLConnection buildConnectionToReplica(HostAndPort replica, String path, String method,
        boolean doOutput, boolean chunkedStreaming, Map<String, String> requestProperties) throws IOException {
    String contextPath = config.getContextPath();
    if (contextPath != null) {
        path = '/' + contextPath + path;
    }
    String protocol = config.isSecure() ? "https" : "http";
    URL url;
    try {
        url = new URL(protocol, replica.getHostText(), replica.getPort(), path);
    } catch (MalformedURLException mue) {
        // can't happen
        throw new IllegalStateException(mue);
    }
    log.debug("{} {}", method, url);

    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    connection.setRequestMethod(method);
    connection.setDoInput(true);
    connection.setDoOutput(doOutput);
    connection.setUseCaches(false);
    connection.setAllowUserInteraction(false);
    connection.setRequestProperty(HttpHeaders.ACCEPT, DESIRED_RESPONSE_CONTENT_TYPE);
    if (closeConnection) {
        connection.setRequestProperty(HttpHeaders.CONNECTION, "close");
    }
    if (chunkedStreaming) {
        if (needAuthentication) {
            // Must buffer in memory if using authentication since it won't handle the authorization challenge
            log.debug("Authentication is enabled, so ingest data must be buffered in memory");
        } else {
            connection.setChunkedStreamingMode(0); // Use default buffer size
        }
    }
    if (requestProperties != null) {
        for (Map.Entry<String, String> entry : requestProperties.entrySet()) {
            connection.setRequestProperty(entry.getKey(), entry.getValue());
        }
    }
    return connection;
}

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

public <T extends SingleResourceTransportDto> T put(final String uri, final String accept,
        final String contentType, final SingleResourceTransportDto body, final Class<T> returnClass) {
    try {//from   ww  w. j  a  v  a 2s.  co  m
        RequestBody requestBody = RequestBody.create(MediaType.parse(withVersion(contentType)),
                json.write(body));
        Request request = new Request.Builder().url(absolute(uri))
                .addHeader(HttpHeaders.ACCEPT, withVersion(accept)).put(requestBody).build();

        return execute(request, returnClass);
    } catch (IOException ex) {
        throw Throwables.propagate(ex);
    }
}

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

public <T extends SingleResourceTransportDto> T put(final String uri, final String accept,
        final TypeToken<T> returnType) {
    try {/*w  w w  .j  a v a2s .c om*/
        Request request = new Request.Builder().url(absolute(uri))
                .addHeader(HttpHeaders.ACCEPT, withVersion(accept)).put(null).build();

        return execute(request, returnType);
    } catch (IOException ex) {
        throw Throwables.propagate(ex);
    }
}

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

public <T extends SingleResourceTransportDto> T put(final String uri, final String accept,
        final String contentType, final SingleResourceTransportDto body, final TypeToken<T> returnType) {
    try {//from ww w .j av a  2s  .  c om
        RequestBody requestBody = RequestBody.create(MediaType.parse(withVersion(contentType)),
                json.write(body));
        Request request = new Request.Builder().url(absolute(uri))
                .addHeader(HttpHeaders.ACCEPT, withVersion(accept)).put(requestBody).build();

        return execute(request, returnType);
    } catch (IOException ex) {
        throw Throwables.propagate(ex);
    }
}