You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by an...@apache.org on 2011/05/03 00:16:25 UTC
svn commit: r1098814 - in /karaf/trunk:
assemblies/features/standard/src/main/feature/ shell/http/ shell/http/src/
shell/http/src/main/ shell/http/src/main/java/
shell/http/src/main/java/org/ shell/http/src/main/java/org/apache/
shell/http/src/main/jav...
Author: anierbeck
Date: Mon May 2 22:16:24 2011
New Revision: 1098814
URL: http://svn.apache.org/viewvc?rev=1098814&view=rev
Log:
[KARAF-572] - Command to show all registered servlets and their contexts
Added:
karaf/trunk/shell/http/
karaf/trunk/shell/http/pom.xml (with props)
karaf/trunk/shell/http/src/
karaf/trunk/shell/http/src/main/
karaf/trunk/shell/http/src/main/java/
karaf/trunk/shell/http/src/main/java/org/
karaf/trunk/shell/http/src/main/java/org/apache/
karaf/trunk/shell/http/src/main/java/org/apache/karaf/
karaf/trunk/shell/http/src/main/java/org/apache/karaf/shell/
karaf/trunk/shell/http/src/main/java/org/apache/karaf/shell/http/
karaf/trunk/shell/http/src/main/java/org/apache/karaf/shell/http/ServletEventHandler.java (with props)
karaf/trunk/shell/http/src/main/java/org/apache/karaf/shell/http/ServletListCommand.java (with props)
karaf/trunk/shell/http/src/main/resources/
karaf/trunk/shell/http/src/main/resources/OSGI-INF/
karaf/trunk/shell/http/src/main/resources/OSGI-INF/blueprint/
karaf/trunk/shell/http/src/main/resources/OSGI-INF/blueprint/shell-http.xml (with props)
Modified:
karaf/trunk/assemblies/features/standard/src/main/feature/feature.xml
Modified: karaf/trunk/assemblies/features/standard/src/main/feature/feature.xml
URL: http://svn.apache.org/viewvc/karaf/trunk/assemblies/features/standard/src/main/feature/feature.xml?rev=1098814&r1=1098813&r2=1098814&view=diff
==============================================================================
--- karaf/trunk/assemblies/features/standard/src/main/feature/feature.xml (original)
+++ karaf/trunk/assemblies/features/standard/src/main/feature/feature.xml Mon May 2 22:16:24 2011
@@ -108,6 +108,7 @@
<bundle>mvn:org.ops4j.pax.web/pax-web-spi/${pax.web.version}</bundle>
<bundle>mvn:org.ops4j.pax.web/pax-web-runtime/${pax.web.version}</bundle>
<bundle>mvn:org.ops4j.pax.web/pax-web-jetty/${pax.web.version}</bundle>
+ <bundle start-level="30">mvn:org.apache.karaf.shell/org.apache.karaf.shell.http/${project.version}</bundle>
</feature>
<feature name="http-whiteboard" version="${project.version}" resolver="(obr)" start-level='30'>
<feature>http</feature>
Added: karaf/trunk/shell/http/pom.xml
URL: http://svn.apache.org/viewvc/karaf/trunk/shell/http/pom.xml?rev=1098814&view=auto
==============================================================================
--- karaf/trunk/shell/http/pom.xml (added)
+++ karaf/trunk/shell/http/pom.xml Mon May 2 22:16:24 2011
@@ -0,0 +1,91 @@
+<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">
+ <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>
+ <name>Apache Karaf :: Shell :: Http Commands</name>
+ <version>3.0.0-SNAPSHOT</version>
+ <description>This bundle provides Karaf shell commands to list details of the http service.</description>
+
+ <properties>
+ <appendedResourcesDirectory>${basedir}/../../etc/appended-resources</appendedResourcesDirectory>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.karaf.shell</groupId>
+ <artifactId>org.apache.karaf.shell.console</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.utils</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.ops4j.pax.web</groupId>
+ <artifactId>pax-web-spi</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.5</version>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <resources>
+ <resource>
+ <directory>${project.basedir}/src/main/resources</directory>
+ <includes>
+ <include>**/*</include>
+ </includes>
+ </resource>
+ <resource>
+ <directory>${project.basedir}/src/main/resources</directory>
+ <filtering>true</filtering>
+ <includes>
+ <include>**/*.info</include>
+ </includes>
+ </resource>
+ </resources>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <configuration>
+ <instructions>
+ <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
+ <Export-Package>${project.artifactId}*;version=${project.version}</Export-Package>
+ <Import-Package>
+ !${project.artifactId}*,
+ org.apache.felix.service.command,
+ org.apache.felix.gogo.commands,
+ org.apache.karaf.shell.console,
+ *
+ </Import-Package>
+ <Private-Package>
+ org.apache.felix.utils.version,
+ org.apache.felix.utils.manifest,
+ !*
+ </Private-Package>
+ <_versionpolicy>${bnd.version.policy}</_versionpolicy>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
\ No newline at end of file
Propchange: karaf/trunk/shell/http/pom.xml
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: 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=1098814&view=auto
==============================================================================
--- karaf/trunk/shell/http/src/main/java/org/apache/karaf/shell/http/ServletEventHandler.java (added)
+++ karaf/trunk/shell/http/src/main/java/org/apache/karaf/shell/http/ServletEventHandler.java Mon May 2 22:16:24 2011
@@ -0,0 +1,47 @@
+/* Copyright 2011 Achim.
+ *
+ * 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
+ *
+ * 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;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.ops4j.pax.web.service.spi.ServletEvent;
+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>();
+
+ public void servletEvent(ServletEvent event) {
+ servletEvents.put(event.getBundle(), event);
+ }
+
+ /**
+ * @return the servletEvents
+ */
+ public Collection<ServletEvent> getServletEvents() {
+ return servletEvents.values();
+ }
+
+}
Propchange: karaf/trunk/shell/http/src/main/java/org/apache/karaf/shell/http/ServletEventHandler.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: 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=1098814&view=auto
==============================================================================
--- karaf/trunk/shell/http/src/main/java/org/apache/karaf/shell/http/ServletListCommand.java (added)
+++ karaf/trunk/shell/http/src/main/java/org/apache/karaf/shell/http/ServletListCommand.java Mon May 2 22:16:24 2011
@@ -0,0 +1,107 @@
+/* Copyright 2011 Achim.
+ *
+ * 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
+ *
+ * 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;
+
+import java.util.Arrays;
+
+import javax.servlet.Servlet;
+
+import org.apache.felix.gogo.commands.Command;
+import org.apache.karaf.shell.console.OsgiCommandSupport;
+import org.ops4j.pax.web.service.spi.ServletEvent;
+import org.ops4j.pax.web.service.spi.WebEvent;
+
+
+@Command(scope = "web", name = "list", description = "Lists details for war bundles.")
+public class ServletListCommand extends OsgiCommandSupport {
+
+ private ServletEventHandler eventHandler;
+
+ @Override
+ protected Object doExecute() throws Exception {
+
+ String headers = " ID Servlet Servlet-Name State Alias Url ";
+ System.out.println(headers);
+ for (ServletEvent event : eventHandler.getServletEvents()) {
+ Servlet servlet = event.getServlet();
+ 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() : " ";
+ if (servletName.contains(".")) {
+ servletName = servletName.substring(servletName.lastIndexOf(".")+1, servletName.length());
+ }
+
+ while (servletName.length() < 23) {
+ servletName += " ";
+ }
+
+ 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) + "]";
+ System.out.println(line);
+ }
+ return null;
+ }
+
+ public String getStateString(int type)
+ {
+ switch(type) {
+ case WebEvent.DEPLOYING:
+ return "Deploying ";
+ case WebEvent.DEPLOYED:
+ return "Deployed ";
+ case WebEvent.UNDEPLOYING:
+ return "Undeploying";
+ case WebEvent.UNDEPLOYED:
+ return "Undeployed ";
+ case WebEvent.FAILED:
+ return "Failed ";
+ case WebEvent.WAITING:
+ return "Waiting ";
+ default:
+ return "Failed ";
+ }
+ }
+
+ /**
+ * @return the eventHandler
+ */
+ public ServletEventHandler getEventHandler() {
+ return eventHandler;
+ }
+
+ /**
+ * @param eventHandler the eventHandler to set
+ */
+ public void setEventHandler(ServletEventHandler eventHandler) {
+ this.eventHandler = eventHandler;
+ }
+
+}
Propchange: karaf/trunk/shell/http/src/main/java/org/apache/karaf/shell/http/ServletListCommand.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: 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=1098814&view=auto
==============================================================================
--- karaf/trunk/shell/http/src/main/resources/OSGI-INF/blueprint/shell-http.xml (added)
+++ karaf/trunk/shell/http/src/main/resources/OSGI-INF/blueprint/shell-http.xml Mon May 2 22:16:24 2011
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" default-activation="lazy">
+
+ <bean id="eaHandler" class="org.apache.karaf.shell.http.ServletEventHandler" />
+
+ <service id="servletListener"
+ interface="org.ops4j.pax.web.service.spi.ServletListener"
+ ref="eaHandler" />
+
+ <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.0.0">
+ <command name="http/list-servlet">
+ <action class="org.apache.karaf.shell.http.ServletListCommand">
+ <property name="eventHandler" ref="eaHandler" />
+ </action>
+ </command>
+ </command-bundle>
+
+</blueprint>
\ No newline at end of file
Propchange: karaf/trunk/shell/http/src/main/resources/OSGI-INF/blueprint/shell-http.xml
------------------------------------------------------------------------------
svn:mime-type = text/plain