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; 018 019 import org.apache.camel.CamelContext; 020 import org.apache.camel.impl.DefaultExchange; 021 import org.apache.cxf.message.Exchange; 022 import org.apache.cxf.message.Message; 023 import org.apache.cxf.transport.Conduit; 024 import org.apache.cxf.transport.Destination; 025 026 /** 027 * An {@link Exchange} for working with Apache CXF which expoes the underlying 028 * CXF messages via {@link #getInMessage()} and {@link #getOutMessage()} along with the 029 * {@link #getExchange()} 030 * 031 * @version $Revision: 563665 $ 032 */ 033 public class CxfExchange extends DefaultExchange { 034 private final CxfBinding binding; 035 private Exchange exchange; 036 037 public CxfExchange(CamelContext context, CxfBinding binding) { 038 super(context); 039 this.binding = binding; 040 } 041 042 public CxfExchange(CamelContext context, CxfBinding binding, Exchange exchange) { 043 super(context); 044 this.binding = binding; 045 this.exchange = exchange; 046 047 setIn(new CxfMessage(exchange.getInMessage())); 048 setOut(new CxfMessage(exchange.getOutMessage())); 049 setFault(new CxfMessage(exchange.getInFaultMessage())); 050 } 051 052 public CxfExchange(CamelContext context, CxfBinding binding, Message inMessage) { 053 super(context); 054 this.binding = binding; 055 this.exchange = inMessage.getExchange(); 056 057 setIn(new CxfMessage(inMessage)); 058 if (exchange != null) { 059 setOut(new CxfMessage(exchange.getOutMessage())); 060 setFault(new CxfMessage(exchange.getInFaultMessage())); 061 } 062 } 063 064 @Override 065 public CxfMessage getIn() { 066 return (CxfMessage) super.getIn(); 067 } 068 069 @Override 070 public CxfMessage getOut() { 071 return (CxfMessage) super.getOut(); 072 } 073 074 @Override 075 public CxfMessage getOut(boolean lazyCreate) { 076 return (CxfMessage) super.getOut(lazyCreate); 077 } 078 079 @Override 080 public CxfMessage getFault() { 081 return (CxfMessage) super.getFault(); 082 } 083 084 /** 085 * @return the Camel <-> JBI binding 086 */ 087 public CxfBinding getBinding() { 088 return binding; 089 } 090 091 // Expose CXF APIs directly on the exchange 092 //------------------------------------------------------------------------- 093 094 /** 095 * Returns the underlying CXF message exchange for an inbound exchange 096 * or null for outbound messages 097 * 098 * @return the inbound message exchange 099 */ 100 public Exchange getExchange() { 101 return exchange; 102 } 103 104 public Message getInMessage() { 105 return getIn().getMessage(); 106 } 107 108 public Message getOutMessage() { 109 return getOut().getMessage(); 110 } 111 112 public Message getOutFaultMessage() { 113 return getExchange().getOutFaultMessage(); 114 } 115 116 public Message getInFaultMessage() { 117 return getExchange().getInFaultMessage(); 118 } 119 120 public Destination getDestination() { 121 return getExchange().getDestination(); 122 } 123 124 public Conduit getConduit(Message message) { 125 return getExchange().getConduit(message); 126 } 127 128 @Override 129 protected CxfMessage createInMessage() { 130 return new CxfMessage(); 131 } 132 133 @Override 134 protected CxfMessage createOutMessage() { 135 return new CxfMessage(); 136 } 137 }