01: /*
02: * $Id: ServiceCatchAllStrategy.java 10961 2008-02-22 19:01:02Z dfeist $
03: * --------------------------------------------------------------------------------------
04: * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
05: *
06: * The software in this package is published under the terms of the CPAL v1.0
07: * license, a copy of which has been included with this distribution in the
08: * LICENSE.txt file.
09: */
10:
11: package org.mule.routing;
12:
13: import org.mule.DefaultMuleEvent;
14: import org.mule.RequestContext;
15: import org.mule.api.MuleEvent;
16: import org.mule.api.MuleException;
17: import org.mule.api.MuleMessage;
18: import org.mule.api.MuleSession;
19: import org.mule.api.endpoint.OutboundEndpoint;
20: import org.mule.api.routing.RoutingException;
21: import org.mule.api.routing.ServiceRoutingException;
22:
23: /**
24: * <code>ServiceCatchAllStrategy</code> is used to catch any events and forward the
25: * events to the service as is.
26: */
27: public class ServiceCatchAllStrategy extends AbstractCatchAllStrategy {
28: public void setEndpoint(OutboundEndpoint endpoint) {
29: throw new UnsupportedOperationException(
30: "The endpoint cannot be set on this catch all");
31: }
32:
33: public OutboundEndpoint getEndpoint() {
34: return null;
35: }
36:
37: public synchronized MuleMessage catchMessage(MuleMessage message,
38: MuleSession session, boolean synchronous)
39: throws RoutingException {
40: MuleEvent event = RequestContext.getEvent();
41: logger.debug("Catch all strategy handling event: " + event);
42: try {
43: logger
44: .info("MuleEvent being routed from catch all strategy for endpoint: "
45: + event.getEndpoint());
46: event = new DefaultMuleEvent(message, event.getEndpoint(),
47: session.getService(), event);
48: if (synchronous) {
49: statistics.incrementRoutedMessage(event.getEndpoint());
50: return session.getService().sendEvent(event);
51: } else {
52: statistics.incrementRoutedMessage(event.getEndpoint());
53: session.getService().dispatchEvent(event);
54: return null;
55: }
56: } catch (MuleException e) {
57: throw new ServiceRoutingException(event.getMessage(), event
58: .getEndpoint(), session.getService(), e);
59: }
60: }
61: }
|