clerezza-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject svn commit: r1423954 - in /incubator/clerezza/trunk: jaxrs.stanbol.fragments/ jaxrs.stanbol.fragments/src/main/scala/org/apache/clerezza/jaxrs/stanbol/webfragements/ jaxrs.stanbol.fragments/src/test/ jaxrs.stanbol.fragments/src/test/scala/ parent/ plat...
Date Wed, 19 Dec 2012 17:05:15 GMT
Author: reto
Date: Wed Dec 19 17:05:14 2012
New Revision: 1423954

URL: http://svn.apache.org/viewvc?rev=1423954&view=rev
Log:
CLEREZZA-722: registering classes as well (supported by snapshot wink version) and setting
a ContextResolver for the ServletContext

Added:
    incubator/clerezza/trunk/jaxrs.stanbol.fragments/src/test/
    incubator/clerezza/trunk/jaxrs.stanbol.fragments/src/test/scala/
Modified:
    incubator/clerezza/trunk/jaxrs.stanbol.fragments/   (props changed)
    incubator/clerezza/trunk/jaxrs.stanbol.fragments/pom.xml
    incubator/clerezza/trunk/jaxrs.stanbol.fragments/src/main/scala/org/apache/clerezza/jaxrs/stanbol/webfragements/WebFragmentRunner.scala
    incubator/clerezza/trunk/parent/pom.xml
    incubator/clerezza/trunk/platform.launcher.storageless.parent/pom.xml

Propchange: incubator/clerezza/trunk/jaxrs.stanbol.fragments/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Wed Dec 19 17:05:14 2012
@@ -1,3 +1,6 @@
 jaxrs.stanbol.fragments.iml
 .idea
 target
+.project
+.classpath
+.cache

Modified: incubator/clerezza/trunk/jaxrs.stanbol.fragments/pom.xml
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/jaxrs.stanbol.fragments/pom.xml?rev=1423954&r1=1423953&r2=1423954&view=diff
==============================================================================
--- incubator/clerezza/trunk/jaxrs.stanbol.fragments/pom.xml (original)
+++ incubator/clerezza/trunk/jaxrs.stanbol.fragments/pom.xml Wed Dec 19 17:05:14 2012
@@ -48,6 +48,10 @@
 			<artifactId>org.apache.felix.scr.annotations</artifactId>
             <version>1.7.0</version>
 		</dependency>
+        <dependency>
+            <groupId>org.apache.wink</groupId>
+            <artifactId>wink-osgi</artifactId>
+        </dependency>
         <!-- testing with last released version, testutils is doscontinued as
        triaxrs is -->
 		<dependency>
@@ -63,7 +67,7 @@
         <dependency>
             <groupId>org.apache.stanbol</groupId>
             <artifactId>org.apache.stanbol.commons.web.base</artifactId>
-            <version>0.10.1-SNAPSHOT</version>
+            <version>0.11.0-SNAPSHOT</version>
         </dependency>
         <dependency>
 			<groupId>org.scala-lang</groupId>

Modified: incubator/clerezza/trunk/jaxrs.stanbol.fragments/src/main/scala/org/apache/clerezza/jaxrs/stanbol/webfragements/WebFragmentRunner.scala
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/jaxrs.stanbol.fragments/src/main/scala/org/apache/clerezza/jaxrs/stanbol/webfragements/WebFragmentRunner.scala?rev=1423954&r1=1423953&r2=1423954&view=diff
==============================================================================
--- incubator/clerezza/trunk/jaxrs.stanbol.fragments/src/main/scala/org/apache/clerezza/jaxrs/stanbol/webfragements/WebFragmentRunner.scala
(original)
+++ incubator/clerezza/trunk/jaxrs.stanbol.fragments/src/main/scala/org/apache/clerezza/jaxrs/stanbol/webfragements/WebFragmentRunner.scala
Wed Dec 19 17:05:14 2012
@@ -16,11 +16,28 @@
 
 package org.apache.clerezza.jaxrs.stanbol.webfragements
 
