cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dani...@apache.org
Subject svn commit: r394738 - /cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/java/org/apache/cocoon/blocks/Activator.java
Date Mon, 17 Apr 2006 17:59:29 GMT
Author: danielf
Date: Mon Apr 17 10:59:27 2006
New Revision: 394738

URL: http://svn.apache.org/viewcvs?rev=394738&view=rev
Log:
The ServletContext.getResource should be resolved in the bundle of the servlet instead of
the bundle of the cocoon-blocks-fw. 

Modified:
    cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/java/org/apache/cocoon/blocks/Activator.java

Modified: cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/java/org/apache/cocoon/blocks/Activator.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/java/org/apache/cocoon/blocks/Activator.java?rev=394738&r1=394737&r2=394738&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/java/org/apache/cocoon/blocks/Activator.java
(original)
+++ cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/java/org/apache/cocoon/blocks/Activator.java
Mon Apr 17 10:59:27 2006
@@ -15,15 +15,21 @@
  */
 package org.apache.cocoon.blocks;
 
+import java.io.IOException;
+import java.net.URL;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map.Entry;
 
 import javax.servlet.Servlet;
 import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
 
+import org.osgi.framework.Bundle;
 import org.osgi.framework.ServiceReference;
 import org.osgi.service.component.ComponentContext;
+import org.osgi.service.http.HttpContext;
 import org.osgi.service.http.HttpService;
 import org.osgi.service.http.NamespaceException;
 import org.osgi.service.log.LogService;
@@ -80,10 +86,27 @@
     protected void deactivate(ComponentContext context) {
     }
     
-    private void registerServlet(String path, ServiceReference reference)
+    private void registerServlet(String path, final ServiceReference reference)
         throws ServletException, NamespaceException {
         Servlet servlet = (Servlet) this.context.locateService("Servlet", reference);
-        this.httpService.registerServlet(path, servlet, null, null);
+        
+        // Create a context that resolves resources in the bundle context where
+        // the servlet origins from
+        HttpContext httpContext = new HttpContext() {
+            private Bundle bundle = reference.getBundle();
+            public boolean handleSecurity(HttpServletRequest request, HttpServletResponse
response) throws IOException {
+                return true;
+            }
+
+            public URL getResource(String name) {
+                return this.bundle.getEntry(name);
+            }
+
+            public String getMimeType(String name) {
+                return null;
+            }
+        };
+        this.httpService.registerServlet(path, servlet, null, httpContext);
         this.log.log(LogService.LOG_DEBUG, "Register Servlet at " + path);    
     }
 



Mime
View raw message