Skip to main content Skip to complementary content

Creating a Bean

About this task

In this section, a JavaBean is created to print the id, first name, and surname from the customer information with the corresponding column names into the execution console.


  1. From the repository tree view, expand the Code node and right click the Beans node. In the contextual menu, select Create Bean.
    The New Bean wizard opens. In the Name field, type in a name for the bean, for example, ReadOrder. Click Finish to close the wizard. The bean is opened automatically in the design workspace.
  2. Enter the following code in the design workspace.
    package beans;
    import org.apache.camel.Exchange;
    public class ReadOrder {
    	public static void getCustomer(Exchange exch) { 
    		if(exch.getIn().getBody() !=null)
    			java.util.Map data = exch.getIn().getBody(java.util.Map.class); 
    			if(data != null){ 
    				String id= (String)(data.get("id")); 
    				System.out.println("id :"+id);
    				String name= (String)(data.get("name")); 
    				System.out.println("name :"+name);
    				String surname= (String)(data.get("surname")); 
    				System.out.println("surname :"+surname);
    				exch.getIn().setBody("<customer><id>" + id + "</id><name>" + name + "</name><surname>" + surname + "</surname></customer>", String.class);
  3. Press Ctrl+S to save your bean.


For more information about creating and using JavaBeans, see Using Beans.

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – let us know how we can improve!