Repository: wicket
Updated Branches:
  refs/heads/master 70606d73e -> 291541f4d


WICKET-6254 Wicket WebSockets problem behind HTTP proxy without servlet context

Make it possible to override the parts needed to construct the WebSocket 
absolute url.
This is needed when the application runs in a servlet container that is proxied 
in front.
The constructed url has to point to the proxy server.
The application may use X-Forwarded-For-** headers set by the proxy, or custom 
configuration for different environments


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

Branch: refs/heads/master
Commit: 291541f4d567ca50cda05863600edeefda5dc3a6
Parents: 70606d7
Author: Martin Tzvetanov Grigorov <mgrigo...@apache.org>
Authored: Sat Oct 15 10:50:13 2016 +0200
Committer: Martin Tzvetanov Grigorov <mgrigo...@apache.org>
Committed: Sat Oct 15 10:55:01 2016 +0200

----------------------------------------------------------------------
 .../protocol/ws/api/BaseWebSocketBehavior.java  | 33 +++++++++++++++-----
 1 file changed, 25 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/291541f4/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/BaseWebSocketBehavior.java
----------------------------------------------------------------------
diff --git 
a/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/BaseWebSocketBehavior.java
 
b/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/BaseWebSocketBehavior.java
index cb654d6..6290aeb 100644
--- 
a/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/BaseWebSocketBehavior.java
+++ 
b/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/BaseWebSocketBehavior.java
@@ -118,28 +118,45 @@ public class BaseWebSocketBehavior extends Behavior
                        variables.put("pageId", false);
                }
 
-               Url baseUrl = 
component.getRequestCycle().getUrlRenderer().getBaseUrl();
-               CharSequence ajaxBaseUrl = 
Strings.escapeMarkup(baseUrl.toString());
-               variables.put("baseUrl", ajaxBaseUrl);
+               CharSequence baseUrl = getBaseUrl(component);
+               Args.notEmpty(baseUrl, "baseUrl");
+               variables.put("baseUrl", baseUrl);
 
-               String contextPath = component.getRequest().getContextPath();
+               String contextPath = getContextPath(component);
                variables.put("contextPath", contextPath);
 
                // preserve the application name for JSR356 based impl
                variables.put("applicationName", 
component.getApplication().getName());
 
+               CharSequence filterPrefix = getFilterPrefix(component);
+               variables.put("filterPrefix", filterPrefix);
+
+               String webSocketSetupScript = 
webSocketSetupTemplate.asString(variables);
+
+               
response.render(OnDomReadyHeaderItem.forScript(webSocketSetupScript));
+       }
+
+       protected CharSequence getFilterPrefix(final Component component) {
+               CharSequence filterPrefix;
                if (USING_JAVAX_WEB_SOCKET)
                {
-                       variables.put("filterPrefix", "");
+                       filterPrefix = "";
                }
                else
                {
-                       variables.put("filterPrefix", 
component.getRequest().getFilterPath());
+                       filterPrefix = component.getRequest().getFilterPath();
                }
+               return filterPrefix;
+       }
 
-               String webSocketSetupScript = 
webSocketSetupTemplate.asString(variables);
+       protected String getContextPath(final Component component) {
+               return component.getRequest().getContextPath();
+       }
 
-               
response.render(OnDomReadyHeaderItem.forScript(webSocketSetupScript));
+       protected CharSequence getBaseUrl(Component component) {
+               Url baseUrl = 
component.getRequestCycle().getUrlRenderer().getBaseUrl();
+               CharSequence ajaxBaseUrl = 
Strings.escapeMarkup(baseUrl.toString());
+               return ajaxBaseUrl;
        }
 
        @Override

Reply via email to