View Javadoc
1   /*
2    * Copyright 2008 the original author or authors.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *     
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.openehealth.ipf.platform.camel.core.camel.exception;
17  
18  import org.apache.camel.Processor;
19  import org.apache.camel.spring.SpringRouteBuilder;
20  import org.openehealth.ipf.platform.camel.core.support.processor.ExceptionProcessor;
21  
22  
23  /**
24   * @author Martin Krasser
25   */
26  public class ExceptionHandlingRouteBuilder extends SpringRouteBuilder {
27  
28      @Override
29      public void configure() throws Exception {
30          
31          from("direct:input")
32          // Enable the following statement if error handling
33          // has been globally turned off via noErrorHandler(),
34          // otherwise exception() statements have no effect.
35          //.errorHandler(deadLetterChannel())
36          .onException(Exception1.class).to("mock:error1").end()
37          .onException(Exception2.class).to("mock:error2").end()
38          .onException(Exception.class).to("mock:error3").end()
39          .process(exceptionProcessor())
40          .to("mock:success");        
41      }
42      
43      private Processor exceptionProcessor() {
44          ExceptionProcessor result = new ExceptionProcessor();
45          result.getExceptions().put("blah", new Exception1());
46          result.getExceptions().put("blub", new Exception2());
47          result.getExceptions().put("oink", new Exception3());
48          return result;
49      }
50  }