You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by ni...@apache.org on 2007/06/01 11:25:13 UTC

svn commit: r543443 - in /incubator/cxf/trunk: distribution/src/main/release/bin/ rt/management/src/main/java/org/apache/cxf/management/utils/ rt/management/src/test/java/org/apache/cxf/management/utils/

Author: ningjiang
Date: Fri Jun  1 02:25:11 2007
New Revision: 543443

URL: http://svn.apache.org/viewvc?view=rev&rev=543443
Log:
[CXF-698] Commandline tool for managed endpoints

Added:
    incubator/cxf/trunk/distribution/src/main/release/bin/mc   (with props)
    incubator/cxf/trunk/distribution/src/main/release/bin/mc.bat   (with props)
Modified:
    incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/utils/ManagementConsole.java
    incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/utils/Messages.properties
    incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/utils/ManagementConsoleTest.java

Added: incubator/cxf/trunk/distribution/src/main/release/bin/mc
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/distribution/src/main/release/bin/mc?view=auto&rev=543443
==============================================================================
--- incubator/cxf/trunk/distribution/src/main/release/bin/mc (added)
+++ incubator/cxf/trunk/distribution/src/main/release/bin/mc Fri Jun  1 02:25:11 2007
@@ -0,0 +1,55 @@
+#
+#
+#    Licensed to the Apache Software Foundation (ASF) under one
+#    or more contributor license agreements. See the NOTICE file
+#    distributed with this work for additional information
+#    regarding copyright ownership. The ASF licenses this file
+#    to you under the Apache License, Version 2.0 (the
+#    "License"); you may not use this file except in compliance
+#    with the License. You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+#    Unless required by applicable law or agreed to in writing,
+#    software distributed under the License is distributed on an
+#    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#    KIND, either express or implied. See the License for the
+#    specific language governing permissions and limitations
+#    under the License.
+#
+#
+#!/bin/sh
+# run the Apache CXF management console tool 
+#
+
+me=`basename $0`
+cxf_home=$CXF_HOME
+if [ ! -f  $cxf_home/lib/cxf-manifest-incubator.jar ]; then
+    cxf_home=`dirname $0`/..
+fi
+
+cxf_jar=$cxf_home/lib/cxf-manifest-incubator.jar
+
+if [ ! -f $cxf_jar ]; then 
+    if [ ! -f ${cxf_home}/../../target/srcbuild_env ]; then
+        echo "ERROR: Unable to find cxf-manifest-incubator.jar in $cxf_home/lib"
+        exit 1
+    else
+        . ${cxf_home}/../../target/srcbuild_env
+        cxf_jar=${CXF_CLASSPATH}
+    fi
+fi 
+
+
+log_config=$cxf_home/etc/logging.properties
+
+
+
+cxf_classpath=${cxf_jar}:${CLASSPATH}
+
+$JAVA_HOME/bin/java -cp ${cxf_classpath} -Djava.util.logging.config.file=$log_config org.apache.cxf.management.utils.ManagementConsole "$@"
+
+
+
+
+

Propchange: incubator/cxf/trunk/distribution/src/main/release/bin/mc
------------------------------------------------------------------------------
    svn:eol-style = LF

Propchange: incubator/cxf/trunk/distribution/src/main/release/bin/mc
------------------------------------------------------------------------------
    svn:executable = *

Propchange: incubator/cxf/trunk/distribution/src/main/release/bin/mc
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/cxf/trunk/distribution/src/main/release/bin/mc.bat
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/distribution/src/main/release/bin/mc.bat?view=auto&rev=543443
==============================================================================
--- incubator/cxf/trunk/distribution/src/main/release/bin/mc.bat (added)
+++ incubator/cxf/trunk/distribution/src/main/release/bin/mc.bat Fri Jun  1 02:25:11 2007
@@ -0,0 +1,49 @@
+@echo off
+rem
+rem
+rem    Licensed to the Apache Software Foundation (ASF) under one
+rem    or more contributor license agreements. See the NOTICE file
+rem    distributed with this work for additional information
+rem    regarding copyright ownership. The ASF licenses this file
+rem    to you under the Apache License, Version 2.0 (the
+rem    "License"); you may not use this file except in compliance
+rem    with the License. You may obtain a copy of the License at
+rem
+rem    http://www.apache.org/licenses/LICENSE-2.0
+rem
+rem    Unless required by applicable law or agreed to in writing,
+rem    software distributed under the License is distributed on an
+rem    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+rem    KIND, either express or implied. See the License for the
+rem    specific language governing permissions and limitations
+rem    under the License.
+rem
+rem
+
+rem 
+rem  invoke the CXF management console tool
+rem 
+rem @setlocal
+
+if not defined CXF_HOME goto set_cxf_home
+                                                                                                                                                             
+:cont
+if not defined JAVA_HOME goto no_java_home
+
+set SUN_TOOL_PATH=%JAVA_HOME%\lib\tools.jar;
+
+if not exist "%CXF_HOME%\lib\cxf-manifest-incubator.jar" goto no_cxf_jar
+
+set CXF_JAR=%CXF_HOME%\lib\cxf-manifest-incubator.jar
+
+"%JAVA_HOME%\bin\java" -cp "%CXF_JAR%;%CLASSPATH%" -Djava.util.logging.config.file="%CXF_HOME%\etc\logging.properties" org.apache.cxf.management.utils.ManagementConsole %*
+
+rem @endlocal
+
+goto end
+
+:no_cxf_jar
+echo ERROR: Unable to find cxf-manifest-incubator.jar in %cxf_home/lib
+goto end
+
+:end

