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