use of org.apache.camel.RuntimeCamelException in project camel by apache.
the class HttpProducerSOTimeoutTest method testSendWithSOTimeoutTimeout.
@Test
public void testSendWithSOTimeoutTimeout() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(1);
try {
// we use a timeout of 1 second
template.requestBody("http://localhost:{{port}}/myservice?httpClient.soTimeout=1000", null, String.class);
fail("Should throw an exception");
} catch (RuntimeCamelException e) {
assertIsInstanceOf(SocketTimeoutException.class, e.getCause());
}
assertMockEndpointsSatisfied();
}
use of org.apache.camel.RuntimeCamelException in project camel by apache.
the class HttpRedirectTest method testHttpRedirectFromCamelRoute.
@Test
public void testHttpRedirectFromCamelRoute() throws Exception {
MockEndpoint errorEndpoint = context.getEndpoint("mock:error", MockEndpoint.class);
errorEndpoint.expectedMessageCount(1);
MockEndpoint resultEndpoint = context.getEndpoint("mock:result", MockEndpoint.class);
resultEndpoint.expectedMessageCount(0);
try {
template.requestBody("direct:start", "Hello World", String.class);
fail("Should have thrown an exception");
} catch (RuntimeCamelException e) {
HttpOperationFailedException cause = assertIsInstanceOf(HttpOperationFailedException.class, e.getCause());
assertEquals(302, cause.getStatusCode());
}
errorEndpoint.assertIsSatisfied();
resultEndpoint.assertIsSatisfied();
}
use of org.apache.camel.RuntimeCamelException in project camel by apache.
the class HttpsAsyncRouteTest method testEndpointWithoutHttps.
@Test
public void testEndpointWithoutHttps() throws Exception {
// these tests does not run well on Windows
if (isPlatform("windows")) {
return;
}
MockEndpoint mockEndpoint = resolveMandatoryEndpoint("mock:a", MockEndpoint.class);
try {
template.sendBodyAndHeader("http://localhost:" + port1 + "/test", expectedBody, "Content-Type", "application/xml");
fail("expect exception on access to https endpoint via http");
} catch (RuntimeCamelException expected) {
}
assertTrue("mock endpoint was not called", mockEndpoint.getExchanges().isEmpty());
}
use of org.apache.camel.RuntimeCamelException in project camel by apache.
the class EndpointMessageListener method onMessage.
@Override
public void onMessage(Message message, Session session) throws JMSException {
LOG.trace("onMessage START");
LOG.debug("{} consumer received JMS message: {}", endpoint, message);
boolean sendReply;
RuntimeCamelException rce;
try {
Object replyDestination = getReplyToDestination(message);
// we can only send back a reply if there was a reply destination configured
// and disableReplyTo hasn't been explicit enabled
sendReply = replyDestination != null && !disableReplyTo;
// we should also not send back reply to ourself if this destination and replyDestination is the same
Destination destination = JmsMessageHelper.getJMSDestination(message);
if (destination != null && sendReply && !endpoint.isReplyToSameDestinationAllowed() && destination.equals(replyDestination)) {
LOG.debug("JMSDestination and JMSReplyTo is the same, will skip sending a reply message to itself: {}", destination);
sendReply = false;
}
final Exchange exchange = createExchange(message, session, replyDestination);
if (eagerLoadingOfProperties) {
exchange.getIn().getHeaders();
}
String correlationId = message.getJMSCorrelationID();
if (correlationId != null) {
LOG.debug("Received Message has JMSCorrelationID [{}]", correlationId);
}
// process the exchange either asynchronously or synchronous
LOG.trace("onMessage.process START");
AsyncCallback callback = new EndpointMessageListenerAsyncCallback(message, exchange, endpoint, sendReply, replyDestination);
// async is by default false, which mean we by default will process the exchange synchronously
// to keep backwards compatible, as well ensure this consumer will pickup messages in order
// (eg to not consume the next message before the previous has been fully processed)
// but if end user explicit configure consumerAsync=true, then we can process the message
// asynchronously (unless endpoint has been configured synchronous, or we use transaction)
boolean forceSync = endpoint.isSynchronous() || endpoint.isTransacted();
if (forceSync || !isAsync()) {
// must process synchronous if transacted or configured to do so
if (LOG.isTraceEnabled()) {
LOG.trace("Processing exchange {} synchronously", exchange.getExchangeId());
}
try {
processor.process(exchange);
} catch (Exception e) {
exchange.setException(e);
} finally {
callback.done(true);
}
} else {
// process asynchronous using the async routing engine
if (LOG.isTraceEnabled()) {
LOG.trace("Processing exchange {} asynchronously", exchange.getExchangeId());
}
boolean sync = processor.process(exchange, callback);
if (!sync) {
// will be done async so return now
return;
}
}
// if we failed processed the exchange from the async callback task, then grab the exception
rce = exchange.getException(RuntimeCamelException.class);
} catch (Exception e) {
rce = wrapRuntimeCamelException(e);
}
// the JMS listener will use the error handler to handle the uncaught exception
if (rce != null) {
LOG.trace("onMessage END throwing exception: {}", rce.getMessage());
// on the JmsEndpoint to handle the exception
throw rce;
}
LOG.trace("onMessage END");
}
use of org.apache.camel.RuntimeCamelException in project camel by apache.
the class KratiHelper method createDataSet.
/**
* Creates a {@link krati.store.DynamicDataSet} with the given parameters.
*
* @param path The directory which the set will use.
* @param initialCapacity
* @param segmentFactory The segment factory, defaults to {@link krati.core.segment.ChannelSegmentFactory}.
* @return
*/
public static DataSet<byte[]> createDataSet(String path, int initialCapacity, SegmentFactory segmentFactory) {
DataSet<byte[]> result = null;
File homeDir = new File(path);
homeDir.mkdirs();
try {
result = new DynamicDataSet(homeDir, initialCapacity, segmentFactory);
} catch (Exception e) {
throw new RuntimeCamelException("Failed to create Krati DataSet. This exception is ignored.", e);
}
return result;
}
Aggregations