Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
EndpointMessageListener |
|
| 0.0;0 |
1 | /** |
|
2 | * |
|
3 | * Licensed to the Apache Software Foundation (ASF) under one or more |
|
4 | * contributor license agreements. See the NOTICE file distributed with |
|
5 | * this work for additional information regarding copyright ownership. |
|
6 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
|
7 | * (the "License"); you may not use this file except in compliance with |
|
8 | * the License. You may obtain a copy of the License at |
|
9 | * |
|
10 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
11 | * |
|
12 | * Unless required by applicable law or agreed to in writing, software |
|
13 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
15 | * See the License for the specific language governing permissions and |
|
16 | * limitations under the License. |
|
17 | */ |
|
18 | package org.apache.camel.component.jms; |
|
19 | ||
20 | import javax.jms.Message; |
|
21 | import javax.jms.MessageListener; |
|
22 | ||
23 | import org.apache.camel.Endpoint; |
|
24 | import org.apache.camel.Exchange; |
|
25 | import org.apache.camel.Processor; |
|
26 | import org.apache.camel.RuntimeCamelException; |
|
27 | import org.apache.commons.logging.Log; |
|
28 | import org.apache.commons.logging.LogFactory; |
|
29 | ||
30 | /** |
|
31 | * A JMS {@link MessageListener} which can be used to delegate processing to a Camel endpoint. |
|
32 | * |
|
33 | * @version $Revision: 534145 $ |
|
34 | */ |
|
35 | public class EndpointMessageListener<E extends Exchange> implements MessageListener { |
|
36 | 1 | private static final transient Log log = LogFactory.getLog(EndpointMessageListener.class); |
37 | private Endpoint<E> endpoint; |
|
38 | private Processor processor; |
|
39 | private JmsBinding binding; |
|
40 | ||
41 | 81 | public EndpointMessageListener(Endpoint<E> endpoint, Processor processor) { |
42 | 81 | this.endpoint = endpoint; |
43 | 81 | this.processor = processor; |
44 | 81 | } |
45 | ||
46 | public void onMessage(Message message) { |
|
47 | try { |
|
48 | ||
49 | 21 | if (log.isDebugEnabled()) { |
50 | 0 | log.debug(endpoint + " receiving JMS message: " + message); |
51 | } |
|
52 | 21 | JmsExchange exchange = createExchange(message); |
53 | 21 | processor.process((E) exchange); |
54 | ||
55 | 4 | } catch (Exception e) { |
56 | 4 | throw new RuntimeCamelException(e); |
57 | 17 | } |
58 | 17 | } |
59 | ||
60 | public JmsExchange createExchange(Message message) { |
|
61 | 21 | return new JmsExchange(endpoint.getContext(), getBinding(), message); |
62 | } |
|
63 | ||
64 | // Properties |
|
65 | //------------------------------------------------------------------------- |
|
66 | public JmsBinding getBinding() { |
|
67 | 21 | if (binding == null) { |
68 | 0 | binding = new JmsBinding(); |
69 | } |
|
70 | 21 | return binding; |
71 | } |
|
72 | ||
73 | /** |
|
74 | * Sets the binding used to convert from a Camel message to and from a JMS message |
|
75 | * |
|
76 | * @param binding the binding to use |
|
77 | */ |
|
78 | public void setBinding(JmsBinding binding) { |
|
79 | 81 | this.binding = binding; |
80 | 81 | } |
81 | } |