Servlet Filter never gets called

I have a filter configured in web.xml to run on hitting the /welcome.jsf(forward, request).
I want to update a statistics table with the hit count for login.  But the servlet is not getting called.
In the debugger, it never stops there and the statistics table never gets updated.

11.1.2.3
<filter>
        <filter-name>IBHSLoginStatistics</filter-name>
        <filter-class>gov.samhsa.dasis.isats.view.servlets.filters.IBHSLoginStatistics</filter-class>
    </filter>
<filter-mapping>
        <filter-name>IBHSLoginStatistics</filter-name>
        <url-pattern>/faces/welcome/*</url-pattern>
        <dispatcher>FORWARD</dispatcher>
        <dispatcher>REQUEST</dispatcher>
    </filter-mapping>
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException,
ServletException {
HttpSession session = (HttpSession)FacesContext.getCurrentInstance().getExternalContext().getSession(false);
if(session.isNew()) {
IbhsStatistics ibhsStatistics = new IbhsStatistics();
ibhsStatistics.setEventDate(new Timestamp(new Date().getTime()));
ibhsStatistics.setEventType("Login");
ibhsStatistics.setUserid(SecurityShell.getUserId());
ManageIbhsStatistics manageIbhsStatistics = new ManageIbhsStatistics();
try {
manageIbhsStatistics.saveIbhsStatistics(ibhsStatistics);
} catch (NamingException e) {
} catch (NotSupportedException e) {
} catch (SystemException e) {
} catch (RollbackException e) {
} catch (HeuristicMixedException e) {
} catch (HeuristicRollbackException e) {
chain.doFilter(request, response);

Similar Messages

  • Setter never get called in selectManyCheckbox!!

    Hello
    I posted a topic about selectManyCheckbox / selectItems , but I didnt receive any reply , so
    I reviewed earlier threads talking about the same problem:
    * setter method NOT CALLED* for selectManyCheckbox :
    http://forum.java.sun.com/thread.jsp?forum=427&thread=398097
    " ....My page is rendered with all of the correct checkboxes I require.
    One for each object in the problemOptions list.
    Once I check the boxes I want and submit the form,
    I am losing my choices when I come back to the same page.
    I noticed that I never see my setter being called.... "
    http://forum.java.sun.com/thread.jsp?forum=427&thread=401926
    "..if one ore more items are selected, ..... ,
    after it called the getter 3 times and the setter not at all.
    there is no error message and no stack in any of the logs...."
    this is sample of my JSP/backing bean :
    JSP :
      <h:selectManyCheckbox  id="foodType" value="#{productBean.foodType}">
            <f:selectItems value="#{productBean.foodTypes}" />
      </h:selectManyCheckbox>
    Backing bean class ProductBean :
      private ArrayList foodType = new ArrayList();
      private ArrayList foodTypes = new ArrayList();
    public ProductBean()  {
        foodTypes.add(new SelectItem("Sweet","Dweet label","Sweets"));
        foodTypes.add(new SelectItem("desert","Desert label","Deserts"));     
        foodTypes.add(new SelectItem("seeFood","SeeFood label","SeeFoods"));   
      public Object[] getFoodType() {
          try {
            return foodType.toArray(); }
          catch (Exception ex) { return null;  }
      public void setFoodType(Object[] newFoodType) {
        // NEVER GET CALLED !!!
        int len=0;
        if (null == newFoodType || ( len = newFoodType.length)==0 ) {    return; }
        foodType.clear();
        foodType = new ArrayList(len);
        for ( int i=0;i<len;i++) {   foodType.add(newFoodType); }
    public ArrayList getFoodTypes() {
    return this.foodTypes;
    public void setFoodTypes(ArrayList foodTypes) {
    this.foodTypes = foodTypes;
    what am I doing wrong ? , I'm really stuck , what may be the reason for JSF not to call setter for setFoodType??
    I saw a reply for Adam.winner stating that it is not suitable to use Object[] type as setter argument ,
    and to use String[] instead, but this was in EA4 .
    is this still applicable for JSF 1.0 FR ?
    I appreciate any help
    -- Erich

    The data type of the SelectItem itemValue properties must be the same basic type (primitive or the corresponding boxed type) as the data type of the UISelectMany/UISelectOne value.
    In this example, the SelectItem itemValue properties are of type String, but the UISelectMany value is of type Object. Change it to String, and it should work.

  • Canvas paint never gets called - Repaint and ServiceRepaints.

    I have a problem that My Canvas never gets Drawn or the Image never gets Displayed;
    I am not sure if there is a DeadLock or If there is nothing to be painted,
    but when I enable the Debugger I notice that it never enters the paint method. ( I call Repaint and ServiceRepaints)
    If however I make the thread that calls setImage external to my Canvas Class the images do get Displayed.
       //Create the Canvas Class, Start Thread Display Canvas
       frame = new ImageCanvas();
        frame.addCommand(exitCommand);
        frame.addCommand(backCommand);
        frame.setCommandListener(this);
        frame.start();
        display.setCurrent(frame);
    //Display Image
    public class ImageCanvas extends Canvas implements Runnable {
    protected void paint(Graphics g) {
      g.drawImage(offscreen, Constants.XPOS, Constants.YPOS,  Graphics.LEFT | Graphics.TOP);
      private void setImage(Image img, String title) {
        this.setTitle(title);
        offscreen = img;
        repaint();
        serviceRepaints();
    public void run() {
         while(true){
           if (Constants.IMGLOCK != null) {
             synchronized (Constants.IMGLOCK) {
                setImage(Constants.IMAGE, title);
                Constants.IMGLOCK.setLockBoolValue(false);
                 image_created = true;
          } else {
               Constants.IMGLOCK.wait(10);
    }

    I found the BUG, But do not understand Why this is Needed to add,
    the Canvas every Time to the Display.
    Can someone please Explain ???
    private void setImage(Image img, String title) {
        this.setTitle(title);
        offscreen = img;
        repaint();
        display.setCurrent(this);  //<<<<<<WHY ????
        serviceRepaints();
      }

  • ApplicationSessionExpiryFilter never gets called

    I have configured a Filter in the web.xml and I have a filter class.  It doesn't seem to be getting called.  I have a page just for the timeout.
    public class ApplicationSessionExpiryFilter implements Filter {
        private FilterConfig _filterConfig = null;
        public void init(FilterConfig filterConfig) throws ServletException {
            _filterConfig = filterConfig;
        public void destroy() {
            _filterConfig = null;
        public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException,
                                                                                                         ServletException {
            String requestedSession = ((HttpServletRequest)request).getRequestedSessionId();
            String currentWebSession = ((HttpServletRequest)request).getSession().getId();
            boolean sessionOk = currentWebSession.equalsIgnoreCase(requestedSession);
            // if the requested session is null then this is the first application
            // request and "false" is acceptable
            if (!sessionOk && requestedSession != null) {
                // the session has expired or renewed. Redirect request
                ((HttpServletResponse)response).sendRedirect(_filterConfig.getInitParameter("SessionTimeoutRedirect"));
            } else {
                chain.doFilter(request, response);
    Please help.  We are already in production

    Hi Veena,
    Please mention your Jdev version always,
    https://www.youtube.com/watch?v=qGDevlbSLcw.
    Anyhow, I think this would help you.
    Thanks.

  • HTMLHost windowClose never gets called.

    Hi.
    I have a HTMLLoader and set to htmlHost a class extending HTMLHost (ie MyHTMLHost).
    Then I have this code in the class
    public class HelpHTMLHost extends HTMLHost
      override public function windowClose():void
             trace('close');
      override public function updateStatus(status:String):void
       trace("HTML: '" + status + "'");
    Then I load a page that has a
    <center><a href="javascript:alert(window);">test1</a></center>
    <center><a href="javascript:window.close();">close</a></center>
    .. Result is that  "test1" link works (shows alert window). close however deos not.
    the updateStatus method gets called (see two EMPTY strings in trace), windowClose does not get called.
    Using Adobe AIR 2 SDK, WIN 10,1,53,64 - Desktop - Windows 7 debug
    Thanks for the help.

    Same problem here, with AIR 2 SDK.

  • Servlet filter in portal irj?

    Hi,
    I am trying to create and deploy a servlet filter in portal irj.
    Here is what I have done:
    1. Created filter class(TestFilter.java).
    2. Created a jar file for the above TestFilter.class.
    3. Copied the jar file to C:\usr\sap\DW1\JC00\j2ee\cluster\server0\apps\sap.com\irj\servlet_jsp\irj\root\WEB-INF\lib folder
    4. Modified the web.xml file under C:\usr\sap\DW1\JC00\j2ee\cluster\server0\apps\sap.com\irj\servlet_jsp\irj\root\WEB-INF folder with the following lines:
      <filter>
        <filter-name>TestFilter</filter-name>
        <display-name>TestFilter</display-name>
        <description>
        </description>
        <filter-class>com.test.TestFilter</filter-class>
      </filter>
      <filter-mapping>
        <filter-name>TestFilter</filter-name>
        <url-pattern>/irj/*</url-pattern>
      </filter-mapping>
      <filter-mapping>
        <filter-name>TestFilter</filter-name>
        <servlet-name>prt</servlet-name>
      </filter-mapping>
    5. Restarted the engine.
    But still my filter doesnot get called. Am I missing something?

    i am trying out the sample filter and did the same steps as you mentioned above. 
    I get the following exception.  Looks like the irj didn't recognize the .jar file placed inside the lib.
    I am using EP 6.0.
    Stack Trace
    ===========
    Cannot load filter < com.test.TestFilter > The error is: java.lang.ClassNotFoundException: com.test.TestFilter
    Any additional steps to be done for irj to recognize this library.  The exception also shows the other libraries used during loading the application.  I didn't find mine in the list.
    Appreciate ur help
    Message was edited by:
            Anant

  • Canvas never gets shown (visible) on i85s, emulator works

    Hi,
    I have a class that has two canvases: one is very lightweight and I show it immediately, the other I create in a thread and block on the completion.
    The thread run() method after creating the canvas, does
    a setCurrent(canvas) and I'm able to verify that it occurs. The flag to continue is set and I block again
    on showNotify () which I have a second flag.
    showNotify() on the i85s never gets called though and my game never updates. It does work on the emulator i85s though.
    The code stripped down is like this.
    Class Manager extends TimerTask
    Thread loaderT = null;
    Loader loader = null;
    BigCanvas bc = null;
    Manager() {
    loader = new Loader (this);
    loaderT = new Thread(loader);
    loaderT.start();
    // this method called manager is instantiated
    void start() {
    timer = new Timer(); timer.schedule(this,0,delay);
    setCurrentAndVisible(tmpCanvas);
    // managers run
    void run (){
    if (!loader.done){
    current.repaint(); return;
    // done loading,
    loaderThread = null;
    advanceStates();
    if (bc.visible){ // set when showNotify() called
    bg.repaint();
    class Loader implements Runnable{
    Manager m = null; BigCanvas c = null; done = false;
    Loader(Manager m){
    this.m = m;
    run () {
    m.bc = new BigCanvas();
    m.d.setCurrent(c);
    done = true;
    please note that the classes and methods arent exactly as they are in my code, i just copied what the process was and renamed variables to make sense in a forum-setting. the code all compiles and runs fine in the emulator (so if i misspelled things, or left out of part of method sigs above please dont worry about correcting it), I'm just trying to explain my programming method above not write exactly compiling code.
    TempCanvas and Loader are both inner-classes of Manager also.
    thanks a lot!
    ps. why isnt there a cldc-interest mailing list?
    I find mailing lists easier to keep track of then forums.

    please note,
    setCurrentAndVisible does the following
    setCurrentAndVisible(BaseCanvas c)
    current = c;
    d.setCurrent(current);
    and current is a BaseCanvas in Manager.
    Also in Loader.run() , m.d.setCurrent(c); is actually
    m.setCurrentAndVisible(c);
    thanks!

  • TableSorter class never ever calls getModelToView()

    I am using TableSorter class to sort tables. There is a piece of optimization code that never gets called: getModelToView(). For that method to be called a check is performed (modelToView != null). But modelToView is assigned inside that method! This causes a single cell update to trigger fireTableDataChanged(). Is that a known bug? Is there a fix?

    I see what you mean.. you're right, it seems like modelToView will always be null.
    I found another bug.. when mouse is clicked on the tableheader area where it doesn't have any column (when table is stretched it can have no column there) , columnModel.getColumnIndexAtX(e.getX()) returns -1, and if the check there is not added, then get a runtime out-of-bounds exception on the following line columnModel.getColumn(viewColumn).getModelIndex() because viewColumn is set to -1. See the code snippet below:
    public void mouseClicked(MouseEvent e) {
                JTableHeader h = (JTableHeader) e.getSource();
                TableColumnModel columnModel = h.getColumnModel();
                int viewColumn = columnModel.getColumnIndexAtX(e.getX());
                if(viewColumn == -1) {  // added!
                    return;
                int column = columnModel.getColumn(viewColumn).getModelIndex();

  • Getting FacesContext from a Servlet Filter

    I am trying to get at the FacesContext from within a servlet filter, but when I call this in the doFilter(request, response) method:
    FacesContext context = FacesContext.getCurrentInstance();
    context is null.
    Any ideas to get around this?

    Those links might be helpful for you:
    http://www.thoughtsabout.net/blog/archives/000033.html
    http://jroller.com/page/why/20050124
    Sergey : http://jsfTutorials.net

  • When i try to set up my icloud account the system says it is sending me an email to verify.  I never get the email and it is not in my spam filter.  How can i get set up??

    when i try to set up my icloud account the system says it is sending me an email to verify.  I never get the email and it is not in my spam filter.  How can i get set up??

    Make sure that your Apple ID is your email address and you do not have any other or old IDs associated with you. Go to www.appleid.apple.com and confirm this info. Make sure that the email address you are trying to sign up with is your primary one.

  • I just want to know why money was taken out mi bank account,i still have a itunes balence and used a gift card.id love someone 2 call me about this but i never get thru to you

    i just want to know why money was taken out mi bank account,i still have a itunes balence and used a gift card.id love someone 2 call me about this but i never get thru to you

    This is a User to User Forum... You are not addressing Apple Here...
    Suggest you use this link to Contact iTunes Customer Service
    Apple  Support  iTunes Store  Contact Us

  • Faces Servlet no getting called when accessing JSF portlet

    Hi,
    I have a JSF web application and I am exposing the functionality of this JSF web application using native Weblogic Portal JSF portlets. I have configured this JSF web application as a simple producer and I am consuming these portlets in my portal using WSRP.
    I have written a custom FacesServlet and configured it in the web.xml of the producer web application. When I access the pages in the producer web app like a normal web app, I see that my faces servlet is being called but when I consume these pages via the JSF portlet and view the portlets in the portal then the Faces servlet is not being called.
    Is this normal behavior or is WSRP causing this problem or am I missing something. Your help is greatly appreciated.
    Regards,
    Hitesh

    Hi Hitesh,
    What I was asking you to give a try was, configure the standard faces servlet for example if you are using JSF RI
    the configuration will look like
        <servlet>
            <servlet-name>FacesServlet</servlet-name>
            <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
            <load-on-startup>100</load-on-startup>
        </servlet>I am not very sure whether this can solve the problem.
    Thanks
    Sreeram
    Edited by sreeram.jonnalagadda at 06/10/2008 4:46 AM

  • Servlet Filter issue

    Hi,
    In my project we have written custom filter which will intercept each request and check whether session is active or not. If not then redirect it to login page else user can do normal operation.
    but the problem is, whenever i make a request, CustomFilter.doFilter() method is getting called 7-8 times. Ideally it should be called once, can anybody tell me what would be the root cause?
    following are the configuration made for customfilter in web.xml
    <filter>
    <filter-name>customfilter</filter-name>
    <filter-class>com.foo.CustomFilter</filter-class>
    </filter>
    <filter-mapping>
    <filter-name>customfilter</filter-name>
    <url-pattern>*.jfsf</url-pattern>
    </filter-mapping>
    Apart from this, i do have faces-servlets default filter in web.xml
    Am I am missing something in the filter configuration?>
    Please advice.
    Thanks
    chintan

    I have the same problem, but in my case its looping inside the doFilter and never terminationg from it, and becz of that I dont see the 1st page(Login page ) what could be the problem,
    here is my web.xml..
         <filter>
              <filter-name>LoginFilter</filter-name>
              <filter-class>
                   com.indemand.indab.architecture.LoginFilter
              </filter-class>
              <init-param>
                   <param-name>error_page</param-name>
                   <param-value>login.jsp</param-value>
              </init-param>
              <init-param>
                   <param-name>login_page</param-name>
                   <param-value>login.jsp</param-value>
              </init-param>
         </filter>
         <filter-mapping>
              <filter-name>LoginFilter</filter-name>
              <url-pattern>/*</url-pattern>
         </filter-mapping>
    and here is filter class----
    public void doFilter(ServletRequest request, ServletResponse response,
                   FilterChain chain) throws IOException, ServletException {
              HttpSession session = ((HttpServletRequest) request).getSession(true);
              User currentUser = (User) session.getAttribute("user");
              String URI = ((HttpServletRequest) request).getRequestURI();
              System.out.println("Filter doFilter ......");
              if (filterConfig == null) {
                   System.out.println("filterConfig null.");
                   return;
              if (filterConfig.getInitParameter("error_page") != null) {
                   errorPage = filterConfig.getInitParameter("error_page");
              } else {
                   errorPage = "/indabch/login.jsp";
              if (filterConfig.getInitParameter("login_page") != null) {
                   loginPage = filterConfig.getInitParameter("login_page");
              } else {
                   loginPage = "/indabch/login.jsp";
              if (currentUser == null) {
                   ((HttpServletResponse) response).sendRedirect(loginPage);
              } else {
                   AuthorizationManager loginMan = new LoginManager();
                   boolean authorized = loginMan.isUserAuthorized(currentUser
                             .getLoginName(), currentUser.getPassword());
                   if (authorized) {
                        chain.doFilter(request, response);
                   } else {
                        ((HttpServletResponse) response).sendRedirect(errorPage);
         }

  • Is a Servlet-Filter which serializes requests in the same user session ok?

    The Servelt specification states that the Web-Application is itself responsible for synchronizing access to HttpSessions. It is from the serversite not possible to prevent multiple threads to access the same HttpSession (i.e. the user could always open a second window, retransmit a form etc). My assumption is that while this does not happen often it can happen and therefore I think each access to the HttpSession must be synchronized. For a further discussion see http://forum.java.sun.com/thread.jsp?forum=4&thread=169872 .
    Concurrent programming is generally complicated and errorprone. At least in developing JSPs it is inconvenient and easy to forget. My Web-App uses often HttpSession and it can be used in different not predefined places, so I had the idea to implement a ServletFilter which serializes threads which happen in the same session. This involves certainly some overhead. However for the advantages of easier code maintains and higher consistency I am ready to pay this overhead.
    My question is generally what you think of this approach and second whether the way I implemented the Filter works.
    The Filter actually generates for each Request an HttpServletRequestWrapper which intercepts calls to getSession and on call aquires a Lock so that other threads have to wait for the same Session. The lock is released when the doFilter method of the Filter returns. So threads run concurrently until the first access to the Session and from there they are serialized until the end of the Request.
    For the details I will give the code for the Filter and the Wrapper (that?s all the code needed except the ReentrantLock which is Doug Lea?s implementation http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/intro.html )
    the Filter
    public class SessionThreadFilter implements Filter
      public static final String MUTEXT_IN_SESSION_KEY = "org.jaul.filter.SessionThreadFilter.MUTEX";
      //constructor, init, destroy methods do nothing
      public void doFilter(ServletRequest reqIn,ServletResponse res,FilterChain filterChain)
        throws IOException, ServletException
        //if req not instanceof of HttpRequest don't do anything
        if (!(reqIn instanceof HttpServletRequest))
          filterChain.doFilter(reqIn, res);
        } else
          HttpServletRequest req = (HttpServletRequest) reqIn;
          //We use a HttpRequestWrapper each time a user accesses
          //through this
          //Wrapper a Session is Lock is aquired. The filter method returns
          //the lock if it exists is released
          //each thread needs it's own wrapper so the wrapper itself
          //doesn't have to be synchronized
          SessionThreadRequestWrapper wrapper = new SessionThreadRequestWrapper(req);
          try{
            filterChain.doFilter(wrapper, res);
          }finally{
            ReentrantLock lock = wrapper.getLock();
            if (lock != null && lock.holds() != 0)
                       lock.release(lock.holds());
    the Wrapper
    final public class SessionThreadRequestWrapper extends HttpServletRequestWrapper {
      private ReentrantLock lock = null;
       * Constructor for SessionThreadRequestWrapper.
       * @param arg0
      public SessionThreadRequestWrapper(HttpServletRequest req){
        super(req);
       * @see javax.servlet.http.HttpServletRequest#getSession()
      public HttpSession getSession(){
        return getSession(true);
       * @see javax.servlet.http.HttpServletRequest#getSession(boolean)
      public HttpSession getSession(boolean construct){
        //this will get the session an the lock
        HttpSession session = getLockFromSession(construct);
        if (session == null) return null;
        //get a lock on the mutex
        try{
          lock.acquire();
        } catch (InterruptedException e){
          throw new IllegalStateException("Interrupted while thread waiting for session");
        //now we check again if the session is still valid
        try{
          session.getAttribute(SessionThreadFilter.MUTEXT_IN_SESSION_KEY);
        } catch (IllegalStateException e){
          //again we go recusively but first release the lock
          lock.release();
          lock = null;
          return getSession(construct);
        //after you got the lock you can return the session
        return session;
       * gets the lock from the session
       * @param construct
       * @return HttpSession
      private HttpSession getLockFromSession(boolean construct){
        //test if it is a new Session
        HttpSession session = super.getSession(construct);
        //if is null no session was realy requested
        if (session == null) return null;
        //otherwise try to get the lock if necessery construct it
        //syncrhonized over session
        synchronized (session){
          //this migth throw an Exception if the session has been
          //invalidated in the mean time
          try{
            lock = (ReentrantLock) session.getAttribute(SessionThreadFilter.MUTEXT_IN_SESSION_KEY);
            if (lock == null){
              lock = new ReentrantLock();
              session.setAttribute (SessionThreadFilter.MUTEXT_IN_SESSION_KEY, lock);
            return session;
          } catch (IllegalStateException e){
            //the session has been invalidated before we tried to get the
            //lock we recursively call getLockFromSession
            //( assumption checked with Jetty: if the session is invalidated
            //and getSession is called on the thread a new valid session
            // should is returend)
            //I hope sometime you should get a valid session but I am not
            //sure. This is crucial for breaking of the recursion
            lock = null;
            return this.getLockFromSession(construct);
      /** used by the Filter to get the lock so that it can release it
      ReentrantLock getLock(){
         return this.lock;
    }As stated I would be very thankful if you could check the code and give some commends.

    synchronized (session){Are you sure that the session instance returned by two
    concurrent calls to getSession(...) are the same? I
    think that tomcat for instance may return different
    instances for the same "logical " session, which would
    break your scheme I think... Thank you (I did not know that on Tomcat). The same thing could also occur if another filter wrapped the Session.
    That's indeed a problem,which I have already adressed in another thread, but did not get an answer. ( http://forum.java.sun.com/thread.jsp?forum=33&thread=412380). The already cited thread http://forum.java.sun.com/thread.jsp?forum=4&thread=169872 adresses the same problem, but the discussion there ends with the recomandation that you should synchronize on HttpSession as I did it. Also in other forums I've read so.
    However like you I've at least strong doubts in this approach, so now my question is on what should I than generally for any access in any web-app syncrhonize the access to Http-Session as demanded by the Servlet specs.
    A few not realy satisfying answers:
    Synchronize on the HttpSession itself: I think still the best approach, but as you say is it guaranteed that the same instance of an HttpSession is given to each Request (in one Session)?
    Synchronized on the HttpServlet: This only works if no other servlet (or jsp) accesses in the session the value with the same key ( of course only if the session itself is threadsave). In case of ThingleThread it is not possible at all there can be multiple instances (you could use a static variable)
    Holding the object to synchronize on in applicaton scope or session scope: This obiously doesn't help, because somehow you have to obtain the lock and at least there you need another synchronize.Holding in application socpe is slow a static variable lock would be better there.
    Synchronize on some static variable: This will work, but is very slow (each request not only in the same session would synchronize on this).
    Hold a map in application scope, which holds for each Session-key a lock: Is probably faster than the static variable thing. However the access and the management of the Map (removing of unused locks etc.- Mabe you could use a WeakHashMap to collect the locks for not used keys anymore) is time consuming too and again the map must be accessed syncrhonasly by all requests.
    Syncrhonize on the Filter (only in my case): This is as slow as the static variable approach because each request will use the same lock the one instance of the Filter.
    So synchronizing on the session is propably the best approach if the same attribute name is accesed by different servlets. However if you say that some Web-Containers return different HttpSession instances for the same Session (which is legal according to the specification) this of course does not work.
    So I have realy no clue on what to syncrhonize than. Now help is not only neede on my Thread serialization filter but on my generally Servlet prgromming.
    May be you could help me for another synchronization aproach.

  • Servlet Filter - Reading Request Error

    I have a servlet filter that sits in front of a webservice servlet (AXIS) - what I want the filter to do is to look at the content of the ServletRequest and if a particular string is located in the request, I want to call another service. Everything works just fine except (isin't there always an execept) that when I execute the following code in the filter:
    BufferedReader inReader = request.getReader();
    String line = null;
    StringBuffer sbuf = new StringBuffer();
    // Read the current request into a buffer
    while((line = inReader.readLine()) != null) {
    sbuf.append(line);
    sbuf.append("\n\r");
    if (sbuf.toString().indexOf("mystring") > -1) {
    // I do some code
    } else {
    chain.doFilter(request, wrapper);
    When I execute this code, at the chain.doFilter I get an "java.lang.IllegalStateException: getReader() has already been called for this request"
    I know that this is because I obtained the Reader from the request. But my question is - How can I look at the request string so that I can evaluate it and not have this exception thrown..
    Thx in advance...

    My guess is that when you do the chain.doFilter you pass the request to another resource that then tries to access the request.getInputStream method.
    From the JavaDocs:
    getReader
    public java.io.BufferedReader getReader()
    throws java.io.IOException
    Retrieves the body of the request as character data using a BufferedReader. The reader translates the character data according to the character encoding used on the body. Either this method or getInputStream() may be called to read the body, not both.
    Returns:
    a BufferedReader containing the body of the request
    Throws:
    java.io.UnsupportedEncodingException - if the character set encoding used is not supported and the text cannot be decoded
    IllegalStateException - if getInputStream() method has been called on this request
    java.io.IOException - if an input or output exception occurred

Maybe you are looking for