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.InOut;
23: import javax.jbi.messaging.MessageExchange;
24: import javax.jbi.messaging.MessageExchangeFactory;
25: import javax.jbi.messaging.MessagingException;
26: import javax.xml.namespace.QName;
27:
28: import org.apache.servicemix.MessageExchangeListener;
29: import org.apache.servicemix.jbi.util.MessageUtil;
30:
31: public class ConsumerListener implements MessageExchangeListener {
32:
33: @Resource
34: private DeliveryChannel channel;
35:
36: public void onMessageExchange(MessageExchange exchange)
37: throws MessagingException {
38: if (exchange.getRole() == MessageExchange.Role.CONSUMER) {
39: if (exchange.getStatus() == ExchangeStatus.ACTIVE) {
40: MessageExchange io = (MessageExchange) exchange
41: .getProperty("exchange");
42: MessageUtil.transferOutToOut(exchange, io);
43: io.setProperty("exchange", exchange);
44: channel.send(io);
45: } else if (exchange.getStatus() == ExchangeStatus.DONE) {
46: MessageExchange io = (MessageExchange) exchange
47: .getProperty("exchange");
48: io.setStatus(ExchangeStatus.DONE);
49: channel.send(io);
50: }
51: } else {
52: if (exchange.getStatus() == ExchangeStatus.ACTIVE) {
53: MessageExchangeFactory factory = channel
54: .createExchangeFactory();
55: InOut io = factory.createInOutExchange();
56: MessageUtil.transferInToIn(exchange, io);
57: io.setService(new QName("echo"));
58: io.setProperty("exchange", exchange);
59: channel.send(io);
60: } else if (exchange.getStatus() == ExchangeStatus.DONE) {
61: // Do nothing
62: }
63: }
64: }
65:
66: }
|