Package org.exolab.jms.util

Examples of org.exolab.jms.util.CommandLine


        }
        admin.close();
    }

    public static void main(String[] args) throws Exception {
        CommandLine cmdline = new CommandLine(args);
        String url = cmdline.value("url");

        if (url == null || cmdline.exists("help")) {
            usage();
        } else if (cmdline.exists("list")) {
            list(url);
        } else if (cmdline.exists("add")) {
            add(url, cmdline.value("add"), cmdline.value("name"));
        } else if (cmdline.exists("queue")) {
            queueCount(url, cmdline.value("queue"));
        } else if (cmdline.exists("topic") && (cmdline.exists("name"))) {
            topicCount(url, cmdline.value("topic"), cmdline.value("name"));
        } else if (cmdline.exists("remove")) {
            remove(url, cmdline.value("name"));
        } else {
            usage();
        }
    }
View Full Code Here


    static public void main(String[] args)
    {
        try
        {
            CommandLine cmdline = new CommandLine(args);

            if (cmdline.exists("help"))
            {
                // the help option has been specified, print the usage
                // information
                usage();
            }
            else if (cmdline.exists("queue"))
            {
              // see if an ack mode has been specified. If it hasn't
            // then assume CLIENT_ACKNOWLEDGE mode.
                int ackMode = Session.CLIENT_ACKNOWLEDGE;
                if (cmdline.exists("ackmode"))
                {
                    String mode = cmdline.value("ackmode");
                    if (mode.equals("auto"))
                    {
                        ackMode = Session.AUTO_ACKNOWLEDGE;
                    }
                    else if (mode.equals("dups"))
                    {
                        ackMode = Session.DUPS_OK_ACKNOWLEDGE;
                    }
                    else if (!mode.equals("client"))
                    {
                        // ignore all ack modes, to test no acking
                        ackMode = -1;
                    }
                }
       
                // enable debugging - unbdocumented option
                if (cmdline.exists("debug")) {
                    LoggerIfc logger = LoggerFactory.getLogger();
                    logger.setLogLevel(LogEventType.Debug);
                }

                String queue_name = cmdline.value("queue");
                if (queue_name != null)
                {
                    // connect to the JNDI server and get a reference to
                    // root context
                    Hashtable props = new Hashtable();
                    String mode = cmdline.value("mode");
                    String modeType =
                        RmiJndiInitialContextFactory.class.getName();
         
                    if (cmdline.exists("jndiport"))
                    {
                        props.put(JndiConstants.PORT_NUMBER_PROPERTY,
                                  new Integer(cmdline.value("jndiport")));
                    }

                    if (cmdline.exists("jndihost"))
                    {
                        props.put(JndiConstants.HOST_PROPERTY,
                                  cmdline.value("jndihost"));
                    }
         
                    // override the default server name if specified on the
                    // command line.
                    if (cmdline.exists("jndiname"))
                    {
                        props.put(JndiConstants.NAME_PROPERTY,
                                  cmdline.value("jndiname"));
                    }
                   
                    if ((mode != null) &&
                        (mode.equals("ipc")))
                    {
                        System.out.println("Using IPC mode");
                        modeType =
                            org.exolab.jms.jndi.mipc.IpcJndiInitialContextFactory.class.getName();
                    }
                    props.put(Context.INITIAL_CONTEXT_FACTORY, modeType);

                    Context context = new InitialContext(props);

                    // lookup the connection factory from the context
                    QueueConnectionFactory factory = (QueueConnectionFactory)
                        context.lookup("JmsQueueConnectionFactory");

                    // if we can't find the factory then throw an exception
                    if (factory == null)
                    {
                        throw new RuntimeException(
                            "Failed to locate connection factory");
                    }
                   
                    LoggerFactory.getLogger().logDebug("Have the connection factory " + factory);
                    QueueConnection connection =
                        factory.createQueueConnection();
                    connection.start();

                    QueueSession session =
                        connection.createQueueSession(false, ackMode);

                    Queue queue = null;
                    if (cmdline.exists("persistent"))
                    {
                        queue = (Queue)context.lookup(queue_name);
                    }
                    else
                    {
                        queue = session.createQueue(queue_name);
                    }
         
                    if (queue == null)
                    {
                        System.err.println("Failed to get administered object"
                                           + " exiting.....");
                        System.exit(-1);
                    }
                    // if the 'name' option has been specified then assume a
                    // durable receiver otherwise transient
                    QueueReceiver receiver = null;
                    receiver = session.createReceiver(queue);
                    
                    int secs = 10;
                    boolean counted = false;
                    int count = 1;

                    if (cmdline.exists("count"))
                    {
                        counted = true;
                        try
                        {
                            String value = cmdline.value("count");
                            count = Integer.parseInt(value);
                        }
                        catch (Exception exception)
                        {
                            System.err.println("Illegal count value");
                            System.exit(-1);
                        }

                        secs = 5 * 60; // timeout after 5 mins by default
                    }

                    if (cmdline.exists("timeout"))
                    {
                        secs = Integer.parseInt(cmdline.value("timeout"));
                    }

                    SimpleQueueListener listener = (counted)
                        ? new SimpleQueueListener(connection, receiver, ackMode, count, secs)
                        : new SimpleQueueListener(connection, receiver, ackMode, secs);
View Full Code Here

* The simple browser will browse messages on a queue
*/
public class SimpleBrowser {
    static public void main(String[] args) {
        try {
            CommandLine cmdline = new CommandLine(args);

            if (cmdline.exists("help")) {
                // the help option has been specified, print the usage
                // information
                usage();
                System.exit(0);
            } else if (cmdline.exists("queue")) {
                // connect to the JNDI server and get a reference to
                // root context
                Hashtable props = new Hashtable();
                String topic_name = cmdline.value("topic");
                String host = "localhost";
                String port = null;
                String jndiname = "JndiServer";

                String mode = null;
                if (cmdline.exists("mode")) {
                    mode = cmdline.value("mode");
                } else {
                    mode = "rmi";
                }

                String modeType =
                    RmiJndiInitialContextFactory.class.getName();

                if (cmdline.exists("jndiport")) {
                    port = cmdline.value("jndiport");
                }

                if (cmdline.exists("jndihost")) {
                    host = cmdline.value("jndihost");
                }

                // override the default server name if specified on the
                // command line.
                if (cmdline.exists("jndiname")) {
                    jndiname = cmdline.value("jndiname");
                }

                if (mode.equals("ipc") || mode.equals("tcp")) {
                    if (port == null) {
                        port = "3035";
                    }

                    props.put(Context.PROVIDER_URL,
                        "tcp://" + host + ":" + port + "/");
                    modeType =
                        "org.exolab.jms.jndi.mipc.IpcJndiInitialContextFactory";
                } else if (mode.equals("http")) {
                    System.out.println("Using HTTP");

                    /* CONNECTING BY WAY OF PROXY 
                       Client needs to set these system properties if
                       it requires to go through a proxy for HTTP.
                       System.setProperty("http.proxyHost", host);
                       System.setProperty("http.proxyPort", port);
                    */

                    /* CONNECTING FOR SSL TRANSACTIONS.
                       Client needs to set these system properties
                       if it requires to go through a proxy for HTTPS.

                       System.setProperty("https.proxyHost", "host");
                       System.setProperty("https.proxyPort", "port");


                       Client needs to pass in "-mode http -secure"
                       to use https
                       Client needs -Djavax.net.ssl.trustStore=cacerts
                       passed in. JSSE is required to make this work.
                    */

                    String type = "http://";
                    if (cmdline.exists("secure")) {
                        if (port == null) {
                            port = "8443";
                        }
                        type = "https://";
                        modeType =
                            "org.exolab.jms.jndi.http.SslHttpJndiInitialContextFactory";
                    } else {
                        if (port == null) {
                            port = "8080";
                        }
                        modeType =
                            "org.exolab.jms.jndi.http.HttpJndiInitialContextFactory";
                    }

                    props.put(Context.PROVIDER_URL,
                        type + host + ":" + port + "/" +
                        "openjms/servlet/OpenJMSJndi");

                    String url = cmdline.value("url");
                    if (url == null) {
                        url = type + "localhost:8080";
                    }

                    // Client URL to allow server to send messages
                    // to registered consumers/receivers
                    System.getProperties().setProperty
                        (JndiConstants.HTTP_CLIENT_URL_PROPERTY, url);

                } else {
                    if (port == null) {
                        port = "1099";
                    }

                    props.put(Context.PROVIDER_URL,
                        "rmi://" + host + ":" + port + "/" + jndiname);
                }

                System.err.println("Using provider url " + props.get(Context.PROVIDER_URL));
                props.put(Context.INITIAL_CONTEXT_FACTORY, modeType);
                Context context = new InitialContext(props);


                String name = cmdline.value("queue");
                if (name != null) {
                    // lookup the connection factory from the context
                    QueueConnectionFactory factory = (QueueConnectionFactory)
                    context.lookup("JmsQueueConnectionFactory");

                    // if we can't find the factory then throw an exception
                    if (factory == null) {
                        throw new RuntimeException(
                            "Failed to locate connection factory");
                    }

                    QueueConnection connection =
                        factory.createQueueConnection();
                    connection.start();

                    QueueSession session = connection.createQueueSession(
                        false, Session.AUTO_ACKNOWLEDGE);

                    // if the persistent flag is not specified then create the
                    // queue object otherwise look it up
                    Queue queue = null;
                    if (cmdline.exists("persistent")) {
                        queue = (Queue)context.lookup(name);
                    } else {
                        // The queue object is therefore created as non
                        // persistent.
                        queue = (Queue)session.createQueue(name);
                    }

                    // determine whether the summary flag has been set. By
                    // default it is false, which means the message details
                    // are displayed as they are browsed
                    boolean summary = false;
                    if (cmdline.exists("summary")) {
                        summary = true;
                    }

                    if (queue == null) {
                        getLogger().logError("Failed to create the queue " +
                            queue);
                        System.exit(-1);
                    }

                    String selector = "JMSPriority = 4";
                    QueueBrowser browser = null;
                    if (cmdline.exists("selector")) {
                        browser = session.createBrowser(queue, selector);
                    } else {
                        browser = session.createBrowser(queue);
                    }
                    // return the number of messages to receive
                    int count = -1;
                    if (cmdline.exists("count")) {
                        try {
                            count = Integer.parseInt(cmdline.value("count"));
                        } catch (Exception exception) {
                            System.err.println("Illegal count value");
                            System.exit(-1);
                        }
                    }
View Full Code Here

TOP

Related Classes of org.exolab.jms.util.CommandLine

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.