9 Replies Latest reply on Sep 27, 2006 9:33 PM by ilavenila

    Exception recieving problem

      Hopefully someone has had to deal with this before.

      I'm deploying two EAR files (isolated) that can only communicate through the remote interface. In order to enforce this I have set the JBoss Isolated and CallByValue options to true.

      When standard operating procedure happens things are normal. Entities serialize nicely and all is well with the world.

      On most methods in the remote interface there are multiple exceptions that can be thrown, each in a certain instance. However when they get back to the other EAR the catch blocks won't/can't recognise them. All are annonated with @ApplicationException and everything compiles okay. I have tried both including and excluding the exceptions from the client jar in the calling EAR to no affect.

      I am also unable to cast the exceptions to the correct class.

      Any help would be appreciated.

      Thanks, Grant

      The stack trace of the exception is below.

      13:41:36,684 ERROR [STDERR] au.gov.deh.ieda.bus.pitem.pd.exceptions.PimInvalidSearchTermException: Valid taxon must be greater than zero
      13:41:36,684 ERROR [STDERR] at au.gov.deh.ieda.bus.pitem.pd.managers.QueryManagerBean.searchForSpecies(QueryManagerBean.java:539)
      13:41:36,684 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      13:41:36,684 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      13:41:36,700 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      13:41:36,700 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:585)
      13:41:36,700 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
      13:41:36,700 ERROR [STDERR] at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
      13:41:36,700 ERROR [STDERR] at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
      13:41:36,700 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      13:41:36,700 ERROR [STDERR] at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
      13:41:36,700 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      13:41:36,715 ERROR [STDERR] at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
      13:41:36,715 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      13:41:36,715 ERROR [STDERR] at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:79)
      13:41:36,715 ERROR [STDERR] at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:197)
      13:41:36,715 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      13:41:36,715 ERROR [STDERR] at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
      13:41:36,715 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      13:41:36,715 ERROR [STDERR] at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
      13:41:36,731 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      13:41:36,731 ERROR [STDERR] at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:78)
      13:41:36,731 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      13:41:36,731 ERROR [STDERR] at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:47)
      13:41:36,731 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      13:41:36,731 ERROR [STDERR] at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
      13:41:36,731 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      13:41:36,731 ERROR [STDERR] at org.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:225)
      13:41:36,747 ERROR [STDERR] at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:55)
      13:41:36,747 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      13:41:36,747 ERROR [STDERR] at org.jboss.ejb3.stateless.StatelessRemoteProxy.invoke(StatelessRemoteProxy.java:102)
      13:41:36,747 ERROR [STDERR] at $Proxy234.searchForSpecies(Unknown Source)
      13:41:36,747 ERROR [STDERR] at au.gov.deh.ieda.bus.pitem.pd.test.TestQueryManager.testSearchTaxonBad(TestQueryManager.java:193)
      13:41:36,747 ERROR [STDERR] at au.gov.deh.ieda.bus.pitem.pd.test.TestQueryManager.testSearchs(TestQueryManager.java:91)
      13:41:36,747 ERROR [STDERR] at au.gov.deh.ieda.bus.pitem.pd.test.TestQueryManager.doTests(TestQueryManager.java:74)
      13:41:36,747 ERROR [STDERR] at au.gov.deh.ieda.sys.generic.test.TestBase.runTests(TestBase.java:42)
      13:41:36,762 ERROR [STDERR] at org.apache.jsp.pages.testpdQueryManager_jsp._jspService(testpdQueryManager_jsp.java:89)
      13:41:36,762 ERROR [STDERR] at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
      13:41:36,762 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
      13:41:36,762 ERROR [STDERR] at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
      13:41:36,762 ERROR [STDERR] at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
      13:41:36,762 ERROR [STDERR] at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
      13:41:36,762 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
      13:41:36,762 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
      13:41:36,778 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      13:41:36,778 ERROR [STDERR] at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
      13:41:36,778 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
      13:41:36,778 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      13:41:36,778 ERROR [STDERR] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
      13:41:36,778 ERROR [STDERR] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
      13:41:36,778 ERROR [STDERR] at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
      13:41:36,778 ERROR [STDERR] at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
      13:41:36,793 ERROR [STDERR] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
      13:41:36,793 ERROR [STDERR] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
      13:41:36,793 ERROR [STDERR] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
      13:41:36,793 ERROR [STDERR] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
      13:41:36,793 ERROR [STDERR] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
      13:41:36,793 ERROR [STDERR] at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
      13:41:36,793 ERROR [STDERR] at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
      13:41:36,809 ERROR [STDERR] at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
      13:41:36,809 ERROR [STDERR] at java.lang.Thread.run(Thread.java:595)
      




        • 1. Re: Exception recieving problem

          They are caught by the Exception block. But it would be a lot nicer if I could identify the correct execption in order to handle the execption without a massive if {} else if {} construct

          • 2. Re: Exception recieving problem

            You should be able to catch the exception type thrown by the Session Bean and you will need to include the exception classes in the client. Have to tried calling the EJB from a plain java client. Do you get the same result.

            What JBoss Server and EJB 3 versions are you using

            I put together a test and am able to catch the Exception

            I'm using JBoss 4.0.4.GA with version of EJB3 bundled with the installer I think it's RC8


            Stateless Session Bean Code

            import javax.ejb.ApplicationException;
            import javax.ejb.Stateless;
            
            
            @Stateless
            @ApplicationException(rollback=false)
            public class MyStatelessSessionBean implements MyStatelessSessionRemote
            {
             public void throwsException() throws MyClientSideException
             {
             System.out.println("about to throw remote exception");
             throw new MyClientSideException("Server Side Exception thrown to the client");
             }
            }
            


            Remote Interface
            import javax.ejb.ApplicationException;
            import javax.ejb.Remote;
            
            @Remote
            public interface MyStatelessSessionRemote
            {
             public void throwsException() throws MyClientSideException;
            
            }
            


            Client code
            import javax.naming.InitialContext;
            import junit.framework.TestCase;
            
            public class ClientTestCase extends TestCase
            {
             public void testThrowException()
             {
             try
             {
             InitialContext ctx = new InitialContext();
             MyStatelessSessionRemote slsb = (MyStatelessSessionRemote)ctx.lookup("/MyStatelessSessionBean/remote");
            
             slsb.throwsException();
             fail("shouldn't get here");
             }
             catch(Exception ex)
             {
             ex.printStackTrace();
             assertTrue((ex instanceof MyClientSideException));
             }
             }
            }
            


            • 3. Re: Exception recieving problem
              ilavenila

              I am working on the same project as Grant. The problem doesn't occur when we run a client to invoke the EJBs.

              Our project is layered into different applications. Hence we deploy multiple applications as multiple EARS in JBOSS. And yes, we have the exception classes packaged as JARs in the consumer EAR.

              When the isolation value in ear.deployer xml is set to false, the exception classes are loaded using same class loader. So, there is no problem.. I am able to catch the exception. But when I set the isolation atribute to true, the classes in the different EARS are loaded by different classloaders.

              Hence when the exception is thrown by the first EAR, the exception handling code in the second EAR is not recognizing it as the class that is loaded by the EAR's class loader. Interestingly, this happens just for exceptions, the user objects such as entities are passed properly from one EAR to another.

              probably, its a bug in JBOSS where it is not marshalling the class when it is supposed to do..

              I believe this will keep you thinking..I will try to post some code tommorrow when i get into my office..

              Thanks
              ila

              • 4. Re: Exception recieving problem
                bill.burke

                what version? I thought I fixed this awhile ago...

                • 5. Re: Exception recieving problem
                  ilavenila

                  I am using JBOSS4.0.4 installed using jboss-4.0.4.GA-Patch1-installer.jar with ejb3 profile selected during installation

                  • 6. Re: Exception recieving problem

                    Bill,

                    Is there a test in the ejb3 testsutie to test for this scenario?

                    Thanks heap
                    Aaron

                    • 7. Re: Exception recieving problem

                      We are using jboss-4.0.4.GA-Patch1-installer.jar using the ejb3 profile (not clustered) during installation.
                      We are using JDK 1.5.0_06-b05 to compile the source with a ANT build script run using ANT 1.6.5.

                      Just having a look at your code snippets, does the annontation order matter?


                      Here's the build script for one of the layers.

                      <project basedir="." default="build" name="IEDA-BP">
                       <!--Loads are the Property files required for this project-->
                       <loadproperties srcfile="build/default.properties" />
                       <property environment="env" />
                       <path id="jboss-libs.classpath">
                       <pathelement location="${env.JBOSS_HOME}/client/jnp-client.jar" />
                       <pathelement location="${env.JBOSS_HOME}/client/jbosssx-client.jar" />
                       <pathelement location="${env.JBOSS_HOME}/client/jboss-j2ee.jar" />
                       <pathelement location="${env.JBOSS_HOME}/client/jboss-transaction-client.jar" />
                       <pathelement location="${env.JBOSS_HOME}/lib/commons-logging.jar" />
                       <pathelement location="${env.JBOSS_HOME}/server/default/deploy/ejb3.deployer/jboss-ejb3.jar" />
                       <pathelement location="${env.JBOSS_HOME}/server/default/deploy/ejb3.deployer/jboss-ejb3x.jar" />
                       <pathelement location="${env.JBOSS_HOME}/server/default/deploy/ejb3.deployer/jboss-annotations-ejb3.jar" />
                       <pathelement location="${env.JBOSS_HOME}/server/default/lib/hibernate3.jar" />
                       <pathelement location="${env.JBOSS_HOME}/server/default/lib/ejb3-persistence.jar" />
                       <pathelement location="${env.JBOSS_HOME}/server/default/lib/hibernate-annotations.jar" />
                       <pathelement location="${env.JBOSS_HOME}/server/default/lib/jboss-remoting.jar" />
                       <pathelement location="${env.JBOSS_HOME}/server/default/lib/log4j.jar" />
                       <pathelement location="${env.JBOSS_HOME}/server/default/lib/mail.jar" />
                       </path>
                       <path id="ieda.classpath">
                       <path refid="jboss-libs.classpath" />
                       <fileset dir="${bp.dir}" includes="**/*.class"/>
                       <fileset dir="${lib.dir}" includes="**/*.jar" />
                       <fileset dir="${dist.dir}" includes="**/*.jar" />
                       </path>
                       <target name="init">
                       <mkdir dir="${bp.dir}" />
                       <mkdir dir="${client.dir}" />
                       <mkdir dir="${manifest.location}" />
                       <copy includeemptydirs="false" todir="${bp.dir}">
                       <fileset dir="${src.dir}" excludes="**/*.launch, **/*.java" />
                       <fileset dir="${pd.location}/src" includes="META-INF/*persistence.xml" />
                       </copy>
                       </target>
                       <target name="clean">
                       <delete dir="${bp.dir}" />
                       <delete dir="${client.dir}" />
                       <delete dir="${manifest.location}" />
                       <delete>
                       <fileset dir="${dist.dir}">
                       <include name="**/*.jar" />
                       </fileset>
                       </delete>
                       </target>
                       <!--Clean Routines are done here -->
                       <target depends="clean" name="cleanall">
                       </target>
                      
                       <!-- Run the builds in the sequence -->
                       <!--<antcall target="build-project" />-->
                      
                       <!--Builds all the dependent subprojects-->
                       <target name="build-subprojects">
                       </target>
                      
                       <target depends="init, build-subprojects,build" name="buildEar">
                       <!-- create the ear -->
                       <ear destfile="${dist.dir}/${bp.filename}.ear" appxml="src/META-INF/application.xml" update="true">
                       <fileset dir="${dist.dir}" includes="**/*" />
                       </ear>
                       </target>
                      
                       <!-- build the manifest file -->
                       <target name="create-manifest">
                       <delete>
                       <fileset dir="${basedir}">
                       <include name="${manifest.file}" />
                       </fileset>
                       </delete>
                       <tstamp>
                       <format property="today_aus" pattern="${time.pattern}" locale="en" />
                       </tstamp>
                       <manifest file="${manifest.file}">
                       <attribute name="Version" value="${version}" />
                       <attribute name="Class-Path" value="${classpath}" />
                       <attribute name="Built-By" value="${built-by}" />
                       <attribute name="Built-On" value="${today_aus}" />
                       </manifest>
                       </target>
                      
                       <!-- Package the Project -->
                       <target depends="init, build-subprojects" name="build">
                       <antcall target="create-manifest">
                       <param name="classpath" value="${client.classpath}" />
                       </antcall>
                       <!-- Build client jar -->
                       <javac debug="true" debuglevel="${debuglevel}" destdir="${bp.dir}" source="${source}" target="${target}">
                       <src path="${pd.location}/${src.dir}" />
                       <src path="${generic.location}/${src.dir}" />
                       <src path="${src.dir}" />
                       <classpath refid="ieda.classpath" />
                       </javac>
                       <jar destfile="${dist.dir}/${client.filename}.jar" basedir="${bp.dir}" update="true" manifest="${manifest.file}">
                       <include name="**/test/**" />
                       <include name="**/generic/**" />
                       <include name="**/interfaces/**" />
                       <include name="**/entities/**" />
                       <include name="**/exceptions/**" />
                       </jar>
                       <!-- Build bp jar -->
                       <antcall target="create-manifest">
                       <param name="classpath" value="${bp.classpath}" />
                       </antcall>
                       <jar destfile="${dist.dir}/${bp.filename}.jar" basedir="${bp.dir}" update="true" manifest="${manifest.file}">
                       <exclude name="**/test/**" />
                       <exclude name="**/generic/**" />
                       <exclude name="**/interfaces/**" />
                       <exclude name="**/entities/**" />
                       <exclude name="**/exceptions/**" />
                       </jar>
                       </target>
                      </project>
                      


                      And here's the build script to create the ear packages
                      <project basedir="." default="build" name="IEDA-EAR">
                       <!--Loads are the Property files required for this project-->
                       <loadproperties srcfile="build/app.properties" />
                       <loadproperties srcfile="build/bp.properties" />
                       <loadproperties srcfile="build/ui.properties" />
                       <loadproperties srcfile="build/test.properties" />
                       <property environment="env" />
                      
                       <!--Clean Routines are done here -->
                       <target name="clean">
                       <delete>
                       <fileset dir="${basedir}">
                       <include name="${dist.dir}/*.jar" />
                       <include name="${dist.dir}/*.war" />
                       </fileset>
                       </delete>
                       </target>
                      
                       <!-- Run the builds in the sequence -->
                       <!--<antcall target="build-project" />-->
                      
                       <!--Builds all the BP dependent subprojects-->
                       <target name="bp-pim-sub-build">
                       <echo message="${ant.project.name}: Building PIM BP Projects" />
                       <ant antfile="${bp.pim.location}/build.xml" target="build" inheritall="false" />
                       <!--Copy the files to the library-->
                       <copy todir="${dist.dir}" description="Copying the Depenedent Libraries" overwrite="true">
                       <fileset dir="${bp.pim.location}/${dist.dir}" includes="**/*.jar" />
                       </copy>
                       </target>
                      
                      
                       <!-- BP Individual app build targets -->
                       <target depends="clean, bp-pim-sub-build" name="build-bp-pim">
                       <antcall target="buildEar">
                       <param name="appxml" value="${bp.pim.appxml}" />
                       <param name="ear.filename" value="${bp.ear.filename}" />
                       </antcall>
                       </target>
                      
                       <!--Builds all the UI dependent subprojects-->
                       <target name="ui-pim-sub-build">
                       <echo message="${ant.project.name}: Building PIM UI Projects" />
                       <ant antfile="${ui.pim.location}/build.xml" target="build" inheritall="false" />
                       <!--Copy the files to the library-->
                       <copy todir="${dist.dir}" description="Copying the Depenedent Libraries" overwrite="true">
                       <fileset dir="${ui.pim.location}/${dist.dir}" includes="**/*.jar" />
                       <fileset dir="${ui.pim.location}/${dist.dir}" includes="**/*.war" />
                       </copy>
                       </target>
                      
                       <!-- UI Individual app build targets -->
                       <target depends="clean, ui-pim-sub-build" name="build-ui-pim">
                       <antcall target="buildEar">
                       <param name="appxml" value="${ui.pim.appxml}" />
                       <param name="ear.filename" value="${ui.ear.filename}" />
                       </antcall>
                       </target>
                      
                       <!--Builds all the TEST dependent subprojects-->
                       <target name="test-pim-sub-build">
                       <echo message="${ant.project.name}: Building PIM UI Projects" />
                       <ant antfile="${test.pim.location}/build.xml" target="build" inheritall="false" />
                       <!--Copy the files to the library-->
                       <copy todir="${dist.dir}" description="Copying the Depenedent Libraries" overwrite="true">
                       <fileset dir="${test.pim.location}/${dist.dir}" includes="**/*.jar" />
                       <fileset dir="${test.pim.location}/${dist.dir}" includes="**/*.war" />
                       </copy>
                       </target>
                      
                       <!-- TEST Individual app build targets -->
                       <target depends="clean, test-pim-sub-build" name="build-test-pim">
                       <antcall target="buildEar">
                       <param name="appxml" value="${test.pim.appxml}" />
                       <param name="ear.filename" value="${test.ear.filename}" />
                       </antcall>
                       </target>
                      
                       <target depends="create-manifest" name="buildEar">
                       <!-- create the ear -->
                       <ear destfile="${dist.dir}/${ear.filename}.ear" appxml="${appxml}" update="true" manifest="${manifest.file}">
                       <fileset dir="${dist.dir}" includes="**/*.jar" />
                       <fileset dir="${dist.dir}" includes="**/*.war" />
                       </ear>
                       </target>
                      
                       <!-- build the manifest file -->
                       <target name="create-manifest">
                       <delete>
                       <fileset dir="${basedir}">
                       <include name="${manifest.file}" />
                       </fileset>
                       </delete>
                       <tstamp>
                       <format property="today_aus" pattern="${time.pattern}" locale="en" />
                       </tstamp>
                       <manifest file="${manifest.file}">
                       <attribute name="Version" value="${version}" />
                       <attribute name="Built-By" value="${built-by}" />
                       <attribute name="Built-On" value="${today_aus}" />
                       </manifest>
                       </target>
                      
                       <target name="build"></target>
                      </project>
                      


                      Here's some code snippets for the actual app.

                      Remote Interface
                      package pitem.pd.interfaces;
                      
                      import java.util.List;
                      
                      import javax.ejb.Remote;
                      
                      
                      import pitem.pd.entities.lookup.SpratSpecies;
                      import pitem.pd.entities.search.SpratSearch;
                      import pitem.pd.exceptions.PimInvalidSearchTermException;
                      import sys.generic.JndiLookupSupport;
                      
                      
                      /**
                       * @author QuimbyG
                       * Remote Interface for the use of the Process Layer for the UserManagement of the PAD2 system.
                       *
                       */
                      @Remote
                      public interface QueryManager extends sys.pd.interfaces.QueryManager {
                      
                       /** JNDI location string */
                       public final static String location = JndiLookupSupport.getJndiName(QueryManager.class);
                      
                       /**
                       * Find a SPRAT entry for the given criteria
                       * @param searchTerms object containing the search criteria
                       * @return a SPRAT species entry
                       * @throws PimNoEntityException
                       * @throws PimIllegalArgumentException
                       * @throws PimInvalidSearchTermException
                       * @throws DataLayerException
                       */
                       public SpratSpecies searchForSpecies(SpratSearch searchTerms) throws PimInvalidSearchTermException, Exception;
                      }
                      



                      Stateless Session Bean
                      package pitem.pd.managers;
                      
                      import java.util.ArrayList;
                      import java.util.List;
                      
                      import javax.ejb.ApplicationException;
                      import javax.ejb.Stateless;
                      import javax.persistence.EntityManager;
                      import javax.persistence.NoResultException;
                      import javax.persistence.NonUniqueResultException;
                      import javax.persistence.PersistenceContext;
                      import javax.persistence.Query;
                      
                      import org.apache.log4j.Logger;
                      
                      
                      import pitem.pd.entities.lookup.SpratSpecies;
                      import pitem.pd.entities.search.SpratSearch;
                      import pitem.pd.exceptions.PimDataException;
                      import pitem.pd.exceptions.PimIllegalArgumentException;
                      import pitem.pd.exceptions.PimInvalidSearchTermException;
                      import pitem.pd.exceptions.PimNoEntityException;
                      import pitem.pd.interfaces.QueryManager;
                      import sys.pd.exceptions.DataLayerException;
                      
                      
                      /**
                       * @author QuimbyG
                       * This class implements the remote interface for PIM queries.
                       */
                      @ApplicationException(rollback=false)
                      public @Stateless class QueryManagerBean implements QueryManager {
                      
                       /** Inject the entity manager */
                       @PersistenceContext(unitName="PITEM")
                       private EntityManager manager;
                      
                       /** Log4j logging */
                       static Logger logger = Logger.getLogger(QueryManagerBean.class);
                      
                       /*
                       * (non-Javadoc)
                       * @see au.gov.deh.pim.pd.dm.PimQueryManager#searchForSpecies(au.gov.deh.pim.pd.search.SpratSearch)
                       */
                       public SpratSpecies searchForSpecies(SpratSearch searchTerms) throws PimInvalidSearchTermException,
                       PimNoEntityException,
                       PimIllegalArgumentException,
                       DataLayerException {
                       if (searchTerms == null) {
                       logger.warn("No search terms passed");
                       throw new PimInvalidSearchTermException("searchForSpecies","Null passed",
                       "Must have a valid SpratSearch object");
                       }
                      
                       logger.info("search for Species with SpratTerms");
                       SpratSpecies result = new SpratSpecies();
                      
                       /* Query for the taxon id if set */
                       if (searchTerms.getTaxon() != null) {
                       Integer taxon = searchTerms.getTaxon();
                       /* Check if TAXON_ID is valid */
                       if (taxon > 0) {
                       try {
                       result = (SpratSpecies) manager.createQuery("select OBJECT(s) from SpratSpecies s" +
                       " WHERE s.taxon = :taxon")
                       .setParameter("taxon",taxon)
                       .getSingleResult();
                       } catch (NonUniqueResultException e) {
                       logger.warn("Multiple records");
                       throw new PimInvalidSearchTermException("searchForSpecies","Not unique",
                       "Query term must return only one result",e);
                       } catch (NoResultException e) {
                       logger.warn("No record");
                       throw new PimNoEntityException("searchForSpecies","No Record","Proposal does not exist",e);
                       } catch (IllegalArgumentException e){
                       logger.error("Illegal argument",e);
                       throw new PimIllegalArgumentException("searchForSpecies", "Illegal Argument", e.toString(), null, e);
                       } catch (Throwable e) {
                       logger.error("Error with Species Search query",e);
                       throw new DataLayerException(PimDataException.ERR_NUMBER, "searchForSpecies", "Unknown", e.toString(), null, e);
                       }
                       } else {
                       logger.warn("invalid taxon id passed");
                       throw new PimInvalidSearchTermException("searchForSpecies","taxon is less than zero",
                       "Valid taxon must be greater than zero");
                       }
                       } else if (searchTerms.getScientificName() != null) {
                       /* Query for the species name otherwise */
                       String s = "%" + replaceWildCards(searchTerms.getScientificName()) + "%";
                      
                       try {
                       result = (SpratSpecies) manager.createQuery("select OBJECT(s) from SpratSpecies s" +
                       " WHERE UPPER(s.scientificName) LIKE UPPER(:sciName)")
                       .setParameter("sciName", s)
                       .getSingleResult();
                       } catch (NonUniqueResultException e) {
                       logger.warn("Multiple records");
                       throw new PimInvalidSearchTermException("searchForSpecies","Not unique",
                       "Query term must return only one result",e);
                       } catch (NoResultException e) {
                       logger.warn("No record");
                       throw new PimNoEntityException("searchForSpecies","No Record","Proposal does not exist",e);
                       } catch (IllegalArgumentException e){
                       logger.error("Illegal argument",e);
                       throw new PimIllegalArgumentException("searchForSpecies", "Illegal Argument", e.toString(), null, e);
                       } catch (Throwable e) {
                       logger.error("Error with Species search query",e);
                       throw new DataLayerException(PimDataException.ERR_NUMBER, "searchForSpecies", "Unknown", e.toString(), null, e);
                       }
                       } else {
                       logger.warn("No search terms passed");
                       throw new PimInvalidSearchTermException("searchForSpecies","Empty object",
                       "Must have a valid SpratSearch object");
                       }
                       return result;
                       }
                      
                       /** Method to turn standard wildcards into EJBQL wildcards
                       *
                       * @param s the String to convert
                       * @return the converted string
                       */
                       private String replaceWildCards(String s) {
                       logger.debug("replacing wildcards");
                      
                       s = s.replace("%","_"); // escape all percentage signs
                       s = s.replace(' ','%'); // turn spaces into wildcards
                       s = s.replace('*','%'); // convert * to % for SQL search
                       s = s.replace('?','_'); // convert ? to _ for SQL search
                      
                       return s;
                       }
                      }
                      


                      The place where it is called in the Backing Bean to test things
                       try {
                       SpratSearch s = new SpratSearch(new Integer(-1));
                       SpratSpecies t = Qm.searchForSpecies(s);
                       result.setDesc("Found " + t.getMigratoryScientificName());
                      
                       } catch (PimInvalidSearchTermException e) {
                      
                       result.setDesc(e.getMessage());
                       result.setPass(true);
                      
                       } catch (Exception e) {
                       if (e instanceof PimInvalidSearchTermException) {
                       PimInvalidSearchTermException t = (PimInvalidSearchTermException) e;
                       result.setDesc(t.traceBack());
                       result.setPass(true);
                       } else {
                       result.setDesc(e.toString());
                       result.setPass(false);
                       e.printStackTrace();
                       }
                       }
                      


                      If it can identify the correct Exception the test passes otherwise it fails.

                      Hope this helps clarify what is happening.

                      Thanks for you time.

                      Grant

                      • 8. Re: Exception recieving problem

                        Just tried the the same code on two separate computers and it works.

                        However still does not work on one server instance with isolation set to true.

                        Thanks,

                        Grant

                        • 9. Re: Exception recieving problem
                          ilavenila

                          And also, the same code works on two different instances on the same machine. But it is not working inside the same JBOSS instance with isolated EARs.

                          I believe it may be JBOSS trying to be smart and optimising the call within the same instance by not doing the marshalling for the thrown application exception... isn't that make isolation/call-by-value option void? hmm..

                          ila