WebLogic Server 6.0 Code Examples, BEA Systems, Inc.

examples.jms.sender
Class SenderServlet

java.lang.Object
  |
  +--javax.servlet.GenericServlet
        |
        +--javax.servlet.http.HttpServlet
              |
              +--examples.jms.sender.SenderServlet
All Implemented Interfaces:
java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

public class SenderServlet
extends javax.servlet.http.HttpServlet

This example shows how to send JMS messages from a Java servlet.

The following sections describe how to:

  1. Build the example
  2. Configure the server
  3. Run the example

Build the Example

  1. Set up your development shell, as described in Setting up your environment.
  2. Compile the example by executing the following command or by executing the build script provided for this example in the samples/examples/jms/sender directory. The script will perform the following step:

    Compile the SenderServlet as shown in this example for Windows NT/2000:

      $ javac -d %EX_WEBAPP_CLASSES% SenderServlet.java

Configure the Server

The following have been preset and/or preconfigured for your convenience:

Note: If you have configured the server to run the examples.jms.queue and examples.jms.topic examples, then no additional configuration changes are required to run the SenderServlet example, and you can skip to the section Run the Example.

To configure the server:

  1. Start the server with the examples configuration.
  2. Bring up the Administration Console in your browser.
  3. Click to expand the JMS node in the left pane.
  4. Click to expand the JMS Connection Factories node in the left pane.
  5. Choose the server target for the exampleQueue connection factory as follows:
    1. Select the exampleQueue node. The exampleQueue connection factory configuration information displays in the right pane.
    2. Select the Targets tab in the right pane to display the Available and Chosen targets.
    3. Move the examplesServer target to the Chosen column and click the Apply button to save the assignment.
  6. Repeat step 5 to configure the exampleTopic connection factory, selecting the exampleTopic node instead of the exampleQueue node.

Run the Example

  1. Start the server with the examples configuration (if it not already started).
  2. Load the servlet in a browser using the following URL:
      http://hostname:port/examplesWebApp/jmssender
    where:
    hostname
    Host name of the WebLogic Server.
    port
    Port where the WebLogic Server is listening for connections (weblogic.system.ListenPort).

  3. Enter a message to send and click the Send Message button.
  4. You can use the QueueReceive and TopicReceive examples to observe messages being sent to the queue and topic, respectively, based on the destination selected. For a queue, persistent messages will be sent even if the queue is not connected to the server and listening at the time the messages are sent.

Author:
Copyright (c) 1999-2000 by BEA Systems, Inc. All Rights Reserved.

Field Summary
static java.lang.String JMS_FACTORY
          Defines the JMS connection factory.
static java.lang.String QUEUE
          Defines the queue.
static java.lang.String TOPIC
          Defines the topic.
 
Constructor Summary
SenderServlet()
           
 
Method Summary
 void printForm(java.io.PrintWriter pw)
          Displays the web page for message input.
 void sendQueueMessage(boolean persistent, int priority, long ttl, java.lang.String correlate, java.lang.String replyto, java.lang.String topicMessage)
          Sends a message to the queue.
 void sendTopicMessage(boolean persistent, int priority, long ttl, java.lang.String correlate, java.lang.String replyto, java.lang.String topicMessage)
          Sends message to the topic.
 void service(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
          Processes HTTP requests.
 
Methods inherited from class javax.servlet.http.HttpServlet
, doDelete, doGet, doOptions, doPost, doPut, doTrace, getLastModified, service
 
Methods inherited from class javax.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

JMS_FACTORY

public static final java.lang.String JMS_FACTORY
Defines the JMS connection factory.

QUEUE

public static final java.lang.String QUEUE
Defines the queue.

TOPIC

public static final java.lang.String TOPIC
Defines the topic.
Constructor Detail

SenderServlet

public SenderServlet()
Method Detail

printForm

public void printForm(java.io.PrintWriter pw)
               throws java.lang.Exception
Displays the web page for message input.
Parameters:
pw - print writer
Throws:
java.lang.Exception - if problem with printing form

sendQueueMessage

public void sendQueueMessage(boolean persistent,
                             int priority,
                             long ttl,
                             java.lang.String correlate,
                             java.lang.String replyto,
                             java.lang.String topicMessage)
                      throws javax.naming.NamingException,
                             javax.jms.JMSException
Sends a message to the queue.
Parameters:
persistent - persistency setting
priority - priority setting
ttl - time-to-live setting
correlate - correlation ID setting
replyto - reply-to setting
topicMessage - message
Throws:
javax.naming.NamingException - if problem with JNDI context interface
javax.jms.JMSException - if JMS fails send message due to internal error

sendTopicMessage

public void sendTopicMessage(boolean persistent,
                             int priority,
                             long ttl,
                             java.lang.String correlate,
                             java.lang.String replyto,
                             java.lang.String topicMessage)
                      throws javax.naming.NamingException,
                             javax.jms.JMSException
Sends message to the topic.
Parameters:
persistent - persistency setting
priority - priority setting
ttl - time-to-live setting
correlate - correlation ID setting
replyto - reply-to setting
topicMessage - message
Throws:
javax.naming.NamingException - if problem with JNDI context interface
javax.jms.JMSException - if JMS fails send message due to internal error

service

public void service(javax.servlet.http.HttpServletRequest req,
                    javax.servlet.http.HttpServletResponse res)
             throws java.io.IOException,
                    javax.servlet.ServletException
Processes HTTP requests.
Overrides:
service in class javax.servlet.http.HttpServlet
Parameters:
req - HTTP servlet request
res - HTTP servlet response
Throws:
java.io.IOException - if problem with I/O operation
javax.servlet.ServletException - if problem with servlet

Documentation is available at
http://e-docs.bea.com/wls/docs60

Copyright © 2000 BEA Systems, Inc. All Rights Reserved.