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