servlet-filters

What is doFilter doing in doFilter method in filters of java?

I wanna know that in our dofilter method i made this call chain.doFilter. What is doFilter doing inside a doFilter?Is it not gonna get recursive call? ...

Tomcat not able to get ServletContext of another webapp

I am using tomcat 6 and I have two webapps. One is webapp1 and the other one is webapp2. From a filter inside webapp2, I am trying to access the other webapp i.e webapp1. My Filter code is something like below public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {...

Java - How does the Tuckee URL Rewrite filter change the url of the request?

I want to write my own version of url rewriting for my app, but I don't know how to change the url of the incoming request in the filter. I tried just forwarding to the rewritten url, but that makes it so all other filters in the chain are not called. ...

Can I intercept calls for my WSDL on Glassfish (or on any app server)?

I've created a Java web service using the @WebService annotation and deployed the service to a Glassfish server that lives behind a proxy server. The problem is when someone accesses our WSDL and looks at the service endpoint address location they see http://app server url/service... instead of http://proxy server url/service... I...

Java Servlet Filter redirect problem

Hello, I'm having a problem with my authentication filter. When the filter redirects to the login page, no images gets displayed in the login JSP. However, if I go to the login page manually after I'm logged in, the images are displayed. I don't understand why this is happening! I appreciate any help. :-) AuthFilter: if (authorized...

Set attribute into JSP PageContext for use in EL from a Filter

How can I put an attribute into the JSP PageContext for the current request (so that it becomes accessible via ${myVar} ) from a Filter that runs before the JSP? ...

Most useful java servlet Filter out there?

Very interesting tricks can be done with java servlet filters in security, performance, etc. What are the best servlet filters out there? ...

Request for code review of JEE authentication and authorization filter

Hi, I know it's a good idea to use well implemented standard software for authorization and authentication. But this time I wrote it on my own. It is used in a intranet only application, so security requirements are low. But I, as the developer, would like to know, how secure it really is. I would please you to review the code and give ...

Redirecting the response from a filter throws an IllegalStateException

I am writing a filter that will handle all authentication related tasks. My filter is a standard servlet filter as shown below @Override public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { UserSession attribute = (UserSession)request.getSession().getAttribu...

How can I tell why a servlet filter has been invoked.

In the servlet 2.4 spec you can define dispatchers in the filter config [REQUEST | FORWARD | ERROR | INCLUDE]. When the filter is invoked, how can I tell from which condition it was invoked from i.e. how can I tell if it was a request or an include or a forward? ...

Accessing Spring beans from servlet filters and tags

I can access Spring beans in my Servlets using WebApplicationContext springContext = WebApplicationContextUtils.getWebApplicationContext(getServletContext()); in the Servlet's init method. I was wondering is there an equivalent of the WebApplicationContext for servlet filters? Also, is it possible to access Spring beans i...

JEE Filter is not being executed during <h:commandLink> request

Hi, I am working on a JEE application with facelets running in Tomcat 6. I wrote I Filter which works fine. Inside some facelet pages there are <h:commandLink> elements refering to another page inside the application and passing parameters to a managed bean. The refered page works on with the managed bean which got the parameter p...

Writing a Servlet that checks to see if JSP's exist and forwards to another JSP if they aren't

UPDATE: To clarify a generic error catcher that catches 404's doesn't have enough granularity for me. I need to do this only if the jsp is in a particular directory and then only if the filename contains a certain string. /UPDATE I've beeb tasked with writing a servlet that intercepts a call to and JSP in a specific directoy, check th...

Java Filter URL pattern specific to request params

We have a situation where we want to use filter for URL's containing some specific request parameters, e.g: http://mydomain.com/?id=78&formtype=simple_form&....... http://mydomain.com/?id=788&formtype=special_form&....... and so on, id are fetched at run time, I want configure filter in web.xml only if formtype=special_form. ...

Spring Custom Filter Problem?

greetings all,iam using spring security 3 and i want to perform some logic(saving some data in the session) when the user is visiting the site and he's remembered so i extended the GenericFilterBean class and performed the logic in the doFilter method then complete the filter chain by calling the chain.doFilter method,and then inserted t...

Should filters write to the response during or after filtering?

I have a filter which processes generated HTML and rewrites certain elements. For example, it adds class attributes to some anchors. Finally, it writes the processed HTML to the response (a subclass of HttpServletResponseWrapper). Naturally, this means that the processed HTML is a different length after it has passed through the filter. ...

ByteArrayOutputStream to PrintWriter (Java Servlet)

Writing generated PDF (ByteArrayOutputStream) in a Servlet to PrintWriter. I am desperately looking for a way to write a generated PDF file to the response PrintWriter. Since a Filter up the hierarchy chain has already called response.getWriter() I can't get response.getOutputStream(). I do have a ByteArrayOutputStream where I generat...

How to use a filter in Java to change an incoming servlet request url ?

How to use a filter to change an incoming request url : From : "http://nm-java.appspot.com/Check_License/Dir_My_App/Dir_ABC/My_Obj_123" To : "http://nm-java.appspot.com/Check_License?Contact_Id=My_Obj_123" ? Frank Edit : According to BalusC's steps below, I came up with the following lines : import java.io.IOException; import jav...

After Filter redirects to login.jsp, proper servlet doesnt get called

My simple project structure is shown in this link. I am using Eclipse and Tomcat 6. There is login.jsp which submits its form to login_servlet. The login_servlet sets a session variable and then redirects to home.jsp. The home.jsp file has links to the 4 JSP files under a directory called /sam. In web.xml I have given the url-pattern as...

Using a javax.servlet.Filter with Compojure

I'm trying to build a simple web site using Clojure / Compojure and want to feed apply a servlet filter to the request / response (i.e. a standard javax.servlet.Filter instance). e.g. if the current source code is: (defroutes my-app (GET "/*" (html [:h1 "Hello Foo!!"])) ) I would like to add a filter like this: (defroutes my-a...