NewsQueueEJB.java - Web Service
PostToNewsService.java - Web Service Client

/*
 * @author : Elangovan
 * @version 1.0
 *
 * Development Environment : Oracle9i JDeveloper 

 *
 * Name of the File        : ListenToNewsService.java
 *
 * Creation / Modification History
 *
 *    Elangovan          16-May-2003        Created
 *

 */
package oracle.otnsamples.jmswebservice.client;

// XML imports
import org.w3c.dom.Element;
import oracle.xml.parser.v2.XMLElement;

// Proxy stub

import NewsServiceProxy;

/**
 * This class is a stand-alone client application that listens to the
 * 'NewsService' JMS Web Service for News messages. By calling the ''receive()' method
 * on the proxy stub, it registers itself as a subscriber to the NewsService.
 *
 * Whenever a news message is published to this Web Service, it is delivered to
 * all the subscribed clients.

 *
 * It receives the News message in an XML representation, displays it in the
 * Command line and listens to News again.
 */
public class ListenToNewsService  {

  /**
   * Empty default constructor.
   */
  public ListenToNewsService() {

  }

  /**
   *  Main method. This method is called when the application is run.
   */
  public static void main(String[] args) {

    // Create an instance of this application
    ListenToNewsService client = new ListenToNewsService();

    // Listen to News messages from 'NewsService'

    client.listenToNews();
  }

  /**
   * Subscribes to the 'NewsService' JMS Web Service and listens for News messages.
   * When a News is delivered to it, displays it in the Command Line and
   * continues to listen.
   *
   * News is delivered in XML representation.
   *
   * An example,
   *

   *   <News>
   *     <Title> news title <Title>
   *     <NewsType>S</NewsType>
   *     <Snippet> news snippet </Snippet>
   *     <DetailedNews> the detailed news </DetailedNews>
   *   </News>
   */
  public void listenToNews()   {

    // Create an instance of proxy stub
    NewsServiceProxy proxy = new NewsServiceProxy();

    try {


      // Listen to News
      while(true)     {

        System.out.println( "  ****************************************** " );
        System.out.println( "  Listening for News ...Press Ctrl-C to exit " );
        System.out.println( "  ****************************************** " );

        // receive() methods waits(blocks) until News message is delivered to it.
        Element news = proxy.receive();
        if(news != null)
          ((XMLElement) news).print(System.out);
      }
    } catch (Exception ex)     {      // Handle generic errors

      System.out.println( " Error listening to News Service :" + ex.toString() );
    }
  }
}

E-mail this page
Printer View Printer View
Oracle Is The Information Company About Oracle | Oracle RSS Feeds | Careers | Contact Us | Site Maps | Legal Notices | Terms of Use | Privacy