Time for action – using the File gateway

We will now run the Chapter6 sample application that demonstrates the usage of the File gateway:

  1. In JBoss Developer Studio, open the jboss-esb.xml file in Source mode.
  2. Append the following listener definition to the <listeners> tag:
    <listeners>
      <jms-listener busidref="chapter6ESBChannel"
                    name="Chapter6ESBListener"/>
      <jms-listener busidref="chapter6GwChannel" is-gateway="true"
                    name="Chapter6GwListener"/>
      <fs-listener busidref="chapter6FileChannel" is-gateway="true"
                   name="Chapter6FileGwListener"/>
    </listeners>
  3. Replace the following action:
    <action name="notificationAction"
            class="org.jboss.soa.esb.actions.Notifier">
      <property name="okMethod" value="notifyOK"/>
      <property name="notification-details"> 
        <NotificationList type="ok">
          <target class="NotifyQueues" >
            <queue jndiName="queue/chapter6_Request_gw_reply"/>
          </target>
        </NotificationList>
      </property>
    </action>

    With this action:

    <action name="notificationAction"
            class="org.jboss.soa.esb.actions.Notifier">
      <property name="okMethod" value="notifyOK"/>
      <property name="notification-details"> 
        <NotificationList type="ok">
          <target class="NotifyFiles">
            <file append="false" URI="${java.io.tmpdir}/results.log"/>
          </target>
        </NotificationList>
      </property>
    </action>
  4. Click the Save button and the modified application should now be deployed in the server.
  5. Select the src folder and expand it till the SendFileMessage.java file is displayed in the tree. Now click Run | Run As | Java Application.

    The console will display the output as follows:

    File Gateway says Hello!
    

What just happened?

The File gateway picked up an incoming message through a file on the filesystem, sent it through the ESB and created a response in a separate file with the help of a notifier.

Let's now take a look at the client code, concentrating on the sections which are responsible for creating the original request:

public static void main(String[] args) throws Exception {
    String tmpDir = System.getProperty("java.io.tmpdir");
    File file = new File(tmpDir, "file.msg");
    BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file)));
    writer.write("Hello File Gateway!");
    writer.close();
    Thread.sleep(300);
    File result = new File(tmpDir, "results.log");
    BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(result)));
    String line = null;
    while((line = reader.readLine()) != null) {
        System.out.println(line);
    }
    reader.close();
}
..................Content has been hidden....................

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