Updated Branches:
  refs/heads/master cf9d262f5 -> e8fca2405

WICKET-5044: WebSocketRequest should extend from ServletWebRequest to be able 
to use WebClientInfo when needed


Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/e8fca240
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/e8fca240
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/e8fca240

Branch: refs/heads/master
Commit: e8fca2405be6c2691e0f24dee7ab8fc23b6189cf
Parents: d8ce394
Author: Martin Tzvetanov Grigorov <mgrigo...@apache.org>
Authored: Wed Feb 20 17:33:20 2013 +0200
Committer: Martin Tzvetanov Grigorov <mgrigo...@apache.org>
Committed: Wed Feb 20 17:33:20 2013 +0200

----------------------------------------------------------------------
 .../ws/api/AbstractWebSocketProcessor.java         |   39 +++++++++++++--
 .../wicket/protocol/ws/api/WebSocketRequest.java   |   27 ++++------
 .../ws/util/tester/TestWebSocketProcessor.java     |    3 +-
 .../protocol/ws/util/tester/WebSocketTester.java   |    4 ++
 .../protocol/ws/jetty/JettyWebSocketProcessor.java |    4 +-
 .../ws/jetty9/Jetty9WebSocketProcessor.java        |    4 +-
 .../ws/tomcat7/Tomcat7WebSocketFilter.java         |    4 +-
 .../ws/tomcat7/TomcatWebSocketProcessor.java       |    4 +-
 8 files changed, 59 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/e8fca240/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/AbstractWebSocketProcessor.java
----------------------------------------------------------------------
diff --git 
a/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/AbstractWebSocketProcessor.java
 
b/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/AbstractWebSocketProcessor.java
index 13818f3..16eeb5b 100644
--- 
a/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/AbstractWebSocketProcessor.java
+++ 
b/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/AbstractWebSocketProcessor.java
@@ -16,6 +16,8 @@
  */
 package org.apache.wicket.protocol.ws.api;
 
+import java.lang.reflect.Method;
+
 import javax.servlet.http.HttpServletRequest;
 
 import org.apache.wicket.Application;
@@ -24,6 +26,8 @@ import org.apache.wicket.Session;
 import org.apache.wicket.ThreadContext;
 import org.apache.wicket.event.Broadcast;
 import org.apache.wicket.page.IPageManager;
+import org.apache.wicket.protocol.http.WebApplication;
+import org.apache.wicket.protocol.http.WicketFilter;
 import org.apache.wicket.protocol.ws.IWebSocketSettings;
 import org.apache.wicket.protocol.ws.api.event.WebSocketBinaryPayload;
 import org.apache.wicket.protocol.ws.api.event.WebSocketClosedPayload;
