Author: anierbeck
Date: Sat Jan 15 21:05:49 2011
New Revision: 1059412
URL: http://svn.apache.org/viewvc?rev=1059412&view=rev
Log:
[KARAF-211] - osgi:list to other command to display context-path for web
applications or a new war command for that web:list implementation
- The Web command does use the WebEvents of pax web instead of eventadmin
events.
Modified:
karaf/trunk/shell/web/pom.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/blueprint/shell-web.xml
Modified: karaf/trunk/shell/web/pom.xml
URL:
http://svn.apache.org/viewvc/karaf/trunk/shell/web/pom.xml?rev=1059412&r1=1059411&r2=1059412&view=diff
==============================================================================
--- karaf/trunk/shell/web/pom.xml (original)
+++ karaf/trunk/shell/web/pom.xml Sat Jan 15 21:05:49 2011
@@ -33,21 +33,11 @@
<scope>provided</scope>
</dependency>
<dependency>
- <groupId>org.springframework.osgi</groupId>
- <artifactId>spring-osgi-core</artifactId>
- <optional>true</optional>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-context</artifactId>
- <optional>true</optional>
- </dependency>
- <dependency>
- <groupId>org.springframework.osgi</groupId>
- <artifactId>spring-osgi-extender</artifactId>
- <optional>true</optional>
+ <groupId>org.ops4j.pax.web</groupId>
+ <artifactId>pax-web-spi</artifactId>
+ <scope>provided</scope>
</dependency>
- </dependencies>
+ </dependencies>
<build>
<plugins>
<plugin>
@@ -62,7 +52,6 @@
org.apache.felix.service.command,
org.apache.felix.gogo.commands,
org.apache.karaf.shell.console,
- org.springframework*;resolution:=optional,
*
</Import-Package>
<Private-Package>
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=1059412&r1=1059411&r2=1059412&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
Sat Jan 15 21:05:49 2011
@@ -19,30 +19,23 @@ package org.apache.karaf.shell.web;
import java.util.HashMap;
import java.util.Map;
-import org.osgi.service.event.Event;
-import org.osgi.service.event.EventHandler;
+import org.ops4j.pax.web.service.spi.WebEvent;
+import org.ops4j.pax.web.service.spi.WebListener;
/**
- * Class implementing {@link EventHandler} service to retrieve
"org/osgi/service/web/*" specific Events
+ * Class implementing {@link WebListener} service to retrieve {@link WebEvent}
*/
-public class WebEventHandler implements EventHandler {
+//public class WebEventHandler implements WebListener {
+public class WebEventHandler implements WebListener {
- private final Map<Long, String> bundleEvents = new HashMap<Long,
String>();
+ private final Map<Long, WebEvent> bundleEvents = new HashMap<Long,
WebEvent>();
- /* (non-Javadoc)
- * @see
org.osgi.service.event.EventHandler#handleEvent(org.osgi.service.event.Event)
- */
- public void handleEvent(Event event) {
- String topic = event.getTopic();
- Long bundleID = (Long) event.getProperty("bundle.id");
- getBundleEvents().put(bundleID, topic);
- }
-
- /**
- * @return the bundleEvents
- */
- public Map<Long, String> getBundleEvents() {
+ public Map<Long, WebEvent> getBundleEvents() {
return bundleEvents;
}
+
+ public void webEvent(WebEvent event) {
+ getBundleEvents().put(event.getBundle().getBundleId(), event);
+ }
}
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=1059412&r1=1059411&r2=1059412&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
Sat Jan 15 21:05:49 2011
@@ -20,6 +20,8 @@ import java.util.Map;
import org.apache.felix.gogo.commands.Command;
import org.apache.karaf.shell.console.OsgiCommandSupport;
+import org.ops4j.pax.web.service.spi.WebEvent;
+import org.ops4j.pax.web.service.spi.WebEvent.WebTopic;
import org.osgi.framework.Bundle;
import org.osgi.framework.Constants;
import org.osgi.service.startlevel.StartLevel;
@@ -37,12 +39,12 @@ public class WebListCommand extends Osgi
@Override
protected Object doExecute() {
Bundle[] bundles = getBundleContext().getBundles();
- Map<Long, String> bundleEvents = eventHandler.getBundleEvents();
+ Map<Long, WebEvent> bundleEvents =
eventHandler.getBundleEvents();
if (bundles != null) {
String level = (startLevelService == null) ? "" : "
Level ";
String webState = (bundleEvents == null ||
bundleEvents.isEmpty()) ? "" : " Web-State ";
String headers = " ID State ";
- headers += webState + level + " Web-ContextPath
Name";
+ headers += webState + level + " Web-ContextPath
Name";
System.out.println(headers);
for (int i = 0; i < bundles.length; i++) {
//First check if this bundle contains a webapp ctxt
@@ -119,23 +121,40 @@ public class WebListCommand extends Osgi
public String getWebStateString(Bundle bundle) {
long bundleId = bundle.getBundleId();
- Map<Long, String> bundleEvents = eventHandler.getBundleEvents();
+
+ Map<Long, WebEvent> bundleEvents = eventHandler.getBundleEvents();
+ String topic = "Unknown ";
+
if (bundleEvents.containsKey(bundleId)) {
- String topic = bundleEvents.get(bundleId);
- topic = topic.substring(21);
- if ("UNDEPLOYING".equalsIgnoreCase(topic))
- return "Undeploying ";
- else if ("DEPLOYING".equalsIgnoreCase(topic))
- return "Deploying ";
- else if ("DEPLOYED".equalsIgnoreCase(topic))
- return "Deployed ";
- else if ("FAILED".equalsIgnoreCase(topic))
- return "Failed ";
- else if ("UNDEPLOYED".equalsIgnoreCase(topic))
- return "Undeployed ";
- }
+ WebEvent webEvent = bundleEvents.get(bundleId);
+
+ switch(webEvent.getType()) {
+ case WebEvent.DEPLOYING:
+ topic = "Deploying ";
+ break;
+ case WebEvent.DEPLOYED:
+ topic = "Deployed ";
+ break;
+ case WebEvent.UNDEPLOYING:
+ topic = "Undeploying";
+ break;
+ case WebEvent.UNDEPLOYED:
+ topic = "Undeployed ";
+ break;
+ case WebEvent.FAILED:
+ topic = "Unknown ";
+ topic = "Failed ";
+ break;
+ default:
+ topic = "Failed ";
+ }
+ }
+
+ while (topic.length() < 11) {
+ topic += " ";
+ }
- return "Unknown ";
+ return topic;
}
/**
Modified:
karaf/trunk/shell/web/src/main/resources/OSGI-INF/blueprint/shell-web.xml
URL:
http://svn.apache.org/viewvc/karaf/trunk/shell/web/src/main/resources/OSGI-INF/blueprint/shell-web.xml?rev=1059412&r1=1059411&r2=1059412&view=diff
==============================================================================
--- karaf/trunk/shell/web/src/main/resources/OSGI-INF/blueprint/shell-web.xml
(original)
+++ karaf/trunk/shell/web/src/main/resources/OSGI-INF/blueprint/shell-web.xml
Sat Jan 15 21:05:49 2011
@@ -22,8 +22,11 @@
<reference id="slService"
interface="org.osgi.service.startlevel.StartLevel" availability="optional" />
<bean id="eaHandler" class="org.apache.karaf.shell.web.WebEventHandler"
/>
-
- <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.0.0">
+ <service id="webListener"
+ interface="org.ops4j.pax.web.service.spi.WebListener"
+ ref="eaHandler" />
+
+ <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.0.0">
<command name="web/list">
<action class="org.apache.karaf.shell.web.WebListCommand">
<property name="startLevelService" ref="slService" />
@@ -32,13 +35,4 @@
</command>
</command-bundle>
- <!-- right not blueprint dosn't take account of start level so it
might happen after a restart that this
- handler doesn't get all events :( -->
- <service id="eaHandlerSrvc"
interface="org.osgi.service.event.EventHandler" ref="eaHandler">
- <service-properties>
- <entry key="event.topics"
value="org/osgi/service/web/*"/>
- </service-properties>
- </service>
-
-
</blueprint>
\ No newline at end of file