You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by mu...@apache.org on 2009/04/08 15:01:34 UTC
svn commit: r763231 - in /struts/sandbox/trunk/struts2-osgi-plugin: ./
admin-bundle/ admin-bundle/src/main/java/org/apache/struts2/osgi/admin/
admin-bundle/src/main/java/org/apache/struts2/osgi/admin/actions/
admin-bundle/src/main/resources/ admin-bund...
Author: musachy
Date: Wed Apr 8 13:01:33 2009
New Revision: 763231
URL: http://svn.apache.org/viewvc?rev=763231&view=rev
Log:
Add demo bundle (Convention + FreeMarker + Velocity + Spring). Fix several bugs in OSGi plugin
Added:
struts/sandbox/trunk/struts2-osgi-plugin/demo-bundle/
struts/sandbox/trunk/struts2-osgi-plugin/demo-bundle/pom.xml
struts/sandbox/trunk/struts2-osgi-plugin/demo-bundle/src/
struts/sandbox/trunk/struts2-osgi-plugin/demo-bundle/src/main/
struts/sandbox/trunk/struts2-osgi-plugin/demo-bundle/src/main/java/
struts/sandbox/trunk/struts2-osgi-plugin/demo-bundle/src/main/java/actions/
struts/sandbox/trunk/struts2-osgi-plugin/demo-bundle/src/main/java/actions/osgi/
struts/sandbox/trunk/struts2-osgi-plugin/demo-bundle/src/main/java/actions/osgi/HelloWorldAction.java
struts/sandbox/trunk/struts2-osgi-plugin/demo-bundle/src/main/java/actions/osgi/Message.java
struts/sandbox/trunk/struts2-osgi-plugin/demo-bundle/src/main/resources/
struts/sandbox/trunk/struts2-osgi-plugin/demo-bundle/src/main/resources/META-INF/
struts/sandbox/trunk/struts2-osgi-plugin/demo-bundle/src/main/resources/META-INF/spring/
struts/sandbox/trunk/struts2-osgi-plugin/demo-bundle/src/main/resources/META-INF/spring/applicationContext.xml
struts/sandbox/trunk/struts2-osgi-plugin/demo-bundle/src/main/resources/content/
struts/sandbox/trunk/struts2-osgi-plugin/demo-bundle/src/main/resources/content/osgi/
struts/sandbox/trunk/struts2-osgi-plugin/demo-bundle/src/main/resources/content/osgi/hello-convention.ftl
struts/sandbox/trunk/struts2-osgi-plugin/demo-bundle/src/main/resources/content/osgi/hello.ftl
struts/sandbox/trunk/struts2-osgi-plugin/demo-bundle/src/main/resources/content/osgi/hello.vm
struts/sandbox/trunk/struts2-osgi-plugin/demo-bundle/src/main/resources/content/osgi/home.ftl
struts/sandbox/trunk/struts2-osgi-plugin/demo-bundle/src/main/resources/struts.xml
Removed:
struts/sandbox/trunk/struts2-osgi-plugin/admin-bundle/src/main/java/org/apache/struts2/osgi/admin/MyBundleActivator.java
struts/sandbox/trunk/struts2-osgi-plugin/admin-bundle/src/main/resources/META-INF/
Modified:
struts/sandbox/trunk/struts2-osgi-plugin/admin-bundle/ (props changed)
struts/sandbox/trunk/struts2-osgi-plugin/admin-bundle/pom.xml
struts/sandbox/trunk/struts2-osgi-plugin/admin-bundle/src/main/java/org/apache/struts2/osgi/admin/actions/BundlesAction.java
struts/sandbox/trunk/struts2-osgi-plugin/admin-bundle/src/main/java/org/apache/struts2/osgi/admin/actions/ShellAction.java
struts/sandbox/trunk/struts2-osgi-plugin/admin-bundle/src/main/resources/struts.xml
struts/sandbox/trunk/struts2-osgi-plugin/plugin/src/main/java/org/apache/struts2/osgi/BundleAccessor.java
struts/sandbox/trunk/struts2-osgi-plugin/plugin/src/main/java/org/apache/struts2/osgi/DefaultBundleAccessor.java
struts/sandbox/trunk/struts2-osgi-plugin/plugin/src/main/java/org/apache/struts2/osgi/DelegatingObjectFactory.java
struts/sandbox/trunk/struts2-osgi-plugin/plugin/src/main/java/org/apache/struts2/osgi/OsgiConfigurationProvider.java
struts/sandbox/trunk/struts2-osgi-plugin/plugin/src/main/java/org/apache/struts2/osgi/SpringOsgiObjectFactory.java
struts/sandbox/trunk/struts2-osgi-plugin/plugin/src/main/java/org/apache/struts2/osgi/loaders/StaticContentBundleResourceLoader.java
struts/sandbox/trunk/struts2-osgi-plugin/pom.xml
Propchange: struts/sandbox/trunk/struts2-osgi-plugin/admin-bundle/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Wed Apr 8 13:01:33 2009
@@ -0,0 +1 @@
+target
Modified: struts/sandbox/trunk/struts2-osgi-plugin/admin-bundle/pom.xml
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-osgi-plugin/admin-bundle/pom.xml?rev=763231&r1=763230&r2=763231&view=diff
==============================================================================
--- struts/sandbox/trunk/struts2-osgi-plugin/admin-bundle/pom.xml (original)
+++ struts/sandbox/trunk/struts2-osgi-plugin/admin-bundle/pom.xml Wed Apr 8 13:01:33 2009
@@ -1,79 +1,68 @@
<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <groupId>org.apache.struts.osgi</groupId>
- <artifactId>struts2-admin-bundle</artifactId>
- <version>1.0-SNAPSHOT</version>
- <packaging>jar</packaging>
- <name>Struts 2 OSGi Admin Bundle</name>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.struts.osgi</groupId>
+ <artifactId>struts2-admin-bundle</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <packaging>bundle</packaging>
+ <name>Struts 2 OSGi Admin Bundle</name>
- <dependencies>
- <dependency>
- <groupId>org.apache.struts</groupId>
- <artifactId>struts2-osgi-plugin</artifactId>
- <version>1.0.0-SNAPSHOT</version>
- </dependency>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.struts</groupId>
+ <artifactId>struts2-osgi-plugin</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
<version>3.8.1</version>
</dependency>
+ </dependencies>
-
- </dependencies>
-
- <properties>
- <jdkLevel>1.5</jdkLevel>
- </properties>
+ <properties>
+ <jdkLevel>1.5</jdkLevel>
+ </properties>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-jar-plugin</artifactId>
- <configuration>
- <archive>
- <manifestFile>
- src/main/resources/META-INF/MANIFEST.MF
- </manifestFile>
- </archive>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-bundle-plugin</artifactId>
- <extensions>true</extensions>
- <version>1.4.0</version>
- <configuration>
- <instructions>
- <manifestLocation>META-INF</manifestLocation>
- <Export-Package>
- org.apache.struts2.osgi.admin*
- </Export-Package>
- <Import-Package>
- com.opensymphony.xwork2,
- *
- </Import-Package>
- <Bundle-Activator>
- org.apache.struts2.osgi.admin.MyBundleActivator
- </Bundle-Activator>
- </instructions>
- </configuration>
- </plugin>
- </plugins>
- <pluginManagement>
- <plugins>
- <plugin>
- <artifactId>maven-compiler-plugin</artifactId>
- <configuration>
- <source>1.5</source>
- <target>1.5</target>
- </configuration>
- </plugin>
- </plugins>
- </pluginManagement>
- </build>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <version>2.0.0</version>
+ <configuration>
+ <instructions>
+ <manifestLocation>META-INF</manifestLocation>
+ <Import-Package>
+ *,com.opensymphony.xwork2
+ </Import-Package>
+ <Export-Package>
+ org.apache.struts2.osgi.admin*
+ </Export-Package>
+ <Bundle-Activator>
+ org.apache.struts2.osgi.StrutsActivator
+ </Bundle-Activator>
+ <Spring-Context>
+ *;create-asynchronously:=false
+ </Spring-Context>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
</project>
Modified: struts/sandbox/trunk/struts2-osgi-plugin/admin-bundle/src/main/java/org/apache/struts2/osgi/admin/actions/BundlesAction.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-osgi-plugin/admin-bundle/src/main/java/org/apache/struts2/osgi/admin/actions/BundlesAction.java?rev=763231&r1=763230&r2=763231&view=diff
==============================================================================
--- struts/sandbox/trunk/struts2-osgi-plugin/admin-bundle/src/main/java/org/apache/struts2/osgi/admin/actions/BundlesAction.java (original)
+++ struts/sandbox/trunk/struts2-osgi-plugin/admin-bundle/src/main/java/org/apache/struts2/osgi/admin/actions/BundlesAction.java Wed Apr 8 13:01:33 2009
@@ -1,15 +1,18 @@
package org.apache.struts2.osgi.admin.actions;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+
import org.apache.struts2.dispatcher.DefaultActionSupport;
import org.apache.struts2.osgi.BundleAccessor;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;
-import com.opensymphony.xwork2.inject.Inject;
-import com.opensymphony.xwork2.config.entities.PackageConfig;
-import com.opensymphony.xwork2.config.Configuration;
-import java.util.*;
-import java.lang.reflect.Array;
+import com.opensymphony.xwork2.config.Configuration;
+import com.opensymphony.xwork2.config.entities.PackageConfig;
+import com.opensymphony.xwork2.inject.Inject;
public class BundlesAction extends DefaultActionSupport {
Modified: struts/sandbox/trunk/struts2-osgi-plugin/admin-bundle/src/main/java/org/apache/struts2/osgi/admin/actions/ShellAction.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-osgi-plugin/admin-bundle/src/main/java/org/apache/struts2/osgi/admin/actions/ShellAction.java?rev=763231&r1=763230&r2=763231&view=diff
==============================================================================
--- struts/sandbox/trunk/struts2-osgi-plugin/admin-bundle/src/main/java/org/apache/struts2/osgi/admin/actions/ShellAction.java (original)
+++ struts/sandbox/trunk/struts2-osgi-plugin/admin-bundle/src/main/java/org/apache/struts2/osgi/admin/actions/ShellAction.java Wed Apr 8 13:01:33 2009
@@ -1,17 +1,13 @@
package org.apache.struts2.osgi.admin.actions;
import java.io.ByteArrayOutputStream;
-import java.io.IOException;
import java.io.PrintStream;
-import org.apache.struts2.osgi.BundleAccessor;
import org.apache.struts2.osgi.admin.services.ServicesFactory;
import org.apache.struts2.osgi.admin.services.shell.ShellService;
-import org.osgi.framework.ServiceReference;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;
-import com.opensymphony.xwork2.inject.Inject;
public class ShellAction extends ActionSupport {
private String command;
Modified: struts/sandbox/trunk/struts2-osgi-plugin/admin-bundle/src/main/resources/struts.xml
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-osgi-plugin/admin-bundle/src/main/resources/struts.xml?rev=763231&r1=763230&r2=763231&view=diff
==============================================================================
--- struts/sandbox/trunk/struts2-osgi-plugin/admin-bundle/src/main/resources/struts.xml (original)
+++ struts/sandbox/trunk/struts2-osgi-plugin/admin-bundle/src/main/resources/struts.xml Wed Apr 8 13:01:33 2009
@@ -3,24 +3,26 @@
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
-<struts>
+<struts>
<package name="bundle-admin" namespace="/osgi/admin" extends="struts-default">
+ <default-action-ref name="bundles" />
+
<action name="bundle_*!*" class="org.apache.struts2.osgi.admin.actions.BundlesAction" method="{2}">
<param name="id">{1}</param>
<result type="freemarker">viewBundle.ftl</result>
- </action>
+ </action>
<action name="bundles" class="org.apache.struts2.osgi.admin.actions.BundlesAction" method="index">
<result type="freemarker">viewBundles.ftl</result>
- </action>
-
-
- <action name="execCommand" class="org.apache.struts2.osgi.admin.actions.ShellAction">
- <result type="freemarker">commandResult.ftl</result>
- </action>
-
- <action name="shell">
- <result type="freemarker">shell.ftl</result>
- </action>
+ </action>
+
+
+ <action name="execCommand" class="org.apache.struts2.osgi.admin.actions.ShellAction">
+ <result type="freemarker">commandResult.ftl</result>
+ </action>
+
+ <action name="shell">
+ <result type="freemarker">shell.ftl</result>
+ </action>
</package>
</struts>
Added: struts/sandbox/trunk/struts2-osgi-plugin/demo-bundle/pom.xml
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-osgi-plugin/demo-bundle/pom.xml?rev=763231&view=auto
==============================================================================
--- struts/sandbox/trunk/struts2-osgi-plugin/demo-bundle/pom.xml (added)
+++ struts/sandbox/trunk/struts2-osgi-plugin/demo-bundle/pom.xml Wed Apr 8 13:01:33 2009
@@ -0,0 +1,84 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.struts.osgi</groupId>
+ <artifactId>struts2-demo-bundle</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <packaging>bundle</packaging>
+ <name>Struts 2 OSGi Demo Bundle</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.struts</groupId>
+ <artifactId>struts2-core</artifactId>
+ <version>2.1.7-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>velocity</groupId>
+ <artifactId>velocity</artifactId>
+ <version>1.5</version>
+ </dependency>
+
+ <dependency>
+ <groupId>velocity-tools</groupId>
+ <artifactId>velocity-tools</artifactId>
+ <version>1.3</version>
+ </dependency>
+
+ <dependency>
+ <groupId>commons-digester</groupId>
+ <artifactId>commons-digester</artifactId>
+ <version>1.8</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.struts</groupId>
+ <artifactId>struts2-convention-plugin</artifactId>
+ <version>2.1.7-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.struts</groupId>
+ <artifactId>struts2-spring-plugin</artifactId>
+ <version>2.1.7-SNAPSHOT</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <version>2.0.0</version>
+ <configuration>
+ <instructions>
+ <manifestLocation>META-INF</manifestLocation>
+ <Import-Package>
+ *,com.opensymphony.xwork2
+ </Import-Package>
+ <Bundle-Activator>
+ org.apache.struts2.osgi.StrutsActivator
+ </Bundle-Activator>
+ <Spring-Context>
+ *;create-asynchronously:=false
+ </Spring-Context>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+</project>
Added: struts/sandbox/trunk/struts2-osgi-plugin/demo-bundle/src/main/java/actions/osgi/HelloWorldAction.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-osgi-plugin/demo-bundle/src/main/java/actions/osgi/HelloWorldAction.java?rev=763231&view=auto
==============================================================================
--- struts/sandbox/trunk/struts2-osgi-plugin/demo-bundle/src/main/java/actions/osgi/HelloWorldAction.java (added)
+++ struts/sandbox/trunk/struts2-osgi-plugin/demo-bundle/src/main/java/actions/osgi/HelloWorldAction.java Wed Apr 8 13:01:33 2009
@@ -0,0 +1,31 @@
+package actions.osgi;
+
+import com.opensymphony.xwork2.ActionSupport;
+import org.apache.struts2.convention.annotation.ParentPackage;
+import org.apache.struts2.convention.annotation.ResultPath;
+import org.apache.struts2.convention.annotation.Action;
+
+@ResultPath("/content")
+public class HelloWorldAction extends ActionSupport {
+ private Message message;
+
+ @Action("hello-convention")
+ public String execute() {
+ return SUCCESS;
+ }
+
+ public Message getMessage() {
+ return message;
+ }
+
+ public void setMessage(Message message) {
+ this.message = message;
+ }
+
+ public String toString() {
+ StringBuilder sb = new StringBuilder("{message:");
+ sb.append(message != null ? message.getText() : "null");
+ sb.append("}");
+ return sb.toString();
+ }
+}
\ No newline at end of file
Added: struts/sandbox/trunk/struts2-osgi-plugin/demo-bundle/src/main/java/actions/osgi/Message.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-osgi-plugin/demo-bundle/src/main/java/actions/osgi/Message.java?rev=763231&view=auto
==============================================================================
--- struts/sandbox/trunk/struts2-osgi-plugin/demo-bundle/src/main/java/actions/osgi/Message.java (added)
+++ struts/sandbox/trunk/struts2-osgi-plugin/demo-bundle/src/main/java/actions/osgi/Message.java Wed Apr 8 13:01:33 2009
@@ -0,0 +1,37 @@
+/*
+ * $Id$
+ *
+ * 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 actions.osgi;
+
+public class Message {
+ private String text;
+
+ public Message(String text) {
+ this.text = text;
+ }
+
+ public String getText() {
+ return text;
+ }
+
+ public void setText(String text) {
+ this.text = text;
+ }
+}
Added: struts/sandbox/trunk/struts2-osgi-plugin/demo-bundle/src/main/resources/META-INF/spring/applicationContext.xml
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-osgi-plugin/demo-bundle/src/main/resources/META-INF/spring/applicationContext.xml?rev=763231&view=auto
==============================================================================
--- struts/sandbox/trunk/struts2-osgi-plugin/demo-bundle/src/main/resources/META-INF/spring/applicationContext.xml (added)
+++ struts/sandbox/trunk/struts2-osgi-plugin/demo-bundle/src/main/resources/META-INF/spring/applicationContext.xml Wed Apr 8 13:01:33 2009
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
+ http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
+ http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
+
+ <bean class="actions.osgi.Message" id="message">
+ <constructor-arg type="java.lang.String" value="Welcome to the OSGi plugin. You can checkout any time you like, but can never leave"/>
+ </bean>
+
+ <bean class="actions.osgi.HelloWorldAction" id="helloWorldAction" scope="prototype">
+ <property name="message" ref="message" />
+ </bean>
+</beans>
+
Added: struts/sandbox/trunk/struts2-osgi-plugin/demo-bundle/src/main/resources/content/osgi/hello-convention.ftl
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-osgi-plugin/demo-bundle/src/main/resources/content/osgi/hello-convention.ftl?rev=763231&view=auto
==============================================================================
--- struts/sandbox/trunk/struts2-osgi-plugin/demo-bundle/src/main/resources/content/osgi/hello-convention.ftl (added)
+++ struts/sandbox/trunk/struts2-osgi-plugin/demo-bundle/src/main/resources/content/osgi/hello-convention.ftl Wed Apr 8 13:01:33 2009
@@ -0,0 +1,10 @@
+<html>
+ <head>
+ <title>Action mapped by the Convention plugin</title>
+ </head>
+ <body>
+ This is an action mapped by the Convention plugin, using a FreeMarker result.
+ <br />
+ Message from Action: ${message.text}
+ </body>
+</html>
\ No newline at end of file
Added: struts/sandbox/trunk/struts2-osgi-plugin/demo-bundle/src/main/resources/content/osgi/hello.ftl
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-osgi-plugin/demo-bundle/src/main/resources/content/osgi/hello.ftl?rev=763231&view=auto
==============================================================================
--- struts/sandbox/trunk/struts2-osgi-plugin/demo-bundle/src/main/resources/content/osgi/hello.ftl (added)
+++ struts/sandbox/trunk/struts2-osgi-plugin/demo-bundle/src/main/resources/content/osgi/hello.ftl Wed Apr 8 13:01:33 2009
@@ -0,0 +1,10 @@
+<html>
+ <head>
+ <title>Action mapped by the XML configurationn</title>
+ </head>
+ <body>
+ This is an action mapped by XML configuration, using a FreeMarker result.
+ <br />
+ Message from Action: ${message.text}
+ </body>
+</html>
\ No newline at end of file
Added: struts/sandbox/trunk/struts2-osgi-plugin/demo-bundle/src/main/resources/content/osgi/hello.vm
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-osgi-plugin/demo-bundle/src/main/resources/content/osgi/hello.vm?rev=763231&view=auto
==============================================================================
--- struts/sandbox/trunk/struts2-osgi-plugin/demo-bundle/src/main/resources/content/osgi/hello.vm (added)
+++ struts/sandbox/trunk/struts2-osgi-plugin/demo-bundle/src/main/resources/content/osgi/hello.vm Wed Apr 8 13:01:33 2009
@@ -0,0 +1,11 @@
+<html>
+ <head>
+ <title>Action mapped by the XML configurationn</title>
+ </head>
+ <body>
+ This is an action mapped by XML configuration, using a Velocity result.
+ ->$top
+ <br />
+ Message from Action: $message.text
+ </body>
+</html>
\ No newline at end of file
Added: struts/sandbox/trunk/struts2-osgi-plugin/demo-bundle/src/main/resources/content/osgi/home.ftl
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-osgi-plugin/demo-bundle/src/main/resources/content/osgi/home.ftl?rev=763231&view=auto
==============================================================================
--- struts/sandbox/trunk/struts2-osgi-plugin/demo-bundle/src/main/resources/content/osgi/home.ftl (added)
+++ struts/sandbox/trunk/struts2-osgi-plugin/demo-bundle/src/main/resources/content/osgi/home.ftl Wed Apr 8 13:01:33 2009
@@ -0,0 +1,14 @@
+<html>
+ <head>
+ <title>OSGi Demo Bundle</title>
+ </head>
+ <body>
+ This demo contains actions that will be packaged into an OSGi bundle and loaded by the Struts 2 OSGi plugin.
+ <br />
+ <ul>
+ <li><@s.a namespace="/osgi" action="hello-convention">Action mapped by the Convention plugin, with FreeMarker result</...@s.a></li>
+ <li><@s.a namespace="/osgi" action="hello-freemarker">Action mapped by XML, with FreeMarker result</...@s.a></li>
+ <li><@s.a namespace="/osgi" action="hello-velocity">Action mapped by XML, with Velocity result</...@s.a></li>
+ </ul>
+ </body>
+</html>
\ No newline at end of file
Added: struts/sandbox/trunk/struts2-osgi-plugin/demo-bundle/src/main/resources/struts.xml
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-osgi-plugin/demo-bundle/src/main/resources/struts.xml?rev=763231&view=auto
==============================================================================
--- struts/sandbox/trunk/struts2-osgi-plugin/demo-bundle/src/main/resources/struts.xml (added)
+++ struts/sandbox/trunk/struts2-osgi-plugin/demo-bundle/src/main/resources/struts.xml Wed Apr 8 13:01:33 2009
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE struts PUBLIC
+ "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
+ "http://struts.apache.org/dtds/struts-2.0.dtd">
+
+<struts>
+ <package name="bundle-demo" namespace="/osgi" extends="struts-default">
+ <default-action-ref name="home" />
+ <action name="hello-velocity" class="helloWorldAction">
+ <result type="velocity">/content/osgi/hello.vm</result>
+ </action>
+ <action name="hello-freemarker" class="helloWorldAction">
+ <result type="freemarker">/content/osgi/hello.ftl</result>
+ </action>
+
+ <action name="home">
+ <result type="freemarker">/content/osgi/home.ftl</result>
+ </action>
+ </package>
+</struts>
\ No newline at end of file
Modified: struts/sandbox/trunk/struts2-osgi-plugin/plugin/src/main/java/org/apache/struts2/osgi/BundleAccessor.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-osgi-plugin/plugin/src/main/java/org/apache/struts2/osgi/BundleAccessor.java?rev=763231&r1=763230&r2=763231&view=diff
==============================================================================
--- struts/sandbox/trunk/struts2-osgi-plugin/plugin/src/main/java/org/apache/struts2/osgi/BundleAccessor.java (original)
+++ struts/sandbox/trunk/struts2-osgi-plugin/plugin/src/main/java/org/apache/struts2/osgi/BundleAccessor.java Wed Apr 8 13:01:33 2009
@@ -15,13 +15,15 @@
String CURRENT_BUNDLE_NAME = "__bundle_name__";
- void init(Map<String, Bundle> bundles, Map<String, String> packageToBundle);
+ void setPackageToBundle(Map<String, String> packageToBundle);
Class loadClass(String name) throws ClassNotFoundException;
InputStream loadResourceAsStream(String name) throws IOException;
- URL loadResource(String name);
+ InputStream loadResourceFromAllBundlesAsStream(String name) throws IOException;
+
+ URL loadResourceFromAllBundles(String name) throws IOException;
Map<String, Bundle> getBundles();
@@ -38,4 +40,6 @@
void addPackageFromBundle(Bundle bundle, String packageName);
void setBundleContext(BundleContext bundleContext);
+
+ void setBundles(Map<String, Bundle> bundles);
}
Modified: struts/sandbox/trunk/struts2-osgi-plugin/plugin/src/main/java/org/apache/struts2/osgi/DefaultBundleAccessor.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-osgi-plugin/plugin/src/main/java/org/apache/struts2/osgi/DefaultBundleAccessor.java?rev=763231&r1=763230&r2=763231&view=diff
==============================================================================
--- struts/sandbox/trunk/struts2-osgi-plugin/plugin/src/main/java/org/apache/struts2/osgi/DefaultBundleAccessor.java (original)
+++ struts/sandbox/trunk/struts2-osgi-plugin/plugin/src/main/java/org/apache/struts2/osgi/DefaultBundleAccessor.java Wed Apr 8 13:01:33 2009
@@ -66,8 +66,7 @@
return bundleContext != null ? bundleContext.getServiceReferences(className, params) : null;
}
- public void init(Map<String, Bundle> bundles, Map<String, String> packageToBundle) {
- this.bundles = Collections.unmodifiableMap(bundles);
+ public void setPackageToBundle(Map<String, String> packageToBundle) {
this.packageToBundle = packageToBundle;
this.packagesByBundle = new HashMap<Bundle, Set<String>>();
for (Map.Entry<String, String> entry : packageToBundle.entrySet()) {
@@ -92,27 +91,15 @@
}
public Class<?> loadClass(String className) throws ClassNotFoundException {
- Class cls = null;
-
Bundle bundle = getCurrentBundle();
if (bundle != null) {
- cls = bundle.loadClass(className);
- LOG.debug("Located class [#0] in bundle [#1]", className, bundle.getSymbolicName());
- }
-
- //try all the bundles
- for (Bundle bundle2 : bundles.values()) {
- try {
- return bundle2.loadClass(className);
- } catch (Exception ex) {
- //ignore
- }
+ Class cls = bundle.loadClass(className);
+ if (LOG.isTraceEnabled())
+ LOG.debug("Located class [#0] in bundle [#1]", className, bundle.getSymbolicName());
+ return cls;
}
- if (cls == null) {
- throw new ClassNotFoundException("Unable to find class " + className + " in bundles");
- }
- return cls;
+ throw new ClassNotFoundException("Unable to find class " + className);
}
private Bundle getCurrentBundle() {
@@ -208,4 +195,8 @@
public void setBundleContext(BundleContext bundleContext) {
this.bundleContext = bundleContext;
}
+
+ public void setBundles(Map<String, Bundle> bundles) {
+ this.bundles = Collections.unmodifiableMap(bundles);
+ }
}
Modified: struts/sandbox/trunk/struts2-osgi-plugin/plugin/src/main/java/org/apache/struts2/osgi/DelegatingObjectFactory.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-osgi-plugin/plugin/src/main/java/org/apache/struts2/osgi/DelegatingObjectFactory.java?rev=763231&r1=763230&r2=763231&view=diff
==============================================================================
--- struts/sandbox/trunk/struts2-osgi-plugin/plugin/src/main/java/org/apache/struts2/osgi/DelegatingObjectFactory.java (original)
+++ struts/sandbox/trunk/struts2-osgi-plugin/plugin/src/main/java/org/apache/struts2/osgi/DelegatingObjectFactory.java Wed Apr 8 13:01:33 2009
@@ -12,22 +12,22 @@
private ObjectFactory delegateObjectFactory;
private BundleAccessor bundleResourceLoader;
private OsgiConfigurationProvider osgiConfigurationProvider;
-
+
@Inject
- public void setDelegateObjectFactory(@Inject Container container,
+ public void setDelegateObjectFactory(@Inject Container container,
@Inject("struts.objectFactory.delegate") String delegate) {
if (delegate == null) {
delegate = "struts";
}
delegateObjectFactory = container.getInstance(ObjectFactory.class, delegate);
}
-
+
@Inject
public void setBundleResourceLoader(BundleAccessor rl) {
this.bundleResourceLoader = rl;
}
-
-
+
+
public boolean isNoArgConstructorRequired() {
return delegateObjectFactory.isNoArgConstructorRequired();
}
@@ -36,14 +36,16 @@
return delegateObjectFactory.buildBean(clazz, extraContext);
}
+ public Object buildBean(String className, Map<String, Object> extraContext, boolean injectInternal) throws Exception {
+ return delegateObjectFactory.buildBean(className, extraContext, injectInternal);
+ }
+
@Override
public Class getClassInstance(String className) throws ClassNotFoundException {
- try
- {
+ try {
return delegateObjectFactory.getClassInstance(className);
}
- catch (Exception e)
- {
+ catch (Exception e) {
return bundleResourceLoader.loadClass(className);
}
}
Modified: struts/sandbox/trunk/struts2-osgi-plugin/plugin/src/main/java/org/apache/struts2/osgi/OsgiConfigurationProvider.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-osgi-plugin/plugin/src/main/java/org/apache/struts2/osgi/OsgiConfigurationProvider.java?rev=763231&r1=763230&r2=763231&view=diff
==============================================================================
--- struts/sandbox/trunk/struts2-osgi-plugin/plugin/src/main/java/org/apache/struts2/osgi/OsgiConfigurationProvider.java (original)
+++ struts/sandbox/trunk/struts2-osgi-plugin/plugin/src/main/java/org/apache/struts2/osgi/OsgiConfigurationProvider.java Wed Apr 8 13:01:33 2009
@@ -63,6 +63,7 @@
try {
osgiHost.setExtraBundleActivators(Arrays.asList(new BundleRegistrationListener()));
osgiHost.init();
+ bundleAccessor.setBundles(osgiHost.getBundles());
} catch (Exception e) {
if (LOG.isErrorEnabled())
LOG.error("Failed to start the OSGi container", e);
@@ -78,26 +79,43 @@
} catch (InvalidSyntaxException e) {
throw new ConfigurationException(e);
}
-
+
+
+ //init action contect
+ ActionContext ctx = ActionContext.getContext();
+ if (ctx == null) {
+ ctx = new ActionContext(new HashMap());
+ ActionContext.setContext(ctx);
+ }
+
Map<String, String> packageToBundle = new HashMap<String, String>();
Set<String> bundleNames = new HashSet<String>();
+
if (refs != null) {
for (ServiceReference ref : refs) {
- if (!bundleNames.contains(ref.getBundle().getSymbolicName())) {
- bundleNames.add(ref.getBundle().getSymbolicName());
+ String bundleName = ref.getBundle().getSymbolicName();
+ if (!bundleNames.contains(bundleName)) {
+ bundleNames.add(bundleName);
if (LOG.isDebugEnabled())
- LOG.debug("Loading packages from bundle [#0]", ref.getBundle().getSymbolicName());
+ LOG.debug("Loading packages from bundle [#0]", bundleName);
PackageLoader loader = (PackageLoader) bundleContext.getService(ref);
- for (PackageConfig pkg : loader.loadPackages(ref.getBundle(), bundleContext, objectFactory, configuration.getPackageConfigs())) {
- configuration.addPackageConfig(pkg.getName(), pkg);
- packageToBundle.put(pkg.getName(), ref.getBundle().getSymbolicName());
+ try {
+ ctx.put(BundleAccessor.CURRENT_BUNDLE_NAME, bundleName);
+ for (PackageConfig pkg : loader.loadPackages(ref.getBundle(), bundleContext, objectFactory, configuration.getPackageConfigs())) {
+ configuration.addPackageConfig(pkg.getName(), pkg);
+ packageToBundle.put(pkg.getName(), bundleName);
+ }
+ } finally {
+ ctx.put(BundleAccessor.CURRENT_BUNDLE_NAME, null);
}
}
}
}
- bundleAccessor.init(osgiHost.getBundles(), packageToBundle);
+
+ //add the loaded packages to the BundleAccessor
+ bundleAccessor.setPackageToBundle(packageToBundle);
//reload container that will load configuration based on bundles (like convention plugin)
reloadExtraProviders(configuration.getContainer());
Modified: struts/sandbox/trunk/struts2-osgi-plugin/plugin/src/main/java/org/apache/struts2/osgi/SpringOsgiObjectFactory.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-osgi-plugin/plugin/src/main/java/org/apache/struts2/osgi/SpringOsgiObjectFactory.java?rev=763231&r1=763230&r2=763231&view=diff
==============================================================================
--- struts/sandbox/trunk/struts2-osgi-plugin/plugin/src/main/java/org/apache/struts2/osgi/SpringOsgiObjectFactory.java (original)
+++ struts/sandbox/trunk/struts2-osgi-plugin/plugin/src/main/java/org/apache/struts2/osgi/SpringOsgiObjectFactory.java Wed Apr 8 13:01:33 2009
@@ -26,13 +26,17 @@
import java.util.Map;
+/**
+ * This Object factory uses the ActionContext(s) published by Spring OSGi
+ * to lookup beans
+ */
public class SpringOsgiObjectFactory extends ObjectFactory {
private final static String SPRING_SERVICE_NAME = "org.springframework.context.ApplicationContext";
private BundleAccessor bundleAccessor;
public Object buildBean(String className, Map<String, Object> extraContext, boolean injectInternal) throws Exception {
- return containsBean(className) ? getBean(className) : super.buildBean(className, extraContext);
+ return containsBean(className) ? getBean(className) : super.buildBean(className, extraContext, injectInternal);
}
public Object buildBean(Class clazz, Map<String, Object> extraContext) throws Exception {
Modified: struts/sandbox/trunk/struts2-osgi-plugin/plugin/src/main/java/org/apache/struts2/osgi/loaders/StaticContentBundleResourceLoader.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-osgi-plugin/plugin/src/main/java/org/apache/struts2/osgi/loaders/StaticContentBundleResourceLoader.java?rev=763231&r1=763230&r2=763231&view=diff
==============================================================================
--- struts/sandbox/trunk/struts2-osgi-plugin/plugin/src/main/java/org/apache/struts2/osgi/loaders/StaticContentBundleResourceLoader.java (original)
+++ struts/sandbox/trunk/struts2-osgi-plugin/plugin/src/main/java/org/apache/struts2/osgi/loaders/StaticContentBundleResourceLoader.java Wed Apr 8 13:01:33 2009
@@ -2,16 +2,26 @@
import java.io.IOException;
import java.io.InputStream;
+import java.net.URL;
import org.apache.struts2.dispatcher.DefaultStaticContentLoader;
import org.apache.struts2.osgi.DefaultBundleAccessor;
+import org.apache.struts2.osgi.BundleAccessor;
+import com.opensymphony.xwork2.inject.Inject;
/**
* Loads static resources from bundles
*
*/
public class StaticContentBundleResourceLoader extends DefaultStaticContentLoader {
- protected InputStream findInputStream(String path) throws IOException {
- return DefaultBundleAccessor.getInstance().loadResourceFromAllBundlesAsStream(path);
+ private BundleAccessor bundleAccessor;
+
+ protected URL findResource(String path) throws IOException {
+ return bundleAccessor.loadResourceFromAllBundles(path);
+ }
+
+ @Inject
+ public void setBundleAccessor(BundleAccessor bundleAccessor) {
+ this.bundleAccessor = bundleAccessor;
}
}
Modified: struts/sandbox/trunk/struts2-osgi-plugin/pom.xml
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-osgi-plugin/pom.xml?rev=763231&r1=763230&r2=763231&view=diff
==============================================================================
--- struts/sandbox/trunk/struts2-osgi-plugin/pom.xml (original)
+++ struts/sandbox/trunk/struts2-osgi-plugin/pom.xml Wed Apr 8 13:01:33 2009
@@ -32,6 +32,7 @@
<modules>
<module>admin-bundle</module>
+ <module>demo-bundle</module>
<module>plugin</module>
</modules>
</project>