HTTP Client Sample Program

In order to run the HTTP client sample program, it is first necessary to install the ORB's HTTP tunnel servlet. This example is divided into two sections:

Installing the HTTP Tunnel

Running the Client

You can of course skip the first step, if you already have the tunnel installed in a servlet container.

1 Installing the HTTP Tunnel

The ORB's HTTP tunnel is a standard servlet, which can be installed into any servlet container. You can for instance install it into the Novell eXtend Application Server or Tomcat. Depending on how the ORB was installed on your system, you need to select an appropriate installation:

  1. If the ORB is installed as a Java 2 extension in the JRE used by your servlet container, you need to create a very simple web.xml file and package a small WAR file. Since a Java 2 extension can only load classes, which are also in the extension, you need to copy the servlet.jar file into the extension as well (normally the jre/lib/ext directory).
  2. If the ORB is not installed as a Java 2 extension, you need to create a WAR file, which contains the mp-orb.jar file and the ORB license files. The structure of the archive must be:
       WEB-INF
          |
          +--- web.xml
          |
          +--- lib
                |
                +--- mp-orb.jar
                |
                +--- license.jar
    
    Please refer to the build.{sh,bat} for an example of creating this WAR.

Once the WAR file has been created, you must install it into the servlet container. In Novell eXtend Application Server, please refer to the documentation for the SilverCmd utility. You can use the jb_tunnel_deploy_plan.xml deployment plan when deploying on the Novell eXtend Application Server. In Tomcat, you must copy the WAR into the webapps directory and restart Tomcat.

2 Running the Client

From a client's perspective, there is not much difference between running using IIOP or HTTP (except performance of course). However, the client must specify the ORBHttpTunnelURL command line property in order to instruct the runtime that tunneling is used. The value of this property is the URL where the ORB's HTTP tunnel servlet is running.

Below is the source for the Client class:

package http;
                                                                           
import javax.naming.InitialContext;
                                                                           
import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.jms.QueueSender;
import javax.jms.QueueSession;
import javax.jms.QueueReceiver;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
                                                                           
/**
   This client should be run with the ORBHttpTunnelURL property. For example:
  
   
      jmqrun -J-DORBHttpTunnelURL=http://titus:80/tunnel http.Client
   
*/ public class Client { public static void main(String[] args) throws Exception { | // get the initial context | InitialContext ctx = new InitialContext(); | | // lookup the queue object | Queue queue = (Queue) ctx.lookup("queue/queue0"); | | // lookup the queue connection factory | QueueConnectionFactory connFactory = (QueueConnectionFactory) ctx. | lookup("queue/connectionFactory"); | | // create a queue connection | QueueConnection queueConn = connFactory.createQueueConnection(); | | // start the connection | queueConn.start(); | | // create a queue session | QueueSession queueSession = queueConn.createQueueSession(false, | Session.AUTO_ACKNOWLEDGE); | | if (args.length > 0 && args[0].equals("-receive")) | { | | // create a queue receiver | | QueueReceiver queueReceiver = queueSession.createReceiver(queue); | | | | // receive a message | | TextMessage message = (TextMessage) queueReceiver.receive(); | | | | // print the message | | System.out.println("received: " + message.getText()); | } | else | { | | // create a queue sender | | QueueSender queueSender = queueSession.createSender(queue); | | | | // create a simple message to say "Hello" | | TextMessage message = queueSession.createTextMessage("Hello"); | | | | // send the message | | queueSender.send(message); | } | | // close the queue connection | queueConn.close(); } }

This is just a regular queue sender and receiver, which by default sends a message to a queue, or if run with the -receive flag receives a message from a queue. You can specify the tunnel property using the -J flag for jmqrun client runner:

   jmqrun -J-DORBHttpTunnelURL=http://titus:80/tunnel http.Client
You should check that the tunnel is successfully running by opening the tunnel URL in a browser. The tunnel will display an error message stating that it does not understand HTTP GET. You also must make sure that the JMS server is running on a host reachable from the servlet container.

Back to top


Copyright © 2000-2003, Novell, Inc. All rights reserved.