Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / September 2007

Tip: Looking for answers? Try searching our database.

2 problems with servlet filter

Thread view: 
odelya - 05 Sep 2007 07:25 GMT
Hi,
I wrote the following filter and wrapper:
* filters parameters: ContentType and expires.
*/
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
if (filterConfig == null) {
return;
}
long startTime = System.currentTimeMillis();

HttpServletResponse res = (HttpServletResponse) response;
HttpServletRequest req = (HttpServletRequest) request;
JPServletResponseWrapper responseWrapper = new
JPServletResponseWrapper(res);

chain.doFilter(req, responseWrapper);

String result = responseWrapper.toString();

PrintWriter out = response.getWriter();

int length = result.length() >= 10000 ? 10000 : result.length();
int jpHTTPHeaderTag = result.substring(0, length).indexOf("jp-http-
header");
if (jpHTTPHeaderTag != -1) {
int contentTypeIndex = result.indexOf("Content-type",
jpHTTPHeaderTag);
int contentTypeIndexStart = result.indexOf("#", contentTypeIndex);
int contentTypeIndexEnd = result.indexOf("#", contentTypeIndexStart +
1);
String contentType = result.substring(contentTypeIndexStart + 1,
contentTypeIndexEnd);
res.setContentType(contentType);
out.write(result);
} else {
out.write(result);
}
out.close();

long stopTime = System.currentTimeMillis();
System.out.println("Time to execute request: " + (stopTime -
startTime) + " milliseconds");

}
public void init(FilterConfig config) {
filterConfig = config;
}
public void destroy() {
filterConfig = null;

}

but when condition to set the content type as from the html file
applies,
res.setContentType(contentType) - doesn't do anything!
Manish Pandit - 05 Sep 2007 15:28 GMT
> Hi,
> I wrote the following filter and wrapper:
[quoted text clipped - 53 lines]
> applies,
> res.setContentType(contentType) - doesn't do anything!

You might want to debug the filter via Eclipse or something similar.
How do you know it does not do anything ? Did you check the content
Type received on the browser ? I strongly suggest debugging/stepping
through every line of the filter.

-cheers,
Manish


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.