List of usage examples for com.google.common.net HttpHeaders ACCEPT
String ACCEPT
To view the source code for com.google.common.net HttpHeaders ACCEPT.
Click Source Link
From source file:org.glassfish.jersey.server.RequestContextBuilder.java
public RequestContextBuilder accept(MediaType... acceptHeader) { putHeaders(HttpHeaders.ACCEPT, (Object[]) acceptHeader); return this; }
From source file:com.abiquo.apiclient.RestClient.java
public <T extends SingleResourceTransportDto> T get(final String uri, final String accept, final Class<T> returnClass) { try {/* w w w .java2s .com*/ Request request = new Request.Builder().url(absolute(uri)) .addHeader(HttpHeaders.ACCEPT, withVersion(accept)).get().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 get(final String uri, final String accept, final TypeToken<T> returnType) { try {/* w ww .j a va2 s .c o m*/ Request request = new Request.Builder().url(absolute(uri)) .addHeader(HttpHeaders.ACCEPT, withVersion(accept)).get().build(); return execute(request, returnType); } catch (IOException ex) { throw Throwables.propagate(ex); } }
From source file:org.killbill.billing.plugin.util.http.HttpClient.java
protected AsyncHttpClient.BoundRequestBuilder getBuilderWithHeaderAndQuery(final String verb, final String url, final Map<String, String> immutableOptions) { final AsyncHttpClient.BoundRequestBuilder builder; if (GET.equals(verb)) { builder = httpClient.prepareGet(url); } else if (POST.equals(verb)) { builder = httpClient.preparePost(url); } else if (PUT.equals(verb)) { builder = httpClient.preparePut(url); } else if (DELETE.equals(verb)) { builder = httpClient.prepareDelete(url); } else if (HEAD.equals(verb)) { builder = httpClient.prepareHead(url); } else if (OPTIONS.equals(verb)) { builder = httpClient.prepareOptions(url); } else {//from www . j a v a 2 s.c o m throw new IllegalArgumentException("Unrecognized verb: " + verb); } if (username != null || password != null) { final Realm.RealmBuilder realm = new Realm.RealmBuilder(); if (username != null) { realm.setPrincipal(username); } if (password != null) { realm.setPassword(password); } // Unclear why it's now needed realm.setUsePreemptiveAuth(true); realm.setScheme(Realm.AuthScheme.BASIC); builder.setRealm(realm.build()); } final Map<String, String> options = new HashMap<String, String>(immutableOptions); if (options.get(HttpHeaders.ACCEPT) != null) { builder.addHeader(HttpHeaders.ACCEPT, options.remove(HttpHeaders.ACCEPT)); } if (options.get(HttpHeaders.CONTENT_TYPE) != null) { builder.addHeader(HttpHeaders.CONTENT_TYPE, options.remove(HttpHeaders.CONTENT_TYPE)); } for (final String key : options.keySet()) { if (options.get(key) != null) { builder.addQueryParam(key, options.get(key)); } } if (proxyHost != null && proxyPort != null) { final ProxyServer proxyServer = new ProxyServer(proxyHost, proxyPort); builder.setProxyServer(proxyServer); } return builder; }
From source file:com.b2international.snowowl.snomed.api.rest.SnomedConceptRestService.java
@ApiOperation(value = "Retrieve Concepts from a branch", notes = "Returns a list with all/filtered Concepts from a branch." + "<p>The following properties can be expanded:" + "<p>" + "• pt() – the description representing the concept's preferred term in the given locale<br>" + "• fsn() – the description representing the concept's fully specified name in the given locale<br>" + "• descriptions() – 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", method = RequestMethod.GET, produces = { AbstractRestService.SO_MEDIA_TYPE, AbstractRestService.TEXT_CSV_MEDIA_TYPE }) public @ResponseBody DeferredResult<SnomedConcepts> search( @ApiParam(value = "The branch path") @PathVariable(value = "path") final String branch, @ApiParam(value = "The concept status to match") @RequestParam(value = "active", required = false) final Boolean activeFilter, @ApiParam(value = "The concept module identifier to match") @RequestParam(value = "module", required = false) final String moduleFilter, @ApiParam(value = "The namespace to match") @RequestParam(value = "namespace", required = false) final String namespaceFilter, @ApiParam(value = "The effective time to match (yyyyMMdd, exact matches only)") @RequestParam(value = "effectiveTime", required = false) final String effectiveTimeFilter, @ApiParam(value = "The definition status to match") @RequestParam(value = "definitionStatus", required = false) final String definitionStatusFilter, @ApiParam(value = "The description term to match") @RequestParam(value = "term", required = false) final String termFilter, @ApiParam(value = "The description active state to match") @RequestParam(value = "termActive", required = false) final Boolean descriptionActiveFilter, @ApiParam(value = "The ECL expression to match in the inferred tree") @RequestParam(value = "ecl", required = false) final String eclFilter, @ApiParam(value = "The ECL expression to match in the stated tree") @RequestParam(value = "statedEcl", required = false) final String statedEclFilter, @ApiParam(value = "A set of concept identifiers") @RequestParam(value = "conceptIds", required = false) final Set<String> conceptIds, @ApiParam(value = "The scrollKeepAlive to start a scroll using this query") @RequestParam(value = "scrollKeepAlive", required = false) final String scrollKeepAlive, @ApiParam(value = "A scrollId to continue scrolling a previous query") @RequestParam(value = "scrollId", required = false) final String scrollId, @ApiParam(value = "The search key to use for retrieving the next page of results") @RequestParam(value = "searchAfter", required = false) final String searchAfter, @ApiParam(value = "The maximum number of items to return") @RequestParam(value = "limit", defaultValue = "50", required = false) final int limit, @ApiParam(value = "Expansion parameters") @RequestParam(value = "expand", required = false) final String expand, @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, required = false) final String contentType) { return doSearch(branch, activeFilter, moduleFilter, namespaceFilter, effectiveTimeFilter, definitionStatusFilter, termFilter, descriptionActiveFilter, eclFilter, statedEclFilter, conceptIds, scrollKeepAlive, scrollId, searchAfter, limit, expand, acceptLanguage, contentType); }
From source file:com.abiquo.apiclient.RestClient.java
public <T extends SingleResourceTransportDto> T get(final String uri, final Map<String, Object> queryParams, final String accept, final Class<T> returnClass) { try {//w w w .ja va 2 s . c o m Request request = new Request.Builder().url(absolute(uri) + "?" + queryLine(queryParams)) .addHeader(HttpHeaders.ACCEPT, withVersion(accept)).get().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 get(final String uri, final Map<String, Object> queryParams, final String accept, final TypeToken<T> returnType) { try {//from ww w .j a va 2 s. c o m Request request = new Request.Builder().url(absolute(uri) + "?" + queryLine(queryParams)) .addHeader(HttpHeaders.ACCEPT, withVersion(accept)).get().build(); return execute(request, returnType); } catch (IOException ex) { throw Throwables.propagate(ex); } }
From source file:brooklyn.entity.nosql.couchbase.CouchbaseNodeImpl.java
protected void renameServerToPublicHostname() { // http://docs.couchbase.com/couchbase-manual-2.5/cb-install/#couchbase-getting-started-hostnames URI apiUri = null;// ww w .j a v a2 s . c o m try { HostAndPort accessible = BrooklynAccessUtils.getBrooklynAccessibleAddress(this, getAttribute(COUCHBASE_WEB_ADMIN_PORT)); apiUri = URI.create(String.format("http://%s:%d/node/controller/rename", accessible.getHostText(), accessible.getPort())); UsernamePasswordCredentials credentials = new UsernamePasswordCredentials( getConfig(COUCHBASE_ADMIN_USERNAME), getConfig(COUCHBASE_ADMIN_PASSWORD)); HttpToolResponse response = HttpTool.httpPost( // the uri is required by the HttpClientBuilder in order to set the AuthScope of the credentials HttpTool.httpClientBuilder().uri(apiUri).credentials(credentials).build(), apiUri, MutableMap.of(HttpHeaders.CONTENT_TYPE, MediaType.FORM_DATA.toString(), HttpHeaders.ACCEPT, "*/*", // this appears needed; without it we get org.apache.http.NoHttpResponseException !? HttpHeaders.AUTHORIZATION, HttpTool.toBasicAuthorizationValue(credentials)), Charsets.UTF_8.encode("hostname=" + Urls.encode(accessible.getHostText())).array()); log.debug("Renamed Couchbase server " + this + " via " + apiUri + ": " + response); if (!HttpTool.isStatusCodeHealthy(response.getResponseCode())) { log.warn("Invalid response code, renaming " + apiUri + ": " + response); } } catch (Exception e) { Exceptions.propagateIfFatal(e); log.warn("Error renaming server, using " + apiUri + ": " + e, e); } }
From source file:org.apache.brooklyn.entity.nosql.couchbase.CouchbaseNodeImpl.java
protected void renameServerToPublicHostname() { // http://docs.couchbase.com/couchbase-manual-2.5/cb-install/#couchbase-getting-started-hostnames URI apiUri = null;/*from w w w .j a va 2s . co m*/ try { HostAndPort accessible = BrooklynAccessUtils.getBrooklynAccessibleAddress(this, getAttribute(COUCHBASE_WEB_ADMIN_PORT)); apiUri = URI.create(String.format("http://%s:%d/node/controller/rename", accessible.getHostText(), accessible.getPort())); UsernamePasswordCredentials credentials = new UsernamePasswordCredentials( getConfig(COUCHBASE_ADMIN_USERNAME), getConfig(COUCHBASE_ADMIN_PASSWORD)); HttpToolResponse response = HttpTool.httpPost( // the uri is required by the HttpClientBuilder in order to set the AuthScope of the credentials HttpTool.httpClientBuilder().uri(apiUri).credentials(credentials).build(), apiUri, MutableMap.of(HttpHeaders.CONTENT_TYPE, MediaType.FORM_DATA.toString(), HttpHeaders.ACCEPT, "*/*", // this appears needed; without it we get org.apache.http.NoHttpResponseException !? HttpHeaders.AUTHORIZATION, HttpTool.toBasicAuthorizationValue(credentials)), Charsets.UTF_8.encode("hostname=" + Urls.encode(accessible.getHostText())).array()); log.debug("Renamed Couchbase server " + this + " via " + apiUri + ": " + response); if (!HttpTool.isStatusCodeHealthy(response.getResponseCode())) { log.warn("Invalid response code, renaming {} ({}): {}", new Object[] { apiUri, response.getResponseCode(), response.getContentAsString() }); } } catch (Exception e) { Exceptions.propagateIfFatal(e); log.warn("Error renaming server, using " + apiUri + ": " + e, e); } }
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 Class<T> returnClass) { try {/* w w w . j a v a 2s.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, returnClass); } catch (IOException ex) { throw Throwables.propagate(ex); } }