commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject cvs commit: jakarta-commons-sandbox/messenger/src/java/org/apache/commons/messagelet ManagerServlet.java
Date Tue, 13 Aug 2002 07:19:10 GMT
jstrachan    2002/08/13 00:19:10

  Modified:    messenger/src/java/org/apache/commons/messagelet
                        ManagerServlet.java
  Log:
  Applied patches suggested by Louis Burroughs that allow exceptions that occur while subscribing
to JMS in the Messagelet engine to be handled differently, such as to continue if one subscription
fails, or to allow certain kinds of subscription exception but fail on others etc.
  
  So now developers can derive from ManagerServlet to provide their own servlet and overload
the handleJMSException() method to handle exceptions however they wish - only throwing a ServletException
if they want to fail the initialization of the Messagelet Engine
  
  Revision  Changes    Path
  1.13      +46 -7     jakarta-commons-sandbox/messenger/src/java/org/apache/commons/messagelet/ManagerServlet.java
  
  Index: ManagerServlet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/messenger/src/java/org/apache/commons/messagelet/ManagerServlet.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- ManagerServlet.java	15 May 2002 14:36:34 -0000	1.12
  +++ ManagerServlet.java	13 Aug 2002 07:19:10 -0000	1.13
  @@ -25,9 +25,9 @@
   
   import org.apache.commons.messagelet.impl.MessageServletDispatcher;
   import org.apache.commons.messagelet.impl.MessageHttpServletDispatcher;
  -import org.apache.commons.messagelet.impl.Subscription;
  -import org.apache.commons.messagelet.impl.SubscriptionDigester;
  -import org.apache.commons.messagelet.impl.SubscriptionList;
  +import org.apache.commons.messagelet.model.Subscription;
  +import org.apache.commons.messagelet.model.SubscriptionDigester;
  +import org.apache.commons.messagelet.model.SubscriptionList;
   import org.apache.commons.messenger.Messenger;
   import org.apache.commons.messenger.MessengerManager;
   
  @@ -48,6 +48,12 @@
       /** Should HTTP servlets be used or generic servlets. If true then JSP can be dispatched
to easily */
       private static final boolean USE_HTTP_SERVLETS = true;
   
  +    /** 
  +     * Whether exceptions occurring during subscriptions on startup should 
  +     * terminate the initialization
  +     */
  +    private boolean continueOnSubscribeException;
  +    
       public ManagerServlet() {
       }
       
  @@ -89,6 +95,11 @@
       //-------------------------------------------------------------------------    
       
       public synchronized void init() throws ServletException {        
  +        String text = getServletContext().getInitParameter( "continueOnSubscribeException"
);
  +        if ( text != null && text.equals( "true" ) ) {
  +            continueOnSubscribeException = true;
  +        }
  +        
           // ensure Messenger is initialised
           MessengerManager manager = getMessengerManager();
           if ( manager == null ) {
  @@ -132,6 +143,22 @@
       
       public void service(ServletRequest request, ServletResponse response) throws ServletException
{
       }
  +
  +
  +    // Properties
  +    //-------------------------------------------------------------------------    
  +    public boolean isContinueOnSubscriptionException() {
  +        return continueOnSubscribeException;
  +    }
  +    
  +    /** 
  +     * Sets whether exceptions occurring during subscriptions on startup should 
  +     * terminate the initialization
  +     */
  +    public void setContinueOnSubscribeException(boolean continueOnSubscribeException) {
  +        this.continueOnSubscribeException = continueOnSubscribeException;
  +    }
  +
       
       // Implementation methods
       //-------------------------------------------------------------------------    
  @@ -186,7 +213,7 @@
               destination = messenger.getDestination( subject );
           }
           catch (JMSException e) {
  -            throw new ServletException( "Could not create destination for name: " + subject
+ " for subscription: " + subscription, e );
  +            handleJMSException( "Could not create destination for name: " + subject + "
for subscription: " + subscription, e );
           }
           if ( destination == null ) {
               throw new ServletException( "No destination could be found for name: " + subject
+ " for subscription: " + subscription );
  @@ -209,7 +236,7 @@
               }
           }
           catch (JMSException e) {
  -            throw new ServletException( "Could not subscribe to destination:" + destination
+ " for subscription: " + subscription, e );
  +            handleJMSException( "Could not subscribe to destination:" + destination + "
for subscription: " + subscription, e );
           }
       }
       
  @@ -322,5 +349,17 @@
               // ignore, must be an absolute URL
           }
           return config;
  +    }
  +
  +    /**
  +     * Allows derived servlets to handle JMS exceptions differently, such as ignoring certain
kinds of
  +     * exceptions or performing custom logging etc.
  +     */
  +    protected void handleJMSException(String message, JMSException exception) throws ServletException
{    
  +        log( message, exception );
  +        
  +        if ( ! isContinueOnSubscriptionException() ) {
  +            throw new ServletException( message, exception );
  +        }
       }
   }
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message