Author: veithen
Date: Sun Nov  9 06:11:56 2008
New Revision: 712501

URL: http://svn.apache.org/viewvc?rev=712501&view=rev
Log:
Solved a problem with AbstractTransportListener#startListeningForService.

Problem description: When a runtime exception is thrown by the implementation 
of the startListeningForService (either explicitly or e.g. a NPE), it is not 
caught by AbstractTransportListener, but in AxisConfiguration#notifyObservers. 
The exception then gets logged at DEBUG level without a full stack trace. Also 
the service will not be disabled for the transport and not be marked as faulty.

In addition, the transports built on AbstractTransportListener behave quite 
differently when a problem occurs in startListeningForService:
* JMSListener marks the service as faulty and disables it for the transport.
* AbstractPollingTransportListener and AbstractDatagramTransportListener only 
disable the service for the transport, but will not mark it as faulty.
* FIXTransportListener only logs the error.

Changes:
* Intercept exceptions thrown by startListeningForService (including runtime 
exceptions) in AbstractTransportListener and take appropriate action, i.e. 
disable the service for the transport and mark it as faulty.
* Allow startListeningForService to throw AxisFaults, so that implementations 
can simply throw this exception and don't need to care themselves about 
disabling the service or marking it as faulty.

Modified:
    
webservices/commons/trunk/modules/transport/modules/base/src/main/java/org/apache/axis2/transport/base/AbstractPollingTransportListener.java
    
webservices/commons/trunk/modules/transport/modules/base/src/main/java/org/apache/axis2/transport/base/AbstractTransportListener.java
    
webservices/commons/trunk/modules/transport/modules/base/src/main/java/org/apache/axis2/transport/base/datagram/AbstractDatagramTransportListener.java
    
webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSListener.java

Modified: 
webservices/commons/trunk/modules/transport/modules/base/src/main/java/org/apache/axis2/transport/base/AbstractPollingTransportListener.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/base/src/main/java/org/apache/axis2/transport/base/AbstractPollingTransportListener.java?rev=712501&r1=712500&r2=712501&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/transport/modules/base/src/main/java/org/apache/axis2/transport/base/AbstractPollingTransportListener.java
 (original)
+++ 
webservices/commons/trunk/modules/transport/modules/base/src/main/java/org/apache/axis2/transport/base/AbstractPollingTransportListener.java
 Sun Nov  9 06:11:56 2008
@@ -160,26 +160,14 @@
     }
     
     @Override
