You have to wrap the HttpServletRequest with a class that overrides the methods
relating to the URI. I've attached an abstract class that I wrote to make this
a bit easier.
You will have to implement the rewriteURL method to do the necessary String
parsing.
Then in your filter doFilter:
chain.doFilter(new WrappedRequest(request), response);
(assuming you've written WrappedRequest - that extends the abstract class I've
attached).
Good luck.
Martin
PS You're question actually has nothing to do with Tomcat specifically...
Jaynika Barot wrote:
hi all,
I want to write a filter which will overwrite the request URL in
incoming httprequest.
if incoming request's URI contains *./myservletName/extra1/extra2.*
I want to reset it to *./myservletName?param1=extra1¶m2=extra2 and
pass this request object to subsequent processing (filter chain).
Is it possible to do?? If so how?
thx,
Jaynika
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
package com.mbromley.util.servlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
/** This enables the URLs in an HttpServletRequest to be consistently rewritten.
* This needs to be extended for it to do anything useful. At least one of the
* rewriteURL methods needs to be overridden.
*/
public abstract class URLRewritingRequestWrapper
extends HttpServletRequestWrapper {
public URLRewritingRequestWrapper(
final HttpServletRequest request) {
super(request);
}
@Override
public final String getPathInfo() {
return getPossiblyNull(super.getPathInfo());
}
@Override
public final String getPathTranslated() {
return getPossiblyNull(super.getPathTranslated());
}
@Override
public final String getRequestURI() {
return rewriteURL(super.getRequestURI());
}
@Override
public final StringBuffer getRequestURL() {
return rewriteURL(super.getRequestURL());
}
@Override
public final String getServletPath() {
return rewriteURL(super.getServletPath());
}
private String getPossiblyNull(final String s) {
if (s == null) {
return null;
}
return rewriteURL(s);
}
/** Subclasses can override this if they can improve efficiency by
rewriting
* a StringBuffer. By default this calls the other method and creates
a new
* StringBuffer from the result.
*/
protected StringBuffer rewriteURL(final StringBuffer sB) {
return new StringBuffer(rewriteURL(sB.toString()));
}
protected abstract String rewriteURL(final String url);
@Override
public String toString() {
return super.toString() + " wrapping " +
getRequest().toString();
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]