1 Reply Latest reply on Jan 4, 2008 1:44 PM by starkc

    JBoss + custom tags error

    starkc

      I have a confounding error while doing a migration from WebLogic to JBoss involving custom JSP tags. Tags appear to stop instantiating new tag objects between requests. The first few times I hit a page, it will perform the tag correctly, but later requests result in errors that seem to trace back to the tag object itself not being instantiated. I post this here in the configuration forum because the code has worked before and I'm willing to bet I have a small error that may be tripping everything here up.

      As an example, I coded a custom tag that loops over the values in an ArrayList and prints trace statements to the console and to the jsp that uses the tag.

      Tag:

      package com.cybersource.riskmanager.admin.tag;
      
      import java.io.IOException;
      import java.sql.SQLException;
      import java.util.ArrayList;
      import javax.naming.NamingException;
      import javax.servlet.jsp.JspTagException;
      import javax.servlet.jsp.PageContext;
      import javax.servlet.jsp.tagext.IterationTag;
      import javax.servlet.jsp.tagext.TagSupport;
      
      public class TestBusinessListTag extends TagSupport implements IterationTag
      {
      
       private ArrayList businesses = new ArrayList();
      
       private int numBusinesses;
       private int currentBusiness;
      
       public TestBusinessListTag()
       {
       System.out.println( "DEBUG ---- CONSTRUCTOR" );
      
       businesses.add( "a" );
       businesses.add( "b" );
       businesses.add( "c" );
       businesses.add( "d" );
      
       numBusinesses = 0;
       currentBusiness = 0;
       }
      
       public void resetAll()
       {
       businesses.clear();
       businesses.add( "a" );
       businesses.add( "b" );
       businesses.add( "c" );
       businesses.add( "d" );
      
       currentBusiness = 0;
       }
      
       public int doStartTag() throws JspTagException
       {
       try
       {
       pageContext.getOut().print( "doStartTag()<br>" );
       }
       catch( IOException ioe )
       {
       throw new JspTagException( ioe.getMessage() );
       }
      /* catch(NamingException namingexception)
       {
       throw new JspTagException("Unable to contact the database connection pool to get a connection.");
       }
       catch(SQLException sqlexception)
       {
       throw new JspTagException("The database query to retrieve the list of businesses failed.");
       }
      */
       numBusinesses = businesses.size();
       if(numBusinesses > 0)
       {
       super.pageContext.setAttribute("anyBusinesses", Boolean.TRUE);
       nextBusiness();
       return 1;
       } else
       {
       super.pageContext.setAttribute("anyBusinesses", Boolean.FALSE);
       return 0;
       }
       }
      
       public int doEndTag() throws JspTagException
       {
       try
       {
       pageContext.getOut().print( "doEndTag()<br>" );
       }
       catch( IOException ioe )
       {
       throw new JspTagException( ioe.getMessage() );
       }
      
       super.pageContext.removeAttribute("rowBusiness");
       return 6;
       }
      
       public int doAfterBody() throws JspTagException
       {
       try
       {
       pageContext.getOut().print( "doAfterTag()<br>" );
       }
       catch( IOException ioe )
       {
       throw new JspTagException( ioe.getMessage() );
       }
      
      
       if(currentBusiness == numBusinesses)
       {
       System.out.println( currentBusiness + " == " + numBusinesses );
       return 0;
       }
       else
       {
       System.out.println( currentBusiness + " != " + numBusinesses );
       nextBusiness();
       return 2;
       }
       }
      
       public void nextBusiness() throws JspTagException
       {
       if( currentBusiness >= numBusinesses )
       {
       System.out.println( "You cant fool me!" );
       //resetAll();
       }
      
       try
       {
       pageContext.getOut().print( "nextBusiness()<br>" );
       pageContext.getOut().print( "CURRENT BUSINESS: " + (String)businesses.get(currentBusiness) );
       }
       catch( IOException ioe )
       {
       throw new JspTagException( ioe.getMessage() );
       }
      
       super.pageContext.setAttribute("rowBusiness", businesses.get(currentBusiness));
       currentBusiness++;
      
       }
      }
      


      Which is embedded in a simple jsp as follows:
      <%@ page import="com.cybersource.riskmanager.admin*" %>
      <%@ taglib uri="/riskmanageradmin" prefix="rma" %>
      
      <html>
       <body>
       <h1>Testing sample tag</h1>
      
       <rma:test-business-list>
       <br>
       INSIDE TAG
       <br>
       </rma:test-list>
      
       </body>
      </html>
      


      When this runs, it will begin by running correctly, spitting out tracing statements as it goes through the logic of the tag, along with the "INSIDE TAG" tracing to show that it is going through the inside of the tag as well.

      After a refresh or two, an error is returned, as follows:
      org.apache.jasper.JasperException: Exception in JSP: /testtag.jsp:8
      
      5: <body>
      6: <h1>Testing sample tag</h1>
      7:
      8: <rma:test-business-list>
      9: <br>
      10: INSIDE TAG
      11: <br>
      
      
      Stacktrace:
       org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:504)
       org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
       org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
       org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
       javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
       org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
      
      root cause
      
      java.lang.IndexOutOfBoundsException: Index: 4, Size: 4
       java.util.ArrayList.RangeCheck(ArrayList.java:507)
       java.util.ArrayList.get(ArrayList.java:324)
       com.cybersource.riskmanager.admin.tag.TestBusinessListTag.nextBusiness(TestBusinessListTag.java:127)
       com.cybersource.riskmanager.admin.tag.TestBusinessListTag.doStartTag(TestBusinessListTag.java:67)
       org.apache.jsp.testtag_jsp._jspx_meth_rma_test$1business$1list_0(testtag_jsp.java:92)
       org.apache.jsp.testtag_jsp._jspService(testtag_jsp.java:66)
       org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
       javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
       org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
       org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
       org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
       javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
       org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
      


      The tag appears to pick up where it left off after the previous request, and jumps into the nextBusiness() method, where it errors out by trying to get a value out of the bounds of the ArrayList.

      If I uncomment the resetAll() method in nextBusiness(), the tag works as intended to, every time, unfortunately this is not a viable solution for the migration.


      Thanks for your help and comments in advance

        • 1. Re: JBoss + custom tags error
          starkc

          This appears to be fixed, with a change to the jbossweb-tomcat-55.sar/web.xml file. By setting a jsp param as follows:

           <servlet>
           <servlet-name>jsp</servlet-name>
          ...
           <init-param>
           <param-name>enablePooling</param-name>
           <param-value>false</param-value>
           </init-param>
          


          ...and then deleting the tmp and work directories in JBOSS_HOME/server/ and restarting JBoss.

          Wish I could have been more successful searching for this answer instead of posting again, but without much to go on as to what the actual problem was in the beginning, finding correct search terms was tough.

          Thanks anyways :)