Author: [email protected]
Date: Thu Apr  7 15:09:11 2011
New Revision: 950

Log:
AMDATU-283 dispatcher support / javadoc / junit

Added:
   
branches/AMDATU-283-dev/amdatu-web/dispatcher/src/test/java/org/amdatu/web/dispatcher/dispatch/
   
branches/AMDATU-283-dev/amdatu-web/dispatcher/src/test/java/org/amdatu/web/dispatcher/dispatch/DispatcherForwardRequestWrapperTest.java
   
branches/AMDATU-283-dev/amdatu-web/dispatcher/src/test/java/org/amdatu/web/dispatcher/dispatch/DispatcherRequestWrapperTest.java
   branches/AMDATU-283-dev/amdatu-web/httpcontext/src/test/
   branches/AMDATU-283-dev/amdatu-web/httpcontext/src/test/java/
   branches/AMDATU-283-dev/amdatu-web/httpcontext/src/test/java/org/
   branches/AMDATU-283-dev/amdatu-web/httpcontext/src/test/java/org/amdatu/
   branches/AMDATU-283-dev/amdatu-web/httpcontext/src/test/java/org/amdatu/web/
   
branches/AMDATU-283-dev/amdatu-web/httpcontext/src/test/java/org/amdatu/web/httpcontext/
   
branches/AMDATU-283-dev/amdatu-web/httpcontext/src/test/java/org/amdatu/web/httpcontext/context/
   
branches/AMDATU-283-dev/amdatu-web/httpcontext/src/test/java/org/amdatu/web/httpcontext/context/DelegatingHttpContextTest.java
Removed:
   
branches/AMDATU-283-dev/amdatu-web/dispatcher/src/main/java/org/amdatu/web/dispatcher/dispatch/CustomServletPipeline.java
Modified:
   
branches/AMDATU-283-dev/amdatu-authentication/oauth-server/src/main/java/org/amdatu/authentication/oauth/server/service/OAuthAuthorizeTokenServletImpl.java
   branches/AMDATU-283-dev/amdatu-release/pom.xml
   
branches/AMDATU-283-dev/amdatu-web/dispatcher/src/main/java/org/amdatu/web/dispatcher/dispatch/CustomFilterChain.java
   
branches/AMDATU-283-dev/amdatu-web/dispatcher/src/main/java/org/amdatu/web/dispatcher/dispatch/CustomFilterPipeline.java
   
branches/AMDATU-283-dev/amdatu-web/dispatcher/src/main/java/org/amdatu/web/dispatcher/dispatch/ExtenderFilterPipeline.java
   
branches/AMDATU-283-dev/amdatu-web/dispatcher/src/main/java/org/amdatu/web/dispatcher/handler/AbstractHandler.java
   
branches/AMDATU-283-dev/amdatu-web/dispatcher/src/main/java/org/amdatu/web/dispatcher/handler/AbstractHandlerRegistry.java
   
branches/AMDATU-283-dev/amdatu-web/dispatcher/src/main/java/org/amdatu/web/dispatcher/handler/FilterHandler.java
   
branches/AMDATU-283-dev/amdatu-web/dispatcher/src/main/java/org/amdatu/web/dispatcher/handler/FilterHandlerRegistry.java
   
branches/AMDATU-283-dev/amdatu-web/dispatcher/src/main/java/org/amdatu/web/dispatcher/handler/ServletHandler.java
   
branches/AMDATU-283-dev/amdatu-web/dispatcher/src/main/java/org/amdatu/web/dispatcher/handler/ServletHandlerRegistry.java
   
branches/AMDATU-283-dev/amdatu-web/httpcontext/src/main/java/org/amdatu/web/httpcontext/HttpContextManagerService.java
   
branches/AMDATU-283-dev/amdatu-web/httpcontext/src/main/java/org/amdatu/web/httpcontext/MimeTypeResolver.java
   
branches/AMDATU-283-dev/amdatu-web/httpcontext/src/main/java/org/amdatu/web/httpcontext/SecurityHandler.java
   
branches/AMDATU-283-dev/amdatu-web/jsp/src/main/java/org/amdatu/web/jsp/JspSupport.java
   
branches/AMDATU-283-dev/amdatu-web/resource/src/main/java/org/amdatu/web/resource/ResourceSupport.java
   
branches/AMDATU-283-dev/amdatu-web/rest-wink/src/main/java/org/amdatu/web/rest/wink/service/WinkRestServlet.java
   
branches/AMDATU-283-dev/integration-tests/src/test/java/org/amdatu/test/integration/base/IntegrationTestBase.java
   branches/AMDATU-283-dev/src/main/resources/conf/felix-config.properties

Modified: 
branches/AMDATU-283-dev/amdatu-authentication/oauth-server/src/main/java/org/amdatu/authentication/oauth/server/service/OAuthAuthorizeTokenServletImpl.java
==============================================================================
--- 
branches/AMDATU-283-dev/amdatu-authentication/oauth-server/src/main/java/org/amdatu/authentication/oauth/server/service/OAuthAuthorizeTokenServletImpl.java
 (original)
+++ 
branches/AMDATU-283-dev/amdatu-authentication/oauth-server/src/main/java/org/amdatu/authentication/oauth/server/service/OAuthAuthorizeTokenServletImpl.java
 Thu Apr  7 15:09:11 2011
@@ -124,23 +124,8 @@
         m_logService.log(LogService.LOG_DEBUG, "Forwarding authorize token 
request to " + m_serviceProvider.getAuthorizeURL()
             + ", token=" + accessor.requestToken + ", callback=" + callback);
        
-        // Create a request wrapper returning the path of the JSP servlet 
instead of this servlet
-        HttpServletRequestWrapper wrapper = new 
HttpServletRequestWrapper(request) {
-            public String getPathInfo() {
-                return m_serviceProvider.getAuthorizeURL();
-            }
-            
-            public String getContextPath() {
-                return request.getContextPath();
-            }
-            
-            public String getServletPath() {
-                return "";
-            }
-        };
-        
         // Dispatch the request to the authorize JSP       
