本文整理汇总了Java中org.apache.camel.util.ExchangeHelper.getContentType方法的典型用法代码示例。如果您正苦于以下问题:Java ExchangeHelper.getContentType方法的具体用法?Java ExchangeHelper.getContentType怎么用?Java ExchangeHelper.getContentType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.camel.util.ExchangeHelper
的用法示例。
在下文中一共展示了ExchangeHelper.getContentType方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: process
import org.apache.camel.util.ExchangeHelper; //导入方法依赖的package包/类
public void process(Exchange exchange) throws Exception {
String user = exchange.getIn().getHeader("User", String.class);
String contentType = ExchangeHelper.getContentType(exchange);
String body = exchange.getIn().getBody(String.class);
String encoding = exchange.getIn().getHeader(Exchange.CONTENT_ENCODING, String.class);
if (encoding != null) {
exchange.getOut().setHeader(Exchange.CONTENT_ENCODING, encoding);
}
if ("Claus".equals(user) && contentType.startsWith("text/xml") && body.equals("<order>123</order>")) {
assertEquals("test", exchange.getIn().getHeader("SOAPAction", String.class));
if (contentType.endsWith("UTF-8")) {
assertEquals("Get a wrong charset name.", exchange.getProperty(Exchange.CHARSET_NAME, String.class), "UTF-8");
}
exchange.getOut().setBody("<order>OK</order>");
exchange.getOut().setHeader("Content-Type", "text/xml");
} else {
exchange.getOut().setBody("FAIL");
exchange.getOut().setHeader(Exchange.CONTENT_TYPE, "text/plain");
}
}
示例2: setCharsetWithContentType
import org.apache.camel.util.ExchangeHelper; //导入方法依赖的package包/类
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);
}
}
}
示例3: getContentType
import org.apache.camel.util.ExchangeHelper; //导入方法依赖的package包/类
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;
}
示例4: asRequestEntity
import org.apache.camel.util.ExchangeHelper; //导入方法依赖的package包/类
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);
}
}
}