fix FilterInvocation so it doesn't lose the tail end (past the servlet path) of the request url

This commit is contained in:
Colin Sampaleanu 2004-04-23 02:29:18 +00:00
parent 0537900357
commit 6eb0a47632
3 changed files with 25 additions and 17 deletions

View File

@ -101,10 +101,11 @@ public class FilterInvocation {
}
public String getRequestUrl() {
return getHttpRequest().getServletPath()
+ ((getHttpRequest().getQueryString() == null) ? ""
: ("?"
+ getHttpRequest().getQueryString()));
String pathInfo = getHttpRequest().getPathInfo();
String queryString = getHttpRequest().getQueryString();
return getHttpRequest().getServletPath() + (pathInfo == null ? "" : pathInfo)
+ (queryString == null ? "" : ("?" + queryString));
}
public ServletResponse getResponse() {

View File

@ -59,6 +59,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
private String serverName;
private String servletPath;
private int serverPort;
private String pathInfo; // null for no extra path
//~ Constructors ===========================================================
@ -196,8 +197,13 @@ public class MockHttpServletRequest implements HttpServletRequest {
throw new UnsupportedOperationException("mock method not implemented");
}
public void setPathInfo(String pathInfo) {
this.pathInfo = pathInfo;
}
public String getPathInfo() {
throw new UnsupportedOperationException("mock method not implemented");
return pathInfo;
}
public String getPathTranslated() {
@ -240,8 +246,8 @@ public class MockHttpServletRequest implements HttpServletRequest {
throw new UnsupportedOperationException("mock method not implemented");
}
public void setRequestURL(String newRequestURL) {
requestURL = newRequestURL;
public void setRequestURL(String requestURL) {
this.requestURL = requestURL;
}
public StringBuffer getRequestURL() {
@ -268,8 +274,8 @@ public class MockHttpServletRequest implements HttpServletRequest {
throw new UnsupportedOperationException("mock method not implemented");
}
public void setScheme(String newScheme) {
scheme = newScheme;
public void setScheme(String scheme) {
this.scheme = scheme;
}
public String getScheme() {
@ -280,16 +286,16 @@ public class MockHttpServletRequest implements HttpServletRequest {
throw new UnsupportedOperationException("mock method not implemented");
}
public void setServerName(String newServerName) {
serverName = newServerName;
public void setServerName(String serverName) {
this.serverName = serverName;
}
public String getServerName() {
return serverName;
}
public void setServerPort(int newPort) {
serverPort = newPort;
public void setServerPort(int serverPort) {
this.serverPort = serverPort;
}
public int getServerPort() {

View File

@ -68,7 +68,8 @@ public class FilterInvocationTests extends TestCase {
public void testGettersAndStringMethods() {
MockHttpServletRequest request = new MockHttpServletRequest(null, null);
request.setServletPath("/HelloWorld");
request.setRequestURL("http://www.example.com/mycontext/HelloWorld");
request.setPathInfo("/some/more/segments.html");
request.setRequestURL("http://www.example.com/mycontext/HelloWorld/some/more/segments.html");
MockHttpServletResponse response = new MockHttpServletResponse();
MockFilterChain chain = new MockFilterChain();
@ -78,9 +79,9 @@ public class FilterInvocationTests extends TestCase {
assertEquals(response, fi.getResponse());
assertEquals(response, fi.getHttpResponse());
assertEquals(chain, fi.getChain());
assertEquals("/HelloWorld", fi.getRequestUrl());
assertEquals("FilterInvocation: URL: /HelloWorld", fi.toString());
assertEquals("http://www.example.com/mycontext/HelloWorld",
assertEquals("/HelloWorld/some/more/segments.html", fi.getRequestUrl());
assertEquals("FilterInvocation: URL: /HelloWorld/some/more/segments.html", fi.toString());
assertEquals("http://www.example.com/mycontext/HelloWorld/some/more/segments.html",
fi.getFullRequestUrl());
}