@@ -57,10 +61,23 @@ public abstract class AbstractWebSocketProcessor implements 
IWebSocketProcessor
 {
        private static final Logger LOG = 
LoggerFactory.getLogger(AbstractWebSocketProcessor.class);
 
+       private static final Method GET_FILTER_PATH_METHOD;
+       static
+       {
+               try
+               {
+                       GET_FILTER_PATH_METHOD = 
WicketFilter.class.getDeclaredMethod("getFilterPath", new Class[]{});
+               } catch (Exception e)
+               {
+                       throw new RuntimeException(e);
+               }
+               GET_FILTER_PATH_METHOD.setAccessible(true);
+       }
+
        private final WebRequest webRequest;
        private final int pageId;
        private final Url baseUrl;
-       private final Application application;
+       private final WebApplication application;
        private final String sessionId;
        private final IWebSocketConnectionRegistry connectionRegistry;
 
@@ -72,7 +89,7 @@ public abstract class AbstractWebSocketProcessor implements 
IWebSocketProcessor
         * @param application
         *      the current Wicket Application
         */
-       public AbstractWebSocketProcessor(final HttpServletRequest request, 
final Application application)
+       public AbstractWebSocketProcessor(final HttpServletRequest request, 
final WebApplication application)
        {
                this.sessionId = request.getSession(true).getId();
                Session.get().bind();
@@ -85,13 +102,27 @@ public abstract class AbstractWebSocketProcessor 
implements IWebSocketProcessor
                Checks.notNull(baseUrl, String.format("Request parameter '%s' 
is required!", WebRequest.PARAM_AJAX_BASE_URL));
                this.baseUrl = Url.parse(baseUrl);
 
-               this.webRequest = new WebSocketRequest(new 
ServletRequestCopy(request));
+               WicketFilter wicketFilter = application.getWicketFilter();
+               this.webRequest = new WebSocketRequest(new 
ServletRequestCopy(request), getFilterPath(wicketFilter));
 
                this.application = Args.notNull(application, "application");
                IWebSocketSettings webSocketSettings = 
IWebSocketSettings.Holder.get(application);
                this.connectionRegistry = 
webSocketSettings.getConnectionRegistry();
        }
 
+       private String getFilterPath(WicketFilter wicketFilter)
+       {
+               String filterPath;
+               try
+               {
+                       filterPath = (String) 
GET_FILTER_PATH_METHOD.invoke(wicketFilter);
+               } catch (Exception e)
+               {
+                       throw new RuntimeException(e);
+               }
+               return filterPath;
+       }
+
        @Override
        public void onMessage(final String message)
        {
@@ -224,7 +255,7 @@ public abstract class AbstractWebSocketProcessor implements 
IWebSocketProcessor
                }
        }
 
-       protected final Application getApplication()
+       protected final WebApplication getApplication()
        {
                return application;
        }

http://git-wip-us.apache.org/repos/asf/wicket/blob/e8fca240/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/WebSocketRequest.java
----------------------------------------------------------------------
diff --git 
a/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/WebSocketRequest.java
 
b/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/WebSocketRequest.java
index c9ac95b..f7eaf5b 100644
--- 
a/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/WebSocketRequest.java
+++ 
b/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/WebSocketRequest.java
@@ -26,6 +26,7 @@ import javax.servlet.http.Cookie;
 import javax.servlet.http.HttpServletRequest;
 
 import org.apache.wicket.protocol.http.RequestUtils;
+import org.apache.wicket.protocol.http.servlet.ServletWebRequest;
 import org.apache.wicket.request.Url;
 import org.apache.wicket.request.http.WebRequest;
 import org.apache.wicket.util.lang.Generics;
@@ -38,32 +39,30 @@ import org.apache.wicket.util.time.Time;
  *
  * @since 6.0
  */
-public class WebSocketRequest extends WebRequest
+public class WebSocketRequest extends ServletWebRequest
 {
-       private final HttpServletRequest request;
-
        /**
         * Constructor.
         *
         * @param req
         *      the copy of the HttpServletRequest used for the upgrade of the 
HTTP protocol
         */
-       public WebSocketRequest(HttpServletRequest req)
+       public WebSocketRequest(HttpServletRequest req, String filterPrefix)
        {
-               this.request = req;
+               super(req, filterPrefix);
        }
 
        @Override
        public List<Cookie> getCookies()
        {
-               List<Cookie> cookies = Arrays.asList(request.getCookies());
+               List<Cookie> cookies = 
Arrays.asList(getContainerRequest().getCookies());
                return cookies;
        }
 
        @Override
        public List<String> getHeaders(String name)
        {
-               Enumeration<String> headers = request.getHeaders(name);
+               Enumeration<String> headers = 
getContainerRequest().getHeaders(name);
                List<String> h = Generics.newArrayList();
                while (headers.hasMoreElements())
                {
@@ -76,13 +75,13 @@ public class WebSocketRequest extends WebRequest
        @Override
        public String getHeader(String name)
        {
-               return request.getHeader(name);
+               return getContainerRequest().getHeader(name);
        }
 
        @Override
        public Time getDateHeader(String name)
        {
-               long dateHeader = request.getDateHeader(name);
+               long dateHeader = getContainerRequest().getDateHeader(name);
                return Time.millis(dateHeader);
        }
 
@@ -101,19 +100,13 @@ public class WebSocketRequest extends WebRequest
        @Override
        public Locale getLocale()
        {
-               return request.getLocale();
+               return getContainerRequest().getLocale();
        }
 
        @Override
        public Charset getCharset()
        {
-               return RequestUtils.getCharset(request);
-       }
-
-       @Override
-       public Object getContainerRequest()
-       {
-               return request;
+               return RequestUtils.getCharset(getContainerRequest());
        }
 
        @Override

http://git-wip-us.apache.org/repos/asf/wicket/blob/e8fca240/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/util/tester/TestWebSocketProcessor.java
----------------------------------------------------------------------
diff --git 
a/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/util/tester/TestWebSocketProcessor.java
 
b/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/util/tester/TestWebSocketProcessor.java
index 69ab800..0d79e9e 100644
--- 
a/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/util/tester/TestWebSocketProcessor.java
+++ 
b/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/util/tester/TestWebSocketProcessor.java
@@ -21,6 +21,7 @@ import javax.servlet.http.HttpSession;
 
 import org.apache.wicket.Application;
 import org.apache.wicket.Page;
+import org.apache.wicket.protocol.http.WebApplication;
 import org.apache.wicket.protocol.http.mock.MockHttpServletRequest;
 import org.apache.wicket.protocol.ws.api.AbstractWebSocketProcessor;
 import org.apache.wicket.protocol.ws.api.message.IWebSocketPushMessage;
@@ -43,7 +44,7 @@ abstract class TestWebSocketProcessor extends 
AbstractWebSocketProcessor
         */
        public TestWebSocketProcessor(final WicketTester wicketTester, final 
Page page)
        {
-               super(createRequest(wicketTester, page), page.getApplication());
+               super(createRequest(wicketTester, page), (WebApplication) 
page.getApplication());
        }
 
        /**

http://git-wip-us.apache.org/repos/asf/wicket/blob/e8fca240/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/util/tester/WebSocketTester.java
----------------------------------------------------------------------
diff --git 
a/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/util/tester/WebSocketTester.java
 
b/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/util/tester/WebSocketTester.java
index 2cd6eeb..761690b 100644
--- 
a/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/util/tester/WebSocketTester.java
+++ 
b/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/util/tester/WebSocketTester.java
@@ -17,6 +17,7 @@
 package org.apache.wicket.protocol.ws.util.tester;
 
 import org.apache.wicket.Page;
+import org.apache.wicket.protocol.http.WebApplication;
 import org.apache.wicket.protocol.ws.api.IWebSocketProcessor;
 import org.apache.wicket.util.lang.Args;
 import org.apache.wicket.util.tester.WicketTester;
@@ -43,6 +44,9 @@ public class WebSocketTester
                Args.notNull(wicketTester, "wicketTester");
                Args.notNull(page, "page");
 
+               WebApplication webApplication = wicketTester.getApplication();
+               webApplication.getWicketFilter().setFilterPath("");
+
                socketProcessor = new TestWebSocketProcessor(wicketTester, 
page) {
 
                        @Override

http://git-wip-us.apache.org/repos/asf/wicket/blob/e8fca240/wicket-experimental/wicket-native-websocket/wicket-native-websocket-jetty/src/main/java/org/apache/wicket/protocol/ws/jetty/JettyWebSocketProcessor.java
----------------------------------------------------------------------
diff --git 
a/wicket-experimental/wicket-native-websocket/wicket-native-websocket-jetty/src/main/java/org/apache/wicket/protocol/ws/jetty/JettyWebSocketProcessor.java
 
b/wicket-experimental/wicket-native-websocket/wicket-native-websocket-jetty/src/main/java/org/apache/wicket/protocol/ws/jetty/JettyWebSocketProcessor.java
index 3665611..bab53e4 100644
--- 
a/wicket-experimental/wicket-native-websocket/wicket-native-websocket-jetty/src/main/java/org/apache/wicket/protocol/ws/jetty/JettyWebSocketProcessor.java
+++ 
b/wicket-experimental/wicket-native-websocket/wicket-native-websocket-jetty/src/main/java/org/apache/wicket/protocol/ws/jetty/JettyWebSocketProcessor.java
@@ -18,7 +18,7 @@ package org.apache.wicket.protocol.ws.jetty;
 
 import javax.servlet.http.HttpServletRequest;
 
-import org.apache.wicket.Application;
+import org.apache.wicket.protocol.http.WebApplication;
 import org.apache.wicket.protocol.ws.api.AbstractWebSocketProcessor;
 import org.eclipse.jetty.websocket.WebSocket;
 
@@ -65,7 +65,7 @@ public class JettyWebSocketProcessor extends 
AbstractWebSocketProcessor
         * @param application
         *      the current Wicket Application
         */
-       public JettyWebSocketProcessor(final HttpServletRequest request, final 
Application application)
+       public JettyWebSocketProcessor(final HttpServletRequest request, final 
WebApplication application)
        {
                super(request, application);
        }

http://git-wip-us.apache.org/repos/asf/wicket/blob/e8fca240/wicket-experimental/wicket-native-websocket/wicket-native-websocket-jetty9/src/main/java/org/apache/wicket/protocol/ws/jetty9/Jetty9WebSocketProcessor.java
----------------------------------------------------------------------
diff --git 
a/wicket-experimental/wicket-native-websocket/wicket-native-websocket-jetty9/src/main/java/org/apache/wicket/protocol/ws/jetty9/Jetty9WebSocketProcessor.java
 
b/wicket-experimental/wicket-native-websocket/wicket-native-websocket-jetty9/src/main/java/org/apache/wicket/protocol/ws/jetty9/Jetty9WebSocketProcessor.java
index fbb7625..9f0f53f 100644
--- 
a/wicket-experimental/wicket-native-websocket/wicket-native-websocket-jetty9/src/main/java/org/apache/wicket/protocol/ws/jetty9/Jetty9WebSocketProcessor.java
+++ 
b/wicket-experimental/wicket-native-websocket/wicket-native-websocket-jetty9/src/main/java/org/apache/wicket/protocol/ws/jetty9/Jetty9WebSocketProcessor.java
@@ -19,7 +19,7 @@ package org.apache.wicket.protocol.ws.jetty9;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletRequestWrapper;
 
-import org.apache.wicket.Application;
+import org.apache.wicket.protocol.http.WebApplication;
 import org.apache.wicket.protocol.ws.api.AbstractWebSocketProcessor;
 import org.eclipse.jetty.websocket.core.annotations.WebSocket;
 import org.eclipse.jetty.websocket.core.api.UpgradeRequest;
@@ -53,7 +53,7 @@ public class Jetty9WebSocketProcessor extends 
AbstractWebSocketProcessor
         *            the current Wicket Application
         */
        public Jetty9WebSocketProcessor(final UpgradeRequest upgradeRequest,
-               final UpgradeResponse upgradeResponse, final Application 
application)
+               final UpgradeResponse upgradeResponse, final WebApplication 
application)
        {
                
super((HttpServletRequest)((HttpServletRequestWrapper)upgradeRequest).getRequest(),
                        application);

http://git-wip-us.apache.org/repos/asf/wicket/blob/e8fca240/wicket-experimental/wicket-native-websocket/wicket-native-websocket-tomcat/src/main/java/org/apache/wicket/protocol/ws/tomcat7/Tomcat7WebSocketFilter.java
----------------------------------------------------------------------
diff --git 
a/wicket-experimental/wicket-native-websocket/wicket-native-websocket-tomcat/src/main/java/org/apache/wicket/protocol/ws/tomcat7/Tomcat7WebSocketFilter.java
 
b/wicket-experimental/wicket-native-websocket/wicket-native-websocket-tomcat/src/main/java/org/apache/wicket/protocol/ws/tomcat7/Tomcat7WebSocketFilter.java
index fbb4d0b..6d88d91 100644
--- 
a/wicket-experimental/wicket-native-websocket/wicket-native-websocket-tomcat/src/main/java/org/apache/wicket/protocol/ws/tomcat7/Tomcat7WebSocketFilter.java
+++ 
b/wicket-experimental/wicket-native-websocket/wicket-native-websocket-tomcat/src/main/java/org/apache/wicket/protocol/ws/tomcat7/Tomcat7WebSocketFilter.java
@@ -28,7 +28,7 @@ import javax.servlet.http.HttpServletResponse;
 import org.apache.catalina.connector.RequestFacade;
 import org.apache.catalina.util.Base64;
 import org.apache.tomcat.util.buf.B2CConverter;
-import org.apache.wicket.Application;
+import org.apache.wicket.protocol.http.WebApplication;
 import org.apache.wicket.protocol.ws.AbstractUpgradeFilter;
 
 /**
@@ -71,7 +71,7 @@ public class Tomcat7WebSocketFilter extends 
AbstractUpgradeFilter
                String key = req.getHeader("Sec-WebSocket-Key");
                resp.setHeader("Sec-WebSocket-Accept", getWebSocketAccept(key));
 
-               Application application = getApplication();
+               WebApplication application = getApplication();
                // Small hack until the Servlet API provides a way to do this.
                TomcatWebSocketProcessor webSocketHandler = new 
TomcatWebSocketProcessor(req, application);
                TomcatWebSocketProcessor.TomcatWebSocket tomcatWebSocket = 
webSocketHandler.new TomcatWebSocket();

http://git-wip-us.apache.org/repos/asf/wicket/blob/e8fca240/wicket-experimental/wicket-native-websocket/wicket-native-websocket-tomcat/src/main/java/org/apache/wicket/protocol/ws/tomcat7/TomcatWebSocketProcessor.java
----------------------------------------------------------------------
diff --git 
a/wicket-experimental/wicket-native-websocket/wicket-native-websocket-tomcat/src/main/java/org/apache/wicket/protocol/ws/tomcat7/TomcatWebSocketProcessor.java
 
b/wicket-experimental/wicket-native-websocket/wicket-native-websocket-tomcat/src/main/java/org/apache/wicket/protocol/ws/tomcat7/TomcatWebSocketProcessor.java
index 694b46d..b89a608 100644
--- 
a/wicket-experimental/wicket-native-websocket/wicket-native-websocket-tomcat/src/main/java/org/apache/wicket/protocol/ws/tomcat7/TomcatWebSocketProcessor.java
+++ 
b/wicket-experimental/wicket-native-websocket/wicket-native-websocket-tomcat/src/main/java/org/apache/wicket/protocol/ws/tomcat7/TomcatWebSocketProcessor.java
@@ -24,7 +24,7 @@ import javax.servlet.http.HttpServletRequest;
 
 import org.apache.catalina.websocket.MessageInbound;
 import org.apache.catalina.websocket.WsOutbound;
-import org.apache.wicket.Application;
+import org.apache.wicket.protocol.http.WebApplication;
 import org.apache.wicket.protocol.ws.api.AbstractWebSocketProcessor;
 
 /**
@@ -64,7 +64,7 @@ public class TomcatWebSocketProcessor extends 
AbstractWebSocketProcessor
                        TomcatWebSocketProcessor.this.onClose(status, 
"Connection closed by client");
                }
        }
-       public TomcatWebSocketProcessor(final HttpServletRequest request, final 
Application application)
+       public TomcatWebSocketProcessor(final HttpServletRequest request, final 
WebApplication application)
        {
                super(request, application);
        }

Reply via email to