]> source.dussan.org Git - vaadin-framework.git/commitdiff
#8164 Make WrappedHttpServletRequest extend HttpServletRequestWrapper
authorLeif Åstrand <leif@vaadin.com>
Fri, 6 Jan 2012 10:27:01 +0000 (12:27 +0200)
committerLeif Åstrand <leif@vaadin.com>
Fri, 6 Jan 2012 10:27:01 +0000 (12:27 +0200)
Clean up some of the code as WrappedHttpServletRequest can directly be
used as a HttpServletRequest

Similar changes for WrappedHttpServletResponse

src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java
src/com/vaadin/terminal/gwt/server/ApplicationRunnerServlet.java
src/com/vaadin/terminal/gwt/server/WrappedHttpServletRequest.java
src/com/vaadin/terminal/gwt/server/WrappedHttpServletResponse.java

index 188e35fc2ad218fc40da9fd3c047f1d5c0568b42..b28cb361b0598c57f1ecc21b6dd1b904e135ebee 100644 (file)
@@ -75,10 +75,9 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
         public void criticalNotification(WrappedRequest request,
                 WrappedResponse response, String cap, String msg,
                 String details, String outOfSyncURL) throws IOException {
-            servlet.criticalNotification(WrappedHttpServletRequest
-                    .cast(request).getHttpServletRequest(),
-                    ((WrappedHttpServletResponse) response)
-                            .getHttpServletResponse(), cap, msg, details,
+            servlet.criticalNotification(
+                    WrappedHttpServletRequest.cast(request),
+                    ((WrappedHttpServletResponse) response), cap, msg, details,
                     outOfSyncURL);
         }
     }
