This example was tested on JBoss 3.0.0-Tomcat 4.0.6
In application.xml, make sure you have
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
Make sure you have the jar you compiled
do not play with jndi.properties
don't need jboss-web.xml
public class BasicTestInterceptor extends DbEventInterceptorSupport { static Category log = Category.getInstance(BasicTestInterceptor.class.getName()); /** * Checks to see if a number is in range inclusively given three Strings. * @param check String representing a number. * @param low String representing the low number of the range. * @param high String representing the high number of the range * @param inclusive set to true if you want the low <= check and check <= high . * @param digits the number in digits to the left of the decimal to round. * positive, non-zero int * @return value converted to a string. * @throws ValidationException when encountering other exceptions like * NumberFormatException. * */ public static boolean inRange(String check, String low, String high, boolean inclusive) throws ValidationException { try { NumericValidationLocal numericValidation = EjbUtil.getNumericValdiationBean(); if(numericValidation==null) { System.out.println("Null numericValidation"); return false; } return numericValidation.inRange(check,low,high,inclusive); } catch(MathException me) { throw new ValidationException(me.getMessage()); } catch(Exception e) { throw new ValidationException(""); } }//inRange(...) ... }//BasicTestInterceptor
package com.atser.sejb.math; public interface NumericValidationLocal extends javax.ejb.EJBLocalObject { /** * Checks to see if a number is in range. * Range is inclusive given three Strings. * @param check String representing a number. * @param low String representing the low number of the range. * @param high String representing the high number of the range * @param inclusive set to true * if you want the low <= check and check <= high . * @param digits the number in digits to the * left of the decimal to round. positive, non-zero integer only. * For example: 1438 with 1 passed in will give us 1440. * @return value converted to a string. * @throws ValidationException for any number format problems. */ public boolean inRange( String check, String low, String high, boolean inclusive ) throws MathException; }//NumericValidationLocal
package com.atser.sejb.math; public interface NumericValidationLocalHome extends javax.ejb.EJBLocalHome { NumericValidationLocal create() throws javax.ejb.CreateException; }//NumericValidationLocal
import javax.ejb.*;//SessionContext import org.apache.log4j.*;//Category public class NumericValidationStatelessBean implements javax.ejb.SessionBean { private static Category log = Category.getInstance("NumericValidationStatefulBean"); private javax.ejb.SessionContext ctx; /** * Provides generic range checking. * Checks to see if a number is in range. * Range is inclusive given three Strings. * and returns true if in range or false if out of * specified range. */ public static boolean inRange(String check, String low, String high, boolean inclusive) throws MathException { try { double c = Double.parseDouble(check); double l = Double.parseDouble(low); double h = Double.parseDouble(high); if(inclusive) return (l<=c && c<=h); else return (l<c && c<h); } catch(NumberFormatException nfe) { throw new MathException("Invalid arguements to method: inRange(String check, String low, String high, boolean inclusive):"+check+","+low+" ,"+high+","+inclusive); } }//inRange(...) public void ejbCreate() { log.debug("ejbCreate()"); }//ejbCreate() public void ejbRemove() { log.debug("ejbRemove()"); }//ejbRemove() public void ejbActivate() { log.debug("ejbActivate()"); }//ejbActivate() public void ejbPassivate() { log.debug("ejbPassivate()"); }//ejbPassivate() public void setSessionContext(javax.ejb.SessionContext ctx) { this.ctx = ctx; log.debug("setSessionContext(..)"); return; }//setSessionContext(..) }//NumericValidationStatefulBean
<?xml version="1.0" encoding="UTF-8"?> <jboss> <enterprise-beans> <session> <ejb-name>com/atser/sejb/math/NumericValidation</ejb-name> <jndi-name>com/atser/sejb/math/NumericValidation</jndi-name> </session> </enterprise-beans> </jboss>
<!DOCTYPE ejb-jar PUBLIC '-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN' 'http://java.sun.com/j2ee/dtds/ejb-jar_2_0.dtd'> <ejb-jar> <enterprise-beans> <session> <!-- The JNDI name of the bean. --> <ejb-name>com/atser/sejb/math/NumericValidation</ejb-name> <!-- Class configuration for the bean --> <local-home>com.atser.sejb.math.NumericValidationLocalHome</local-home> <local>com.atser.sejb.math.NumericValidationLocal</local> <ejb-class>com.atser.sejb.math.NumericValidationStatelessBean</ejb-class> <session-type>Stateless</session-type> <transaction-type>Container</transaction-type> </session> </enterprise-beans> </ejb-jar>
<ejb-local-ref> <ejb-ref-name>ejb/NumericValidation</ejb-ref-name> <ejb-ref-type>Session</ejb-ref-type> <local-home>com.atser.sejb.math.NumericValidationLocalHome</local-home> <local>com.atser.sejb.math.NumericValidationLocal</local> <ejb-link>com/atser/sejb/math/NumericValidation</ejb-link> </ejb-local-ref>