Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
CamelTransportBase |
|
| 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.cxf.transport; |
|
19 | ||
20 | import org.apache.camel.CamelContext; |
|
21 | import org.apache.camel.Exchange; |
|
22 | import org.apache.camel.CamelTemplate; |
|
23 | import org.apache.cxf.Bus; |
|
24 | import org.apache.cxf.message.Message; |
|
25 | import org.apache.cxf.message.MessageImpl; |
|
26 | import org.apache.cxf.service.model.EndpointInfo; |
|
27 | ||
28 | /** |
|
29 | * @version $Revision: 535478 $ |
|
30 | */ |
|
31 | public class CamelTransportBase { |
|
32 | private String replyDestination; |
|
33 | CamelTemplate<Exchange> template; |
|
34 | private final CamelContext camelContext; |
|
35 | Bus bus; |
|
36 | EndpointInfo endpointInfo; |
|
37 | ||
38 | 0 | public CamelTransportBase(CamelContext camelContext, Bus bus, EndpointInfo endpointInfo, boolean b, String baseBeanNameSuffix) { |
39 | 0 | this.camelContext = camelContext; |
40 | 0 | this.bus = bus; |
41 | 0 | this.endpointInfo = endpointInfo; |
42 | 0 | this.template = new CamelTemplate<Exchange>(camelContext); |
43 | 0 | } |
44 | ||
45 | public void populateIncomingContext(Exchange exchange, MessageImpl inMessage, String camelServerRequestHeaders) { |
|
46 | ||
47 | 0 | } |
48 | ||
49 | public String getReplyDestination() { |
|
50 | 0 | return replyDestination; |
51 | } |
|
52 | ||
53 | public void setMessageProperties(Message inMessage, Exchange reply) { |
|
54 | ||
55 | 0 | } |
56 | ||
57 | public void close() { |
|
58 | 0 | if (template != null) { |
59 | try { |
|
60 | 0 | template.stop(); |
61 | } |
|
62 | 0 | catch (Exception e) { |
63 | // do nothing? |
|
64 | // TODO |
|
65 | 0 | } |
66 | } |
|
67 | 0 | } |
68 | ||
69 | /** |
|
70 | * Populates a Camel exchange with a payload |
|
71 | * |
|
72 | * @param payload the message payload, expected to be either of type |
|
73 | * String or byte[] depending on payload type |
|
74 | * @param replyTo the ReplyTo destination if any |
|
75 | * @param exchange the underlying exchange to marshal to |
|
76 | */ |
|
77 | protected void marshal(Object payload, String replyTo, Exchange exchange) { |
|
78 | 0 | org.apache.camel.Message message = exchange.getIn(); |
79 | 0 | message.setBody(payload); |
80 | 0 | if (replyTo != null) { |
81 | 0 | message.setHeader(CamelConstants.CAMEL_CORRELATION_ID, replyTo); |
82 | } |
|
83 | 0 | } |
84 | ||
85 | /** |
|
86 | * Unmarshal the payload of an incoming message. |
|
87 | */ |
|
88 | public byte[] unmarshal(Exchange exchange) { |
|
89 | 0 | return exchange.getIn().getBody(byte[].class); |
90 | } |
|
91 | ||
92 | /* |
|
93 | protected CamelMessageHeadersType populateIncomingContext(javax.camel.Message message, |
|
94 | org.apache.cxf.message.Message inMessage, |
|
95 | String headerType) throws CamelException { |
|
96 | CamelMessageHeadersType headers = null; |
|
97 | ||
98 | headers = (CamelMessageHeadersType)inMessage.get(headerType); |
|
99 | ||
100 | if (headers == null) { |
|
101 | headers = new CamelMessageHeadersType(); |
|
102 | inMessage.put(headerType, headers); |
|
103 | } |
|
104 | ||
105 | headers.setCamelCorrelationID(message.getCamelCorrelationID()); |
|
106 | headers.setCamelDeliveryMode(new Integer(message.getCamelDeliveryMode())); |
|
107 | headers.setCamelExpiration(new Long(message.getCamelExpiration())); |
|
108 | headers.setCamelMessageID(message.getCamelMessageID()); |
|
109 | headers.setCamelPriority(new Integer(message.getCamelPriority())); |
|
110 | headers.setCamelRedelivered(Boolean.valueOf(message.getCamelRedelivered())); |
|
111 | headers.setCamelTimeStamp(new Long(message.getCamelTimestamp())); |
|
112 | headers.setCamelType(message.getCamelType()); |
|
113 | ||
114 | List<CamelPropertyType> props = headers.getProperty(); |
|
115 | Enumeration enm = message.getPropertyNames(); |
|
116 | while (enm.hasMoreElements()) { |
|
117 | String name = (String)enm.nextElement(); |
|
118 | String val = message.getStringProperty(name); |
|
119 | CamelPropertyType prop = new CamelPropertyType(); |
|
120 | prop.setName(name); |
|
121 | prop.setValue(val); |
|
122 | props.add(prop); |
|
123 | } |
|
124 | ||
125 | return headers; |
|
126 | } |
|
127 | ||
128 | protected int getCamelDeliveryMode(CamelMessageHeadersType headers) { |
|
129 | int deliveryMode = Message.DEFAULT_DELIVERY_MODE; |
|
130 | ||
131 | if (headers != null && headers.isSetCamelDeliveryMode()) { |
|
132 | deliveryMode = headers.getCamelDeliveryMode(); |
|
133 | } |
|
134 | return deliveryMode; |
|
135 | } |
|
136 | ||
137 | protected int getCamelPriority(CamelMessageHeadersType headers) { |
|
138 | int priority = Message.DEFAULT_PRIORITY; |
|
139 | if (headers != null && headers.isSetCamelPriority()) { |
|
140 | priority = headers.getCamelPriority(); |
|
141 | } |
|
142 | return priority; |
|
143 | } |
|
144 | ||
145 | protected long getTimeToLive(CamelMessageHeadersType headers) { |
|
146 | long ttl = -1; |
|
147 | if (headers != null && headers.isSetTimeToLive()) { |
|
148 | ttl = headers.getTimeToLive(); |
|
149 | } |
|
150 | return ttl; |
|
151 | } |
|
152 | ||
153 | protected String getCorrelationId(CamelMessageHeadersType headers) { |
|
154 | String correlationId = null; |
|
155 | if (headers != null |
|
156 | && headers.isSetCamelCorrelationID()) { |
|
157 | correlationId = headers.getCamelCorrelationID(); |
|
158 | } |
|
159 | return correlationId; |
|
160 | } |
|
161 | ||
162 | ||
163 | protected String getAddrUriFromCamelAddrPolicy() { |
|
164 | AddressType camelAddressPolicy = transport.getCamelAddress(); |
|
165 | return "camel:" + camelAddressPolicy.getJndiConnectionFactoryName() |
|
166 | + "#" |
|
167 | + camelAddressPolicy.getJndiDestinationName(); |
|
168 | } |
|
169 | ||
170 | protected String getReplyTotAddrUriFromCamelAddrPolicy() { |
|
171 | AddressType camelAddressPolicy = transport.getCamelAddress(); |
|
172 | return "camel:" |
|
173 | + camelAddressPolicy.getJndiConnectionFactoryName() |
|
174 | + "#" |
|
175 | + camelAddressPolicy.getJndiReplyDestinationName(); |
|
176 | } |
|
177 | ||
178 | protected boolean isDestinationStyleQueue() { |
|
179 | return CamelConstants.CAMEL_QUEUE.equals( |
|
180 | transport.getCamelAddress().getDestinationStyle().value()); |
|
181 | } |
|
182 | */ |
|
183 | } |