-    protected void startListeningForService(AxisService service) {
-        T entry;
-        try {
-            entry = createPollTableEntry(service);
-            if (entry == null) {
-                log.warn("The service " + service.getName() + " has no 
configuration for the " +
-                        getTransportName() + " transport and will be disabled 
for that transport");
-            }
-        } catch (AxisFault ex) {
-            log.warn("Error configuring the " + getTransportName() + " 
transport for Service : " +
-                    service.getName() + " :: " + ex.getMessage());
-            entry = null;
-        }
+    protected void startListeningForService(AxisService service) throws 
AxisFault {
+        T entry = createPollTableEntry(service);
         if (entry == null) {
-            disableTransportForService(service);
-        } else {
-            entry.setService(service);
-            schedulePoll(entry, getPollInterval(service));
-            pollTable.add(entry);
+            throw new AxisFault("The service has no configuration for the 
transport");
         }
+        entry.setService(service);
+        schedulePoll(entry, getPollInterval(service));
+        pollTable.add(entry);
     }
     
     /**

Modified: 
webservices/commons/trunk/modules/transport/modules/base/src/main/java/org/apache/axis2/transport/base/AbstractTransportListener.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/base/src/main/java/org/apache/axis2/transport/base/AbstractTransportListener.java?rev=712501&r1=712500&r2=712501&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/transport/modules/base/src/main/java/org/apache/axis2/transport/base/AbstractTransportListener.java
 (original)
+++ 
webservices/commons/trunk/modules/transport/modules/base/src/main/java/org/apache/axis2/transport/base/AbstractTransportListener.java
 Sun Nov  9 06:11:56 2008
@@ -196,8 +196,28 @@
     }
 
     private void internalStartListeningForService(AxisService service) {
-        startListeningForService(service);
         String serviceName = service.getName();
+        try {
+            startListeningForService(service);
+        } catch (AxisFault ex) {
+            String transportName = getTransportName().toUpperCase();
+            String msg = "Unable to configure the service " + serviceName + " 
for the " +
+                    transportName + " transport: " + ex.getMessage() + ". " + 
+                    "This service is being marked as faulty and will not be 
available over the " +
+                    transportName + " transport.";
+            log.warn(msg, ex);
+            BaseUtils.markServiceAsFaulty(serviceName, msg, 
service.getAxisConfiguration());
+            disableTransportForService(service);
+            return;
+        } catch (Throwable ex) {
+            String msg = "Unexpected error when configuring service " + 
serviceName +
+                    " for the " + getTransportName().toUpperCase() + " 
transport. It will be" +
+                    " disabled for this transport and marked as faulty.";
+            log.error(msg, ex);
+            BaseUtils.markServiceAsFaulty(serviceName, msg, 
service.getAxisConfiguration());
+            disableTransportForService(service);
+            return;
+        }
         registerMBean(new TransportListenerEndpointView(this, serviceName),
                       getEndpointMBeanName(serviceName));
     }
@@ -207,7 +227,7 @@
         stopListeningForService(service);
     }
     
-    protected abstract void startListeningForService(AxisService service);
+    protected abstract void startListeningForService(AxisService service) 
throws AxisFault;
 
     protected abstract void stopListeningForService(AxisService service);
 

Modified: 
webservices/commons/trunk/modules/transport/modules/base/src/main/java/org/apache/axis2/transport/base/datagram/AbstractDatagramTransportListener.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/base/src/main/java/org/apache/axis2/transport/base/datagram/AbstractDatagramTransportListener.java?rev=712501&r1=712500&r2=712501&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/transport/modules/base/src/main/java/org/apache/axis2/transport/base/datagram/AbstractDatagramTransportListener.java
 (original)
+++ 
webservices/commons/trunk/modules/transport/modules/base/src/main/java/org/apache/axis2/transport/base/datagram/AbstractDatagramTransportListener.java
 Sun Nov  9 06:11:56 2008
@@ -61,29 +61,19 @@
     }
        
     @Override
-    protected void startListeningForService(AxisService service) {
-        E endpoint;
-        try {
-               endpoint = createEndpoint(service);
-            endpoint.setListener(this);
-            endpoint.setService(service);
-            endpoint.setContentType(ParamUtils.getRequiredParam(
-                    service, "transport." + getTransportName() + 
".contentType"));
-            endpoint.setMetrics(metrics);
-        } catch (AxisFault ex) {
-            log.warn("Error configuring the " + getTransportName()
-                    + " transport for service '" + service.getName() + "': " + 
ex.getMessage());
-            disableTransportForService(service);
-            return;
-        }
+    protected void startListeningForService(AxisService service) throws 
AxisFault {
+        E endpoint = createEndpoint(service);
+        endpoint.setListener(this);
+        endpoint.setService(service);
+        endpoint.setContentType(ParamUtils.getRequiredParam(
+                service, "transport." + getTransportName() + ".contentType"));
+        endpoint.setMetrics(metrics);
         
         try {
             dispatcher.addEndpoint(endpoint);
         } catch (IOException ex) {
-            log.error("Unable to listen on endpoint "
+            throw new AxisFault("Unable to listen on endpoint "
                     + endpoint.getEndpointReference(defaultIp), ex);
-            disableTransportForService(service);
-            return;
         }
         if (log.isDebugEnabled()) {
             log.debug("Started listening on endpoint " + 
endpoint.getEndpointReference(defaultIp)

Modified: 
webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSListener.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSListener.java?rev=712501&r1=712500&r2=712501&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSListener.java
 (original)
+++ 
webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSListener.java
 Sun Nov  9 06:11:56 2008
@@ -144,17 +144,11 @@
      *
      * @param service the service for which to listen for messages
      */
-    protected void startListeningForService(AxisService service) {
+    protected void startListeningForService(AxisService service) throws 
AxisFault {
         JMSConnectionFactory cf = getConnectionFactory(service);
         if (cf == null) {
-            String msg = "Service " + service.getName() + " does not specify" +
-                         "a JMS connection factory or refers to an invalid 
factory. " +
-                         "This service is being marked as faulty and will not 
be " +
-                         "available over the JMS transport";
-            log.warn(msg);
-            BaseUtils.markServiceAsFaulty(service.getName(), msg, 
service.getAxisConfiguration());
-            disableTransportForService(service);
-            return;
+            throw new AxisFault("The service doesn't specify a JMS connection 
factory or refers " +
+                       "to an invalid factory.");
         }
 
         JMSEndpoint endpoint = new JMSEndpoint();
@@ -175,7 +169,7 @@
                     JMSConstants.DESTINATION_TYPE_TOPIC.equals(paramValue) )  {
                 endpoint.setDestinationType(paramValue);
             } else {
-                throw new AxisJMSException("Invalid destinaton type value " + 
paramValue);
+                throw new AxisFault("Invalid destinaton type value " + 
paramValue);
             }
         } else {
             log.debug("JMS destination type not given. default queue");
@@ -195,12 +189,7 @@
             contentTypeRuleSet.addRule(new MessageTypeRule(TextMessage.class, 
"text/plain"));
             endpoint.setContentTypeRuleSet(contentTypeRuleSet);
         } else {
-            try {
-                
endpoint.setContentTypeRuleSet(ContentTypeRuleFactory.parse(contentTypeParam));
-            } catch (AxisFault ex) {
-                // TODO: this is ugly; we should allow 
startListeningForService to throw AxisFaults
-                throw new AxisJMSException("Invalid value in parameter " + 
JMSConstants.CONTENT_TYPE_PARAM, ex);
-            }
+            
endpoint.setContentTypeRuleSet(ContentTypeRuleFactory.parse(contentTypeParam));
         }
         
         log.info("Starting to listen on destination : " + 
endpoint.getJndiDestinationName() + " of type "


Reply via email to