当前位置: 首页>>代码示例>>Java>>正文


Java CamelExchangeException类代码示例

本文整理汇总了Java中org.apache.camel.CamelExchangeException的典型用法代码示例。如果您正苦于以下问题:Java CamelExchangeException类的具体用法?Java CamelExchangeException怎么用?Java CamelExchangeException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


CamelExchangeException类属于org.apache.camel包,在下文中一共展示了CamelExchangeException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: process

import org.apache.camel.CamelExchangeException; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public boolean process(Exchange exchange, AsyncCallback callback) {
    Exception cause = exception;

    try {
        if (message != null && type != null) {
            // create the message using simple language so it can be dynamic
            String text = simple.evaluate(exchange, String.class);
            // create a new exception of that type, and provide the message as
            Constructor<?> constructor = type.getDeclaredConstructor(String.class);
            cause = (Exception) constructor.newInstance(text);
            exchange.setException(cause);
        } else {
            exchange.setException(cause);
        }
    } catch (Throwable e) {
        exchange.setException(new CamelExchangeException("Error creating new instance of " + exception.getClass(), exchange, e));
    }

    callback.done(true);
    return true;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:23,代码来源:ThrowExceptionProcessor.java

示例2: handleException

import org.apache.camel.CamelExchangeException; //导入依赖的package包/类
public void handleException(String message, Exchange exchange, Throwable exception) {
    try {
        if (!isSuppressLogging()) {
            String msg = CamelExchangeException.createExceptionMessage(message, exchange, exception);
            if (isCausedByRollbackExchangeException(exception)) {
                // do not log stack trace for intended rollbacks
                logger.log(msg);
            } else {
                if (exception != null) {
                    logger.log(msg, exception);
                } else {
                    logger.log(msg);
                }
            }
        }
    } catch (Throwable e) {
        // the logging exception handler must not cause new exceptions to occur
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:20,代码来源:LoggingExceptionHandler.java

示例3: testSplitWithTryCatchAndRollbackException

import org.apache.camel.CamelExchangeException; //导入依赖的package包/类
public void testSplitWithTryCatchAndRollbackException() throws Exception {
    MockEndpoint split = getMockEndpoint("mock:split");
    MockEndpoint ile = getMockEndpoint("mock:ile");
    MockEndpoint exception = getMockEndpoint("mock:exception");

    split.expectedBodiesReceived("A", "B");
    ile.expectedMessageCount(0);
    exception.expectedMessageCount(1);

    try {
        template.sendBody("direct:start", "A,B,Kaboom,C");
        fail("Should thrown an exception");
    } catch (CamelExecutionException e) {
        CamelExchangeException ee = assertIsInstanceOf(CamelExchangeException.class, e.getCause());
        assertTrue(ee.getMessage().startsWith("Sequential processing failed for number 2."));
        RollbackExchangeException re = assertIsInstanceOf(RollbackExchangeException.class, ee.getCause());
        assertTrue(re.getMessage().startsWith("Intended rollback"));
    }

    assertMockEndpointsSatisfied();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:22,代码来源:CharlesSplitAndTryCatchRollbackIssueTest.java

示例4: testSplitWithTryCatchAndRollbacILEAndException

import org.apache.camel.CamelExchangeException; //导入依赖的package包/类
public void testSplitWithTryCatchAndRollbacILEAndException() throws Exception {
    MockEndpoint split = getMockEndpoint("mock:split");
    MockEndpoint ile = getMockEndpoint("mock:ile");
    MockEndpoint exception = getMockEndpoint("mock:exception");

    split.expectedBodiesReceived("A", "B");
    ile.expectedMessageCount(1);
    exception.expectedMessageCount(1);

    try {
        template.sendBody("direct:start", "A,Forced,B,Kaboom,C");
        fail("Should thrown an exception");
    } catch (CamelExecutionException e) {
        CamelExchangeException ee = assertIsInstanceOf(CamelExchangeException.class, e.getCause());
        assertTrue(ee.getMessage().startsWith("Sequential processing failed for number 3."));
        RollbackExchangeException re = assertIsInstanceOf(RollbackExchangeException.class, ee.getCause());
        assertTrue(re.getMessage().startsWith("Intended rollback"));
    }

    assertMockEndpointsSatisfied();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:22,代码来源:CharlesSplitAndTryCatchRollbackIssueTest.java

示例5: testInOutWithRequestBody

import org.apache.camel.CamelExchangeException; //导入依赖的package包/类
@Test
public void testInOutWithRequestBody() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:pickedUp");
    mock.expectedMessageCount(1);
    // this direct endpoint should receive an exception
    try {
        Future<Object> obj = template.asyncRequestBody("direct:in", "Hello World");
        // wait five seconds at most; else, let's assume something went wrong
        obj.get(5000, TimeUnit.MILLISECONDS);
    } catch (Exception e) {
        // if we receive an exception, the async routing engine is working correctly
        // before the Enricher was fixed for cases where routing was async and the AggregationStrategy 
        // threw an exception, the call to requestBody would stall indefinitely
        // unwrap the exception chain
        assertTrue(e instanceof ExecutionException);
        assertTrue(e.getCause() instanceof CamelExecutionException);
        assertTrue(e.getCause().getCause() instanceof CamelExchangeException);
        assertTrue(e.getCause().getCause().getCause() instanceof RuntimeException);
        assertTrue(e.getCause().getCause().getCause().getMessage().equals("Bang! Unhandled exception"));
        mock.assertIsSatisfied();
        return;
    }
    fail("Expected an RuntimeException");
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:25,代码来源:EnricherAsyncUnhandledExceptionTest.java

示例6: testMulticastParalllelStopOnExceptionStop

import org.apache.camel.CamelExchangeException; //导入依赖的package包/类
public void testMulticastParalllelStopOnExceptionStop() throws Exception {
    // we run in parallel so we may get 0 or 1 messages
    getMockEndpoint("mock:foo").expectedMinimumMessageCount(0);
    getMockEndpoint("mock:bar").expectedMinimumMessageCount(0);
    getMockEndpoint("mock:baz").expectedMinimumMessageCount(0);
    // we should not complete and thus 0
    getMockEndpoint("mock:result").expectedMessageCount(0);

    try {
        template.sendBody("direct:start", "Kaboom");
        fail("Should thrown an exception");
    } catch (CamelExecutionException e) {
        CamelExchangeException cause = assertIsInstanceOf(CamelExchangeException.class, e.getCause());
        assertTrue(cause.getMessage().startsWith("Parallel processing failed for number "));
        assertEquals("Forced", cause.getCause().getMessage());

        String body = cause.getExchange().getIn().getBody(String.class);
        assertTrue(body.contains("Kaboom"));
    }

    assertMockEndpointsSatisfied();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:23,代码来源:MulticastParallelStopOnExceptionTest.java

示例7: testMulticastStopOnExceptionStop

import org.apache.camel.CamelExchangeException; //导入依赖的package包/类
public void testMulticastStopOnExceptionStop() throws Exception {
    getMockEndpoint("mock:foo").expectedBodiesReceived("Kaboom");
    getMockEndpoint("mock:bar").expectedMessageCount(0);
    // we do stop so we should NOT continue and thus baz do not receive any message
    getMockEndpoint("mock:baz").expectedMessageCount(0);
    getMockEndpoint("mock:result").expectedMessageCount(0);

    try {
        template.sendBody("direct:start", "Kaboom");
        fail("Should thrown an exception");
    } catch (CamelExecutionException e) {
        CamelExchangeException cause = assertIsInstanceOf(CamelExchangeException.class, e.getCause());
        assertTrue(cause.getMessage().startsWith("Sequential processing failed for number 1."));
        assertEquals("Forced", cause.getCause().getMessage());
    }

    assertMockEndpointsSatisfied();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:19,代码来源:MulticastStopOnExceptionTest.java

示例8: testRecipientListStopOnException

import org.apache.camel.CamelExchangeException; //导入依赖的package包/类
public void testRecipientListStopOnException() throws Exception {
    getMockEndpoint("mock:result").expectedMessageCount(0);
    getMockEndpoint("mock:a").expectedMessageCount(1);
    getMockEndpoint("mock:b").expectedMessageCount(1);
    getMockEndpoint("mock:c").expectedMessageCount(0);

    try {
        template.sendBodyAndHeader("direct:start", "Hello World", "foo", "direct:a,direct:b,direct:c");
        fail("Should have thrown exception");
    } catch (CamelExecutionException e) {
        assertIsInstanceOf(CamelExchangeException.class, e.getCause());
        assertIsInstanceOf(IllegalArgumentException.class, e.getCause().getCause());
        assertEquals("Damn", e.getCause().getCause().getMessage());
    }

    assertMockEndpointsSatisfied();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:RecipientListStopOnExceptionTest.java

示例9: testAsyncEndpoint

import org.apache.camel.CamelExchangeException; //导入依赖的package包/类
public void testAsyncEndpoint() throws Exception {
    getMockEndpoint("mock:error").expectedMessageCount(0);
    getMockEndpoint("mock:result").expectedMessageCount(0);

    try {
        template.requestBody("direct:start", "Hello Camel", String.class);
        fail("Should throw exception");
    } catch (CamelExecutionException e) {
        CamelExchangeException cause = assertIsInstanceOf(CamelExchangeException.class, e.getCause());
        assertTrue(cause.getMessage().startsWith("Simulated error at attempt 1."));
    }

    assertMockEndpointsSatisfied();

    assertFalse("Should use different threads", beforeThreadName.equalsIgnoreCase(afterThreadName));
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:17,代码来源:AsyncOnExceptionFailureProcessorWithRedeliveryTest.java

示例10: process

import org.apache.camel.CamelExchangeException; //导入依赖的package包/类
@Override
public void process(Exchange exchange) throws Exception {

    JobParameters jobParameters = prepareJobParameters(exchange.getIn().getHeaders());
    String messageJobName = jobParameters.getString(SpringBatchConstants.JOB_NAME);

    Job job2run = this.job;

    if (messageJobName != null) {
        job2run = CamelContextHelper.mandatoryLookup(getEndpoint().getCamelContext(), messageJobName, Job.class);
    }

    if (job2run == null) {
        exchange.setException(new CamelExchangeException("jobName was not specified in the endpoint construction "
                + " and header " + SpringBatchConstants.JOB_NAME + " could not be found", exchange));
        return;
    }

    JobExecution jobExecution = jobLauncher.run(job2run, jobParameters);
    exchange.getOut().getHeaders().putAll(exchange.getIn().getHeaders());
    exchange.getOut().setBody(jobExecution);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:23,代码来源:SpringBatchProducer.java

示例11: process

import org.apache.camel.CamelExchangeException; //导入依赖的package包/类
public boolean process(Exchange exchange, final AsyncCallback callback) {
    boolean flag = true;
    
    if ((((RouteboxDirectEndpoint)getRouteboxEndpoint()).getConsumer() == null) 
        && ((getRouteboxEndpoint()).getConfig().isSendToConsumer())) {
        exchange.setException(new CamelExchangeException("No consumers available on endpoint: " + getRouteboxEndpoint(), exchange));
        callback.done(true);
        flag = true;
    } else {
        try {
            LOG.debug("Dispatching to Inner Route {}", exchange);
            
            RouteboxDispatcher dispatcher = new RouteboxDispatcher(producer);
            exchange = dispatcher.dispatchAsync(getRouteboxEndpoint(), exchange);      
            if (getRouteboxEndpoint().getConfig().isSendToConsumer()) {
                AsyncProcessor processor = ((RouteboxDirectEndpoint)getRouteboxEndpoint()).getConsumer().getAsyncProcessor();
                flag = processor.process(exchange, callback);
            } 
        } catch (Exception e) {
            getExceptionHandler().handleException("Error processing exchange", exchange, e);
        }
    }
    return flag;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:25,代码来源:RouteboxDirectProducer.java

示例12: doAddEmbeddedCartridge

import org.apache.camel.CamelExchangeException; //导入依赖的package包/类
protected void doAddEmbeddedCartridge(Exchange exchange, IDomain domain) throws CamelExchangeException {
    String name = exchange.getIn().getHeader(OpenShiftConstants.APPLICATION, getEndpoint().getApplication(), String.class);
    if (name == null) {
        throw new CamelExchangeException("Application not specified", exchange);
    }

    IApplication app = domain.getApplicationByName(name);
    if (app == null) {
        throw new CamelExchangeException("Application with id " + name + " not found.", exchange);
    } else {
        String embeddedCartridgeName = exchange.getIn().getHeader(OpenShiftConstants.EMBEDDED_CARTRIDGE_NAME, getEndpoint().getApplication(), String.class);
        if (ObjectHelper.isNotEmpty(embeddedCartridgeName)) {
            IEmbeddedCartridge p = app.addEmbeddableCartridge((new LatestEmbeddableCartridge(embeddedCartridgeName)).get(app));
            exchange.getIn().setBody(p.getDisplayName());
        } else {
            throw new CamelExchangeException("Cartridge not specified", exchange);
        }
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:20,代码来源:OpenShiftProducer.java

示例13: doRemoveEmbeddedCartridge

import org.apache.camel.CamelExchangeException; //导入依赖的package包/类
protected void doRemoveEmbeddedCartridge(Exchange exchange, IDomain domain) throws CamelExchangeException {
    String name = exchange.getIn().getHeader(OpenShiftConstants.APPLICATION, getEndpoint().getApplication(), String.class);
    if (name == null) {
        throw new CamelExchangeException("Application not specified", exchange);
    }

    IApplication app = domain.getApplicationByName(name);
    if (app == null) {
        throw new CamelExchangeException("Application with id " + name + " not found.", exchange);
    } else {
        String embeddedCartridgeName = exchange.getIn().getHeader(OpenShiftConstants.EMBEDDED_CARTRIDGE_NAME, getEndpoint().getApplication(), String.class);
        if (ObjectHelper.isNotEmpty(embeddedCartridgeName)) {
            IEmbeddableCartridge removingCartridge = (new LatestEmbeddableCartridge(embeddedCartridgeName)).get(app);
            for (IEmbeddedCartridge cartridge : app.getEmbeddedCartridges()) {
                if (cartridge.equals(removingCartridge)) {
                    cartridge.destroy();
                    exchange.getIn().setBody(cartridge.getDisplayName());
                }
            }
        } else {
            throw new CamelExchangeException("Cartridge not specified", exchange);
        }
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:25,代码来源:OpenShiftProducer.java

示例14: doScaleUp

import org.apache.camel.CamelExchangeException; //导入依赖的package包/类
protected void doScaleUp(Exchange exchange, IDomain domain) throws CamelExchangeException {
    String name = exchange.getIn().getHeader(OpenShiftConstants.APPLICATION, getEndpoint().getApplication(), String.class);
    if (name == null) {
        throw new CamelExchangeException("Application not specified", exchange);
    }

    IApplication app = domain.getApplicationByName(name);
    if (app == null) {
        throw new CamelExchangeException("Application with id " + name + " not found.", exchange);
    } else {
        try {
            app.scaleUp();
            ApplicationScale result = app.getApplicationScale();
            exchange.getIn().setBody(result.getValue());
        } catch (OpenShiftException e) {
            throw new CamelExchangeException("Application with id " + name + " is not scalable", exchange);
        }
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:20,代码来源:OpenShiftProducer.java

示例15: doScaleDown

import org.apache.camel.CamelExchangeException; //导入依赖的package包/类
protected void doScaleDown(Exchange exchange, IDomain domain) throws CamelExchangeException {
    String name = exchange.getIn().getHeader(OpenShiftConstants.APPLICATION, getEndpoint().getApplication(), String.class);
    if (name == null) {
        throw new CamelExchangeException("Application not specified", exchange);
    }

    IApplication app = domain.getApplicationByName(name);
    if (app == null) {
        throw new CamelExchangeException("Application with id " + name + " not found.", exchange);
    } else {
        ApplicationScale scale = app.getApplicationScale();
        if (scale.getValue().equals(ApplicationScale.NO_SCALE.getValue())) {
            log.info("Scaling on application with id " + name + " is not enabled");
        } else {
            app.scaleDown();
            ApplicationScale result = app.getApplicationScale();
            exchange.getIn().setBody(result.getValue());
        }
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:21,代码来源:OpenShiftProducer.java


注:本文中的org.apache.camel.CamelExchangeException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。