karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anierb...@apache.org
Subject svn commit: r1099271 - in /karaf/trunk/shell: http/ http/src/main/java/org/apache/karaf/shell/http/ http/src/main/resources/OSGI-INF/ http/src/main/resources/OSGI-INF/blueprint/ web/src/main/java/org/apache/karaf/shell/web/ web/src/main/resources/OSGI-...
Date Tue, 03 May 2011 21:35:29 GMT
Author: anierbeck
Date: Tue May  3 21:35:29 2011
New Revision: 1099271

URL: http://svn.apache.org/viewvc?rev=1099271&view=rev
Log:
[KARAF-572] - Command to show all registered servlets and their contexts
- together with minor refactoring on web command (codecleanup)

Added:
    karaf/trunk/shell/http/src/main/java/org/apache/karaf/shell/http/CommandUtils.java   (with
props)
    karaf/trunk/shell/http/src/main/resources/OSGI-INF/bundle.info
    karaf/trunk/shell/web/src/main/java/org/apache/karaf/shell/web/CommandUtils.java   (with
props)
Modified:
    karaf/trunk/shell/http/pom.xml
    karaf/trunk/shell/http/src/main/java/org/apache/karaf/shell/http/ServletEventHandler.java
    karaf/trunk/shell/http/src/main/java/org/apache/karaf/shell/http/ServletListCommand.java
    karaf/trunk/shell/http/src/main/resources/OSGI-INF/blueprint/shell-http.xml
    karaf/trunk/shell/web/src/main/java/org/apache/karaf/shell/web/WebEventHandler.java
    karaf/trunk/shell/web/src/main/java/org/apache/karaf/shell/web/WebListCommand.java
    karaf/trunk/shell/web/src/main/resources/OSGI-INF/bundle.info

Modified: karaf/trunk/shell/http/pom.xml
URL: http://svn.apache.org/viewvc/karaf/trunk/shell/http/pom.xml?rev=1099271&r1=1099270&r2=1099271&view=diff
==============================================================================
--- karaf/trunk/shell/http/pom.xml (original)
+++ karaf/trunk/shell/http/pom.xml Tue May  3 21:35:29 2011
@@ -1,11 +1,32 @@
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+    <!--
+
+        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.
+    -->
+
 	<modelVersion>4.0.0</modelVersion>
+
 	<parent>
 		<artifactId>shell</artifactId>
 		<groupId>org.apache.karaf.shell</groupId>
 		<version>3.0.0-SNAPSHOT</version>
 	</parent>
+
 	<groupId>org.apache.karaf.shell</groupId>
 	<artifactId>org.apache.karaf.shell.http</artifactId>
 	<packaging>bundle</packaging>
@@ -22,7 +43,7 @@
 			<groupId>org.apache.karaf.shell</groupId>
 			<artifactId>org.apache.karaf.shell.console</artifactId>
 		</dependency>
-
+		
 		<dependency>
 			<groupId>org.osgi</groupId>
 			<artifactId>org.osgi.core</artifactId>
@@ -36,11 +57,11 @@
 		<dependency>
 			<groupId>org.ops4j.pax.web</groupId>
 			<artifactId>pax-web-spi</artifactId>
+			<scope>provided</scope>
 		</dependency>
 		<dependency>
 			<groupId>javax.servlet</groupId>
 			<artifactId>servlet-api</artifactId>
-			<version>2.5</version>
 			<scope>provided</scope>
 		</dependency>
 	</dependencies>

