We will now run the Chapter6
sample application that demonstrates the usage of the File gateway:
jboss-esb.xml
file in Source mode.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>
<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>
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!
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(); }