Repository: wicket Updated Branches: refs/heads/master e8b3f4643 -> 2ec1b5524
WICKET-6063 Add support for WebSocketRequest#getUrl() and other properties which are available in the handshake request Project: http://git-wip-us.apache.org/repos/asf/wicket/repo Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/2ec1b552 Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/2ec1b552 Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/2ec1b552 Branch: refs/heads/master Commit: 2ec1b5524431393274d459e2da2649dcf4446233 Parents: e8b3f46 Author: Martin Tzvetanov Grigorov <[email protected]> Authored: Sun Jan 10 20:39:57 2016 +0100 Committer: Martin Tzvetanov Grigorov <[email protected]> Committed: Sun Jan 10 20:43:23 2016 +0100 ---------------------------------------------------------------------- .../protocol/ws/api/ServletRequestCopy.java | 95 +++++++++++++++----- .../protocol/ws/api/WebSocketRequest.java | 72 +-------------- 2 files changed, 76 insertions(+), 91 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/wicket/blob/2ec1b552/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/ServletRequestCopy.java ---------------------------------------------------------------------- diff --git a/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/ServletRequestCopy.java b/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/ServletRequestCopy.java index ceecb81..f301c43 100644 --- a/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/ServletRequestCopy.java +++ b/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/ServletRequestCopy.java @@ -64,6 +64,24 @@ public class ServletRequestCopy implements HttpServletRequest private final String method; private final String serverName; private final int serverPort; + private final String protocol; + private final String scheme; + private final String contentType; + private final Locale locale; + private final Enumeration<Locale> locales; + private final boolean isSecure; + private final String remoteUser; + private final String remoteAddr; + private final String remoteHost; + private final int remotePort; + private final String localAddr; + private final String localName; + private final int localPort; + private final String pathTranslated; + private final String requestedSessionId; + private final Principal principal; + + private String characterEncoding; public ServletRequestCopy(HttpServletRequest request) { this.servletPath = request.getServletPath(); @@ -74,6 +92,23 @@ public class ServletRequestCopy implements HttpServletRequest this.method = request.getMethod(); this.serverName = request.getServerName(); this.serverPort = request.getServerPort(); + this.protocol = request.getProtocol(); + this.scheme = request.getScheme(); + this.characterEncoding = request.getCharacterEncoding(); + this.contentType = request.getContentType(); + this.locale = request.getLocale(); + this.locales = request.getLocales(); + this.isSecure = request.isSecure(); + this.remoteUser = request.getRemoteUser(); + this.remoteAddr = request.getRemoteAddr(); + this.remoteHost = request.getRemoteHost(); + this.remotePort = request.getRemotePort(); + this.localAddr = request.getLocalAddr(); + this.localName = request.getLocalName(); + this.localPort = request.getLocalPort(); + this.pathTranslated = request.getPathTranslated(); + this.requestedSessionId = request.getRequestedSessionId(); + this.principal = request.getUserPrincipal(); HttpSession session = request.getSession(true); httpSession = new HttpSessionCopy(session); @@ -118,13 +153,13 @@ public class ServletRequestCopy implements HttpServletRequest @Override public String getRemoteAddr() { - return null; + return remoteAddr; } @Override public String getRemoteHost() { - return null; + return remoteHost; } @Override @@ -190,19 +225,29 @@ public class ServletRequestCopy implements HttpServletRequest @Override public Map getParameterMap() { - return null; + return parameters; } @Override public String getProtocol() { - return null; + String _protocol = "ws"; + if ("https".equalsIgnoreCase(protocol)) + { + _protocol = "wss"; + } + return _protocol; } @Override public String getScheme() { - return null; + String _scheme = "ws"; + if ("https".equalsIgnoreCase(scheme)) + { + _scheme = "wss"; + } + return _scheme; } @Override @@ -213,7 +258,14 @@ public class ServletRequestCopy implements HttpServletRequest @Override public int getIntHeader(String name) { - return 0; + Enumeration<String> values = headers.get(name); + int result = -1; + if (values.hasMoreElements()) + { + String value = values.nextElement(); + result = Integer.parseInt(value, 10); + } + return result; } @Override @@ -229,12 +281,13 @@ public class ServletRequestCopy implements HttpServletRequest @Override public String getCharacterEncoding() { - return null; + return characterEncoding; } @Override - public void setCharacterEncoding(String env) throws UnsupportedEncodingException + public void setCharacterEncoding(String characterEncoding) throws UnsupportedEncodingException { + this.characterEncoding = characterEncoding; } @Override @@ -252,7 +305,7 @@ public class ServletRequestCopy implements HttpServletRequest @Override public String getContentType() { - return null; + return contentType; } @Override @@ -274,19 +327,19 @@ public class ServletRequestCopy implements HttpServletRequest @Override public Locale getLocale() { - return null; + return locale; } @Override public Enumeration getLocales() { - return null; + return locales; } @Override public boolean isSecure() { - return false; + return isSecure; } @Override @@ -304,25 +357,25 @@ public class ServletRequestCopy implements HttpServletRequest @Override public int getRemotePort() { - return 0; + return remotePort; } @Override public String getLocalName() { - return null; + return localName; } @Override public String getLocalAddr() { - return null; + return localAddr; } @Override public int getLocalPort() { - return 0; + return localPort; } @Override @@ -381,7 +434,7 @@ public class ServletRequestCopy implements HttpServletRequest @Override public String getRemoteUser() { - return null; + return remoteUser; } @Override @@ -393,13 +446,13 @@ public class ServletRequestCopy implements HttpServletRequest @Override public Principal getUserPrincipal() { - return null; + return principal; } @Override public String getRequestedSessionId() { - return null; + return requestedSessionId; } @Override @@ -415,7 +468,7 @@ public class ServletRequestCopy implements HttpServletRequest @Override public String getPathTranslated() { - return null; + return pathTranslated; } @Override @@ -477,7 +530,7 @@ public class ServletRequestCopy implements HttpServletRequest @Override public Collection<Part> getParts() throws IOException, ServletException { - return null; + return Collections.emptyList(); } @Override http://git-wip-us.apache.org/repos/asf/wicket/blob/2ec1b552/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/WebSocketRequest.java ---------------------------------------------------------------------- diff --git a/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/WebSocketRequest.java b/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/WebSocketRequest.java index f7eaf5b..01a91d0 100644 --- a/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/WebSocketRequest.java +++ b/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/WebSocketRequest.java @@ -16,21 +16,10 @@ */ package org.apache.wicket.protocol.ws.api; -import java.nio.charset.Charset; -import java.util.Arrays; -import java.util.Enumeration; -import java.util.List; -import java.util.Locale; - -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; -import org.apache.wicket.util.time.Time; + +import javax.servlet.http.HttpServletRequest; /** * A {@link WebRequest} implementation used for the lifecycle of a web socket @@ -53,63 +42,6 @@ public class WebSocketRequest extends ServletWebRequest } @Override - public List<Cookie> getCookies() - { - List<Cookie> cookies = Arrays.asList(getContainerRequest().getCookies()); - return cookies; - } - - @Override - public List<String> getHeaders(String name) - { - Enumeration<String> headers = getContainerRequest().getHeaders(name); - List<String> h = Generics.newArrayList(); - while (headers.hasMoreElements()) - { - h.add(headers.nextElement()); - } - - return h; - } - - @Override - public String getHeader(String name) - { - return getContainerRequest().getHeader(name); - } - - @Override - public Time getDateHeader(String name) - { - long dateHeader = getContainerRequest().getDateHeader(name); - return Time.millis(dateHeader); - } - - @Override - public Url getUrl() - { - return null; - } - - @Override - public Url getClientUrl() - { - return null; - } - - @Override - public Locale getLocale() - { - return getContainerRequest().getLocale(); - } - - @Override - public Charset getCharset() - { - return RequestUtils.getCharset(getContainerRequest()); - } - - @Override public boolean isAjax() { return true;
