You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by mg...@apache.org on 2016/01/10 20:40:24 UTC

wicket git commit: WICKET-6063 Add support for WebSocketRequest#getUrl() and other properties which are available in the handshake request

Repository: wicket
Updated Branches:
  refs/heads/wicket-7.x e0502b880 -> e2725482f


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

Branch: refs/heads/wicket-7.x
Commit: e2725482f6d39ee9751193efe70b3d3442e5cbb9
Parents: e0502b8
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Sun Jan 10 20:39:57 2016 +0100
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Sun Jan 10 20:39:57 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/e2725482/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 218b1f7..0565a33 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
@@ -63,6 +63,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();
@@ -73,6 +91,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);
@@ -117,13 +152,13 @@ public class ServletRequestCopy implements HttpServletRequest
 	@Override
 	public String getRemoteAddr()
 	{
-		return null;
+		return remoteAddr;
 	}
 
 	@Override
 	public String getRemoteHost()
 	{
-		return null;
+		return remoteHost;
 	}
 
 	@Override
@@ -189,19 +224,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
@@ -212,7 +257,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
@@ -228,12 +280,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
@@ -245,7 +298,7 @@ public class ServletRequestCopy implements HttpServletRequest
 	@Override
 	public String getContentType()
 	{
-		return null;
+		return contentType;
 	}
 
 	@Override
@@ -267,19 +320,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
@@ -297,25 +350,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
@@ -374,7 +427,7 @@ public class ServletRequestCopy implements HttpServletRequest
 	@Override
 	public String getRemoteUser()
 	{
-		return null;
+		return remoteUser;
 	}
 
 	@Override
@@ -386,13 +439,13 @@ public class ServletRequestCopy implements HttpServletRequest
 	@Override
 	public Principal getUserPrincipal()
 	{
-		return null;
+		return principal;
 	}
 
 	@Override
 	public String getRequestedSessionId()
 	{
-		return null;
+		return requestedSessionId;
 	}
 
 	@Override
@@ -408,7 +461,7 @@ public class ServletRequestCopy implements HttpServletRequest
 	@Override
 	public String getPathTranslated()
 	{
-		return null;
+		return pathTranslated;
 	}
 
 	@Override
@@ -464,7 +517,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/e2725482/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;