本文整理汇总了Java中org.apache.camel.RuntimeCamelException类的典型用法代码示例。如果您正苦于以下问题:Java RuntimeCamelException类的具体用法?Java RuntimeCamelException怎么用?Java RuntimeCamelException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RuntimeCamelException类属于org.apache.camel包,在下文中一共展示了RuntimeCamelException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testNak
import org.apache.camel.RuntimeCamelException; //导入依赖的package包/类
@Test
public void testNak() throws Exception {
out.expectedMessageCount(0);
err.expectedMessageCount(1);
try {
producerTemplate.sendBody("direct:render-test", "error");
// DeadLetterChannel marks Exception as handled
// No failure should be reported
} catch (RuntimeCamelException e) {
// ok
}
out.assertIsSatisfied();
err.assertIsSatisfied();
FlowInfo flow = flowManager.findFlow(flowId(err), true);
assertEquals("Init: error", flow.getText());
assertEquals("Nak: error", flow.getPartInfos().iterator().next().getText());
}
示例2: processInBody
import org.apache.camel.RuntimeCamelException; //导入依赖的package包/类
private boolean processInBody(Exchange exchange, Map<String, Object> properties) {
final String inBodyProperty = endpoint.getInBody();
if (inBodyProperty != null) {
Object value = exchange.getIn().getBody();
try {
value = getEndpoint().getCamelContext().getTypeConverter().mandatoryConvertTo(
FacebookEndpointConfiguration.class.getDeclaredField(inBodyProperty).getType(),
exchange, value);
} catch (Exception e) {
exchange.setException(new RuntimeCamelException(String.format(
"Error converting value %s to property %s: %s", value, inBodyProperty, e.getMessage()), e));
return false;
}
LOG.debug("Property [{}] has message body value {}", inBodyProperty, value);
properties.put(inBodyProperty, value);
}
return true;
}
示例3: testEndpointWithoutHttps
import org.apache.camel.RuntimeCamelException; //导入依赖的package包/类
@Test
public void testEndpointWithoutHttps() throws Exception {
// these tests does not run well on Windows
if (isPlatform("windows")) {
return;
}
// give Jetty time to startup properly
Thread.sleep(1000);
MockEndpoint mockEndpoint = resolveMandatoryEndpoint("mock:a", MockEndpoint.class);
try {
template.sendBodyAndHeader("jetty://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());
}
示例4: doRun
import org.apache.camel.RuntimeCamelException; //导入依赖的package包/类
private void doRun(final Exchange exchange, final AsyncCallback callback, IgniteCompute compute) throws Exception {
Object job = exchange.getIn().getBody();
if (Collection.class.isAssignableFrom(job.getClass())) {
Collection<?> col = (Collection<?>) job;
TypeConverter tc = exchange.getContext().getTypeConverter();
Collection<IgniteRunnable> runnables = new ArrayList<>(col.size());
for (Object o : col) {
runnables.add(tc.mandatoryConvertTo(IgniteRunnable.class, o));
}
compute.run(runnables);
} else if (IgniteRunnable.class.isAssignableFrom(job.getClass())) {
compute.run((IgniteRunnable) job);
} else {
throw new RuntimeCamelException(String.format(
"Ignite Compute endpoint with RUN executionType is only " + "supported for IgniteRunnable payloads, or collections of them. The payload type was: %s.", job.getClass().getName()));
}
}
示例5: getNextElement
import org.apache.camel.RuntimeCamelException; //导入依赖的package包/类
private Message getNextElement() {
if (zipInputStream == null) {
return null;
}
try {
ZipEntry current = getNextEntry();
if (current != null) {
LOGGER.debug("read zipEntry {}", current.getName());
Message answer = new DefaultMessage();
answer.getHeaders().putAll(inputMessage.getHeaders());
answer.setHeader("zipFileName", current.getName());
answer.setHeader(Exchange.FILE_NAME, current.getName());
answer.setBody(new ZipInputStreamWrapper(zipInputStream));
return answer;
} else {
LOGGER.trace("close zipInputStream");
return null;
}
} catch (IOException exception) {
//Just wrap the IOException as CamelRuntimeException
throw new RuntimeCamelException(exception);
}
}
示例6: convertTo
import org.apache.camel.RuntimeCamelException; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public <T> T convertTo(Class<T> type, Exchange exchange, Object value) {
Object instance = injector.newInstance();
if (instance == null) {
throw new RuntimeCamelException("Could not instantiate an instance of: " + type.getCanonicalName());
}
// inject parent type converter
if (instance instanceof TypeConverterAware) {
if (registry instanceof TypeConverter) {
TypeConverter parentTypeConverter = (TypeConverter) registry;
((TypeConverterAware) instance).setTypeConverter(parentTypeConverter);
}
}
return useExchange
? (T)ObjectHelper.invokeMethod(method, instance, value, exchange) : (T)ObjectHelper
.invokeMethod(method, instance, value);
}
示例7: setParameter
import org.apache.camel.RuntimeCamelException; //导入依赖的package包/类
@Override
public <T> void setParameter(String name, T value) throws RuntimeCamelException {
ParameterConfiguration config = getPropertyConfiguration(name);
// lets try set the property regardless of if this maps to a valid property name
// then if the injection fails we will get a valid error otherwise
// lets raise a warning afterwards that we should update the metadata on the endpoint class
try {
IntrospectionSupport.setProperty(endpoint, name, value);
} catch (Exception e) {
throw new RuntimeCamelException(
"Failed to set property '" + name + "' on " + endpoint + " to value " + value + " due "
+ e.getMessage(), e);
}
if (config == null) {
warnMissingUriParamOnProperty(name);
}
}
示例8: create
import org.apache.camel.RuntimeCamelException; //导入依赖的package包/类
@Override
public Writable create(Object value, TypeConverter typeConverter, Holder<Integer> size) {
InputStream is = null;
try {
is = typeConverter.convertTo(InputStream.class, value);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
IOUtils.copyBytes(is, bos, HdfsConstants.DEFAULT_BUFFERSIZE, false);
BytesWritable writable = new BytesWritable();
writable.set(bos.toByteArray(), 0, bos.toByteArray().length);
size.value = bos.toByteArray().length;
return writable;
} catch (IOException ex) {
throw new RuntimeCamelException(ex);
} finally {
IOHelper.close(is);
}
}
示例9: testCannotBindToParameter
import org.apache.camel.RuntimeCamelException; //导入依赖的package包/类
public void testCannotBindToParameter() throws Exception {
// Create hashmap for testing purpose
users.put("charles", new User("Charles", "43"));
users.put("claus", new User("Claus", "33"));
Exchange out = template.send("direct:in", new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.setProperty("p1", "abc");
exchange.setProperty("p2", 123);
Message in = exchange.getIn();
in.setHeader("users", users); // add users hashmap
in.setBody("TheBody");
}
});
assertTrue("Should fail", out.isFailed());
assertIsInstanceOf(RuntimeCamelException.class, out.getException());
assertIsInstanceOf(NoTypeConversionAvailableException.class, out.getException().getCause());
}
示例10: testBridge
import org.apache.camel.RuntimeCamelException; //导入依赖的package包/类
@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);
}
}
示例11: hasNext
import org.apache.camel.RuntimeCamelException; //导入依赖的package包/类
@Override
public boolean hasNext() {
try {
if (tarInputStream == null) {
return false;
}
boolean availableDataInCurrentEntry = tarInputStream.available() > 0;
if (!availableDataInCurrentEntry) {
// advance to the next entry.
parent = getNextElement();
if (parent == null) {
tarInputStream.close();
availableDataInCurrentEntry = false;
} else {
availableDataInCurrentEntry = true;
}
}
return availableDataInCurrentEntry;
} catch (IOException exception) {
//Just wrap the IOException as CamelRuntimeException
throw new RuntimeCamelException(exception);
}
}
示例12: testTransactionRollback
import org.apache.camel.RuntimeCamelException; //导入依赖的package包/类
public void testTransactionRollback() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:error");
mock.expectedMessageCount(1);
try {
template.sendBody("direct:fail", "Hello World");
fail("Should have thrown exception");
} catch (RuntimeCamelException e) {
// expected as we fail
assertIsInstanceOf(RuntimeCamelException.class, e.getCause());
RollbackExchangeException rollback = assertIsInstanceOf(RollbackExchangeException.class, e.getCause().getCause());
assertEquals("Donkey in Action", rollback.getExchange().getIn().getBody());
}
assertMockEndpointsSatisfied();
int count = jdbc.queryForObject("select count(*) from books", Integer.class);
assertEquals("Number of books", 1, count);
}
示例13: testRequiredAndNewRollback
import org.apache.camel.RuntimeCamelException; //导入依赖的package包/类
public void testRequiredAndNewRollback() throws Exception {
try {
template.sendBody("direct:requiredAndNewRollback", "Tiger in Action");
} catch (RuntimeCamelException e) {
// expeced as we fail
assertIsInstanceOf(RuntimeCamelException.class, e.getCause());
assertTrue(e.getCause().getCause() instanceof IllegalArgumentException);
assertEquals("We don't have Donkeys, only Camels", e.getCause().getCause().getMessage());
}
int count = jdbc.queryForObject("select count(*) from books", Integer.class);
assertEquals(new Integer(1), jdbc.queryForObject("select count(*) from books where title = ?", Integer.class, "Tiger in Action"));
assertEquals(new Integer(0), jdbc.queryForObject("select count(*) from books where title = ?", Integer.class, "Donkey in Action"));
// the tiger in action should be committed, but our 2nd route should rollback
assertEquals("Number of books", 2, count);
}
示例14: testInvalidMessage
import org.apache.camel.RuntimeCamelException; //导入依赖的package包/类
public void testInvalidMessage() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:invalid");
mock.expectedMessageCount(1);
String xml = "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>"
+ "<user xmlns=\"http://foo.com/bar\">"
+ " <username>someone</username>"
+ "</user>";
try {
template.sendBody("direct:start", xml);
fail("Should have thrown a RuntimeCamelException");
} catch (RuntimeCamelException e) {
assertTrue(e.getCause() instanceof SchemaValidationException);
// expected
}
assertMockEndpointsSatisfied();
}
示例15: testRollback
import org.apache.camel.RuntimeCamelException; //导入依赖的package包/类
@Test
public void testRollback() throws Exception {
// will rollback forever so we run 3 times or more
rollback.expectedMinimumMessageCount(3);
// use requestBody to force a InOut message exchange pattern ( = request/reply)
// will send and wait for a response
try {
template.requestBodyAndHeader(data,
"<?xml version=\"1.0\"?><request><status id=\"123\"/></request>", "user", "guest");
fail("Should throw an exception");
} catch (RuntimeCamelException e) {
assertTrue("Should timeout", e.getCause() instanceof ExchangeTimedOutException);
}
rollback.assertIsSatisfied();
}