private static RequestEntity asRequestEntity(byte[] data, Exchange exchange) throws Exception { if (exchange != null && !exchange.getProperty(Exchange.SKIP_GZIP_ENCODING, Boolean.FALSE, Boolean.class)) { return new InputStreamRequestEntity(GZIPHelper.compressGzip(exchange.getIn() .getHeader(Exchange.CONTENT_ENCODING, String.class), data), ExchangeHelper .getContentType(exchange)); } else { // should set the content type here if (exchange != null) { return new InputStreamRequestEntity(new ByteArrayInputStream(data), ExchangeHelper.getContentType(exchange)); } else { return new InputStreamRequestEntity(new ByteArrayInputStream(data)); } } } }
/** * Given an exchange, extract the contentType value for use with a Content-Type header. The order of preference is * so: 1) a contentType value set on the endpoint 2) a contentType value set on the Exchange.CONTENT_TYPE header * * @param exchange the incoming message exchange */ private String getContentType(final Exchange exchange) { final String contentTypeString = ExchangeHelper.getContentType(exchange); if (!isBlank(endpoint.getContentType())) { return endpoint.getContentType(); } else if (!isBlank(contentTypeString)) { return contentTypeString; } else { return null; } }
protected void setCharsetWithContentType(Exchange camelExchange) { // setup the charset from content-type header String contentTypeHeader = ExchangeHelper.getContentType(camelExchange); if (contentTypeHeader != null) { String charset = HttpHeaderHelper.findCharset(contentTypeHeader); String normalizedEncoding = HttpHeaderHelper.mapCharset(charset, Charset.forName("UTF-8").name()); if (normalizedEncoding != null) { camelExchange.setProperty(Exchange.CHARSET_NAME, normalizedEncoding); } } }
protected void setCharsetWithContentType(Exchange camelExchange) { // setup the charset from content-type header String contentTypeHeader = ExchangeHelper.getContentType(camelExchange); if (contentTypeHeader != null) { String charset = HttpHeaderHelper.findCharset(contentTypeHeader); String normalizedEncoding = HttpHeaderHelper.mapCharset(charset, Charset.forName("UTF-8").name()); if (normalizedEncoding != null) { camelExchange.setProperty(Exchange.CHARSET_NAME, normalizedEncoding); } } }
private static RequestEntity asRequestEntity(InputStream in, Exchange exchange) throws IOException { if (exchange != null && !exchange.getProperty(Exchange.SKIP_GZIP_ENCODING, Boolean.FALSE, Boolean.class)) { return new InputStreamRequestEntity(GZIPHelper.compressGzip(exchange.getIn() .getHeader(Exchange.CONTENT_ENCODING, String.class), in), ExchangeHelper .getContentType(exchange)); } else { // should set the content type here if (exchange != null) { return new InputStreamRequestEntity(in, ExchangeHelper.getContentType(exchange)); } else { return new InputStreamRequestEntity(in); } } }
private ContentType getContentType(Exchange exchange) throws ParseException { String contentTypeStr = ExchangeHelper.getContentType(exchange); if (contentTypeStr == null) { contentTypeStr = DEFAULT_CONTENT_TYPE; } ContentType contentType = new ContentType(contentTypeStr); String contentEncoding = ExchangeHelper.getContentEncoding(exchange); // add a charset parameter for text subtypes if (contentEncoding != null && contentType.match("text/*")) { contentType.setParameter("charset", MimeUtility.mimeCharset(contentEncoding)); } return contentType; }
Object data = in.getBody(); if (data != null) { String contentType = ExchangeHelper.getContentType(exchange);