use of org.apache.camel.RuntimeCamelException in project camel by apache.
the class MailProducerUnsupportedCharsetTest method testSencUnsupportedCharsetDisabledOption.
@Test
public void testSencUnsupportedCharsetDisabledOption() throws Exception {
Mailbox.clearAll();
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("pop3://jones@localhost?password=secret&delay=1000&ignoreUnsupportedCharset=false").to("mock:result");
}
});
context.start();
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedBodiesReceived("Hello World");
mock.allMessages().header("Content-Type").isEqualTo("text/plain");
Map<String, Object> headers = new HashMap<String, Object>();
headers.put("To", "jones@localhost");
headers.put("Content-Type", "text/plain");
template.sendBodyAndHeaders("smtp://localhost?ignoreUnsupportedCharset=false", "Hello World", headers);
headers.clear();
headers.put("To", "jones@localhost");
headers.put("Content-Type", "text/plain; charset=XXX");
try {
template.sendBodyAndHeaders("smtp://localhost?ignoreUnsupportedCharset=false", "Bye World", headers);
fail("Should have thrown an exception");
} catch (RuntimeCamelException e) {
assertIsInstanceOf(UnsupportedEncodingException.class, e.getCause());
}
mock.assertIsSatisfied();
}
use of org.apache.camel.RuntimeCamelException in project camel by apache.
the class MinaNoResponseFromServerTest method testNoResponse.
@Test
public void testNoResponse() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(0);
try {
template.requestBody("mina:tcp://localhost:{{port}}?sync=true&codec=#myCodec", "Hello World");
fail("Should throw a CamelExchangeException");
} catch (RuntimeCamelException e) {
assertIsInstanceOf(CamelExchangeException.class, e.getCause());
assertTrue(e.getCause().getMessage().startsWith("No response received from remote server"));
}
mock.assertIsSatisfied();
}
use of org.apache.camel.RuntimeCamelException in project camel by apache.
the class Mina2NoResponseFromServerTest method testNoResponse.
@Test
public void testNoResponse() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(0);
try {
template.requestBody(String.format("mina2:tcp://localhost:%1$s?sync=true&codec=#myCodec", getPort()), "Hello World");
fail("Should throw a CamelExchangeException");
} catch (RuntimeCamelException e) {
assertIsInstanceOf(CamelExchangeException.class, e.getCause());
}
mock.assertIsSatisfied();
}
use of org.apache.camel.RuntimeCamelException in project camel by apache.
the class NettyHttpBridgeRouteUsingHttpClientTest method testBridge.
@Test
public void testBridge() throws Exception {
String response = template.requestBodyAndHeader("http://localhost:" + port2 + "/test/hello", new ByteArrayInputStream("This is a test".getBytes()), "Content-Type", "application/xml", String.class);
assertEquals("Get a wrong response", "/", response);
response = template.requestBody("http://localhost:" + port1 + "/hello/world", "hello", String.class);
assertEquals("Get a wrong response", "/hello/world", response);
try {
template.requestBody("http://localhost:" + port2 + "/hello/world", "hello", String.class);
fail("Expect exception here!");
} catch (Exception ex) {
assertTrue("We should get a RuntimeCamelException", ex instanceof RuntimeCamelException);
}
}
use of org.apache.camel.RuntimeCamelException in project camel by apache.
the class Olingo2Consumer method poll.
@Override
protected int poll() throws Exception {
// invoke the consumer method
final Map<String, Object> args = new HashMap<String, Object>();
args.putAll(endpoint.getEndpointProperties());
// let the endpoint and the Consumer intercept properties
endpoint.interceptProperties(args);
interceptProperties(args);
try {
// create responseHandler
final CountDownLatch latch = new CountDownLatch(1);
final Object[] result = new Object[1];
final Exception[] error = new Exception[1];
args.put(Olingo2Endpoint.RESPONSE_HANDLER_PROPERTY, new Olingo2ResponseHandler<Object>() {
@Override
public void onResponse(Object response) {
result[0] = response;
latch.countDown();
}
@Override
public void onException(Exception ex) {
error[0] = ex;
latch.countDown();
}
@Override
public void onCanceled() {
error[0] = new RuntimeCamelException("OData HTTP Request cancelled");
latch.countDown();
}
});
doInvokeMethod(args);
// guaranteed to return, since an exception on timeout is expected!!!
latch.await();
if (error[0] != null) {
throw error[0];
}
return ApiConsumerHelper.getResultsProcessed(this, result[0], isSplitResult());
} catch (Throwable t) {
throw ObjectHelper.wrapRuntimeCamelException(t);
}
}
Aggregations