本文整理汇总了Java中org.apache.camel.util.ExchangeHelper.convertToType方法的典型用法代码示例。如果您正苦于以下问题:Java ExchangeHelper.convertToType方法的具体用法?Java ExchangeHelper.convertToType怎么用?Java ExchangeHelper.convertToType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.camel.util.ExchangeHelper
的用法示例。
在下文中一共展示了ExchangeHelper.convertToType方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getProperty
import org.apache.camel.util.ExchangeHelper; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public <T> T getProperty(String name, Class<T> type) {
Object value = getProperty(name);
if (value == null) {
// lets avoid NullPointerException when converting to boolean for null values
if (boolean.class.isAssignableFrom(type)) {
return (T) Boolean.FALSE;
}
return null;
}
// eager same instance type test to avoid the overhead of invoking the type converter
// if already same type
if (type.isInstance(value)) {
return type.cast(value);
}
return ExchangeHelper.convertToType(this, type, value);
}
示例2: marshal
import org.apache.camel.util.ExchangeHelper; //导入方法依赖的package包/类
public void marshal(Exchange exchange, Object graph, OutputStream stream) throws IOException {
String text = ExchangeHelper.convertToType(exchange, String.class, graph);
byte[] bytes;
if (charset != null) {
bytes = text.getBytes(charset);
} else {
bytes = text.getBytes();
}
stream.write(bytes);
}
示例3: unmarshal
import org.apache.camel.util.ExchangeHelper; //导入方法依赖的package包/类
public Object unmarshal(Exchange exchange, InputStream stream) throws IOException {
byte[] bytes = ExchangeHelper.convertToType(exchange, byte[].class, stream);
String answer;
if (charset != null) {
answer = new String(bytes, charset);
} else {
answer = new String(bytes);
}
return answer;
}
示例4: evaluate
import org.apache.camel.util.ExchangeHelper; //导入方法依赖的package包/类
protected Object evaluate(Exchange exchange) {
Object answer = evaluateAs(exchange, resultQName);
if (resultType != null) {
return ExchangeHelper.convertToType(exchange, resultType, answer);
}
return answer;
}
示例5: getPayloadFromExchange
import org.apache.camel.util.ExchangeHelper; //导入方法依赖的package包/类
public static byte[] getPayloadFromExchange(Exchange exchange) {
return ExchangeHelper.convertToType(exchange, byte[].class, exchange.getIn().getBody());
}
示例6: appendJmsProperty
import org.apache.camel.util.ExchangeHelper; //导入方法依赖的package包/类
public void appendJmsProperty(Message jmsMessage, Exchange exchange, org.apache.camel.Message in,
String headerName, Object headerValue) throws JMSException {
if (isStandardJMSHeader(headerName)) {
if (headerName.equals("JMSCorrelationID")) {
jmsMessage.setJMSCorrelationID(ExchangeHelper.convertToType(exchange, String.class, headerValue));
} else if (headerName.equals("JMSReplyTo") && headerValue != null) {
if (headerValue instanceof String) {
// if the value is a String we must normalize it first, and must include the prefix
// as ActiveMQ requires that when converting the String to a javax.jms.Destination type
headerValue = normalizeDestinationName((String) headerValue, true);
}
Destination replyTo = ExchangeHelper.convertToType(exchange, Destination.class, headerValue);
JmsMessageHelper.setJMSReplyTo(jmsMessage, replyTo);
} else if (headerName.equals("JMSType")) {
jmsMessage.setJMSType(ExchangeHelper.convertToType(exchange, String.class, headerValue));
} else if (headerName.equals("JMSPriority")) {
jmsMessage.setJMSPriority(ExchangeHelper.convertToType(exchange, Integer.class, headerValue));
} else if (headerName.equals("JMSDeliveryMode")) {
JmsMessageHelper.setJMSDeliveryMode(exchange, jmsMessage, headerValue);
} else if (headerName.equals("JMSExpiration")) {
jmsMessage.setJMSExpiration(ExchangeHelper.convertToType(exchange, Long.class, headerValue));
} else {
// The following properties are set by the MessageProducer:
// JMSDestination
// The following are set on the underlying JMS provider:
// JMSMessageID, JMSTimestamp, JMSRedelivered
// log at trace level to not spam log
LOG.trace("Ignoring JMS header: {} with value: {}", headerName, headerValue);
}
} else if (shouldOutputHeader(in, headerName, headerValue, exchange)) {
// only primitive headers and strings is allowed as properties
// see message properties: http://java.sun.com/j2ee/1.4/docs/api/javax/jms/Message.html
Object value = getValidJMSHeaderValue(headerName, headerValue);
if (value != null) {
// must encode to safe JMS header name before setting property on jmsMessage
String key = jmsKeyFormatStrategy.encodeKey(headerName);
// set the property
JmsMessageHelper.setProperty(jmsMessage, key, value);
} else if (LOG.isDebugEnabled()) {
// okay the value is not a primitive or string so we cannot sent it over the wire
LOG.debug("Ignoring non primitive header: {} of class: {} with value: {}",
new Object[]{headerName, headerValue.getClass().getName(), headerValue});
}
}
}
示例7: appendJmsProperty
import org.apache.camel.util.ExchangeHelper; //导入方法依赖的package包/类
public void appendJmsProperty(Message jmsMessage, Exchange exchange, String headerName, Object headerValue) throws JMSException {
if (isStandardJMSHeader(headerName)) {
if (headerName.equals("JMSCorrelationID")) {
jmsMessage.setJMSCorrelationID(ExchangeHelper.convertToType(exchange, String.class, headerValue));
} else if (headerName.equals("JMSReplyTo") && headerValue != null) {
if (headerValue instanceof String) {
// if the value is a String we must normalize it first, and must include the prefix
// as ActiveMQ requires that when converting the String to a javax.jms.Destination type
headerValue = normalizeDestinationName((String) headerValue, true);
}
Destination replyTo = ExchangeHelper.convertToType(exchange, Destination.class, headerValue);
JmsMessageHelper.setJMSReplyTo(jmsMessage, replyTo);
} else if (headerName.equals("JMSType")) {
jmsMessage.setJMSType(ExchangeHelper.convertToType(exchange, String.class, headerValue));
} else if (headerName.equals("JMSPriority")) {
jmsMessage.setJMSPriority(ExchangeHelper.convertToType(exchange, Integer.class, headerValue));
} else if (headerName.equals("JMSDeliveryMode")) {
JmsMessageHelper.setJMSDeliveryMode(exchange, jmsMessage, headerValue);
} else if (headerName.equals("JMSExpiration")) {
jmsMessage.setJMSExpiration(ExchangeHelper.convertToType(exchange, Long.class, headerValue));
} else {
// The following properties are set by the MessageProducer:
// JMSDestination
// The following are set on the underlying JMS provider:
// JMSMessageID, JMSTimestamp, JMSRedelivered
// log at trace level to not spam log
LOG.trace("Ignoring JMS header: {} with value: {}", headerName, headerValue);
}
} else if (shouldOutputHeader(headerName, headerValue, exchange)) {
// only primitive headers and strings is allowed as properties
// see message properties: http://java.sun.com/j2ee/1.4/docs/api/javax/jms/Message.html
Object value = getValidJMSHeaderValue(headerName, headerValue);
if (value != null) {
// must encode to safe JMS header name before setting property on jmsMessage
String key = jmsJmsKeyFormatStrategy.encodeKey(headerName);
// set the property
JmsMessageHelper.setProperty(jmsMessage, key, value);
} else if (LOG.isDebugEnabled()) {
// okay the value is not a primitive or string so we cannot sent it over the wire
LOG.debug("Ignoring non primitive header: {} of class: {} with value: {}",
new Object[]{headerName, headerValue.getClass().getName(), headerValue});
}
}
}