Propchange: incubator/cxf/trunk/distribution/src/main/release/bin/mc.bat
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/distribution/src/main/release/bin/mc.bat
------------------------------------------------------------------------------
    svn:executable = *

Propchange: incubator/cxf/trunk/distribution/src/main/release/bin/mc.bat
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/utils/ManagementConsole.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/utils/ManagementConsole.java?view=diff&rev=543443&r1=543442&r2=543443
==============================================================================
--- incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/utils/ManagementConsole.java (original)
+++ incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/utils/ManagementConsole.java Fri Jun  1 02:25:11 2007
@@ -104,8 +104,8 @@
         throws MalformedObjectNameException, NullPointerException {
         StringBuffer buffer = new StringBuffer();
         buffer.append(ManagementConstants.DEFAULT_DOMAIN_NAME + ":type=Bus.Service.Endpoint,");
-        buffer.append(ManagementConstants.SERVICE_NAME_PROP + "='" + serviceName + "',");
-        buffer.append(ManagementConstants.PORT_NAME_PROP + "='" + portName + "',*");
+        buffer.append(ManagementConstants.SERVICE_NAME_PROP + "=\"" + serviceName + "\",");
+        buffer.append(ManagementConstants.PORT_NAME_PROP + "=\"" + portName + "\",*");        
         return new ObjectName(buffer.toString());
     }
     
@@ -123,10 +123,18 @@
                 // only deal with the first endpoint object which retrun from the list.
                 endpointName = (ObjectName)it.next();
                 mbsc.invoke(endpointName, operation, new Object[0], new String[0]);
+                System.out.println("invoke endpoint " + endpointName 
+                                   + " operation " + operation + " succeed!");
             }
             
         } catch (Exception e) {
-            LOG.log(Level.SEVERE, "FAIL_TO_LIST_ENDPOINTS", new Object[]{endpointName, operation, e}); 
+            if (null == endpointName) {
+                LOG.log(Level.SEVERE, "FAILT_TO_CREATE_ENDPOINT_OBEJCTNAME", new Object[]{e});
+                
+            } else {
+                LOG.log(Level.SEVERE, "FAIL_TO_INVOKE_MANAGED_OBJECT_OPERTION",
+                    new Object[]{endpointName, operation, e.toString()});
+            }
         } 
     }
     
@@ -144,49 +152,75 @@
     }
     
     
