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:com.cslysy.githubgist.client.v3.GitHubGistClientV3.java
@Override public Gist getGist(String id) { try {// w w w . ja v a 2 s . c o m new JdkRequest(baseUrl).uri().path(String.format("/gists/%s", id)).back().method(Request.GET) .header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON).fetch(); return null; } catch (IOException ex) { logger.error(ex.getMessage(), ex); throw new RuntimeException(ex); } }
From source file:org.jclouds.abiquo.http.filters.AppendApiVersionToMediaType.java
@VisibleForTesting HttpRequest appendVersionToNonPayloadHeaders(final HttpRequest request) { Collection<String> accept = request.getHeaders().get(HttpHeaders.ACCEPT); return accept.isEmpty() ? request : request.toBuilder()/*w w w . j a va 2 s . c o m*/ .replaceHeader(HttpHeaders.ACCEPT, Iterables.toArray(Iterables.transform(accept, versionAppender), String.class)) .build(); }
From source file:org.jclouds.openstack.keystone.v2_0.internal.KeystoneFixture.java
public HttpRequest initialAuthWithUsernameAndPasswordAndTenantName(String username, String password) { return HttpRequest.builder().method("POST").endpoint("http://localhost:5000/v2.0/tokens") .addHeader(HttpHeaders.ACCEPT, "application/json") .payload(payloadFromStringWithContentType(format( "{\"auth\":{\"passwordCredentials\":{\"username\":\"%s\",\"password\":\"%s\"},\"tenantName\":\"%s\"}}", username, password, getTenantName()), "application/json")) .build();/* w ww .j a v a2 s. c o m*/ }
From source file:org.jclouds.hpcloud.objectstorage.internal.KeystoneFixture.java
public HttpRequest initialAuthWithAccessKeyAndSecretKey(String accessKey, String secretKey) { return HttpRequest.builder().method("POST") .endpoint("https://region-a.geo-1.identity.hpcloudsvc.com:35357/v2.0/tokens") .addHeader(HttpHeaders.ACCEPT, "application/json") .payload(payloadFromStringWithContentType(format( "{\"auth\":{\"apiAccessKeyCredentials\":{\"accessKey\":\"%s\",\"secretKey\":\"%s\"},\"tenantName\":\"%s\"}}", accessKey, secretKey, getTenantName()), "application/json")) .build();// w w w . ja v a 2 s. c om }
From source file:be.solidx.hot.shows.spring.RequestMappingMvcRequestMappingAdapter.java
RequestMappingInfo getRequestMappingInfo(final ClosureRequestMapping requestMapping) { List<String> consumeConditions = new ArrayList<>(); List<String> produceConditions = new ArrayList<>(); List<String> nameValueHeaders = new ArrayList<>(); for (String header : requestMapping.getHeaders()) { nameValueHeaders.add(header.replaceFirst(":", "=")); if (header.contains(HttpHeaders.CONTENT_TYPE)) { // consumeConditions.add(HttpHeaders.CONTENT_TYPE+":"+ header.split(":")[1]); consumeConditions.add(header.split(":")[1].trim()); }/*from ww w . ja va 2 s . c o m*/ if (header.contains(HttpHeaders.ACCEPT)) { produceConditions.add(header.split(":")[1].trim()); // produceConditions.add(HttpHeaders.ACCEPT+":"+ header.split(":")[1]); } } String[] headers = requestMapping.getHeaders().toArray(new String[] {}); return new RequestMappingInfo( new PatternsRequestCondition(requestMapping.getPaths().toArray(new String[] {})), new RequestMethodsRequestCondition(requestMapping.getRequestMethod()), new ParamsRequestCondition(requestMapping.getParams().toArray(new String[] {})), new HeadersRequestCondition(nameValueHeaders.toArray(new String[] {})), new ConsumesRequestCondition(consumeConditions.toArray(new String[] {}), headers), new ProducesRequestCondition(produceConditions.toArray(new String[] {}), headers), null); }
From source file:com.cslysy.githubgist.client.v3.GitHubGistClientV3.java
@Override public Set<Gist> getGistsFor(GitHubUser gitHubUser) { try {/*from www. j a v a 2 s. com*/ new JdkRequest(baseUrl).uri().path(String.format("/users/%s/gists", gitHubUser.getUsername())).back() .method(Request.GET).header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON).fetch(); return null; } catch (IOException ex) { logger.error(ex.getMessage(), ex); throw new RuntimeException(ex); } }
From source file:utils.teamcity.wallt.controller.api.ApiRequestController.java
@Override public <T extends ApiResponse> ListenableFuture<T> sendRequest(final ApiVersion version, final String path, final Class<T> expectedType) { final SettableFuture<T> apiResponseFuture = SettableFuture.create(); try {/*from w w w .ja v a 2 s. co m*/ final ApiRequest request = ApiRequestBuilder.newRequest().to(_configuration.getServerUrl()) .forUser(_configuration.getCredentialsUser()) .withPassword(_configuration.getCredentialsPassword()).request(path).apiVersion(version) .build(); LOGGER.info("<< REQUEST: to {}", request); final AsyncHttpClient.BoundRequestBuilder httpRequest = _httpClient.prepareGet(request.getURI()) .addHeader(HttpHeaders.ACCEPT, "application/json"); if (!request.isGuestMode()) { final Realm realm = new Realm.RealmBuilder().setPrincipal(request.getUsername()) .setPassword(request.getPassword()).setUsePreemptiveAuth(true) .setScheme(Realm.AuthScheme.BASIC).build(); httpRequest.setRealm(realm); } if (_configuration.isUseProxy()) { // CODEREVIEW Let the user choose the protocol ? final ProxyServer proxyServer = new ProxyServer(ProxyServer.Protocol.HTTP, checkNotNull(_configuration.getProxyHost(), "Proxy hostname is not defined"), _configuration.getProxyPort(), _configuration.getProxyCredentialsUser(), _configuration.getProxyCredentialsPassword()); httpRequest.setProxyServer(proxyServer); } httpRequest.execute(new AsyncCompletionHandler<Void>() { @Override public void onThrowable(final Throwable t) { super.onThrowable(t); apiResponseFuture.setException(t); } @Override public Void onCompleted(final Response response) throws Exception { if (response.getStatusCode() != 200) { LOGGER.error(">> RESPONSE: for {} has status code {}", request, response.getStatusCode()); apiResponseFuture.setException(new ApiException("Http status code is " + response.getStatusCode() + " when requesting uri: " + response.getUri())); return null; } final String content = response.getResponseBody(Charsets.UTF_8.name()); LOGGER.debug(">> RESPONSE: for {} has content: {}", request, content); final Gson gson = new GsonBuilder().create(); final T jsonResponse = gson.fromJson(content, expectedType); apiResponseFuture.set(jsonResponse); return null; } }); } catch (Exception e) { apiResponseFuture.setException(e); } return apiResponseFuture; }
From source file:org.jclouds.openstack.keystone.v2_0.internal.KeystoneFixture.java
public HttpRequest initialAuthWithAccessKeyAndSecretKeyAndTenantName(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\"},\"tenantName\":\"%s\"}}", accessKey, secretKey, getTenantName()), "application/json")) .build();//from ww w. j av a 2 s.c om }
From source file:clocker.mesos.entity.MesosUtils.java
public static final Optional<String> httpPost(Entity framework, String subUrl, String dataUrl, Map<String, Object> substitutions) { String targetUrl = Urls.mergePaths(framework.sensors().get(MesosFramework.FRAMEWORK_URL), subUrl); String templateContents = ResourceUtils.create().getResourceAsString(dataUrl); String processedJson = TemplateProcessor.processTemplateContents(templateContents, substitutions); LOG.debug("Posting JSON to {}: {}", targetUrl, processedJson); URI postUri = URI.create(targetUrl); HttpToolResponse response = HttpTool .httpPost(MesosUtils.buildClient(framework), postUri, MutableMap.of(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON.getMimeType(), HttpHeaders.ACCEPT, ContentType.APPLICATION_JSON.getMimeType()), processedJson.getBytes()); LOG.debug("Response: " + response.getContentAsString()); if (!HttpTool.isStatusCodeHealthy(response.getResponseCode())) { LOG.warn("Invalid response code {}: {}", response.getResponseCode(), response.getReasonPhrase()); return Optional.absent(); } else {/* w w w . java 2 s. c o m*/ LOG.debug("Successfull call to {}: {}", targetUrl); return Optional.of(response.getContentAsString()); } }
From source file:lu.list.itis.dkd.assess.cloze.util.UrlHelper.java
/** * This method requires an proper UTF8 encoded url to connect to a website and returns * the source code of the page or an empty String if the connection failed. * @param encodedUrl//from w w w .j ava 2 s. c om * @param A mediatype. E.g. JSON_UTF_8 or MediaType.APPLICATION_XML_UTF_8 * @return */ public static String getSource(String encodedUrl, MediaType mediatype) { URL myURL; try { //Connect to url myURL = new URL(encodedUrl); CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ALL)); HttpURLConnection myURLConnection = (HttpURLConnection) myURL.openConnection(); //Set mediatype myURLConnection.setRequestProperty(HttpHeaders.ACCEPT.toString(), mediatype.toString()); myURLConnection.connect(); int status = myURLConnection.getResponseCode(); if (status == 500) { return ""; } final InputStream is = myURLConnection.getInputStream(); final BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF8")); final StringBuilder sb = new StringBuilder(); String line = ""; while ((line = br.readLine()) != null) { sb.append(line); sb.append(System.lineSeparator()); } return sb.toString(); } catch (IOException e) { //TODO Stop when ... //https://cloud.google.com/storage/docs/exponential-backoff logger.log(Level.INFO, encodedUrl + " is busy. Waiting 1 minute and retry."); try { Thread.sleep(64000); getSource(encodedUrl); } catch (InterruptedException e1) { logger.log(Level.SEVERE, "Connection to " + encodedUrl + " failed permanently."); return ""; } return ""; } }