+import org.apache.stanbol.commons.web.base.resource.BaseStanbolResource
+import org.apache.wink.osgi.WinkRequestProcessor
+import java.util.ArrayList
+import java.util.Collections
+import javax.servlet.FilterChain
+import javax.servlet.Servlet
+import javax.servlet.ServletContext
+import javax.servlet.ServletRequest
+import javax.servlet.ServletResponse
+import javax.servlet.http.HttpServlet
+import javax.ws.rs.ext.ContextResolver
+import javax.ws.rs.ext.Provider
 import org.apache.clerezza.osgi.services.ActivationHelper
 import org.apache.felix.scr.annotations._
+import org.apache.stanbol.commons.web.base.LinkResource
+import org.apache.stanbol.commons.web.base.NavigationLink
+import org.apache.stanbol.commons.web.base.ScriptResource
 import org.apache.stanbol.commons.web.base.WebFragment
 import org.osgi.framework.BundleContext
 import org.osgi.service.component.ComponentContext
+import org.slf4j.scala.Logging
+
 
 
 @Component
@@ -28,16 +45,79 @@ import org.osgi.service.component.Compon
            referenceInterface = classOf[WebFragment], 
            cardinality = ReferenceCardinality.OPTIONAL_MULTIPLE, 
            policy = ReferencePolicy.DYNAMIC)