-    void parserArguments(String[] args) {
+    boolean parserArguments(String[] args) {
         portName = "";
-        serviceName = "";
-        jmxServerURL = "";
+        serviceName = "";        
+        operationName = "";
+        boolean result = false;
         
         int i;
         String arg;
         for (i = 0; i < args.length; i++) {
             arg = args[i];
-            if ("-port".equals(arg)) {
+            if ("--port".equals(arg) || "-p".equals(arg)) {
                 portName = args[++i];
                 continue;
             }
-            if ("-service".equals(arg)) {
+            if ("--service".equals(arg) || "-s".equals(arg)) {
                 serviceName = args[++i];
                 continue;
             }
-            if ("-jmx".equals(arg)) {
+            if ("--jmx".equals(arg) || "-j".equals(arg)) {
                 jmxServerURL = args[++i];
                 continue;
             }
-            if ("-operation".equals(arg)) {
+            if ("--operation".equals(arg) || "-o".equals(arg)) {
                 operationName = args[++i];
+                result = true;
                 continue;
             }
-        }    
+        }  
+        return result;
+    }
+    
+    private static void printUsage() {
+        System.out.println("Managed Console for CXF");
+        System.out.println("\t Valid options");
+        System.out.println("-j [--jmx] arg \t\t the jmxServerURL that need to connet mbean server ");
+        System.out.println("\t\t\t the default value is " 
+            + "service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi");
+        System.out.println("-p [--port] arg \t the port name of the managed endpoint");
+        System.out.println("\t\t\t the arg is the Qname of port");
+        System.out.println("-s [--service] arg \t the service name of the managed endpoint");
+        System.out.println("\t\t\t the arg format the Qname of service");
+        System.out.println("-o [--operation] {list|start|stop|restart} \t call the jmx functions");
+        System.out.println("\t\t\t list: show all the managed endpoints' objectNames and attributs ");
+        System.out.println("\t\t\t start: start the endpoint with the --port and --service arguments");
+        System.out.println("\t\t\t stop: stop the endpoint with the --port and --service arguments");
+        System.out.println("\t\t\t restart: restart the endpoint with the --port and --service arguments");
+        
     }
     
     public void doManagement() {
         try {
             connectToMBserver();
-            if ("listall".equalsIgnoreCase(operationName)) {
+            if ("list".equalsIgnoreCase(operationName)) {
                 listAllManagedEndpoint();
+                return;
             }
             if ("start".equalsIgnoreCase(operationName)) {
                 startEndpoint();
+                return;
             }
             if ("stop".equalsIgnoreCase(operationName)) {
                 stopEndpoint();
+                return;
             }
             if ("restart".equalsIgnoreCase(operationName)) {
                 restartEndpoint();
-            }            
+                return;
+            } 
+            printUsage();           
         } catch (IOException e) {            
             LOG.log(Level.SEVERE, "FAIL_TO_CONNECT_TO_MBEAN_SERVER", new Object[]{jmxServerURL}); 
         } 
@@ -198,8 +232,12 @@
      */
     public static void main(String[] args) {
         ManagementConsole mc = new ManagementConsole();
-        mc.parserArguments(args);
-        mc.doManagement();
+        if (mc.parserArguments(args)) {
+            mc.doManagement();
+        } else {
+            printUsage();
+        }
+        
     }
    
 

Modified: incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/utils/Messages.properties
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/utils/Messages.properties?view=diff&rev=543443&r1=543442&r2=543443
==============================================================================
--- incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/utils/Messages.properties (original)
+++ incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/utils/Messages.properties Fri Jun  1 02:25:11 2007
@@ -19,6 +19,7 @@
 #
 #
 NO_MBEAN_SERVER = Can't find the MBeanServer, please Connect the MBeanServer first.
-FAIL_TO_CONNECT_TO_MBEAN_SERVER = Failed to connect to the MBeanServer with is url {0};
+FAIL_TO_CONNECT_TO_MBEAN_SERVER = Failed to connect to the MBeanServer with is url {0}
 FAIL_TO_LIST_ENDPOINTS = Failed to list the endpoints, the exception is {0}. 
+FAILT_TO_CREATE_ENDPOINT_OBEJCTNAME = Failed to create the endpoints objectname, error is {0}
 FAIL_TO_INVOKE_MANAGED_OBJECT_OPERTION = Failed to invoke the managed object {0}'s operation {1}, the exception is {2}.

Modified: incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/utils/ManagementConsoleTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/utils/ManagementConsoleTest.java?view=diff&rev=543443&r1=543442&r2=543443
==============================================================================
--- incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/utils/ManagementConsoleTest.java (original)
+++ incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/utils/ManagementConsoleTest.java Fri Jun  1 02:25:11 2007
@@ -27,16 +27,16 @@
     
     @Test
     public void paraserCommandTest() {
-        String[] listArgs = new String[] {"-operation", "listall"};
+        String[] listArgs = new String[] {"--operation", "list"};
         mc.parserArguments(listArgs);
-        assertEquals("It is not right operation name", "listall", mc.operationName);
+        assertEquals("It is not right operation name", "list", mc.operationName);
         assertEquals("The portName should be cleared", "", mc.portName);
-        String[] startArgs = new String[] {"-operation", "start", "-jmx", 
+        String[] startArgs = new String[] {"-o", "start", "--jmx", 
                                            "service:jmx:rmi:///jndi/rmi://localhost:1234/jmxrmi",
-                                           "-port", 
-                                           "\"{http://apache.org/hello_world_soap_http}SoapPort\"",
-                                           "-service",
-                                           "\"{http://apache.org/hello_world_soap_http}SOAPService\""};
+                                           "--service",
+                                           "\"{http://apache.org/hello_world_soap_http}SOAPService\"",
+                                           "--port", 
+                                           "\"{http://apache.org/hello_world_soap_http}SoapPort\""};
         mc.parserArguments(startArgs);
         assertEquals("It is not right operation name", "start", mc.operationName);
         assertEquals("It is not right port name", 
@@ -46,6 +46,10 @@
         assertEquals("It is not a jmx url",
                     "service:jmx:rmi:///jndi/rmi://localhost:1234/jmxrmi",
                     mc.jmxServerURL);
+        
+        String[] errorArgs = new String[] {"--op", "listAll"};
+        assertFalse("the arguments are wrong", mc.parserArguments(errorArgs));
+                
     }