I have Spring 3.0 setup with annotated controllers and it is finding my controller and executing it as it should when I send an url to it from a browser . But when rewriting the url with a filter to the exact same that works in the browser I get No mapping found for HTTP request with URI [/test/lookup]
. The filter is loaded by a org.springframework.web.filter.DelegatingFilterProxy.
What have I missed in the filter?
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import org.springframework.stereotype.Component;
@Component("urlLookupFilter")
public class UrlLookupFilter implements Filter {
private class ModifiedRequest extends HttpServletRequestWrapper {
private String mRequestURI;
private String mQueryString;
public ModifiedRequest(HttpServletRequest request) {
super(request);
}
@Override
public String getRequestURI() {
return mRequestURI;
}
public void setRequestUri(String s) {
this.mRequestURI = s;
}
@Override
public String getQueryString() {
return mQueryString;
}
public void setQueryString(String s) {
this.mQueryString = s;
}
}
public void init(FilterConfig filterConfig) throws ServletException {
throw new UnsupportedOperationException("Not supported yet.");
}
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletRequest oRequest = (HttpServletRequest) request;
if (oRequest.getRequestURI().endsWith("test")) {
ModifiedRequest mRequest = new ModifiedRequest(oRequest);
mRequest.setRequestUri(oRequest.getContextPath() + "/lookup");
mRequest.setQueryString(oRequest.getRequestURI().substring(oRequest.getContextPath().length()));
chain.doFilter(mRequest, response);
return;
}
chain.doFilter(request, response);
}
public void destroy() {
throw new UnsupportedOperationException("Not supported yet.");
}
}