Added: karaf/trunk/shell/http/src/main/java/org/apache/karaf/shell/http/CommandUtils.java
URL: http://svn.apache.org/viewvc/karaf/trunk/shell/http/src/main/java/org/apache/karaf/shell/http/CommandUtils.java?rev=1099271&view=auto
==============================================================================
--- karaf/trunk/shell/http/src/main/java/org/apache/karaf/shell/http/CommandUtils.java (added)
+++ karaf/trunk/shell/http/src/main/java/org/apache/karaf/shell/http/CommandUtils.java Tue
May  3 21:35:29 2011
@@ -0,0 +1,46 @@
+/* 
+ * 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.
+ */
+
+package org.apache.karaf.shell.http;
+
+/**
+ * Contains various methods for helping with layout no commands
+ * 
+ * @author anierbeck
+ *
+ */
+public class CommandUtils {
+
+	/**
+	 * The message is either enlarged or trimmed to the given size. 
+	 * 
+	 * @param message - the message to be trimmed or enlarged
+	 * @param length - the length of the message text
+	 * @return the optimized message
+	 */
+	public static String trimToSize(String message, int length) {
+		while (message.length() < length) {
+			message += " ";
+		} 
+		if (message.length() > length) {
+			message = message.substring(0, length);
+		}
+		
+		return message;
+	}
+	
+}

Propchange: karaf/trunk/shell/http/src/main/java/org/apache/karaf/shell/http/CommandUtils.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: karaf/trunk/shell/http/src/main/java/org/apache/karaf/shell/http/ServletEventHandler.java
URL: http://svn.apache.org/viewvc/karaf/trunk/shell/http/src/main/java/org/apache/karaf/shell/http/ServletEventHandler.java?rev=1099271&r1=1099270&r2=1099271&view=diff
==============================================================================
--- karaf/trunk/shell/http/src/main/java/org/apache/karaf/shell/http/ServletEventHandler.java
(original)
+++ karaf/trunk/shell/http/src/main/java/org/apache/karaf/shell/http/ServletEventHandler.java
Tue May  3 21:35:29 2011
@@ -1,16 +1,16 @@
-/* Copyright 2011 Achim.
+/* 
+ * 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
  *
- * Licensed 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
+ *      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.
- *
+ * 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.
  */
@@ -25,10 +25,6 @@ import org.ops4j.pax.web.service.spi.Ser
 import org.ops4j.pax.web.service.spi.ServletListener;
 import org.osgi.framework.Bundle;
 
