Search in sources :

Example 11 with CamelException

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
    }
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) CamelException(org.apache.camel.CamelException) CamelException(org.apache.camel.CamelException) Test(org.junit.Test)

Example 12 with CamelException

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();
}
Also used : CamelExecutionException(org.apache.camel.CamelExecutionException) RouteBuilder(org.apache.camel.builder.RouteBuilder) CamelException(org.apache.camel.CamelException) CamelExecutionException(org.apache.camel.CamelExecutionException) CamelException(org.apache.camel.CamelException)

Example 13 with CamelException

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));
    }
}
Also used : CamelException(org.apache.camel.CamelException)

Example 14 with CamelException

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");
        }
    }
}
Also used : InputSource(org.xml.sax.InputSource) StringWriter(java.io.StringWriter) CamelException(org.apache.camel.CamelException) XMLReader(org.xml.sax.XMLReader) CamelException(org.apache.camel.CamelException)

Example 15 with CamelException

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);
    }
}
Also used : InputSource(org.xml.sax.InputSource) Transformer(javax.xml.transform.Transformer) DOMResult(javax.xml.transform.dom.DOMResult) SAXSource(javax.xml.transform.sax.SAXSource) StringWriter(java.io.StringWriter) CamelException(org.apache.camel.CamelException) XMLReader(org.xml.sax.XMLReader) CamelException(org.apache.camel.CamelException)

Aggregations

CamelException (org.apache.camel.CamelException)28 RouteBuilder (org.apache.camel.builder.RouteBuilder)6 SalesforceException (org.apache.camel.component.salesforce.api.SalesforceException)6 IOException (java.io.IOException)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 CamelExecutionException (org.apache.camel.CamelExecutionException)3 SyncResponseCallback (org.apache.camel.component.salesforce.internal.client.SyncResponseCallback)3 PushTopic (org.apache.camel.component.salesforce.internal.dto.PushTopic)3 QueryRecordsPushTopic (org.apache.camel.component.salesforce.internal.dto.QueryRecordsPushTopic)3 XMLReader (org.xml.sax.XMLReader)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 StringWriter (java.io.StringWriter)2 ConnectException (java.net.ConnectException)2 Exchange (org.apache.camel.Exchange)2 Message (org.apache.camel.Message)2 Message (org.cometd.bayeux.Message)2 ClientSessionChannel (org.cometd.bayeux.client.ClientSessionChannel)2 Channel (org.jboss.netty.channel.Channel)2 ChannelFuture (org.jboss.netty.channel.ChannelFuture)2 Test (org.junit.Test)2