01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.servicemix.bean.beans;
18:
19: import javax.annotation.Resource;
20: import javax.jbi.messaging.DeliveryChannel;
21: import javax.jbi.messaging.ExchangeStatus;
22: import javax.jbi.messaging.InOnly;
23: import javax.jbi.messaging.MessageExchange;
24: import javax.jbi.messaging.MessagingException;
25:
26: import org.apache.commons.logging.Log;
27: import org.apache.commons.logging.LogFactory;
28: import org.apache.servicemix.MessageExchangeListener;
29: import org.apache.servicemix.jbi.util.MessageUtil;
30:
31: /**
32: * A simple POJO which implements the {@link MessageExchangeListener} interface
33: *
34: * @version $Revision: $
35: */
36: public class ListenerBean implements MessageExchangeListener {
37:
38: private static final Log LOG = LogFactory
39: .getLog(ListenerBean.class);
40:
41: @Resource
42: private DeliveryChannel channel;
43:
44: private MessageExchange lastExchange;
45: private String param;
46:
47: public void onMessageExchange(MessageExchange exchange)
48: throws MessagingException {
49: this .lastExchange = exchange;
50: LOG.info("Received exchange: " + exchange);
51: if (exchange instanceof InOnly) {
52: exchange.setStatus(ExchangeStatus.DONE);
53: channel.send(exchange);
54: } else if (exchange.getStatus() == ExchangeStatus.ACTIVE) {
55: MessageUtil.transferInToOut(exchange, exchange);
56: channel.send(exchange);
57: }
58: }
59:
60: public MessageExchange getLastExchange() {
61: return lastExchange;
62: }
63:
64: public String getParam() {
65: return param;
66: }
67:
68: public void setParam(String param) {
69: this.param = param;
70: }
71: }
|