001 /** 002 * 003 * Licensed to the Apache Software Foundation (ASF) under one or more 004 * contributor license agreements. See the NOTICE file distributed with 005 * this work for additional information regarding copyright ownership. 006 * The ASF licenses this file to You under the Apache License, Version 2.0 007 * (the "License"); you may not use this file except in compliance with 008 * the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018 package org.apache.camel.component.cxf.transport; 019 020 import org.apache.camel.CamelContext; 021 import org.apache.camel.Exchange; 022 import org.apache.camel.CamelTemplate; 023 import org.apache.cxf.Bus; 024 import org.apache.cxf.message.Message; 025 import org.apache.cxf.message.MessageImpl; 026 import org.apache.cxf.service.model.EndpointInfo; 027 028 /** 029 * @version $Revision: 535478 $ 030 */ 031 public class CamelTransportBase { 032 private String replyDestination; 033 CamelTemplate<Exchange> template; 034 private final CamelContext camelContext; 035 Bus bus; 036 EndpointInfo endpointInfo; 037 038 public CamelTransportBase(CamelContext camelContext, Bus bus, EndpointInfo endpointInfo, boolean b, String baseBeanNameSuffix) { 039 this.camelContext = camelContext; 040 this.bus = bus; 041 this.endpointInfo = endpointInfo; 042 this.template = new CamelTemplate<Exchange>(camelContext); 043 } 044 045 public void populateIncomingContext(Exchange exchange, MessageImpl inMessage, String camelServerRequestHeaders) { 046 047 } 048 049 public String getReplyDestination() { 050 return replyDestination; 051 } 052 053 public void setMessageProperties(Message inMessage, Exchange reply) { 054 055 } 056 057 public void close() { 058 if (template != null) { 059 try { 060 template.stop(); 061 } 062 catch (Exception e) { 063 // do nothing? 064 // TODO 065 } 066 } 067 } 068 069 /** 070 * Populates a Camel exchange with a payload 071 * 072 * @param payload the message payload, expected to be either of type 073 * String or byte[] depending on payload type 074 * @param replyTo the ReplyTo destination if any 075 * @param exchange the underlying exchange to marshal to 076 */ 077 protected void marshal(Object payload, String replyTo, Exchange exchange) { 078 org.apache.camel.Message message = exchange.getIn(); 079 message.setBody(payload); 080 if (replyTo != null) { 081 message.setHeader(CamelConstants.CAMEL_CORRELATION_ID, replyTo); 082 } 083 } 084 085 /** 086 * Unmarshal the payload of an incoming message. 087 */ 088 public byte[] unmarshal(Exchange exchange) { 089 return exchange.getIn().getBody(byte[].class); 090 } 091 092 /* 093 protected CamelMessageHeadersType populateIncomingContext(javax.camel.Message message, 094 org.apache.cxf.message.Message inMessage, 095 String headerType) throws CamelException { 096 CamelMessageHeadersType headers = null; 097 098 headers = (CamelMessageHeadersType)inMessage.get(headerType); 099 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 }