@@ -144,8 +143,8 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
 
     private DeploymentConfiguration deploymentConfiguration = new DeploymentConfiguration() {
         public String getStaticFileLocation(WrappedRequest request) {
-            HttpServletRequest servletRequest = WrappedHttpServletRequest.cast(
-                    request).getHttpServletRequest();
+            HttpServletRequest servletRequest = WrappedHttpServletRequest
+                    .cast(request);
             return AbstractApplicationServlet.this
                     .getStaticFilesLocation(servletRequest);
         }
@@ -382,14 +381,17 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
      * @throws IOException
      *             if the request for the TRACE cannot be handled.
      */
-    @SuppressWarnings("unchecked")
     @Override
     protected void service(HttpServletRequest request,
             HttpServletResponse response) throws ServletException, IOException {
+        service(createWrappedRequest(request), createWrappedResponse(response));
+    }
+
+    private void service(WrappedHttpServletRequest request,
+            WrappedHttpServletResponse response) throws ServletException,
+            IOException {
         AbstractApplicationServletWrapper servletWrapper = new AbstractApplicationServletWrapper(
                 this);
-        WrappedHttpServletRequest wrappedRequest = createWrappedRequest(request);
-        WrappedHttpServletResponse wrappedResponse = createWrappedResponse(response);
 
         RequestType requestType = getRequestType(request);
         if (!ensureCookiesEnabled(requestType, request, response)) {
@@ -446,8 +448,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
                     .getApplicationManager(application, this);
 
             /* Update browser information from the request */
-            webApplicationContext.getBrowser().updateRequestDetails(
-                    wrappedRequest);
+            webApplicationContext.getBrowser().updateRequestDetails(request);
 
             /*
              * Call application requestStart before Application.init() is called
@@ -471,21 +472,20 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
 
             /* Handle the request */
             if (requestType == RequestType.FILE_UPLOAD) {
-                applicationManager.handleFileUpload(wrappedRequest,
-                        wrappedResponse);
+                applicationManager.handleFileUpload(request, response);
                 return;
             } else if (requestType == RequestType.UIDL) {
                 // Handles AJAX UIDL requests
-                Root root = application.getRootForRequest(wrappedRequest);
+                Root root = application.getRootForRequest(request);
                 if (root == null) {
                     throw new ServletException(ERROR_NO_WINDOW_FOUND);
                 }
-                applicationManager.handleUidlRequest(wrappedRequest,
-                        wrappedResponse, servletWrapper, root);
+                applicationManager.handleUidlRequest(request, response,
+                        servletWrapper, root);
                 return;
             } else if (requestType == RequestType.BROWSER_DETAILS) {
-                applicationManager.handleBrowserDetailsRequest(wrappedRequest,
-                        wrappedResponse, application);
+                applicationManager.handleBrowserDetailsRequest(request,
+                        response, application);
                 return;
             }
 
@@ -496,8 +496,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
                 return;
             }
 
-            if (applicationManager.handleApplicationRequest(wrappedRequest,
-                    wrappedResponse)) {
+            if (applicationManager.handleApplicationRequest(request, response)) {
                 return;
             }
             // TODO Should return 404 error here and not do anything more
index 1fa569fa853804147b5c42acd00a3ee437796c77..064d2b16af4a4e35065d64b1ea5d6f572abac108 100644 (file)
@@ -260,8 +260,7 @@ public class ApplicationRunnerServlet extends AbstractApplicationServlet {
                 getDeploymentConfiguration()) {
             @Override
             public String getRequestPathInfo() {
-                return ApplicationRunnerServlet.this
-                        .getRequestPathInfo(getHttpServletRequest());
+                return ApplicationRunnerServlet.this.getRequestPathInfo(this);
             }
         };
     }
index 5998f905c1babc6730022a603d163462c26365f1..b6f1a192cba25e3bfad29f6a89945e14b638c534 100644 (file)
@@ -4,12 +4,8 @@
 
 package com.vaadin.terminal.gwt.server;
 
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Locale;
-import java.util.Map;
-
 import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletRequestWrapper;
 
 import com.vaadin.Application;
 import com.vaadin.terminal.CombinedRequest;
@@ -25,9 +21,9 @@ import com.vaadin.terminal.WrappedRequest;
  * @see WrappedRequest
  * @see WrappedHttpServletResponse
  */
-public class WrappedHttpServletRequest implements WrappedRequest {
+public class WrappedHttpServletRequest extends HttpServletRequestWrapper
+        implements WrappedRequest {
 
-    private final HttpServletRequest request;
     private final DeploymentConfiguration deploymentConfiguration;
 
     /**
@@ -41,48 +37,24 @@ public class WrappedHttpServletRequest implements WrappedRequest {
      */
     public WrappedHttpServletRequest(HttpServletRequest request,
             DeploymentConfiguration deploymentConfiguration) {
-        this.request = request;
+        super(request);
         this.deploymentConfiguration = deploymentConfiguration;
     }
 
-    public Object getAttribute(String name) {
-        return request.getAttribute(name);
-    }
-
-    public int getContentLength() {
-        return request.getContentLength();
-    }
-
-    public InputStream getInputStream() throws IOException {
-        return request.getInputStream();
-    }
-
-    public String getParameter(String name) {
-        return request.getParameter(name);
-    }
-
-    public Map<String, String[]> getParameterMap() {
-        return request.getParameterMap();
-    }
-
-    public void setAttribute(String name, Object o) {
-        request.setAttribute(name, o);
-    }
-
     public String getRequestPathInfo() {
-        return request.getPathInfo();
+        return getPathInfo();
     }
 
     public int getSessionMaxInactiveInterval() {
-        return request.getSession().getMaxInactiveInterval();
+        return getSession().getMaxInactiveInterval();
     }
 
     public Object getSessionAttribute(String name) {
-        return request.getSession().getAttribute(name);
+        return getSession().getAttribute(name);
     }
 
     public void setSessionAttribute(String name, Object attribute) {
-        request.getSession().setAttribute(name, attribute);
+        getSession().setAttribute(name, attribute);
     }
 
     /**
@@ -91,11 +63,7 @@ public class WrappedHttpServletRequest implements WrappedRequest {
      * @return the servlet request
      */
     public HttpServletRequest getHttpServletRequest() {
-        return request;
-    }
-
-    public String getContentType() {
-        return request.getContentType();
+        return this;
     }
 
     public DeploymentConfiguration getDeploymentConfiguration() {
@@ -120,22 +88,6 @@ public class WrappedHttpServletRequest implements WrappedRequest {
         };
     }
 
-    public Locale getLocale() {
-        return request.getLocale();
-    }
-
-    public String getRemoteAddr() {
-        return request.getRemoteAddr();
-    }
-
-    public boolean isSecure() {
-        return request.isSecure();
-    }
-
-    public String getHeader(String headerName) {
-        return request.getHeader(headerName);
-    }
-
     /**
      * Helper method to get a <code>WrappedHttpServletRequest</code> from a
      * <code>WrappedRequest</code>. Aside from casting, this method also takes
index 03a2eb1c8d096edafb66194a190e8d7a042c5a9a..14a391b21fe0266a99f3f745f7713365ad9d347a 100644 (file)
@@ -4,11 +4,8 @@
 
 package com.vaadin.terminal.gwt.server;
 
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.PrintWriter;
-
 import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpServletResponseWrapper;
 
 import com.vaadin.terminal.DeploymentConfiguration;
 import com.vaadin.terminal.WrappedResponse;
@@ -22,9 +19,9 @@ import com.vaadin.terminal.WrappedResponse;
  * @see WrappedResponse
  * @see WrappedHttpServletRequest
  */
-public class WrappedHttpServletResponse implements WrappedResponse {
+public class WrappedHttpServletResponse extends HttpServletResponseWrapper
+        implements WrappedResponse {
 
-    private final HttpServletResponse response;
     private DeploymentConfiguration deploymentConfiguration;
 
     /**
@@ -37,37 +34,17 @@ public class WrappedHttpServletResponse implements WrappedResponse {
      */
     public WrappedHttpServletResponse(HttpServletResponse response,
             DeploymentConfiguration deploymentConfiguration) {
-        this.response = response;
+        super(response);
         this.deploymentConfiguration = deploymentConfiguration;
     }
 
-    public OutputStream getOutputStream() throws IOException {
-        return response.getOutputStream();
-    }
-
     /**
      * Gets the original unwrapped <code>HttpServletResponse</code>
      * 
      * @return the unwrapped response
      */
     public HttpServletResponse getHttpServletResponse() {
-        return response;
-    }
-
-    public void setContentType(String type) {
-        response.setContentType(type);
-    }
-
-    public PrintWriter getWriter() throws IOException {
-        return response.getWriter();
-    }
-
-    public void setStatus(int responseStatus) {
-        response.setStatus(responseStatus);
-    }
-
-    public void setHeader(String name, String value) {
-        response.setHeader(name, value);
+        return this;
     }
 
     public void setCacheTime(long milliseconds) {
@@ -90,14 +67,6 @@ public class WrappedHttpServletResponse implements WrappedResponse {
         }
     }
 
-    public void setDateHeader(String name, long timestamp) {
-        response.setDateHeader(name, timestamp);
-    }
-
-    public void sendError(int errorCode, String message) throws IOException {
-        response.sendError(errorCode, message);
-    }
-
     public DeploymentConfiguration getDeploymentConfiguration() {
         return deploymentConfiguration;
     }