Time for action – using the JBR gateway

Let us now run the Chapter6 sample application that demonstrates the usage of the JBR gateway:

  1. In JBoss Developer Studio, open the jboss-esb.xml file in Source mode.
  2. Add the following provider to the providers list:
    <jbr-provider name="JBRprovider"
                  protocol="htp" host="localhost">
      <property name="serviceInvokerTimeout" value="20000"/>
      <jbr-bus busid="chapter6JBRChannel" port="9888"/>
    </jbr-provider>
  3. 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"/>
     <jbr-listener busidref="chapter6JBRChannel"
                   name="Chapter6JBRGwListener" is-gateway="true"/>
    </listeners>
  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 SendJBRMessage.java file is displayed in the tree. Now click Run | Run As | Java Application.
  6. The console will display the output as shown:
    JBoss Remoting Gateway says Hello!
    

What just happened?

We sent a message via the JBR gateway listener and we received the response synchronously. Here is the listing of the client code for reference:

public static void main(String[] args) throws Exception {
    String serverURL = "http://localhost:9888";
    HttpURLConnection connection =(HttpURLConnection)new URL(serverURL).openConnection();
    connection.setRequestMethod("POST");
    connection.setDoOutput(true);
    connection.setDoInput(true);
    connection.connect();
    PrintWriter out = new PrintWriter(new OutputStreamWriter(connection.getOutputStream()));
    out.println("Hello JBoss Remoting Gateway!");
    out.close();
    BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
    String inputLine;
    while ((inputLine = in.readLine()) != null) {
        System.out.println(inputLine);
    }
    in.close();
}

Have a go hero – using asynchronous JBR

Go ahead and modify the listener to add asynchronous behavior. Are you able to send a GET request now? What status code and response does it return by default?

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

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