Christina Lin
try{
...
}catch(SomeException e){
...
}finally{
....
}
Open up /errordemo/src/main/resources/OSGI-INF/blueprint/blueprint.xml and remove the demo route, so you are left with a blank canvas.
Remove the hellobean registry in the xml file. And delete all the java files.
<bean id="helloBean" class="com.mycompany.camel.blueprint.HelloBean">
<property name="say" value="Hi from Camel"/>
</bean>
<bean id="randomProcessor" class="org.blogdemo.errordemo.RandomProcessor"/>
package org.blogdemo.errordemo; import java.io.FileNotFoundException; import java.io.IOException; import org.apache.camel.Exchange; import org.apache.camel.Processor; public class RandomProcessor implements Processor { @Override public void process(Exchange exchange) throws Exception { int random = (int )(Math.random() * 100 + 1); if(random< 30){ System.out.println("random number:["+random+"] IOExceotion"); throw new IOException(); }else if(random< 90){ System.out.println("random number:["+random+"] FileNotFoundException"); throw new FileNotFoundException(); }else{System.out.println("random number:["+random+"] PASS"); } } }
<camelContext>
<onException>
<exception>java.io.FileNotFoundException</exception>
<redeliveryPolicy redeliveryDelay="3000" maximumRedeliveries="2"/>
</onException>
<route>…</route>
</camelContext>
<camelContext>
<errorHandler deadLetterUri="file://DLQ" type="DeadLetterChannel" id="myErrorHandler">
<redeliveryPolicy redeliveryDelay="5000" maximumRedeliveries="1"/>
</errorHandler>
<onException>…<onException>
…
</camelContext>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="stocktrading">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="name"/>
<xs:element type="xs:string" name="custId"/>
<xs:element type="xs:byte" name="vip"/>
<xs:element type="xs:string" name="stockId"/>
<xs:element type="xs:byte" name="shares"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
<?xml version="1.0" encoding="UTF-8"?>
<!-- Red Hat Stock Exchange and Trading Systems-->
<stocktrading>
<name>Christina Lin</name>
<custId>A123456789</custId>
<vip>1</vip>
<stockId>XYZ</stockId>
<shares>11</shares>
</stocktrading>
<?xml version="1.0" encoding="UTF-8"?>
<!-- Red Hat Stock Exchange and Trading Systems-->
<stocktrading>
<name>Christina Lin</name>
<custId>A123456789</custId>
<vip>1</vip>
<stockId>XYZ</stockId>
</stocktrading>