本文整理汇总了Java中org.apache.camel.RuntimeExchangeException类的典型用法代码示例。如果您正苦于以下问题:Java RuntimeExchangeException类的具体用法?Java RuntimeExchangeException怎么用?Java RuntimeExchangeException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RuntimeExchangeException类属于org.apache.camel包,在下文中一共展示了RuntimeExchangeException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getHeader
import org.apache.camel.RuntimeExchangeException; //导入依赖的package包/类
public Object getHeader(String name) {
Object answer = null;
// we will exclude using JMS-prefixed headers here to avoid strangeness with some JMS providers
// e.g. ActiveMQ returns the String not the Destination type for "JMSReplyTo"!
// only look in jms message directly if we have not populated headers
if (jmsMessage != null && !hasPopulatedHeaders() && !name.startsWith("JMS")) {
try {
// use binding to do the lookup as it has to consider using encoded keys
answer = getBinding().getObjectProperty(jmsMessage, name);
} catch (JMSException e) {
throw new RuntimeExchangeException("Unable to retrieve header from JMS Message: " + name, getExchange(), e);
}
}
// only look if we have populated headers otherwise there are no headers at all
// if we do lookup a header starting with JMS then force a lookup
if (answer == null && (hasPopulatedHeaders() || name.startsWith("JMS"))) {
answer = super.getHeader(name);
}
return answer;
}
示例2: notify
import org.apache.camel.RuntimeExchangeException; //导入依赖的package包/类
void notify(T event) {
logger.debug("Consuming CDI event [{}] with {}", event, this);
Exchange exchange = getEndpoint().createExchange();
// TODO: would that be possible to propagate the event metadata?
exchange.getIn().setBody(event);
// Avoid infinite loop of exchange events
if (event instanceof AbstractExchangeEvent) {
exchange.setProperty(Exchange.NOTIFY_EVENT, Boolean.TRUE);
}
try {
getProcessor().process(exchange);
} catch (Exception cause) {
throw new RuntimeExchangeException("Error while processing CDI event", exchange, cause);
} finally {
if (event instanceof AbstractExchangeEvent) {
exchange.setProperty(Exchange.NOTIFY_EVENT, Boolean.FALSE);
}
}
}
示例3: notify
import org.apache.camel.RuntimeExchangeException; //导入依赖的package包/类
void notify(T event) {
logger.debug("Consuming CDI event [{}] with {}", event, this);
Exchange exchange = getEndpoint().createExchange();
// TODO: propagate the event metadata
exchange.getIn().setBody(event);
// Avoid infinite loop of exchange events
if (event instanceof AbstractExchangeEvent)
exchange.setProperty(Exchange.NOTIFY_EVENT, Boolean.TRUE);
try {
getProcessor().process(exchange);
} catch (Exception cause) {
throw new RuntimeExchangeException("Error while processing CDI event", exchange, cause);
} finally {
if (event instanceof AbstractExchangeEvent)
exchange.setProperty(Exchange.NOTIFY_EVENT, Boolean.FALSE);
}
}
示例4: onExchangeDone
import org.apache.camel.RuntimeExchangeException; //导入依赖的package包/类
@Override
public void onExchangeDone(Route route, Exchange exchange) {
super.onExchangeDone(route, exchange);
LOG.info("Exchange Done for route " + route.getId() +
" exchange: " + exchange.getExchangeId() + " in: " + exchange.getIn().getBody(String.class));
try {
stopRoute(route);
} catch (Exception e) {
throw new RuntimeExchangeException(e.getMessage(), exchange, e);
}
}
示例5: receive
import org.apache.camel.RuntimeExchangeException; //导入依赖的package包/类
public Exchange receive() {
// must be started
if (!isRunAllowed() || !isStarted()) {
throw new RejectedExecutionException(this + " is not started, but in state: " + getStatus().name());
}
Exchange exchange = getEndpoint().createExchange();
try {
processor.process(exchange);
} catch (Exception e) {
throw new RuntimeExchangeException("Error while processing exchange", exchange, e);
}
return exchange;
}
示例6: marshal
import org.apache.camel.RuntimeExchangeException; //导入依赖的package包/类
/**
* Creates a payload object with the information from the given exchange.
*
* @param exchange the exchange, must <b>not</b> be <tt>null</tt>
* @param includeProperties whether or not to include exchange properties
* @return the holder object with information copied form the exchange
*/
public static DefaultExchangeHolder marshal(Exchange exchange, boolean includeProperties) {
ObjectHelper.notNull(exchange, "exchange");
// we do not support files
Object body = exchange.getIn().getBody();
if (body instanceof WrappedFile || body instanceof File) {
throw new RuntimeExchangeException("Message body of type " + body.getClass().getCanonicalName() + " is not supported by this marshaller.", exchange);
}
DefaultExchangeHolder payload = new DefaultExchangeHolder();
payload.exchangeId = exchange.getExchangeId();
payload.inBody = checkSerializableBody("in body", exchange, exchange.getIn().getBody());
payload.safeSetInHeaders(exchange, false);
if (exchange.hasOut()) {
payload.outBody = checkSerializableBody("out body", exchange, exchange.getOut().getBody());
payload.outFaultFlag = exchange.getOut().isFault();
payload.safeSetOutHeaders(exchange, false);
} else {
payload.inFaultFlag = exchange.getIn().isFault();
}
if (includeProperties) {
payload.safeSetProperties(exchange, false);
}
payload.exception = exchange.getException();
return payload;
}
示例7: testFileNotSupported
import org.apache.camel.RuntimeExchangeException; //导入依赖的package包/类
public void testFileNotSupported() throws Exception {
Exchange exchange = new DefaultExchange(context);
exchange.getIn().setBody(new File("src/test/resources/log4j.properties"));
try {
DefaultExchangeHolder.marshal(exchange);
fail("Should have thrown exception");
} catch (RuntimeExchangeException e) {
// expected
}
}
示例8: testBeanParameterInvalidValueA
import org.apache.camel.RuntimeExchangeException; //导入依赖的package包/类
public void testBeanParameterInvalidValueA() throws Exception {
getMockEndpoint("mock:result").expectedMessageCount(0);
try {
template.sendBody("direct:a", "World");
fail("Should have thrown exception");
} catch (CamelExecutionException e) {
RuntimeExchangeException cause = assertIsInstanceOf(RuntimeExchangeException.class, e.getCause());
assertTrue(cause.getMessage().contains("echo(java.lang.String,int)"));
assertTrue(cause.getMessage().contains("[World, null]"));
assertIsInstanceOf(IllegalArgumentException.class, cause.getCause());
}
assertMockEndpointsSatisfied();
}
示例9: createMethod
import org.apache.camel.RuntimeExchangeException; //导入依赖的package包/类
/**
* Creates the HttpMethod to use to call the remote server, often either its GET or POST.
*
* @param exchange the exchange
* @return the created method
* @throws URISyntaxException
*/
public static HttpMethods createMethod(Exchange exchange, HttpCommonEndpoint endpoint, boolean hasPayload) throws URISyntaxException {
// is a query string provided in the endpoint URI or in a header (header overrules endpoint)
String queryString = exchange.getIn().getHeader(Exchange.HTTP_QUERY, String.class);
// We need also check the HTTP_URI header query part
String uriString = exchange.getIn().getHeader(Exchange.HTTP_URI, String.class);
// resolve placeholders in uriString
try {
uriString = exchange.getContext().resolvePropertyPlaceholders(uriString);
} catch (Exception e) {
throw new RuntimeExchangeException("Cannot resolve property placeholders with uri: " + uriString, exchange, e);
}
if (uriString != null) {
// in case the URI string contains unsafe characters
uriString = UnsafeUriCharactersEncoder.encodeHttpURI(uriString);
URI uri = new URI(uriString);
queryString = uri.getQuery();
}
if (queryString == null) {
queryString = endpoint.getHttpUri().getRawQuery();
}
// compute what method to use either GET or POST
HttpMethods answer;
HttpMethods m = exchange.getIn().getHeader(Exchange.HTTP_METHOD, HttpMethods.class);
if (m != null) {
// always use what end-user provides in a header
answer = m;
} else if (queryString != null) {
// if a query string is provided then use GET
answer = HttpMethods.GET;
} else {
// fallback to POST if we have payload, otherwise GET
answer = hasPayload ? HttpMethods.POST : HttpMethods.GET;
}
return answer;
}
示例10: createMethod
import org.apache.camel.RuntimeExchangeException; //导入依赖的package包/类
/**
* Creates the HttpMethod to use to call the remote server, often either its GET or POST.
*
* @param exchange the exchange
* @return the created method
* @throws URISyntaxException
*/
public static HttpMethods createMethod(Exchange exchange, HttpEndpoint endpoint, boolean hasPayload) throws URISyntaxException {
// is a query string provided in the endpoint URI or in a header (header
// overrules endpoint)
String queryString = exchange.getIn().getHeader(Exchange.HTTP_QUERY, String.class);
// We need also check the HTTP_URI header query part
String uriString = exchange.getIn().getHeader(Exchange.HTTP_URI, String.class);
// resolve placeholders in uriString
try {
uriString = exchange.getContext().resolvePropertyPlaceholders(uriString);
} catch (Exception e) {
throw new RuntimeExchangeException("Cannot resolve property placeholders with uri: " + uriString, exchange, e);
}
if (uriString != null) {
// in case the URI string contains unsafe characters
uriString = UnsafeUriCharactersEncoder.encodeHttpURI(uriString);
URI uri = new URI(uriString);
queryString = uri.getQuery();
}
if (queryString == null) {
queryString = endpoint.getHttpUri().getRawQuery();
}
// compute what method to use either GET or POST
HttpMethods answer;
HttpMethods m = exchange.getIn().getHeader(Exchange.HTTP_METHOD, HttpMethods.class);
if (m != null) {
// always use what end-user provides in a header
answer = m;
} else if (queryString != null) {
// if a query string is provided then use GET
answer = HttpMethods.GET;
} else {
// fallback to POST if we have payload, otherwise GET
answer = hasPayload ? HttpMethods.POST : HttpMethods.GET;
}
return answer;
}
示例11: createMessageId
import org.apache.camel.RuntimeExchangeException; //导入依赖的package包/类
@Override
protected String createMessageId() {
if (jmsMessage == null) {
LOG.trace("No javax.jms.Message set so generating a new message id");
return super.createMessageId();
}
try {
String id = getDestinationAsString(jmsMessage.getJMSDestination()) + jmsMessage.getJMSMessageID();
return getSanitizedString(id);
} catch (JMSException e) {
throw new RuntimeExchangeException("Unable to retrieve JMSMessageID from JMS Message", getExchange(), e);
}
}
示例12: createURL
import org.apache.camel.RuntimeExchangeException; //导入依赖的package包/类
/**
* Creates the URL to invoke.
*
* @param exchange the exchange
* @param endpoint the endpoint
* @return the URL to invoke
*/
public static String createURL(Exchange exchange, UndertowEndpoint endpoint) {
String uri = uri = endpoint.getHttpURI().toASCIIString();
// resolve placeholders in uri
try {
uri = exchange.getContext().resolvePropertyPlaceholders(uri);
} catch (Exception e) {
throw new RuntimeExchangeException("Cannot resolve property placeholders with uri: " + uri, exchange, e);
}
// append HTTP_PATH to HTTP_URI if it is provided in the header
String path = exchange.getIn().getHeader(Exchange.HTTP_PATH, String.class);
// NOW the HTTP_PATH is just related path, we don't need to trim it
if (path != null) {
if (path.startsWith("/")) {
path = path.substring(1);
}
if (path.length() > 0) {
// make sure that there is exactly one "/" between HTTP_URI and
// HTTP_PATH
if (!uri.endsWith("/")) {
uri = uri + "/";
}
uri = uri.concat(path);
}
}
// ensure uri is encoded to be valid
uri = UnsafeUriCharactersEncoder.encodeHttpURI(uri);
return uri;
}
示例13: createMethod
import org.apache.camel.RuntimeExchangeException; //导入依赖的package包/类
/**
* Creates the HttpMethod to use to call the remote server, often either its GET or POST.
*
* @param exchange the exchange
* @return the created method
* @throws URISyntaxException
*/
public static HttpString createMethod(Exchange exchange, UndertowEndpoint endpoint, boolean hasPayload) throws URISyntaxException {
// is a query string provided in the endpoint URI or in a header (header
// overrules endpoint)
String queryString = exchange.getIn().getHeader(Exchange.HTTP_QUERY, String.class);
// We need also check the HTTP_URI header query part
String uriString = exchange.getIn().getHeader(Exchange.HTTP_URI, String.class);
// resolve placeholders in uriString
try {
uriString = exchange.getContext().resolvePropertyPlaceholders(uriString);
} catch (Exception e) {
throw new RuntimeExchangeException("Cannot resolve property placeholders with uri: " + uriString, exchange, e);
}
if (uriString != null) {
URI uri = new URI(uriString);
queryString = uri.getQuery();
}
if (queryString == null) {
queryString = endpoint.getHttpURI().getRawQuery();
}
// compute what method to use either GET or POST
HttpString answer;
String m = exchange.getIn().getHeader(Exchange.HTTP_METHOD, String.class);
if (m != null) {
// always use what end-user provides in a header
answer = new HttpString(m);
} else if (queryString != null) {
// if a query string is provided then use GET
answer = Methods.GET;
} else {
// fallback to POST if we have payload, otherwise GET
answer = hasPayload ? Methods.POST : Methods.GET;
}
return answer;
}
示例14: getFolderOnPath
import org.apache.camel.RuntimeExchangeException; //导入依赖的package包/类
private Folder getFolderOnPath(Exchange exchange, String path) throws Exception {
try {
return (Folder) getSessionFacade().getObjectByPath(path);
} catch (CmisObjectNotFoundException e) {
throw new RuntimeExchangeException("Path not found " + path, exchange, e);
}
}
示例15: failCreatingFolderAtNonExistingPath
import org.apache.camel.RuntimeExchangeException; //导入依赖的package包/类
@Test
public void failCreatingFolderAtNonExistingPath() throws Exception {
String existingFolderStructure = "/No/Path/Here";
Exchange exchange = createExchangeWithInBody(null);
exchange.getIn().getHeaders().put(PropertyIds.NAME, "folder1");
exchange.getIn().getHeaders().put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder");
exchange.getIn().getHeaders().put(CamelCMISConstants.CMIS_FOLDER_PATH, existingFolderStructure);
template.send(exchange);
assertTrue(exchange.getException() instanceof RuntimeExchangeException);
}