01: /*
02: * $Id: ForwardingCatchAllStrategy.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.api.MuleEvent;
15: import org.mule.api.MuleMessage;
16: import org.mule.api.MuleSession;
17: import org.mule.api.endpoint.OutboundEndpoint;
18: import org.mule.api.routing.RoutingException;
19: import org.mule.api.routing.ServiceRoutingException;
20: import org.mule.config.i18n.CoreMessages;
21:
22: /**
23: * <code>ForwardingCatchAllStrategy</code> acts as a catch and forward router for
24: * any events not caught by the router this strategy is associated with. Users can
25: * assign an endpoint to this strategy to forward all events to. This can be used as
26: * a dead letter/error queue.
27: */
28:
29: public class ForwardingCatchAllStrategy extends
30: AbstractCatchAllStrategy {
31: private boolean sendTransformed = false;
32:
33: public MuleMessage catchMessage(MuleMessage message,
34: MuleSession session, boolean synchronous)
35: throws RoutingException {
36: if (getEndpoint() == null) {
37: throw new ServiceRoutingException(CoreMessages
38: .noCatchAllEndpointSet(), message, getEndpoint(),
39: session.getService());
40: }
41: try {
42: OutboundEndpoint endpoint = getEndpoint();
43: if (sendTransformed && endpoint.getTransformers() != null) {
44: message.applyTransformers(endpoint.getTransformers());
45: }
46:
47: MuleEvent newEvent = new DefaultMuleEvent(message,
48: endpoint, session, synchronous);
49:
50: if (synchronous) {
51: MuleMessage result = endpoint.send(newEvent);
52: if (statistics != null) {
53: statistics.incrementRoutedMessage(getEndpoint());
54: }
55: return result;
56: } else {
57: endpoint.dispatch(newEvent);
58: if (statistics != null) {
59: statistics.incrementRoutedMessage(getEndpoint());
60: }
61: return null;
62: }
63: } catch (Exception e) {
64: throw new RoutingException(message, getEndpoint(), e);
65:
66: }
67: }
68:
69: public boolean isSendTransformed() {
70: return sendTransformed;
71: }
72:
73: public void setSendTransformed(boolean sendTransformed) {
74: this.sendTransformed = sendTransformed;
75: }
76: }
|