Refactoring of methods names in UrlUtils for consistency.

This commit is contained in:
Luke Taylor 2009-05-01 10:43:41 +00:00
parent f6800fbe04
commit d1cb85e4f3
4 changed files with 38 additions and 34 deletions

View File

@ -70,7 +70,7 @@ public class FilterInvocation {
* @return the full URL of this request * @return the full URL of this request
*/ */
public String getFullRequestUrl() { public String getFullRequestUrl() {
return UrlUtils.getFullRequestUrl(this); return UrlUtils.buildFullRequestUrl(request);
} }
public HttpServletRequest getHttpRequest() { public HttpServletRequest getHttpRequest() {
@ -87,7 +87,7 @@ public class FilterInvocation {
* @return the URL, excluding any server name, context path or servlet path * @return the URL, excluding any server name, context path or servlet path
*/ */
public String getRequestUrl() { public String getRequestUrl() {
return UrlUtils.getRequestUrl(this); return UrlUtils.buildRequestUrl(request);
} }
public HttpServletRequest getRequest() { public HttpServletRequest getRequest() {

View File

@ -52,6 +52,8 @@ public class SavedRequest implements java.io.Serializable {
protected static final Log logger = LogFactory.getLog(SavedRequest.class); protected static final Log logger = LogFactory.getLog(SavedRequest.class);
public static final String SPRING_SECURITY_SAVED_REQUEST_KEY = "SPRING_SECURITY_SAVED_REQUEST_KEY";
//~ Instance fields ================================================================================================ //~ Instance fields ================================================================================================
private ArrayList<SavedCookie> cookies = new ArrayList<SavedCookie>(); private ArrayList<SavedCookie> cookies = new ArrayList<SavedCookie>();
@ -69,8 +71,6 @@ public class SavedRequest implements java.io.Serializable {
private String servletPath; private String servletPath;
private int serverPort; private int serverPort;
public static final String SPRING_SECURITY_SAVED_REQUEST_KEY = "SPRING_SECURITY_SAVED_REQUEST_KEY";
//~ Constructors =================================================================================================== //~ Constructors ===================================================================================================
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@ -228,7 +228,7 @@ public class SavedRequest implements java.io.Serializable {
*/ */
public String getFullRequestUrl() { public String getFullRequestUrl() {
return UrlUtils.buildFullRequestUrl(this.getScheme(), this.getServerName(), this.getServerPort(), this.getContextPath(), return UrlUtils.buildFullRequestUrl(this.getScheme(), this.getServerName(), this.getServerPort(), this.getContextPath(),
this.getRequestURL(), this.getServletPath(), this.getRequestURI(), this.getPathInfo(), this.getQueryString()); this.getServletPath(), this.getRequestURI(), this.getPathInfo(), this.getQueryString());
} }
public Iterator<String> getHeaderNames() { public Iterator<String> getHeaderNames() {

View File

@ -17,8 +17,6 @@ package org.springframework.security.web.util;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import org.springframework.security.web.FilterInvocation;
/** /**
* Provides static methods for composing URLs.<p>Placed into a separate class for visibility, so that changes to * Provides static methods for composing URLs.<p>Placed into a separate class for visibility, so that changes to
@ -28,21 +26,23 @@ import org.springframework.security.web.FilterInvocation;
* @version $Id$ * @version $Id$
*/ */
public final class UrlUtils { public final class UrlUtils {
//~ Constructors ===================================================================================================
private UrlUtils() {
}
//~ Methods ======================================================================================================== //~ Methods ========================================================================================================
public static String buildFullRequestUrl(HttpServletRequest r) {
return buildFullRequestUrl(r.getScheme(), r.getServerName(), r.getServerPort(), r.getContextPath(),
r.getServletPath(), r.getRequestURI(), r.getPathInfo(), r.getQueryString());
}
/** /**
* Obtains the full URL the client used to make the request.<p>Note that the server port will not be shown * Obtains the full URL the client used to make the request.
* if it is the default server port for HTTP or HTTPS (ie 80 and 443 respectively).</p> * <p>
* Note that the server port will not be shown if it is the default server port for HTTP or HTTPS
* (80 and 443 respectively).
* *
* @return the full URL * @return the full URL
*/ */
public static String buildFullRequestUrl(String scheme, String serverName, int serverPort, String contextPath, public static String buildFullRequestUrl(String scheme, String serverName, int serverPort, String contextPath,
String requestUrl, String servletPath, String requestURI, String pathInfo, String queryString) { String servletPath, String requestURI, String pathInfo, String queryString) {
boolean includePort = true; boolean includePort = true;
@ -58,6 +58,16 @@ public final class UrlUtils {
+ buildRequestUrl(servletPath, requestURI, contextPath, pathInfo, queryString); + buildRequestUrl(servletPath, requestURI, contextPath, pathInfo, queryString);
} }
/**
* Obtains the web application-specific fragment of the request URL.
*
* @return the URL, excluding any server name, context path or servlet path
*/
public static String buildRequestUrl(HttpServletRequest r) {
return buildRequestUrl(r.getServletPath(), r.getRequestURI(), r.getContextPath(), r.getPathInfo(),
r.getQueryString());
}
/** /**
* Obtains the web application-specific fragment of the URL. * Obtains the web application-specific fragment of the URL.
* *
@ -76,20 +86,6 @@ public final class UrlUtils {
return uri + ((pathInfo == null) ? "" : pathInfo) + ((queryString == null) ? "" : ("?" + queryString)); return uri + ((pathInfo == null) ? "" : pathInfo) + ((queryString == null) ? "" : ("?" + queryString));
} }
public static String getFullRequestUrl(FilterInvocation fi) {
HttpServletRequest r = fi.getHttpRequest();
return buildFullRequestUrl(r.getScheme(), r.getServerName(), r.getServerPort(), r.getContextPath(),
r.getRequestURL().toString(), r.getServletPath(), r.getRequestURI(), r.getPathInfo(), r.getQueryString());
}
public static String getRequestUrl(FilterInvocation fi) {
HttpServletRequest r = fi.getHttpRequest();
return buildRequestUrl(r.getServletPath(), r.getRequestURI(), r.getContextPath(), r.getPathInfo(),
r.getQueryString());
}
/** /**
* Returns true if the supplied URL starts with a "/" or "http". * Returns true if the supplied URL starts with a "/" or "http".
*/ */

View File

@ -1,20 +1,28 @@
package org.springframework.security.web.savedrequest; package org.springframework.security.web.savedrequest;
import junit.framework.TestCase; import static org.junit.Assert.*;
import org.junit.Test;
import org.springframework.security.MockPortResolver; import org.springframework.security.MockPortResolver;
import org.springframework.security.web.savedrequest.SavedRequest; import org.springframework.security.web.savedrequest.SavedRequest;
import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpServletRequest;
public class SavedRequestTests extends TestCase { /**
*
*/
public class SavedRequestTests {
public void testCaseInsensitveHeaders() throws Exception { @Test
public void headersAreCaseInsensitive() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletRequest request = new MockHttpServletRequest();
request.addHeader("USER-aGenT", "Mozilla"); request.addHeader("USER-aGenT", "Mozilla");
SavedRequest saved = new SavedRequest(request, new MockPortResolver(8080, 8443)); SavedRequest saved = new SavedRequest(request, new MockPortResolver(8080, 8443));
assertEquals("Mozilla", saved.getHeaderValues("user-agent").next()); assertEquals("Mozilla", saved.getHeaderValues("user-agent").next());
} }
public void testCaseInsensitveParameters() throws Exception { // TODO: Why are parameters case insensitive. I think this is a mistake
@Test
public void parametersAreCaseInsensitive() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletRequest request = new MockHttpServletRequest();
request.addParameter("ThisIsATest", "Hi mom"); request.addParameter("ThisIsATest", "Hi mom");
SavedRequest saved = new SavedRequest(request, new MockPortResolver(8080, 8443)); SavedRequest saved = new SavedRequest(request, new MockPortResolver(8080, 8443));