-        
request.getRequestDispatcher(m_serviceProvider.getAuthorizeURL()).forward(wrapper,
 response);
+        
request.getRequestDispatcher(m_serviceProvider.getAuthorizeURL()).forward(request,
 response);
     }
 
     private void returnToConsumer(HttpServletRequest request,

Modified: branches/AMDATU-283-dev/amdatu-release/pom.xml
==============================================================================
--- branches/AMDATU-283-dev/amdatu-release/pom.xml      (original)
+++ branches/AMDATU-283-dev/amdatu-release/pom.xml      Thu Apr  7 15:09:11 2011
@@ -437,12 +437,6 @@
     </dependency>
     <dependency>
       <groupId>org.apache.felix</groupId>
-      <artifactId>org.apache.felix.dependencymanager.shell</artifactId>
-      <version>${org.apache.felix.dependencymanager.version}</version>
-      <scope>compile</scope>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.felix</groupId>
       <artifactId>org.apache.felix.metatype</artifactId>
       <version>${org.apache.felix.metatype.version}</version>
       <scope>compile</scope>

Modified: 
branches/AMDATU-283-dev/amdatu-web/dispatcher/src/main/java/org/amdatu/web/dispatcher/dispatch/CustomFilterChain.java
==============================================================================
--- 
branches/AMDATU-283-dev/amdatu-web/dispatcher/src/main/java/org/amdatu/web/dispatcher/dispatch/CustomFilterChain.java
       (original)
+++ 
branches/AMDATU-283-dev/amdatu-web/dispatcher/src/main/java/org/amdatu/web/dispatcher/dispatch/CustomFilterChain.java
       Thu Apr  7 15:09:11 2011
@@ -24,6 +24,7 @@
 import javax.servlet.http.HttpServletResponse;
 
 import org.amdatu.web.dispatcher.handler.FilterHandler;
+import org.amdatu.web.dispatcher.handler.ServletHandler;
 
 /**
  * Custom <code>FilterChain</code> implementation that invokes an array of 
<code>FilterHandler</code>
@@ -34,14 +35,14 @@
 public final class CustomFilterChain extends HttpFilterChain {
 
     private final FilterHandler[] m_filterHandlers;
-    private final CustomServletPipeline m_servletPipeline;
+    private final ServletHandler m_targetServletHandler;
     private final FilterChain m_proceedingChain;
     private int m_index = -1;
 
-    public CustomFilterChain(FilterHandler[] handlers, CustomServletPipeline 
servletPipeline,
+    public CustomFilterChain(FilterHandler[] filterHandlers, ServletHandler 
targetServletHandler,
         FilterChain proceedingChain) {
-        m_filterHandlers = handlers;
-        m_servletPipeline = servletPipeline;
+        m_filterHandlers = filterHandlers;
+        m_targetServletHandler = targetServletHandler;
         m_proceedingChain = proceedingChain;
     }
 
@@ -53,7 +54,7 @@
             m_filterHandlers[m_index].handle(req, res, this);
         }
         else {
-            if (!m_servletPipeline.handle(req, res)) {
+            if (!m_targetServletHandler.handle(req, res)) {
                 m_proceedingChain.doFilter(req, res);
             }
         }

Modified: 
branches/AMDATU-283-dev/amdatu-web/dispatcher/src/main/java/org/amdatu/web/dispatcher/dispatch/CustomFilterPipeline.java
==============================================================================
--- 
branches/AMDATU-283-dev/amdatu-web/dispatcher/src/main/java/org/amdatu/web/dispatcher/dispatch/CustomFilterPipeline.java
    (original)
+++ 
branches/AMDATU-283-dev/amdatu-web/dispatcher/src/main/java/org/amdatu/web/dispatcher/dispatch/CustomFilterPipeline.java
    Thu Apr  7 15:09:11 2011
@@ -21,6 +21,8 @@
 import javax.servlet.FilterChain;
 import javax.servlet.RequestDispatcher;
 import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletRequestWrapper;
 import javax.servlet.http.HttpServletResponse;
@@ -31,15 +33,13 @@
 import org.amdatu.web.dispatcher.handler.ServletHandlerRegistry;
 
 /**
- * Pipeline implementation responsible for building the custom filterchain in 
collaboration
- * with the specified handler registries, invoking it and wrapping the request 
to support
- * dispatchers.
+ * Pipeline implementation responsible for building the application 
filterchain in collaboration
+ * with the specified handler registries.
  */
 public final class CustomFilterPipeline {
 
     private final FilterHandlerRegistry m_filterHandlerRegistry;
     private final ServletHandlerRegistry m_servletHandlerRegistry;
-    private CustomServletPipeline m_servletPipeline;
 
     public CustomFilterPipeline(FilterHandlerRegistry filterHandlerRegistry,
         ServletHandlerRegistry servletHandlerRegistry) {
@@ -50,48 +50,115 @@
     public void dispatch(HttpServletRequest httpServletRequest, 
HttpServletResponse httpServletResponse,
         FilterChain proceedingChain) throws ServletException, IOException {
 
+        ServletHandler servletHandler = 
m_servletHandlerRegistry.getServletHandler(httpServletRequest);
+        if (servletHandler == null) {
+            proceedingChain.doFilter(httpServletRequest, httpServletResponse);
+            return;
+        }
         FilterHandler[] filterHandlers = 
m_filterHandlerRegistry.getFilterHandlers(httpServletRequest);
-        ServletHandler[] servletHandlers = 
m_servletHandlerRegistry.getServletHandlers(httpServletRequest);
+        CustomFilterChain chain = new CustomFilterChain(filterHandlers, 
servletHandler, proceedingChain);
+        chain
+            .doFilter(new DispatcherRequestWrapper(this, httpServletRequest, 
servletHandler.getAlias()),
+                httpServletResponse);
+    }
+
+    ServletHandlerRegistry getServletHandlerRegistry() {
+        return m_servletHandlerRegistry;
+    }
 
-        String localRequestUri = httpServletRequest.getRequestURI();
-        if (!httpServletRequest.getContextPath().equals("")) {
-            localRequestUri = 
localRequestUri.replaceFirst(httpServletRequest.getContextPath(), "");
+    interface RegistryAccess {
+        ServletHandlerRegistry getServletHandlerRegistry();
+    }
+    
+    /**
+     * Application <code>RequestDispatcher</code> implementation that invokes 
the specified
+     * <code>ServletHandler</code> and uses a 
<code>DispatcherForwardRequestWrapper</code>
+     * to ensure that subsequent calls to <code>getServletPath()</code> and 
<code>
+     * getPathInfo()</code> correspond to the target 
<code>ServletHandler</code> and
+     * the path the dispatcher was requested for.
+     */
+    static final class DispatcherRequestDispatcher implements 
RequestDispatcher {
+
+        private final ServletHandler m_servletHandler;
+        private final String m_path;
+
+        public DispatcherRequestDispatcher(ServletHandler servletHandler, 
String path) {
+            m_servletHandler = servletHandler;
+            m_path = path;
+        }
+
+        public void forward(ServletRequest servletRequest, ServletResponse 
servletResponse) throws ServletException,
+            IOException {
+            m_servletHandler.handle(new 
DispatcherForwardRequestWrapper((HttpServletRequest) servletRequest,
+                m_servletHandler.getAlias(), m_path), (HttpServletResponse) 
servletResponse);
+        }
+
+        public void include(ServletRequest servletRequest, ServletResponse 
servletResponse) throws ServletException,
+            IOException {
+            m_servletHandler.handle(new 
DispatcherForwardRequestWrapper((HttpServletRequest) servletRequest,
+                m_servletHandler.getAlias(), m_path), (HttpServletResponse) 
servletResponse);
         }
+    }
 
-        ServletHandler target = null;
-        for (ServletHandler handler : servletHandlers) {
-            if (handler.isActive() && handler.matches(localRequestUri)) {
-                target = handler;
-                break;
-            }
+    /**
+     * Application <code>HttpServletRequestWrapper</code> for incomming 
requests. It wraps the original request
+     * so that subsequent calls to <code>getServletPath()</code> and 
<code>getPathInfo()</code>
+     * correspond to the target <code>ServletHandler</code>.
+     */
+    static final class DispatcherRequestWrapper extends 
HttpServletRequestWrapper {
+
+        private final CustomFilterPipeline m_customFilterPipeline;
+        private final String m_pathInfo;
+        private final String m_servletPath;
+
+        public DispatcherRequestWrapper(CustomFilterPipeline 
customFilterPipeline,
+            HttpServletRequest httpServletRequest, String servletAlias) {
+            super(httpServletRequest);
+            m_customFilterPipeline = customFilterPipeline;
+            m_servletPath = servletAlias;
+            m_pathInfo = 
httpServletRequest.getPathInfo().replaceFirst(servletAlias, "");
         }
 
-        if (target == null) {
-            httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND);
-            return;
+        @Override
+        public String getPathInfo() {
+            return m_pathInfo;
         }
 
-        m_servletPipeline = new CustomServletPipeline(new ServletHandler[] { 
target });
+        @Override
+        public String getServletPath() {
+            return m_servletPath;
+        }
 
-        FilterChain chain = new CustomFilterChain(filterHandlers, 
m_servletPipeline, proceedingChain);
-        chain.doFilter(new DispatcherRequestWrapper(httpServletRequest, 
target.getAlias()), httpServletResponse);
+        @Override
+        public RequestDispatcher getRequestDispatcher(String path) {
+            ServletHandler servletHandler =
+                
m_customFilterPipeline.getServletHandlerRegistry().getServletHandler(this, 
path);
+            if (servletHandler != null) {
+                return new DispatcherRequestDispatcher(servletHandler, path);
+            }
+            return null;
+        }
     }
 
-    private final class DispatcherRequestWrapper extends 
HttpServletRequestWrapper {
+    /**
+     * Application <code>HttpServletRequestWrapper</code> for forward 
requests. It wraps the original request
+     * so that subsequent calls to <code>getServletPath()</code> and 
<code>getPathInfo()</code>
+     * correspond to the new target <code>ServletHandler</code>.
+     */
+    static final class DispatcherForwardRequestWrapper extends 
HttpServletRequestWrapper {
 
-        private final String m_pathInfo;
         private final String m_servletPath;
+        private final String m_path;
 
-        public DispatcherRequestWrapper(HttpServletRequest httpServletRequest, 
String servletAlias) {
+        public DispatcherForwardRequestWrapper(HttpServletRequest 
httpServletRequest, String servletAlias, String path) {
             super(httpServletRequest);
-
-            m_servletPath = httpServletRequest.getContextPath() + servletAlias;
-            m_pathInfo = 
httpServletRequest.getPathInfo().replaceFirst(servletAlias, "");
+            m_servletPath = servletAlias;
+            m_path = path;
         }
 
         @Override
         public String getPathInfo() {
-            return m_pathInfo;
+            return m_path.substring(m_servletPath.length());
         }
 
         @Override
@@ -100,9 +167,15 @@
         }
 
         @Override
-        public RequestDispatcher getRequestDispatcher(String path) {
-            final RequestDispatcher dispatcher = 
m_servletPipeline.getRequestDispatcher(this, path);
-            return (null != dispatcher) ? dispatcher : 
super.getRequestDispatcher(path);
+        public String getRequestURI() {
+            return getContextPath() + m_path;
+        }
+
+        @Override
+        public StringBuffer getRequestURL() {
+            String url = super.getRequestURL().toString();
+            url = url.replace(super.getRequestURI(), getRequestURI());
+            return new StringBuffer(url);
         }
     }
 }

Modified: 
branches/AMDATU-283-dev/amdatu-web/dispatcher/src/main/java/org/amdatu/web/dispatcher/dispatch/ExtenderFilterPipeline.java
==============================================================================
--- 
branches/AMDATU-283-dev/amdatu-web/dispatcher/src/main/java/org/amdatu/web/dispatcher/dispatch/ExtenderFilterPipeline.java
  (original)
+++ 
branches/AMDATU-283-dev/amdatu-web/dispatcher/src/main/java/org/amdatu/web/dispatcher/dispatch/ExtenderFilterPipeline.java
  Thu Apr  7 15:09:11 2011
@@ -41,7 +41,7 @@
 
     public void dispatch(HttpServletRequest httpServletRequest, 
HttpServletResponse httpServletResponse,
         FilterChain proceedingChain) throws ServletException, IOException {
-        FilterChain chain = new ExtenderFilterChain(m_filterHandlers, 
m_tenantFilterPipeline, proceedingChain);
+        ExtenderFilterChain chain = new ExtenderFilterChain(m_filterHandlers, 
m_tenantFilterPipeline, proceedingChain);
         chain.doFilter(httpServletRequest, httpServletResponse);
     }
 }
\ No newline at end of file

Modified: 
branches/AMDATU-283-dev/amdatu-web/dispatcher/src/main/java/org/amdatu/web/dispatcher/handler/AbstractHandler.java
==============================================================================
--- 
branches/AMDATU-283-dev/amdatu-web/dispatcher/src/main/java/org/amdatu/web/dispatcher/handler/AbstractHandler.java
  (original)
+++ 
branches/AMDATU-283-dev/amdatu-web/dispatcher/src/main/java/org/amdatu/web/dispatcher/handler/AbstractHandler.java
  Thu Apr  7 15:09:11 2011
@@ -25,6 +25,10 @@
 
 import org.amdatu.web.dispatcher.context.ExtServletContext;
 
+/**
+ * Abstract handler implementing base logic for <code>ServletHandler</code> and
+ * <code>FilterHandler</code>.
+ */
 public abstract class AbstractHandler {
 
     public enum State {
@@ -39,7 +43,7 @@
     protected final int m_ranking;
 
     protected final String m_contextId;
-    
+
     private ExtServletContext m_servletContext;
     private State m_state;
 
@@ -75,10 +79,10 @@
         return m_state;
     }
 
-    public final boolean isActive(){
+    public final boolean isActive() {
         return m_state == State.INITIALIZED;
     }
-    
+
     protected final ExtServletContext getContext() {
         return m_servletContext;
     }
@@ -111,8 +115,8 @@
     public final void destroy() {
         State oldState = m_state;
         m_state = State.DESTROYED;
-        if(oldState == State.INITIALIZED){
-            doDestroy();            
+        if (oldState == State.INITIALIZED) {
+            doDestroy();
         }
     }
 

Modified: 
branches/AMDATU-283-dev/amdatu-web/dispatcher/src/main/java/org/amdatu/web/dispatcher/handler/AbstractHandlerRegistry.java
==============================================================================
--- 
branches/AMDATU-283-dev/amdatu-web/dispatcher/src/main/java/org/amdatu/web/dispatcher/handler/AbstractHandlerRegistry.java
  (original)
+++ 
branches/AMDATU-283-dev/amdatu-web/dispatcher/src/main/java/org/amdatu/web/dispatcher/handler/AbstractHandlerRegistry.java
  Thu Apr  7 15:09:11 2011
@@ -43,9 +43,6 @@
         if (previousHttpContext == null) {
             httpContextAdded(contextId, context);
         }
-        else {
-            // FIXME illegal state
-        }
     }
 
     public abstract void httpContextAdded(String contextId, HttpContext 
context);
@@ -55,9 +52,6 @@
         if (previousHttpContext != null) {
             httpContextRemoved(contextId);
         }
-        else {
-            // FIXME illegal state
-        }
     }
 
     public abstract void httpContextRemoved(String contextId);

Modified: 
branches/AMDATU-283-dev/amdatu-web/dispatcher/src/main/java/org/amdatu/web/dispatcher/handler/FilterHandler.java
==============================================================================
--- 
branches/AMDATU-283-dev/amdatu-web/dispatcher/src/main/java/org/amdatu/web/dispatcher/handler/FilterHandler.java
    (original)
+++ 
branches/AMDATU-283-dev/amdatu-web/dispatcher/src/main/java/org/amdatu/web/dispatcher/handler/FilterHandler.java
    Thu Apr  7 15:09:11 2011
@@ -72,7 +72,12 @@
         }
 
         if (isActive() && matches(localRequestUri)) {
-            doHandle(httpServletRequest, httpServletResponse, filterChain);
+            if (!getContext().handleSecurity(httpServletRequest, 
httpServletResponse)) {
+                
httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN);
+            }
+            else {
+                m_filter.doFilter(httpServletRequest, httpServletResponse, 
filterChain);
+            }
             return;
         }
         filterChain.doFilter(httpServletRequest, httpServletResponse);
@@ -92,14 +97,4 @@
         }
         return other.m_ranking - m_ranking;
     }
-
-    private void doHandle(HttpServletRequest req, HttpServletResponse res, 
FilterChain chain)
-        throws ServletException, IOException {
-        if (!getContext().handleSecurity(req, res)) {
-            res.sendError(HttpServletResponse.SC_FORBIDDEN);
-        }
-        else {
-            m_filter.doFilter(req, res, chain);
-        }
-    }
 }

Modified: 
branches/AMDATU-283-dev/amdatu-web/dispatcher/src/main/java/org/amdatu/web/dispatcher/handler/FilterHandlerRegistry.java
==============================================================================
--- 
branches/AMDATU-283-dev/amdatu-web/dispatcher/src/main/java/org/amdatu/web/dispatcher/handler/FilterHandlerRegistry.java
    (original)
+++ 
branches/AMDATU-283-dev/amdatu-web/dispatcher/src/main/java/org/amdatu/web/dispatcher/handler/FilterHandlerRegistry.java
    Thu Apr  7 15:09:11 2011
@@ -309,10 +309,8 @@
 
     @Override
     public void httpContextRemoved(String contextId) {
-
         m_extenderFilterHandlersLock.readLock().lock();
         try {
-
             for (FilterHandler handler : m_extenderFilterHandlers.values()) {
                 if (handler.isActive() && 
handler.getContextId().equals(contextId)) {
                     handler.destroy();
@@ -325,7 +323,6 @@
 
         m_filterHandlersLock.readLock().lock();
         try {
-
             for (FilterHandler handler : m_filterHandlers.values()) {
                 if (handler.isActive() && 
handler.getContextId().equals(contextId)) {
                     handler.destroy();

Modified: 
branches/AMDATU-283-dev/amdatu-web/dispatcher/src/main/java/org/amdatu/web/dispatcher/handler/ServletHandler.java
==============================================================================
--- 
branches/AMDATU-283-dev/amdatu-web/dispatcher/src/main/java/org/amdatu/web/dispatcher/handler/ServletHandler.java
   (original)
+++ 
branches/AMDATU-283-dev/amdatu-web/dispatcher/src/main/java/org/amdatu/web/dispatcher/handler/ServletHandler.java
   Thu Apr  7 15:09:11 2011
@@ -61,14 +61,15 @@
 
     public boolean handle(HttpServletRequest httpServletRequest, 
HttpServletResponse httpServletResponse)
         throws ServletException, IOException {
-
-        String localRequestUri = httpServletRequest.getRequestURI();
-        if (!httpServletRequest.getContextPath().equals("")) {
-            localRequestUri = 
localRequestUri.replaceFirst(httpServletRequest.getContextPath(), "");
-        }
-
-        if (isActive() && matches(localRequestUri)) {
-            doHandle(httpServletRequest, httpServletResponse);
+        if (isActive()) {
+            if (!getContext().handleSecurity(httpServletRequest, 
httpServletResponse)) {
+                if (!httpServletResponse.isCommitted()) {
+                    
httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN);
+                }
+            }
+            else {
+                m_servlet.service(httpServletRequest, httpServletResponse);
+            }
             return true;
         }
         return false;
@@ -97,16 +98,4 @@
         }
         return other.m_alias.length() - m_alias.length();
     }
-
-    private void doHandle(HttpServletRequest httpServletRequest, 
HttpServletResponse httpServletResponse)
-        throws ServletException, IOException {
-        if (!getContext().handleSecurity(httpServletRequest, 
httpServletResponse)) {
-            if (!httpServletResponse.isCommitted()) {
-                
httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN);
-            }
-        }
-        else {
-            m_servlet.service(httpServletRequest, httpServletResponse);
-        }
-    }
 }

Modified: 
branches/AMDATU-283-dev/amdatu-web/dispatcher/src/main/java/org/amdatu/web/dispatcher/handler/ServletHandlerRegistry.java
==============================================================================
--- 
branches/AMDATU-283-dev/amdatu-web/dispatcher/src/main/java/org/amdatu/web/dispatcher/handler/ServletHandlerRegistry.java
   (original)
+++ 
branches/AMDATU-283-dev/amdatu-web/dispatcher/src/main/java/org/amdatu/web/dispatcher/handler/ServletHandlerRegistry.java
   Thu Apr  7 15:09:11 2011
@@ -172,11 +172,44 @@
         }
     }
 
+    public ServletHandler getServletHandler(HttpServletRequest 
httpServletRequest, String path) {
+
+        if (path == null) {
+            return null;
+        }
+        if (path.equals("")) {
+            path = "/";
+        }
+
+        ServletHandler[] servletHandlers = 
getServletHandlers(httpServletRequest);
+        if (servletHandlers == null) {
+            return null;
+        }
+
+        ServletHandler target = null;
+        for (ServletHandler handler : servletHandlers) {
+            if (handler.isActive() && handler.matches(path)) {
+                target = handler;
+                break;
+            }
+        }
+        return target;
+    }
+
+    public ServletHandler getServletHandler(HttpServletRequest 
httpServletRequest) {
+
+        String localRequestUri = httpServletRequest.getRequestURI();
+        if (!httpServletRequest.getContextPath().equals("")) {
+            localRequestUri = 
localRequestUri.replaceFirst(httpServletRequest.getContextPath(), "");
+        }
+
+        return getServletHandler(httpServletRequest, localRequestUri);
+    }
+
     public ServletHandler[] getServletHandlers(HttpServletRequest 
httpServletRequest) {
 
         Tenant tenant =
             (Tenant) 
httpServletRequest.getAttribute(DispatcherService.TENANT_REQUESTCONTEXT_KEY);
-
         String tenantId = "";
         if (tenant != null) {
             tenantId = tenant.getId();

Added: 
branches/AMDATU-283-dev/amdatu-web/dispatcher/src/test/java/org/amdatu/web/dispatcher/dispatch/DispatcherForwardRequestWrapperTest.java
==============================================================================
--- (empty file)
+++ 
branches/AMDATU-283-dev/amdatu-web/dispatcher/src/test/java/org/amdatu/web/dispatcher/dispatch/DispatcherForwardRequestWrapperTest.java
     Thu Apr  7 15:09:11 2011
@@ -0,0 +1,49 @@
+package org.amdatu.web.dispatcher.dispatch;
+
+import javax.servlet.http.HttpServletRequest;
+
+import junit.framework.Assert;
+
+import 
org.amdatu.web.dispatcher.dispatch.CustomFilterPipeline.DispatcherForwardRequestWrapper;
+import org.jmock.Expectations;
+import org.jmock.Mockery;
+import org.junit.Test;
+
+public class DispatcherForwardRequestWrapperTest {
+
+    @Test
+    public void testForwardWrapping() {
+
+        final Mockery mockContext = new Mockery();
+        final HttpServletRequest request = 
mockContext.mock(HttpServletRequest.class);
+        mockContext.checking(new Expectations() {
+            {
+                allowing(request).getRequestURL();
+                will(returnValue(new StringBuffer(
+                    
"http://localhost:3737/amdatu/dashboard/jsp/dashboard.jsp?hello=world";)));
+                allowing(request).getContextPath();
+                will(returnValue("/amdatu"));
+                allowing(request).getRequestURI();
+                will(returnValue("/amdatu/dashboard/jsp/dashboard.jsp"));
+                allowing(request).getServletPath();
+                will(returnValue("/dashboard/jsp"));
+                allowing(request).getPathInfo();
+                will(returnValue("/dashboard.jsp"));
+                allowing(request).getQueryString();
+                will(returnValue("hello=world"));
+            }
+        });
+
+        DispatcherForwardRequestWrapper wrapper =
+            new DispatcherForwardRequestWrapper(request, "/whatever/alias", 
"/whatever/alias/bla.jsp");
+
+        Assert
+            
.assertEquals("http://localhost:3737/amdatu/whatever/alias/bla.jsp?hello=world";,
+                wrapper.getRequestURL().toString());
+        Assert.assertEquals("/amdatu", wrapper.getContextPath());
+        Assert.assertEquals("/amdatu/whatever/alias/bla.jsp", 
wrapper.getRequestURI());
+        Assert.assertEquals("/whatever/alias", wrapper.getServletPath());
+        Assert.assertEquals("/bla.jsp", wrapper.getPathInfo());
+        Assert.assertEquals("hello=world", wrapper.getQueryString());
+    }
+}

Added: 
branches/AMDATU-283-dev/amdatu-web/dispatcher/src/test/java/org/amdatu/web/dispatcher/dispatch/DispatcherRequestWrapperTest.java
==============================================================================
--- (empty file)
+++ 
branches/AMDATU-283-dev/amdatu-web/dispatcher/src/test/java/org/amdatu/web/dispatcher/dispatch/DispatcherRequestWrapperTest.java
    Thu Apr  7 15:09:11 2011
@@ -0,0 +1,58 @@
+package org.amdatu.web.dispatcher.dispatch;
+
+import javax.servlet.http.HttpServletRequest;
+
+import junit.framework.Assert;
+
+import 
org.amdatu.web.dispatcher.dispatch.CustomFilterPipeline.DispatcherRequestWrapper;
+import org.jmock.Expectations;
+import org.jmock.Mockery;
+import org.junit.Ignore;
+import org.junit.Test;
+
+/**
+ * Test behavior of the standard <code>DispatcherRequestWrapper</code>.
+ * 
+ * FIXME ignored cause CustomFilterPipeline is not an interface so this
+ * does not work yet.
+ */
+public class DispatcherRequestWrapperTest {
+
+    @Ignore
+    @Test
+    public void testWrapping() {
+
+        final Mockery mockContext = new Mockery();
+        final CustomFilterPipeline pipeline = 
mockContext.mock(CustomFilterPipeline.class);
+        final HttpServletRequest request = 
mockContext.mock(HttpServletRequest.class);
+        mockContext.checking(new Expectations() {
+            {
+                allowing(request).getRequestURL();
+                will(returnValue(new StringBuffer(
+                    
"http://localhost:3737/amdatu/dashboard/jsp/dashboard.jsp?hello=world";)));
+                allowing(request).getContextPath();
+                will(returnValue("/amdatu"));
+                allowing(request).getRequestURI();
+                will(returnValue("/amdatu/dashboard/jsp/dashboard.jsp"));
+                allowing(request).getServletPath();
+                will(returnValue(""));
+                allowing(request).getPathInfo();
+                will(returnValue("/dashboard/jsp/dashboard.jsp"));
+                allowing(request).getQueryString();
+                will(returnValue("hello=world"));
+            }
+        });
+
+        DispatcherRequestWrapper wrapper =
+            new DispatcherRequestWrapper(pipeline, request, "/dashboard/jsp");
+
+        Assert
+            
.assertEquals("http://localhost:3737/amdatu/dashboard/jsp/dashboard.jsp?hello=world";,
+                wrapper.getRequestURL().toString());
+        Assert.assertEquals("/amdatu", wrapper.getContextPath());
+        Assert.assertEquals("/amdatu/dashboard/jsp", wrapper.getRequestURI());
+        Assert.assertEquals("/dashboard/jsp", wrapper.getServletPath());
+        Assert.assertEquals("/dashboard.jsp", wrapper.getPathInfo());
+        Assert.assertEquals("hello=world", wrapper.getQueryString());
+    }
+}

Modified: 
branches/AMDATU-283-dev/amdatu-web/httpcontext/src/main/java/org/amdatu/web/httpcontext/HttpContextManagerService.java
==============================================================================
--- 
branches/AMDATU-283-dev/amdatu-web/httpcontext/src/main/java/org/amdatu/web/httpcontext/HttpContextManagerService.java
      (original)
+++ 
branches/AMDATU-283-dev/amdatu-web/httpcontext/src/main/java/org/amdatu/web/httpcontext/HttpContextManagerService.java
      Thu Apr  7 15:09:11 2011
@@ -1,3 +1,19 @@
+/*
+    Copyright (C) 2010 Amdatu.org
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
 package org.amdatu.web.httpcontext;
 
 /**

Modified: 
branches/AMDATU-283-dev/amdatu-web/httpcontext/src/main/java/org/amdatu/web/httpcontext/MimeTypeResolver.java
==============================================================================
--- 
branches/AMDATU-283-dev/amdatu-web/httpcontext/src/main/java/org/amdatu/web/httpcontext/MimeTypeResolver.java
       (original)
+++ 
branches/AMDATU-283-dev/amdatu-web/httpcontext/src/main/java/org/amdatu/web/httpcontext/MimeTypeResolver.java
       Thu Apr  7 15:09:11 2011
@@ -1,3 +1,19 @@
+/*
+    Copyright (C) 2010 Amdatu.org
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
 package org.amdatu.web.httpcontext;
 
 public interface MimeTypeResolver {

Modified: 
branches/AMDATU-283-dev/amdatu-web/httpcontext/src/main/java/org/amdatu/web/httpcontext/SecurityHandler.java
==============================================================================
--- 
branches/AMDATU-283-dev/amdatu-web/httpcontext/src/main/java/org/amdatu/web/httpcontext/SecurityHandler.java
        (original)
+++ 
branches/AMDATU-283-dev/amdatu-web/httpcontext/src/main/java/org/amdatu/web/httpcontext/SecurityHandler.java
        Thu Apr  7 15:09:11 2011
@@ -1,3 +1,19 @@
+/*
+    Copyright (C) 2010 Amdatu.org
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
 package org.amdatu.web.httpcontext;
 
 import java.io.IOException;

Added: 
branches/AMDATU-283-dev/amdatu-web/httpcontext/src/test/java/org/amdatu/web/httpcontext/context/DelegatingHttpContextTest.java
==============================================================================
--- (empty file)
+++ 
branches/AMDATU-283-dev/amdatu-web/httpcontext/src/test/java/org/amdatu/web/httpcontext/context/DelegatingHttpContextTest.java
      Thu Apr  7 15:09:11 2011
@@ -0,0 +1,89 @@
+package org.amdatu.web.httpcontext.context;
+
+import java.net.URL;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import junit.framework.Assert;
+
+import org.amdatu.web.httpcontext.MimeTypeResolver;
+import org.amdatu.web.httpcontext.ResourceProvider;
+import org.amdatu.web.httpcontext.SecurityHandler;
+import org.jmock.Expectations;
+import org.jmock.Mockery;
+import org.junit.Test;
+
+public class DelegatingHttpContextTest {
+
+    @Test
+    public void testResourceProviderDelegation() throws Exception {
+
+        final Mockery mockContext = new Mockery();
+        final DelegatingHttpContext httpContext = new 
DelegatingHttpContext("test-context");
+        final ResourceProvider provider1 = 
mockContext.mock(ResourceProvider.class, "mock1");
+        final ResourceProvider provider2 = 
mockContext.mock(ResourceProvider.class, "mock2");
+        httpContext.addResourceProvider(provider1);
+        httpContext.addResourceProvider(provider2);
+
+        mockContext.checking(new Expectations() {
+            {
+                one(provider1).getResource(with("file.txt"));
+                will(returnValue(null));
+                one(provider2).getResource(with("file.txt"));
+                will(returnValue(new URL("http", "whatever", "file.txt")));
+            }
+        });
+
+        Assert.assertNotNull(httpContext.getResource("file.txt"));
+        mockContext.assertIsSatisfied();
+    }
+
+    @Test
+    public void testMimetypeResolverDelegation() throws Exception {
+
+        final Mockery mockContext = new Mockery();
+        final DelegatingHttpContext httpContext = new 
DelegatingHttpContext("test-context");
+        final MimeTypeResolver resolver1 = 
mockContext.mock(MimeTypeResolver.class, "mock1");
+        final MimeTypeResolver resolver2 = 
mockContext.mock(MimeTypeResolver.class, "mock2");
+        httpContext.addMimeTypeResolver(resolver1);
+        httpContext.addMimeTypeResolver(resolver2);
+
+        mockContext.checking(new Expectations() {
+            {
+                one(resolver1).getMimetype((with("file.xyz")));
+                will(returnValue(null));
+                one(resolver2).getMimetype((with("file.xyz")));
+                will(returnValue("bla/xyz"));
+            }
+        });
+
+        Assert.assertEquals("bla/xyz", httpContext.getMimeType("file.xyz"));
+        mockContext.assertIsSatisfied();
+    }
+
+    @Test
+    public void testSecurityHandlerDelegation() throws Exception {
+
+        final Mockery mockContext = new Mockery();
+        final DelegatingHttpContext httpContext = new 
DelegatingHttpContext("test-context");
+        final SecurityHandler resolver1 = 
mockContext.mock(SecurityHandler.class, "mock1");
+        final SecurityHandler resolver2 = 
mockContext.mock(SecurityHandler.class, "mock2");
+        final HttpServletRequest request = 
mockContext.mock(HttpServletRequest.class);
+        final HttpServletResponse response = 
mockContext.mock(HttpServletResponse.class);
+        httpContext.addSecurityHandler(resolver1);
+        httpContext.addSecurityHandler(resolver2);
+
+        mockContext.checking(new Expectations() {
+            {
+                one(resolver1).handleSecurity(request, response);
+                will(returnValue(true));
+                one(resolver2).handleSecurity(request, response);
+                will(returnValue(false));
+            }
+        });
+
+        Assert.assertFalse(httpContext.handleSecurity(request, response));
+        mockContext.assertIsSatisfied();
+    }
+}

Modified: 
branches/AMDATU-283-dev/amdatu-web/jsp/src/main/java/org/amdatu/web/jsp/JspSupport.java
==============================================================================
--- 
branches/AMDATU-283-dev/amdatu-web/jsp/src/main/java/org/amdatu/web/jsp/JspSupport.java
     (original)
+++ 
branches/AMDATU-283-dev/amdatu-web/jsp/src/main/java/org/amdatu/web/jsp/JspSupport.java
     Thu Apr  7 15:09:11 2011
@@ -1,3 +1,19 @@
+/*
+    Copyright (C) 2010 Amdatu.org
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
 package org.amdatu.web.jsp;
 
 /**

Modified: 
branches/AMDATU-283-dev/amdatu-web/resource/src/main/java/org/amdatu/web/resource/ResourceSupport.java
==============================================================================
--- 
branches/AMDATU-283-dev/amdatu-web/resource/src/main/java/org/amdatu/web/resource/ResourceSupport.java
      (original)
+++ 
branches/AMDATU-283-dev/amdatu-web/resource/src/main/java/org/amdatu/web/resource/ResourceSupport.java
      Thu Apr  7 15:09:11 2011
@@ -1,3 +1,19 @@
+/*
+    Copyright (C) 2010 Amdatu.org
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
 package org.amdatu.web.resource;
 
 /**

Modified: 
branches/AMDATU-283-dev/amdatu-web/rest-wink/src/main/java/org/amdatu/web/rest/wink/service/WinkRestServlet.java
==============================================================================
--- 
branches/AMDATU-283-dev/amdatu-web/rest-wink/src/main/java/org/amdatu/web/rest/wink/service/WinkRestServlet.java
    (original)
+++ 
branches/AMDATU-283-dev/amdatu-web/rest-wink/src/main/java/org/amdatu/web/rest/wink/service/WinkRestServlet.java
    Thu Apr  7 15:09:11 2011
@@ -29,19 +29,13 @@
 import org.apache.wink.server.utils.RegistrationUtils;
 
 /**
- * Override the default RestServlet since that implementation does not 
unregister REST servlets well. It does
- * unregister the servlet but 'forgets' to remove the resources from the 
ResourceRegistry. The ResourceRegistry is
- * associated with the RequestProcessor which is associated with the servlet 
context. Since the servlet context
- * is not changed when a REST servlet is unregistered/registerd, the request 
processor instance is the same for
- * all REST servlets and uneffected. This overridden implementation forces the 
request processor to be tight to
- * the servlet instance.
- * 
- * @author ivol
+ * Extends the default Apache Wink <code>RestServlet</code> to handle multiple
+ * processors and wrap incomming requests to match resources.
  */
 public class WinkRestServlet extends RestServlet {
 
     private final String m_resourceName;
-    
+
     // Indicates if this REST servlet has been initialized
     boolean m_initialized = false;
 
@@ -49,15 +43,10 @@
     private String m_requestProcessorId;
     private Object m_service;
 
-    /**
-     * Constructor.
-     * 
-     * @param servletUrl The URL which serves this servlet
-     */
-    public WinkRestServlet(String servletUrl, Object service, String tenantId) 
{
+    public WinkRestServlet(String resourcePath, Object service, String 
tenantId) {
         super();
-        m_resourceName = servletUrl;
-        m_requestProcessorId = servletUrl + "_" + tenantId;
+        m_resourceName = resourcePath;
+        m_requestProcessorId = resourcePath + "_" + tenantId;
         m_service = service;
     }
 
@@ -113,7 +102,7 @@
 
         @Override
         public String getRequestURI() {
-            return super.getServletPath() + getPathInfo();
+            return getContextPath() + getServletPath() + getPathInfo();
         }
     }
 }

Modified: 
branches/AMDATU-283-dev/integration-tests/src/test/java/org/amdatu/test/integration/base/IntegrationTestBase.java
==============================================================================
--- 
branches/AMDATU-283-dev/integration-tests/src/test/java/org/amdatu/test/integration/base/IntegrationTestBase.java
   (original)
+++ 
branches/AMDATU-283-dev/integration-tests/src/test/java/org/amdatu/test/integration/base/IntegrationTestBase.java
   Thu Apr  7 15:09:11 2011
@@ -17,9 +17,6 @@
 package org.amdatu.test.integration.base;
 
 import static org.ops4j.pax.exam.CoreOptions.bundle;
-import static org.ops4j.pax.exam.CoreOptions.equinox;
-import static org.ops4j.pax.exam.CoreOptions.felix;
-import static org.ops4j.pax.exam.CoreOptions.frameworks;
 import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
 import static org.ops4j.pax.exam.CoreOptions.mavenConfiguration;
 import static org.ops4j.pax.exam.CoreOptions.options;

Modified: 
branches/AMDATU-283-dev/src/main/resources/conf/felix-config.properties
==============================================================================
--- branches/AMDATU-283-dev/src/main/resources/conf/felix-config.properties     
(original)
+++ branches/AMDATU-283-dev/src/main/resources/conf/felix-config.properties     
Thu Apr  7 15:09:11 2011
@@ -78,7 +78,6 @@
 # may be specified for different start levels.
 
felix.auto.start.1=reference:file:amdatu-system/org.apache.felix.configadmin-1.2.4.jar
 \
           
reference:file:amdatu-system/org.apache.felix.dependencymanager-${org.apache.felix.dependencymanager.version}.jar
 \
-          
reference:file:amdatu-system/org.apache.felix.dependencymanager.shell-${org.apache.felix.dependencymanager.version}.jar
 \
           reference:file:amdatu-system/org.apache.felix.eventadmin-1.2.2.jar \
           
reference:file:amdatu-system/org.apache.felix.fileinstall-${org.apache.felix.file.install.version}.jar
 \
           reference:file:amdatu-system/org.apache.felix.log-1.0.0.jar \
_______________________________________________
Amdatu-commits mailing list
[email protected]
http://lists.amdatu.org/mailman/listinfo/amdatu-commits

Reply via email to