-class WebFragmentRunner {
+//@Service(Array(classOf[Servlet]))
+//@Property(name = "alias", value = Array("/stanbol-ugly-servlet-context-initializer"))
+@Service(value = Array(classOf[javax.servlet.Filter]))
+@Property(name ="pattern", value=Array(".*"))
+class WebFragmentRunner extends javax.servlet.Filter with Logging {
+
+  @Reference
+  private var winkRequestProcessor: WinkRequestProcessor = _
+  
+  @Property(name = "org.apache.stanbol.commons.web.alias", value = Array("/"))
+  final val ALIAS_PROPERTY = "org.apache.stanbol.commons.web.alias";
+
+  @Property(name = STATIC_RESOURCES_URL_ROOT_PROPERTY, value = Array("/static"))
+  final val STATIC_RESOURCES_URL_ROOT_PROPERTY = "org.apache.stanbol.commons.web.static.url";
 
-  println("constructing");
+  /**
+   * The origins allowed for multi-host requests
+   */
+  @Property(name = CORS_ORIGIN, cardinality = 100, value = Array("*"))
+  final val CORS_ORIGIN = "org.apache.stanbol.commons.web.cors.origin";
 
+  @Property(name = CORS_ACCESS_CONTROL_EXPOSE_HEADERS, cardinality = 100, value = Array("Location"))
+  final val CORS_ACCESS_CONTROL_EXPOSE_HEADERS = "org.apache.stanbol.commons.web.cors.access_control_expose_headers";
+
+  
   private var webFragments: List[WebFragment] = Nil
   private var bundleContext: BundleContext = _
   private var activator: Option[ActivationHelper] = None
+  
+  private val linkResources = new ArrayList[LinkResource]();
+  private val scriptResources = new ArrayList[ScriptResource]();
+  private val navigationLinks = new ArrayList[NavigationLink]();
+  
+  private var staticUrlRoot: String = _
+  private var applicationAlias: String = _
+  
+  private var corsOrigins : java.util.Set[String] = _
+  private var exposedHeaders : java.util.Set[String] = _
+
+
 
   @Activate
   def activate(c: ComponentContext) {
+    staticUrlRoot = c.getProperties().get(
+      STATIC_RESOURCES_URL_ROOT_PROPERTY).asInstanceOf[String]
+    applicationAlias = c.getProperties().get(
+      ALIAS_PROPERTY).asInstanceOf[String];
+    {
+      val values = c.getProperties().get(CORS_ORIGIN);
+      values match {
+        case s: String => corsOrigins =  Collections.singleton(s)
+        case i: java.lang.Iterable[_] => {
+            corsOrigins = new java.util.HashSet[String]();
+            val iter = i.iterator
+            while (iter.hasNext) {
+              corsOrigins.add(iter.next().toString)
+            };
+        }
+      }
+    }
+    {
+      val values = c.getProperties().get(CORS_ACCESS_CONTROL_EXPOSE_HEADERS);
+      values match {
+        case s: String => exposedHeaders = Collections.singleton(s)
+        case i: java.lang.Iterable[_] => {
+            exposedHeaders = new java.util.HashSet[String]();
+            val iter = i.iterator
+            while (iter.hasNext) {
+              exposedHeaders.add(iter.next().toString)
+            }
+        }
+      }
+    }
     synchronized {
       println("activating with "+webFragments);
       bundleContext = c.getBundleContext
@@ -48,6 +128,7 @@ class WebFragmentRunner {
   @Deactivate
   def deactivate(c: ComponentContext) {
     synchronized {
+      unregisterClasses()
       activator.foreach(_.stop(c.getBundleContext))
       activator = None
     }
@@ -59,19 +140,37 @@ class WebFragmentRunner {
       for (f <- webFragments) {
         import scala.collection.JavaConverters._
         for (s <- f.getJaxrsResourceSingletons.asScala) {
+          //could alos direcly invoke wink as below
           registerRootResource(s)
-          println("Registered: "+s)
+          logger.info("Registered: "+s)
+        }
+        for (c <- f.getJaxrsResourceClasses.asScala) {
+            winkRequestProcessor.bindComponentClass(c)
+            logger.info("Registered class: "+c)
         }
-        println(f)
       }
       start (bundleContext)
     })
   }
+  
+  private def unregisterClasses() {
+    for (f <- webFragments) {
+        import scala.collection.JavaConverters._
+        for (c <- f.getJaxrsResourceClasses.asScala) {
+            winkRequestProcessor.unbindComponentClass(c)
+            logger.info("Unregistered class: "+c)
+        }
+      }
+  }
 
   protected def bindWebFragment(f: WebFragment) {
+    linkResources.addAll(f.getLinkResources());
+    scriptResources.addAll(f.getScriptResources());
+    navigationLinks.addAll(f.getNavigationLinks());
     synchronized {
       webFragments ::= f
       activator.foreach { a =>
+        unregisterClasses();
         a.stop(bundleContext);
         registerFragments()
       }
@@ -79,13 +178,53 @@ class WebFragmentRunner {
   }
 
   protected def unbindWebFragment(f: WebFragment) {
+    linkResources.removeAll(f.getLinkResources());
+    scriptResources.removeAll(f.getScriptResources());
+    navigationLinks.removeAll(f.getNavigationLinks());
     synchronized {
       webFragments = webFragments diff List(f)
       activator.foreach { a=>
+        unregisterClasses()
         a.stop(bundleContext);
         registerFragments()
       }
     }
   }
+  
+  //all this servlet stuff is only needed to get the servlet context
+  //override def init(config: javax.servlet.ServletConfig) {
+  override def init(config: javax.servlet.FilterConfig) {
+    val servletContext = config.getServletContext
+
+    Collections.sort(linkResources);
+    Collections.sort(scriptResources);
+    Collections.sort(navigationLinks);
+    servletContext.setAttribute(classOf[BundleContext].getName(), bundleContext);
+    servletContext.setAttribute(BaseStanbolResource.ROOT_URL, applicationAlias);
+    servletContext.setAttribute(BaseStanbolResource.STATIC_RESOURCES_ROOT_URL, staticUrlRoot);
+    servletContext.setAttribute(BaseStanbolResource.LINK_RESOURCES, linkResources);
+    servletContext.setAttribute(BaseStanbolResource.SCRIPT_RESOURCES, scriptResources);
+    servletContext.setAttribute(BaseStanbolResource.NAVIGATION_LINKS, navigationLinks);
+    servletContext.setAttribute(CORS_ORIGIN, corsOrigins);
+    servletContext.setAttribute(CORS_ACCESS_CONTROL_EXPOSE_HEADERS, exposedHeaders);
+    winkRequestProcessor.bindComponent(new ContextResolverImpl(servletContext))
+  }
+  
+  override def doFilter(request: ServletRequest, response: ServletResponse,
+			chain: FilterChain){
+		chain.doFilter(request, response);
+	}
+
+	override def destroy() {
+	}
+
 
 }
+
+@Provider
+class ContextResolverImpl(servletContext: ServletContext) extends ContextResolver[ServletContext]
{
+
+    def getContext(clazz: Class[_]): ServletContext = {
+        servletContext;
+    }
+}

Modified: incubator/clerezza/trunk/parent/pom.xml
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/pom.xml?rev=1423954&r1=1423953&r2=1423954&view=diff
==============================================================================
--- incubator/clerezza/trunk/parent/pom.xml (original)
+++ incubator/clerezza/trunk/parent/pom.xml Wed Dec 19 17:05:14 2012
@@ -350,6 +350,11 @@
 				<artifactId>junit</artifactId>
 				<version>4.8.2</version>
 			</dependency>
+            <dependency>
+                <groupId>org.apache.wink</groupId>
+                <artifactId>wink-osgi</artifactId>
+                <version>1.3.0-incubating-SNAPSHOT</version>
+            </dependency>
 			<dependency>
 				<groupId>javax.ws.rs</groupId>
 				<artifactId>jsr311-api</artifactId>
@@ -503,7 +508,7 @@
 			<dependency>
 				<groupId>commons-codec</groupId>
 				<artifactId>commons-codec</artifactId>
-				<version>1.5</version>
+				<version>1.7</version>
 			</dependency>
 			<dependency>
 				<groupId>commons-lang</groupId>

Modified: incubator/clerezza/trunk/platform.launcher.storageless.parent/pom.xml
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/platform.launcher.storageless.parent/pom.xml?rev=1423954&r1=1423953&r2=1423954&view=diff
==============================================================================
--- incubator/clerezza/trunk/platform.launcher.storageless.parent/pom.xml (original)
+++ incubator/clerezza/trunk/platform.launcher.storageless.parent/pom.xml Wed Dec 19 17:05:14
2012
@@ -198,9 +198,9 @@
         <dependency>
             <groupId>org.apache.wink</groupId>
             <artifactId>wink-osgi</artifactId>
-            <version>1.2.1-incubating</version>
-            <!-- this has to start early, because of the MEdiaType requiring RuntimeImpl
in 
-			static iinitializer -->
+            <version>1.3.0-incubating-SNAPSHOT</version>
+            <!-- this has to start early, because of the MediaType requiring RuntimeImpl
in 
+			static initializer -->
             <scope>provided</scope>
         </dependency>
         <dependency>
@@ -412,6 +412,11 @@
 		</dependency> --> 
     <dependency>
       <groupId>org.apache.stanbol</groupId>
+      <artifactId>org.apache.stanbol.commons.web.resources</artifactId>
+      <version>0.10.1-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.stanbol</groupId>
       <artifactId>org.apache.stanbol.commons.security</artifactId>
       <version>0.10.0-SNAPSHOT</version>
     </dependency>
@@ -458,7 +463,7 @@
     <dependency>
       <groupId>org.apache.stanbol</groupId>
       <artifactId>org.apache.stanbol.commons.web.base</artifactId>
-      <version>0.10.1-SNAPSHOT</version>
+      <version>0.11.0-SNAPSHOT</version>
     </dependency>
     <dependency>
       <groupId>org.apache.stanbol</groupId>



Mime
View raw message