/**

 * Created by IntelliJ IDEA.
 * User: sgreene
 * Date: May 15, 2003
 * Time: 2:09:47 PM
 * Modified by : Chandar
 * File Name : DocLitLoggerImpl.java

 *
 *   Overview :
 *   This file defines the client for Document Literal Web Service. It looks up
 *    the service, logs sample events and then retrieves the same events
 *   using methods exposed by the Web Service
 */


package oracle.demo.topdowndoclit;

// import Web Service stub classes
import oracle.demo.topdowndoclit.stubs.*;

// User Defined type related imports
import oracle.demo.topdowndoclit.types.LogEventRequestType;
import oracle.demo.topdowndoclit.types.GetEventsRequestType;

import oracle.demo.topdowndoclit.types.GetEventsResponseType;
import oracle.demo.topdowndoclit.types.LogEntry;

// JAX-RPC imports
import javax.xml.rpc.ServiceFactory;
import javax.xml.rpc.Stub;
//import java.util.logging.*;

import java.io.*;

import java.net.URL;

public class DocLitLoggerClient {

   // variable for sample User id
    private static final String USERID = "demoUserID1";

    // variable for storing Web Service URL
    private String m_serviceURL;


    // variable for ServiceFactory
    private ServiceFactory m_factory;

   /*
    *  Constructor definition
    */
    public DocLitLoggerClient(String serviceURL) throws Exception{

      // iinitialize the service URL and factory
       m_serviceURL = serviceURL;
        m_factory = ServiceFactory.newInstance();

    }

   /*
    *  This method defines the main method of the client
    */
    public static void main(String args[]){
        String serviceURL = null;

        // get the service URL argument
        if(args.length > 0){
            serviceURL = args[0];
        }

        else{
             //if argument is not provided
              System.out.println("Service URL should be passed as argument");
            return;
        }
        try{
            // create the client class object
            DocLitLoggerClient demo = new DocLitLoggerClient(serviceURL);

            // call method to invoke Web Service methods
            demo.runDemo();
        }
        // catch any Exceptions

        catch(Exception ex){
            ex.printStackTrace();
        }
    }

   /*
    *  This method gets handle to the Web Service and calls methods on it to
    *   log and retrieve event messages.
    */
    private void runDemo() throws Exception{

        // load service using the Service URL
        DocLitLogger service = (DocLitLogger)m_factory.loadService(new URL(m_serviceURL),
                                DocLitLogger.class, null);

        // get a handle to remote service
        LoggingFacilityLogPortType port = service.getDocLitLoggerPort();
        ((Stub)port)._setProperty(Stub.ENDPOINT_ADDRESS_PROPERTY,m_serviceURL);

        //call method to  invoke Web Service method to log events
        demoLogEvents(port);

        //call method to  invoke Web Service method to retrieve logged events
        demoGetEvents(port);

    }

   /*
    *  This method calls Web Service getEvents method to get the logged events
    *  and prints the event messages on client console

    */
    private void demoGetEvents(LoggingFacilityLogPortType port) throws Exception {
        System.out.println("Here are the events you logged in this session");

       // call Web Service method to get the logged events
        GetEventsResponseType resp = port.getEvents(new GetEventsRequestType(USERID));

      // create LogEntry type array from Web Service return types
        LogEntry entry[] = resp.getLogEntry();

        // iterate through LogEntry array and display the event messages
        for(int i = 0; i < entry.length; i++){
            System.out.println("-------- Entry " + (i+1) + " --------");
            System.out.println("Service ID= " + entry[i].getServiceID());
            System.out.println("Event ID= " + entry[i].getEventID());
            System.out.println("Event Description= " + entry[i].getEventDescription());

            System.out.println("Event Date & TIme= " +
                      entry[i].getTimestamp().getTime().toString());
            System.out.println("------------------------------------------");
            System.out.println();
        }
    }

   /*
    *  This method calls Web Service's logEvents method to log the events
    */
    private void demoLogEvents(LoggingFacilityLogPortType port) throws Exception{

       // create sample log events as objects of LogEventRequestType class
        LogEventRequestType logReq1 = new LogEventRequestType
                                      (USERID,"4","1","A Sample log entry",null);
        LogEventRequestType logReq2 = new LogEventRequestType
                                        (USERID,"4","2","Oracle Application Server 10g",null);

        LogEventRequestType logReq3 = new LogEventRequestType
                                      (USERID,"4","2","Life is beautiful",null);

       // call Web Service method to log above events
        port.logEvent(logReq1);
        port.logEvent(logReq2);
        port.logEvent(logReq3);
    }

}

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