use of org.apache.camel.CamelException in project camel by apache.
the class AvroMarshalAndUnmarshallTest method testMarshalAndUnmarshalWithDSL3.
@Test
public void testMarshalAndUnmarshalWithDSL3() throws Exception {
try {
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:unmarshalC").unmarshal().avro(new CamelException("wrong schema")).to("mock:reverse");
}
});
fail("Expect the exception here");
} catch (Exception ex) {
// expected
}
}
use of org.apache.camel.CamelException in project camel by apache.
the class RedeliveryErrorHandlerLogHandledTest method testRedeliveryErrorHandlerAllOptions.
public void testRedeliveryErrorHandlerAllOptions() throws Exception {
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
errorHandler(defaultErrorHandler().maximumRedeliveries(3).logExhausted(true).logHandled(true).logRetryStackTrace(true).logStackTrace(true).retryAttemptedLogLevel(LoggingLevel.WARN).retriesExhaustedLogLevel(LoggingLevel.ERROR));
from("direct:bar").throwException(new CamelException("Camel rocks"));
}
});
context.start();
getMockEndpoint("mock:handled").expectedMessageCount(0);
try {
template.sendBody("direct:bar", "Hello World");
fail("Should thrown an exception");
} catch (CamelExecutionException e) {
CamelException cause = assertIsInstanceOf(CamelException.class, e.getCause());
assertEquals("Camel rocks", cause.getMessage());
}
assertMockEndpointsSatisfied();
}
use of org.apache.camel.CamelException in project camel by apache.
the class LoopTestProcessor method process.
public void process(Exchange exchange) {
Integer c = exchange.getProperty(Exchange.LOOP_SIZE, Integer.class);
Integer i = exchange.getProperty(Exchange.LOOP_INDEX, Integer.class);
if (c == null || c.intValue() != this.count) {
exchange.setException(new CamelException("Invalid count value. Expected " + this.count + " but was " + c));
}
if (i == null || i.intValue() != this.index++) {
exchange.setException(new CamelException("Invalid index value. Expected " + this.index + " but was " + i));
}
}
use of org.apache.camel.CamelException in project camel by apache.
the class TidyMarkupDataFormat method asStringTidyMarkup.
/**
* Return the tidy markup as a string
*
* @param inputStream
* @return String of XML
* @throws CamelException
*/
public String asStringTidyMarkup(InputStream inputStream) throws CamelException {
XMLReader parser = createTagSoupParser();
StringWriter w = new StringWriter();
parser.setContentHandler(createContentHandler(w));
try {
parser.parse(new InputSource(inputStream));
return w.toString();
} catch (Exception e) {
throw new CamelException("Failed to convert the HTML to tidy Markup", e);
} finally {
try {
inputStream.close();
} catch (Exception e) {
LOG.warn("Failed to close the inputStream");
}
}
}
use of org.apache.camel.CamelException in project camel by apache.
the class TidyMarkupDataFormat method asNodeTidyMarkup.
/**
* Return the HTML Markup as an {@link org.w3c.dom.Node}
*
* @param inputStream
* The input Stream to convert
* @return org.w3c.dom.Node The HTML Markup as a DOM Node
* @throws CamelException
*/
public Node asNodeTidyMarkup(InputStream inputStream) throws CamelException {
XMLReader parser = createTagSoupParser();
StringWriter w = new StringWriter();
parser.setContentHandler(createContentHandler(w));
try {
Transformer transformer = TransformerFactory.newInstance().newTransformer();
DOMResult result = new DOMResult();
transformer.transform(new SAXSource(parser, new InputSource(inputStream)), result);
return result.getNode();
} catch (Exception e) {
throw new CamelException("Failed to convert the HTML to tidy Markup", e);
}
}
Aggregations