3 Replies Latest reply on Jun 16, 2011 3:33 AM by Wolf-Dieter Fink

    ejb3 exception

    karthik karthik Newbie

      hi

       

      JBOSS6 AS,JDK6,LINUX

       

      Can some body provide me Example snippets on How to Customise Exceptions usage in EJB3

       

      Exceptions thrown on Ejb3 in J2ee container should be avaliable on client process

       

       

      ex...

       

       

      //ejb3' server

       

      try{

      }catch(SQLException sqx){

          throws new EjbException(1001)

      }

       

       

      //ejb3 client (web / standalone /.....)

       

      String Error = xyz XXXXXXX("????")  // this should fetch the 1001

       

       

      How to achieve the same in ejb3 ????

       

       

      with regards

      Karthik

        • 1. Re: ejb3 exception
          Wolf-Dieter Fink Master

          If you declare a checked Exception it will be provided to the client.

          RuntimeExceptions might be covered.

           

          Is that what you meant?

          • 2. Re: ejb3 exception
            karthik karthik Newbie

            Hi

             

            My Primary requirement isto display appropriate message in Unicode languages for a single installation...this needs to be displayed Error / Exception Gentel messages raised on account of exceptions...

             

            To achieve the same i have  to customised the my own Exception class called  "EjbException.java" which extends Exception calss

             

            With this process I need the  number raised due to  Exception to return back  to the Clinet . A   Unique number for  every exception's type is  used as key value pair  ..

             

            The number is refrence to a Gentel Error message to the  client User in appropriate Unicoded Fomat

             

            English Users                                       

            1001 = Data Not Provided ( english )   

             

            or    

            Spanish User

            1001 = xxxxxx( Spanish )

             

             

            //Ejb's

            try{

             

             

            }catch(SQLException sqx){

                throws new EjbException(1001)

            }

             

             

             

            //ejb3 client (web / standalone /.....)

            int Error = xyz XXXXXXX("????")  // this should fetch the 1001

            String message  =  xyz.getMessage(Error);  // this should fetch the appropriate message and display

             

             

            with regards

            karthik

            • 3. Re: ejb3 exception
              Wolf-Dieter Fink Master

              I use standard Java ResourceBundle for this, it support what you need.

               

              The Exception include a key (in your case the number) and the native message.

              The getMessage() or getLocalizedMessage() method checks the ResourceBundle and provide the localized message or the native one if nothing was found.