Procedure
-
Double-click the cOnException component,
which is labelled Ignore_exception, to
open its Basic settings view in the
Component tab.
-
Click the plus button to add a line in the Exceptions table, and define the exception to catch. In this
example, enter
java.io.IOException
to handle IO exceptions.In the Exception behavior area, select the Ignore the exceptions option to ignore exceptions and let message routing continue. Leave the other parameters as they are. -
Double-click the cFile component, which
is labelled Source, to open its Basic settings view in the Component tab.
- In the Path field, enter the path of the message source, and leave the other parameters as they are.
-
Double-click the cBean component, which
is labelled Throw_exception, to open its
Basic settings view in the Component tab.
-
Select New Instance and in the Bean class field, enter the name of the bean to
throw an IO exception, beans.throwIOException.class in this scenario.
Note that this bean has already been defined in the Code node of the Repository and it looks like this:
package beans; import java.io.IOException; import org.apache.camel.Exchange; public class throwIOException { /** * @throws IOException */ public static void helloExample(String message, Exchange exchange) throws IOException { throw new IOException("An IOException has been caught"); } }
For more information about creating and using JavaBeans, see Talend Studio User Guide. -
Double-click the cProcessor component,
which is labelled Monitor, to open its
Basic settings view in the Component tab.
-
In the Code area, customize the code to
display the file name of the consumed message on the Run console:
System.out.println("Message consumed: "+ exchange.getIn().getHeader("CamelFileName"));
- Press Ctrl+S to save your Route.