List of usage examples for com.google.common.net HttpHeaders CONTENT_TYPE
String CONTENT_TYPE
To view the source code for com.google.common.net HttpHeaders CONTENT_TYPE.
Click Source Link
From source file:jp.tomorrowkey.irkit4j.http.HttpClient.java
@VisibleForTesting HttpURLConnection newHttpURLConnection(URL url, HttpRequestMethod method, String encoding) throws IOException { HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection(); httpURLConnection.setDoInput(true);//w ww . java2 s.c o m httpURLConnection.setDoOutput(method == HttpRequestMethod.POST); httpURLConnection.setUseCaches(false); httpURLConnection.setRequestMethod(method.toString()); httpURLConnection.setRequestProperty(HttpHeaders.ACCEPT_CHARSET, encoding); if (method == HttpRequestMethod.POST) { httpURLConnection.setRequestProperty(HttpHeaders.CONTENT_TYPE, "application/x-www-form-urlencoded;charset=" + encoding); } return httpURLConnection; }
From source file:com.facebook.nifty.client.HttpClientChannel.java
@Override protected ChannelFuture writeRequest(ChannelBuffer request) { HttpRequest httpRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, endpointUri); httpRequest.setHeader(HttpHeaders.HOST, hostName); httpRequest.setHeader(HttpHeaders.CONTENT_LENGTH, request.readableBytes()); httpRequest.setHeader(HttpHeaders.CONTENT_TYPE, "application/x-thrift"); httpRequest.setHeader(HttpHeaders.USER_AGENT, "Java/Swift-HttpThriftClientChannel"); if (headerDictionary != null) { for (Map.Entry<String, String> entry : headerDictionary.entrySet()) { httpRequest.setHeader(entry.getKey(), entry.getValue()); }/* ww w . jav a2 s .c om*/ } httpRequest.setContent(request); return underlyingNettyChannel.write(httpRequest); }
From source file:org.jclouds.s3.binders.BindObjectMetadataToRequest.java
@SuppressWarnings("unchecked") @Override/* w ww . ja v a 2s. c om*/ public <R extends HttpRequest> R bindToRequest(R request, Object input) { checkArgument(checkNotNull(input, "input") instanceof ObjectMetadata, "this binder is only valid for ObjectMetadata!"); checkNotNull(request, "request"); ObjectMetadata md = ObjectMetadata.class.cast(input); checkArgument(md.getKey() != null, "objectMetadata.getKey() must be set!"); request = metadataPrefixer.bindToRequest(request, md.getUserMetadata()); Builder<String, String> headers = ImmutableMultimap.builder(); if (md.getContentMetadata().getCacheControl() != null) { headers.put(HttpHeaders.CACHE_CONTROL, md.getContentMetadata().getCacheControl()); } if (md.getContentMetadata().getContentDisposition() != null) { headers.put("Content-Disposition", md.getContentMetadata().getContentDisposition()); } if (md.getContentMetadata().getContentEncoding() != null) { headers.put("Content-Encoding", md.getContentMetadata().getContentEncoding()); } String contentLanguage = md.getContentMetadata().getContentLanguage(); if (contentLanguage != null) { headers.put(HttpHeaders.CONTENT_LANGUAGE, contentLanguage); } if (md.getContentMetadata().getContentType() != null) { headers.put(HttpHeaders.CONTENT_TYPE, md.getContentMetadata().getContentType()); } else { headers.put(HttpHeaders.CONTENT_TYPE, "binary/octet-stream"); } if (md.getContentMetadata().getContentMD5() != null) { headers.put("Content-MD5", base64().encode(md.getContentMetadata().getContentMD5())); } return (R) request.toBuilder().replaceHeaders(headers.build()).build(); }
From source file:org.ambraproject.rhino.rest.controller.AssetFileCrudController.java
private void serve(HttpServletRequest request, HttpServletResponse response, RepoObjectMetadata objMeta) throws IOException { objMeta.getContentType().ifPresent((String contentType) -> { response.setHeader(HttpHeaders.CONTENT_TYPE, contentType); });/*from w ww . j av a 2s . co m*/ objMeta.getDownloadName().ifPresent((String downloadName) -> { String contentDisposition = "attachment; filename=" + downloadName; response.setHeader(HttpHeaders.CONTENT_DISPOSITION, contentDisposition); }); Timestamp timestamp = objMeta.getTimestamp(); setLastModifiedHeader(response, timestamp); if (!checkIfModifiedSince(request, timestamp)) { response.setStatus(HttpStatus.NOT_MODIFIED.value()); return; } List<URL> reproxyUrls = objMeta.getReproxyUrls(); if (clientSupportsReproxy(request) && reproxyUrls != null && !reproxyUrls.isEmpty()) { String reproxyUrlHeader = REPROXY_URL_JOINER.join(reproxyUrls); response.setStatus(HttpStatus.OK.value()); response.setHeader("X-Reproxy-URL", reproxyUrlHeader); response.setHeader("X-Reproxy-Cache-For", REPROXY_CACHE_FOR_HEADER); } else { try (InputStream fileStream = contentRepoService.getRepoObject(objMeta.getVersion()); OutputStream responseStream = response.getOutputStream()) { ByteStreams.copy(fileStream, responseStream); } } }
From source file:org.jenkinsci.plugins.kubernetesworkflowsteps.KubeStepExecution.java
private static CloseableHttpClient getClient() throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException { if (client == null) { synchronized (client_lock) { if (client == null) { SSLContextBuilder builder = SSLContexts.custom(); builder.loadTrustMaterial(null, new TrustSelfSignedStrategy()); SSLContext sslContext = builder.build(); SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); Collection<BasicHeader> headers = new ArrayList<BasicHeader>(); headers.add(new BasicHeader(HttpHeaders.CONTENT_TYPE, "application/json")); headers.add(new BasicHeader(HttpHeaders.AUTHORIZATION, "Bearer " + env.get("BEARER_TOKEN"))); client = HttpClients.custom().setDefaultHeaders(headers).setSSLSocketFactory(sslsf).build(); }// w w w. ja v a 2 s.c o m } } return client; }
From source file:com.iblsoft.iwxxm.webservice.ws.ValidationServlet.java
private void addCorsResponseHeaders(HttpServletResponse response) { if (!this.allowOriginHeader.isEmpty()) { response.addHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN, this.allowOriginHeader); response.addHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_METHODS, "GET, POST,OPTIONS"); response.addHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_HEADERS, HttpHeaders.CONTENT_TYPE); }//w w w.java2 s .c om }
From source file:org.jclouds.glacier.util.AWSRequestSignerV4.java
private static Multimap<String, String> buildCanonicalizedHeadersMap(HttpRequest request) { Multimap<String, String> headers = request.getHeaders(); SortedSetMultimap<String, String> canonicalizedHeaders = TreeMultimap.create(); for (Entry<String, String> header : headers.entries()) { if (header.getKey() == null) continue; String key = header.getKey().toString().toLowerCase(Locale.getDefault()); // Ignore any headers that are not particularly interesting. if (key.equalsIgnoreCase(HttpHeaders.CONTENT_TYPE) || key.equalsIgnoreCase(HttpHeaders.CONTENT_MD5) || key.equalsIgnoreCase(HttpHeaders.HOST) || key.startsWith(HEADER_TAG)) { canonicalizedHeaders.put(key, header.getValue()); }/* w w w . j a v a 2 s. co m*/ } return canonicalizedHeaders; }
From source file:com.linkedin.flashback.netty.builder.RecordedHttpMessageBuilder.java
/** * Get content type from headers/*from ww w . ja v a 2 s .co m*/ * * */ protected String getContentType() { String header = getHeader(HttpHeaders.CONTENT_TYPE); if (Strings.isNullOrEmpty(header)) { return DEFAULT_CONTENT_TYPE; } else { return MediaType.parse(header).withoutParameters().toString(); } }
From source file:org.haiku.haikudepotserver.operations.controller.MaintenanceController.java
/** * <p>This triggers hourly tasks.</p> *//*from w w w . j av a 2 s .c om*/ // TODO; remove "mediumterm". @RequestMapping(path = { "/mediumterm", "/hourly" }, method = RequestMethod.GET) public void hourly(HttpServletResponse response) throws IOException { // remove any jobs which are too old and are no longer required. jobService.clearExpiredJobs(); // remove any expired password reset tokens. { if (UserPasswordResetToken.hasAny(serverRuntime.newContext())) { jobService.submit(new PasswordResetMaintenanceJobSpecification(), JobSnapshot.COALESCE_STATUSES_QUEUED_STARTED); } else { LOGGER.debug("did not submit task for password reset maintenance as there are no tokens stored"); } } LOGGER.info("did trigger hourly maintenance"); response.setStatus(HttpServletResponse.SC_OK); response.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.PLAIN_TEXT_UTF_8.toString()); response.getWriter().print("accepted request for hourly maintenance"); }
From source file:com.heliosapm.tsdblite.handlers.http.HttpSwitch.java
@Override protected void decode(final ChannelHandlerContext ctx, final HttpRequest msg, final List<Object> out) throws Exception { final String uri = msg.uri(); log.info("-----------------------> URI [{}]", uri); if (uri.endsWith("/favicon.ico")) { final DefaultFullHttpResponse resp = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK, favicon); resp.headers().set(HttpHeaders.CONTENT_TYPE, "image/x-icon"); resp.headers().setInt(HttpHeaders.CONTENT_LENGTH, favSize); ctx.writeAndFlush(resp);// www .j av a 2s. c o m return; } ReferenceCountUtil.retain(msg); final ChannelPipeline p = ctx.pipeline(); final int index = uri.indexOf("/api/"); final String endpoint = index == -1 ? "" : uri.substring(5); if (index != -1 && pureJsonEndPoints.contains(endpoint)) { log.info("Switching to PureJSON handler"); p.addLast(eventExecutorGroup, "httpToJson", httpToJson); // p.addLast("jsonLogger", loggingHandler); p.addLast("jsonDecoder", new JsonObjectDecoder(true)); // p.addLast("jsonLogger", loggingHandler); p.addLast("traceHandler", traceHandler); p.remove(this); if (msg instanceof FullHttpMessage) { out.add(msg); } } else { log.info("Switching to Http Request Manager"); out.add(msg); p.addLast(eventExecutorGroup, "requestManager", HttpRequestManager.getInstance()); p.remove(this); } }