[Installation, Configuration & DEPLOYMENT] - JBoss + custom tags error
by 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
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4117095#4117095
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4117095
18 years, 3 months
[EJB 3.0] - EJB3 with Eclipse
by pipo323400
Hi,
We are trying to work a simple EJB 3 application. Our goal is to post a stateless bean and acces to it from a web application.
We are developing it with eclipse. Here is the program structure:
-A java application that contains two interfaces and the bean (also a metainf) to implement the stateless bean.
-A web application 2.4 (we had tried also with 2.5).
We deploye the bean as a jar in the jboss, and it seems to recognize it. But when we try to acces with the web app (via servlet) we got an java.nullPointerException.
Ejb Code:
| import java.sql.ResultSet;
| import java.sql.SQLException;
| import javax.ejb.Remote;
|
|
| /**
| * This is the business interface for Carp enterprise bean.
| */
| @Remote
| public interface EjbRemote {
|
| boolean doStatement(String queryName) throws SQLException;
|
| ResultSet doQuery(String query) throws SQLException;
|
| void printQuery(String query);
| }
|
| import java.sql.ResultSet;
| import java.sql.SQLException;
| import javax.ejb.Local;
| @Local
| public interface EjbLocal {
|
| boolean doStatement(String queryName) throws SQLException;
|
| ResultSet doQuery(String query) throws SQLException;
|
| void printQuery(String query);
| }
|
| import javax.annotation.Resource;
| import javax.ejb.Stateless;
| import javax.sql.DataSource;
| import java.sql.Statement;
| import java.sql.Connection;
| import java.sql.ResultSet;
| import java.sql.SQLException;
|
| @Stateless
| public class EjbBean implements EjbLocal, EjbRemote {
|
| @Resource(mappedName = "TACWDS") DataSource TACWDS;
|
| public EjbBean() {
|
| }
|
| public boolean doStatement(String query) {
| //TODO implement doStatement
| return false;
| }
|
| public final ResultSet doQuery(String query) throws SQLException {
| System.out.println("Esecuzione query : " + query);
| Connection conn = TACWDS.getConnection();
| Statement stm = conn.createStatement();
| return stm.executeQuery(query);
| }
|
| public final void printQuery(String query) {
| System.out.println("Esecuzione query : " + query);
| }
| }
|
Servlet Code:
|
| public class appServlet extends HttpServlet {
| @EJB EjbLocal sless;
|
| public void service(HttpServletRequest req, HttpServletResponse resp)
| throws ServletException, IOException{
|
| resp.setContentType("text/html");
| PrintWriter out = resp.getWriter();
| //sless.printQuery("SELECT * FROM FOO");
|
| System.out.println("sless state: "+sless);
| }
| }
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4117092#4117092
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4117092
18 years, 3 months
[EJB 3.0] - How to size EJB3 continer for EJB3 stateless session beans (
by andyredhead
Hi,
I'd like to know if anyone has any guidelines or techniques for sizing the instance pool for EJB3 stateless session beans in JBoss 4.2.1?
We are going live with an EJB3 based application and I'd like to know if I've got the EJB3 container configured sensibly...
In ejb3-interceptors-aop.xml I've got the references to:
| <annotation expr="!class((a)org.jboss.annotation.ejb.PoolClass)">
| @org.jboss.annotation.ejb.PoolClass (value=org.jboss.ejb3.ThreadlocalPool.class, maxSize=300, timeout=10000)
| </annotation>
|
Which means I've multiplied the default by 100!
How can I tell if this is too big or too small?
Are there any other parameters I should be changing to run the EJB3 container under heavy load on poweful servers?
We will be running on jdk1.5_13, solaris 10, sun T2k servers (if that makes any difference).
Thanks
Andy
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4117081#4117081
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4117081
18 years, 3 months
[JBoss Seam] - Re: How to control end of conversations/state of stateful be
by schlafsack
"pete.muir(a)jboss.org" wrote : Post your use case for this.
If I understand the topic of this thread, I *think* I've come up against a similar problem in the search application I'm writing to learn seam.
My application has one page with a text box, a button, a results table and next/previous buttons.
I'd like to define a conversation as:
| * submitting a search query using the button.
| * navigation forwards though the results using the next link.
| * navigation backwards though the results using the previous link.
|
I'd also like the submission of a new query to start a new conversation. Ideally, clicking the button should end the existing conversation and begin a new one. So far I can't see an easy way of doing this.
With a simple @Begin attribute on the search method, performing a second search throws an exception - which is expected, we are already in a conversation.
Using @Begin(join=true) does not meet the requirement of starting a new conversation per search.
I could add a clear button that calls an @End attributed method but this is does not really meet your average user's expectations of a search tool.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4117080#4117080
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4117080
18 years, 3 months