package examples.t3client;

import java.io.*;
import java.net.*;
import weblogic.common.*;

/**
 * This example demonstrates a simple T3Client that makes a connection
 * to the WebLogic Server.  
 * <p>
 * To run this example, supply a URL as the first argument of the form
 * <pre>  scheme://WebLogicURL:port</pre>
 * where scheme is one of:
 * <dl>
 * <dt>t3   <dd>Standard WebLogic t3 protocol
 * <dt>t3s  <dd>WebLogic t3 protocol using Secure Sockets Layer(SSL)
 * <dt>http <dd>HTTP tunneling
 * <dt>https<dd>HTTP tunneling using SSL
 * </dl>
 * <p>
 * Here's an example:
 * <pre> $ <b>java examples.t3client.SimpleT3Client t3://localhost:7001</b></pre>
 *
 * @author Copyright (c) 1996-98 by WebLogic, Inc. All Rights Reserved.
 * @author Copyright (c) 1999-2000 by BEA Systems, Inc. All Rights Reserved.
 */
public class SimpleT3Client {
  
  /**
   * Creates a simple T3Client, connects it, does nothing, and
   * disconnects. This simple class uses a main method so you can run
   * it from a command line.
   */
  public static void main(String[] argv) {
    // Default URL value
    String URL  = "t3://localhost:7001";
    T3Client t3 = null;
    
    // Use the first command line argument as the URL, if it exists
    if (argv.length > 0)
      URL = argv[0];  
    else
      System.out.println("No argument supplied, using default URL " + URL);

    // Wrap the work of your class in a try block
    try {
      t3 = new T3Client(URL);
      t3.connect();
      
      System.out.println("Successfully connected to WebLogic Server at " + URL);
      /*
       * Insert your code to do actual work here
       */
      System.out.println("Successfully disconnected from WebLogic Server");
    }

    // Catch exceptions and deal with them appropriately.
    // You might catch several more specific exceptions if you
    // are debugging or if you want to return specific failure
    // messages to your client. Here we catch Exception (thrown
    // by a main() method) and print the stack trace.
    catch (Exception e) {e.printStackTrace();}

    // Always disconnect from WebLogic or a DBMS in a finally
    // block. Wrapping the disconnect in another try block 
    // and catching disconnect-related exceptions is smart.
    finally {
      try {
        t3.disconnect();
        System.out.println("Disconnected from WebLogic Server");
      }
      catch (Exception e) {e. printStackTrace();}
    }
  }
}