-/**
- * @author Achim
- *
- */
 public class ServletEventHandler implements ServletListener {
 
 	Map<Bundle, ServletEvent> servletEvents =  new HashMap<Bundle, ServletEvent>();

Modified: karaf/trunk/shell/http/src/main/java/org/apache/karaf/shell/http/ServletListCommand.java
URL: http://svn.apache.org/viewvc/karaf/trunk/shell/http/src/main/java/org/apache/karaf/shell/http/ServletListCommand.java?rev=1099271&r1=1099270&r2=1099271&view=diff
==============================================================================
--- karaf/trunk/shell/http/src/main/java/org/apache/karaf/shell/http/ServletListCommand.java
(original)
+++ karaf/trunk/shell/http/src/main/java/org/apache/karaf/shell/http/ServletListCommand.java
Tue May  3 21:35:29 2011
@@ -1,16 +1,16 @@
-/* Copyright 2011 Achim.
+/* 
+ * 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
  *
- * Licensed 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
+ *      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.
- *
+ * 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.
  */
@@ -27,7 +27,7 @@ import org.ops4j.pax.web.service.spi.Ser
 import org.ops4j.pax.web.service.spi.WebEvent;
 
 
-@Command(scope = "web", name = "list", description = "Lists details for war bundles.")
+@Command(scope = "http", name = "list", description = "Lists details for servlets.")
 public class ServletListCommand extends OsgiCommandSupport {
 
 	private ServletEventHandler eventHandler;
@@ -39,29 +39,23 @@ public class ServletListCommand extends 
 		System.out.println(headers);
 		for (ServletEvent event : eventHandler.getServletEvents()) {
 			Servlet servlet = event.getServlet();
-			String servletClassName = "";
+			String servletClassName = " ";
 			if (servlet != null) {
 				servletClassName = servlet.getClass().getName();
 				servletClassName = servletClassName.substring(servletClassName.lastIndexOf(".")+1, servletClassName.length());
-				while (servletClassName.length() < 28) {
-					servletClassName += " ";
-				}
-			} else { 
-				servletClassName = "                            ";
-			}
-			String servletName = event.getServletName() != null ? event.getServletName() : "     
                ";
+			} 
+			servletClassName = CommandUtils.trimToSize(servletClassName, 28);
+			String servletName = event.getServletName() != null ? event.getServletName() : " ";
 			if (servletName.contains(".")) {
 				servletName = servletName.substring(servletName.lastIndexOf(".")+1, servletName.length());
 			}
 			
-			while (servletName.length() < 23) {
-				servletName += " ";
-			}
+			servletName = CommandUtils.trimToSize(servletName, 23);
+			
+			String alias = event.getAlias() != null ? event.getAlias() : " ";
+			
+			alias = CommandUtils.trimToSize(alias, 16);
 			
-			String alias = event.getAlias() != null ? event.getAlias() : "                ";
-			while (alias.length() < 16 ) {
-				alias += " ";
-			}
 			String[] urls = (String[]) (event.getUrlParameter() != null ? event.getUrlParameter()
: new String[] {""});
 			String line = "[" + event.getBundle().getBundleId() + "] [" + servletClassName + "] ["
+ servletName +"] [" 
 			+ getStateString(event.getType())+ "] [" + alias + "] [" + Arrays.toString(urls) + "]";

Modified: karaf/trunk/shell/http/src/main/resources/OSGI-INF/blueprint/shell-http.xml
URL: http://svn.apache.org/viewvc/karaf/trunk/shell/http/src/main/resources/OSGI-INF/blueprint/shell-http.xml?rev=1099271&r1=1099270&r2=1099271&view=diff
==============================================================================
--- karaf/trunk/shell/http/src/main/resources/OSGI-INF/blueprint/shell-http.xml (original)
+++ karaf/trunk/shell/http/src/main/resources/OSGI-INF/blueprint/shell-http.xml Tue May  3
21:35:29 2011
@@ -26,7 +26,7 @@
 		ref="eaHandler" />
 
 	<command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.0.0">
-        <command name="http/list-servlet">
+        <command name="http/list">
             <action class="org.apache.karaf.shell.http.ServletListCommand">
             	<property name="eventHandler" ref="eaHandler" />
             </action>

Added: karaf/trunk/shell/http/src/main/resources/OSGI-INF/bundle.info
URL: http://svn.apache.org/viewvc/karaf/trunk/shell/http/src/main/resources/OSGI-INF/bundle.info?rev=1099271&view=auto
==============================================================================
--- karaf/trunk/shell/http/src/main/resources/OSGI-INF/bundle.info (added)
+++ karaf/trunk/shell/http/src/main/resources/OSGI-INF/bundle.info Tue May  3 21:35:29 2011
@@ -0,0 +1,13 @@
+\u001B[1mSYNOPSIS\u001B[0m
+    ${project.name}
+
+    ${project.description}
+
+    Maven URL:
+        \u001B[33mmvn:${project.groupId}/${project.artifactId}/${project.version}\u001B[0m
+
+\u001B[1mDESCRIPTION\u001B[0m
+    This bundle provides Karaf shell commands to interact with http servlets.
+
+    The following commands are available:
+    \u001B[36mhttp:list\u001B[0m Lists details for servlets.

Added: karaf/trunk/shell/web/src/main/java/org/apache/karaf/shell/web/CommandUtils.java
URL: http://svn.apache.org/viewvc/karaf/trunk/shell/web/src/main/java/org/apache/karaf/shell/web/CommandUtils.java?rev=1099271&view=auto
==============================================================================
--- karaf/trunk/shell/web/src/main/java/org/apache/karaf/shell/web/CommandUtils.java (added)
+++ karaf/trunk/shell/web/src/main/java/org/apache/karaf/shell/web/CommandUtils.java Tue May
 3 21:35:29 2011
@@ -0,0 +1,46 @@
+/* 
+ * 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.
+ */
+
+package org.apache.karaf.shell.web;
+
+/**
+ * Contains various methods for helping with layout no commands
+ * 
+ * @author anierbeck
+ *
+ */
+public class CommandUtils {
+
+	/**
+	 * The message is either enlarged or trimmed to the given size. 
+	 * 
+	 * @param message - the message to be trimmed or enlarged
+	 * @param length - the length of the message text
+	 * @return the optimized message
+	 */
+	public static String trimToSize(String message, int length) {
+		while (message.length() < length) {
+			message += " ";
+		} 
+		if (message.length() > length) {
+			message = message.substring(0, length);
+		}
+		
+		return message;
+	}
+	
+}

Propchange: karaf/trunk/shell/web/src/main/java/org/apache/karaf/shell/web/CommandUtils.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: karaf/trunk/shell/web/src/main/java/org/apache/karaf/shell/web/WebEventHandler.java
URL: http://svn.apache.org/viewvc/karaf/trunk/shell/web/src/main/java/org/apache/karaf/shell/web/WebEventHandler.java?rev=1099271&r1=1099270&r2=1099271&view=diff
==============================================================================
--- karaf/trunk/shell/web/src/main/java/org/apache/karaf/shell/web/WebEventHandler.java (original)
+++ karaf/trunk/shell/web/src/main/java/org/apache/karaf/shell/web/WebEventHandler.java Tue
May  3 21:35:29 2011
@@ -25,7 +25,6 @@ import org.ops4j.pax.web.service.spi.Web
 /**
  * Class implementing {@link WebListener} service to retrieve {@link WebEvent}
  */
-//public class WebEventHandler implements WebListener {
 public class WebEventHandler implements WebListener {
 	
 	private final Map<Long, WebEvent> bundleEvents = new HashMap<Long, WebEvent>();

Modified: karaf/trunk/shell/web/src/main/java/org/apache/karaf/shell/web/WebListCommand.java
URL: http://svn.apache.org/viewvc/karaf/trunk/shell/web/src/main/java/org/apache/karaf/shell/web/WebListCommand.java?rev=1099271&r1=1099270&r2=1099271&view=diff
==============================================================================
--- karaf/trunk/shell/web/src/main/java/org/apache/karaf/shell/web/WebListCommand.java (original)
+++ karaf/trunk/shell/web/src/main/java/org/apache/karaf/shell/web/WebListCommand.java Tue
May  3 21:35:29 2011
@@ -72,21 +72,15 @@ public class WebListCommand extends Osgi
                 }
                 else {
                     level = String.valueOf(startLevelService.getBundleStartLevel(bundles[i]));
-                }
-                while (level.length() < 5) {
-                    level = " " + level;
-                }
-                while (id.length() < 4) {
-                    id = " " + id;
-                }
+                } 
+                level = CommandUtils.trimToSize(level, 5);
+                id = CommandUtils.trimToSize(id, 4);
                 
                 //prepend ctxt with slash (looks better)
                 if (!webappctxt.startsWith("/"))
                 	webappctxt = "/" + webappctxt;
                 
-                while (webappctxt.length() < 24) {
-                	webappctxt += " ";
-                }
+                webappctxt = CommandUtils.trimToSize(webappctxt, 24);
                 
                 String line = "[" + id + "] [" + getStateString(bundles[i]) + "]";
                 if (bundleEvents != null && !bundleEvents.isEmpty())

Modified: karaf/trunk/shell/web/src/main/resources/OSGI-INF/bundle.info
URL: http://svn.apache.org/viewvc/karaf/trunk/shell/web/src/main/resources/OSGI-INF/bundle.info?rev=1099271&r1=1099270&r2=1099271&view=diff
==============================================================================
--- karaf/trunk/shell/web/src/main/resources/OSGI-INF/bundle.info (original)
+++ karaf/trunk/shell/web/src/main/resources/OSGI-INF/bundle.info Tue May  3 21:35:29 2011
@@ -11,6 +11,5 @@
 
     The following commands are available:
     \u001B[36mweb:list\u001B[0m Lists details for war bundles.
-
-\u001B[1mSEE ALSO\u001B[0m
-    \u001B[36mDeployer\u001B[0m section of the Karaf User Guide.
\ No newline at end of file
+    \u001B[36mweb:deploy\u001B[0m Deploys content of a war bundle.
+    \u001B[36mweb:undeploy\u001B[0m Un-deploys content of a war bundles.



Mime
View raw message