| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
| CamelTransportBase |
|
| 0.0;0 |
| 1 | /** |
|
| 2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
|
| 3 | * contributor license agreements. See the NOTICE file distributed with |
|
| 4 | * this work for additional information regarding copyright ownership. |
|
| 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
|
| 6 | * (the "License"); you may not use this file except in compliance with |
|
| 7 | * the License. You may obtain a copy of the License at |
|
| 8 | * |
|
| 9 | * 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.camel.component.cxf.transport; |
|
| 18 | ||
| 19 | import org.apache.camel.CamelContext; |
|
| 20 | import org.apache.camel.CamelTemplate; |
|
| 21 | import org.apache.camel.Exchange; |
|
| 22 | import org.apache.cxf.Bus; |
|
| 23 | import org.apache.cxf.message.Message; |
|
| 24 | import org.apache.cxf.message.MessageImpl; |
|
| 25 | import org.apache.cxf.service.model.EndpointInfo; |
|
| 26 | ||
| 27 | /** |
|
| 28 | * @version $Revision: 563665 $ |
|
| 29 | */ |
|
| 30 | public class CamelTransportBase { |
|
| 31 | CamelTemplate<Exchange> template; |
|
| 32 | Bus bus; |
|
| 33 | EndpointInfo endpointInfo; |
|
| 34 | private String replyDestination; |
|
| 35 | private final CamelContext camelContext; |
|
| 36 | ||
| 37 | 0 | public CamelTransportBase(CamelContext camelContext, Bus bus, EndpointInfo endpointInfo, boolean b, String baseBeanNameSuffix) { |
| 38 | 0 | this.camelContext = camelContext; |
| 39 | 0 | this.bus = bus; |
| 40 | 0 | this.endpointInfo = endpointInfo; |
| 41 | 0 | this.template = new CamelTemplate<Exchange>(camelContext); |
| 42 | 0 | } |
| 43 | ||
| 44 | public void populateIncomingContext(Exchange exchange, MessageImpl inMessage, String camelServerRequestHeaders) { |
|
| 45 | ||
| 46 | 0 | } |
| 47 | ||
| 48 | public String getReplyDestination() { |
|
| 49 | 0 | return replyDestination; |
| 50 | } |
|
| 51 | ||
| 52 | public void setMessageProperties(Message inMessage, Exchange reply) { |
|
| 53 | ||
| 54 | 0 | } |
| 55 | ||
| 56 | public void close() { |
|
| 57 | 0 | if (template != null) { |
| 58 | try { |
|
| 59 | 0 | template.stop(); |
| 60 | 0 | } catch (Exception e) { |
| 61 | // do nothing? |
|
| 62 | // TODO |
|
| 63 | 0 | } |
| 64 | } |
|
| 65 | 0 | } |
| 66 | ||
| 67 | /** |
|
| 68 | * Populates a Camel exchange with a payload |
|
| 69 | * |
|
| 70 | * @param payload the message payload, expected to be either of type String |
|
| 71 | * or byte[] depending on payload type |
|
| 72 | * @param replyTo the ReplyTo destination if any |
|
| 73 | * @param exchange the underlying exchange to marshal to |
|
| 74 | */ |
|
| 75 | protected void marshal(Object payload, String replyTo, Exchange exchange) { |
|
| 76 | 0 | org.apache.camel.Message message = exchange.getIn(); |
| 77 | 0 | message.setBody(payload); |
| 78 | 0 | if (replyTo != null) { |
| 79 | 0 | message.setHeader(CamelConstants.CAMEL_CORRELATION_ID, replyTo); |
| 80 | } |
|
| 81 | 0 | } |
| 82 | ||
| 83 | /** |
|
| 84 | * Unmarshal the payload of an incoming message. |
|
| 85 | */ |
|
| 86 | public byte[] unmarshal(Exchange exchange) { |
|
| 87 | 0 | return exchange.getIn().getBody(byte[].class); |
| 88 | } |
|
| 89 | ||
| 90 | /* |
|
| 91 | * protected CamelMessageHeadersType |
|
| 92 | * populateIncomingContext(javax.camel.Message message, |
|
| 93 | * org.apache.cxf.message.Message inMessage, String headerType) throws |
|
| 94 | * CamelException { CamelMessageHeadersType headers = null; headers = |
|
| 95 | * (CamelMessageHeadersType)inMessage.get(headerType); if (headers == null) { |
|
| 96 | * headers = new CamelMessageHeadersType(); inMessage.put(headerType, |
|
| 97 | * headers); } |
|
| 98 | * headers.setCamelCorrelationID(message.getCamelCorrelationID()); |
|
| 99 | * headers.setCamelDeliveryMode(new |
|
| 100 | * Integer(message.getCamelDeliveryMode())); headers.setCamelExpiration(new |
|
| 101 | * Long(message.getCamelExpiration())); |
|
| 102 | * headers.setCamelMessageID(message.getCamelMessageID()); |
|
| 103 | * headers.setCamelPriority(new Integer(message.getCamelPriority())); |
|
| 104 | * headers.setCamelRedelivered(Boolean.valueOf(message.getCamelRedelivered())); |
|
| 105 | * headers.setCamelTimeStamp(new Long(message.getCamelTimestamp())); |
|
| 106 | * headers.setCamelType(message.getCamelType()); List<CamelPropertyType> |
|
| 107 | * props = headers.getProperty(); Enumeration enm = |
|
| 108 | * message.getPropertyNames(); while (enm.hasMoreElements()) { String name = |
|
| 109 | * (String)enm.nextElement(); String val = message.getStringProperty(name); |
|
| 110 | * CamelPropertyType prop = new CamelPropertyType(); prop.setName(name); |
|
| 111 | * prop.setValue(val); props.add(prop); } return headers; } protected int |
|
| 112 | * getCamelDeliveryMode(CamelMessageHeadersType headers) { int deliveryMode = |
|
| 113 | * Message.DEFAULT_DELIVERY_MODE; if (headers != null && |
|
| 114 | * headers.isSetCamelDeliveryMode()) { deliveryMode = |
|
| 115 | * headers.getCamelDeliveryMode(); } return deliveryMode; } protected int |
|
| 116 | * getCamelPriority(CamelMessageHeadersType headers) { int priority = |
|
| 117 | * Message.DEFAULT_PRIORITY; if (headers != null && |
|
| 118 | * headers.isSetCamelPriority()) { priority = headers.getCamelPriority(); } |
|
| 119 | * return priority; } protected long getTimeToLive(CamelMessageHeadersType |
|
| 120 | * headers) { long ttl = -1; if (headers != null && |
|
| 121 | * headers.isSetTimeToLive()) { ttl = headers.getTimeToLive(); } return ttl; } |
|
| 122 | * protected String getCorrelationId(CamelMessageHeadersType headers) { |
|
| 123 | * String correlationId = null; if (headers != null && |
|
| 124 | * headers.isSetCamelCorrelationID()) { correlationId = |
|
| 125 | * headers.getCamelCorrelationID(); } return correlationId; } protected |
|
| 126 | * String getAddrUriFromCamelAddrPolicy() { AddressType camelAddressPolicy = |
|
| 127 | * transport.getCamelAddress(); return "camel:" + |
|
| 128 | * camelAddressPolicy.getJndiConnectionFactoryName() + "#" + |
|
| 129 | * camelAddressPolicy.getJndiDestinationName(); } protected String |
|
| 130 | * getReplyTotAddrUriFromCamelAddrPolicy() { AddressType camelAddressPolicy = |
|
| 131 | * transport.getCamelAddress(); return "camel:" + |
|
| 132 | * camelAddressPolicy.getJndiConnectionFactoryName() + "#" + |
|
| 133 | * camelAddressPolicy.getJndiReplyDestinationName(); } protected boolean |
|
| 134 | * isDestinationStyleQueue() { return CamelConstants.CAMEL_QUEUE.equals( |
|
| 135 | * transport.getCamelAddress().getDestinationStyle().value()); } |
|
| 136 | */ |
|
| 137 | } |