Repository: wicket
Updated Branches:
  refs/heads/wicket-7.x 3306d9b8a -> 41a3b04a5


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/41a3b04a
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/41a3b04a
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/41a3b04a

Branch: refs/heads/wicket-7.x
Commit: 41a3b04a57a731e5723493092bce748aca58588c
Parents: 3306d9b
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:50:13 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/41a3b04a/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