Time for action – examining configuration properties

Let us add some configuration properties to our MyAction. We will make the & and the number of times it needs to be printed as configurable properties. Follow these steps:

  1. Add two members to the MyAction class:
    public String SYMBOL = "&";
    public int COUNT = 48;
  2. Modify the constructor as follows:
    _config = config;
    String symbol = _config.getAttribute("symbol");
    if (symbol != null) {
        SYMBOL = symbol;
    }
    String count = _config.getAttribute("count");
    if (count != null) {
        COUNT = Integer.parseInt(count);
    }
  3. Add a printLine() method:
    private void printLine() {
        StringBuffer line = new StringBuffer(COUNT); 
        for (int i = 0; i < COUNT; i++) {
            line.append(SYMBOL);
        }
        System.out.println(line);
    }
  4. Modify the printMessage() method as shown in the following snippet:
    printLine();
    System.out.println("Body: " + message.getBody().get());
    printLine();
    return message;
  5. Edit the jboss-esb.xml file and select the action, BodyPrinter. Add two properties symbol as * and count as 50:
    Time for action – examining configuration properties
  6. Click on Save or press Ctrl + S.
  7. Deploy the application using the Run menu and select Run As | Run on Server.
  8. Run SendJMSMessage.java by clicking Run, select Run As and Java Application.

    The following message will be printed in the console:

    INFO  [STDOUT] **************************************************
    INFO  [STDOUT] Body: Chapter 3 says Hello!
    INFO  [STDOUT] **************************************************
    

What just happened?

You just added two properties to the MyAction class. You also retrieved these properties from the ConfigTree and used them.

Have a go hero – additional header contents

Experiment with the other API methods. Write hierarchicalProperty and see how that can be retrieved.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.223.172.252