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 java.util.Map;
020    
021    import org.apache.camel.impl.DefaultMessage;
022    import org.apache.cxf.message.Message;
023    import org.apache.cxf.message.MessageImpl;
024    
025    /**
026     * An Apache CXF {@link Message} which provides access to the underlying CXF
027     * features
028     * 
029     * @version $Revision: 563665 $
030     */
031    public class CxfMessage extends DefaultMessage {
032        private Message cxfMessage;
033    
034        public CxfMessage() {
035            this(new MessageImpl());
036        }
037    
038        public CxfMessage(Message cxfMessage) {
039            this.cxfMessage = cxfMessage;
040        }
041    
042        @Override
043        public String toString() {
044            if (cxfMessage != null) {
045                return "CxfMessage: " + cxfMessage;
046            } else {
047                return "CxfMessage: " + getBody();
048            }
049        }
050    
051        @Override
052        public CxfExchange getExchange() {
053            return (CxfExchange)super.getExchange();
054        }
055    
056        /**
057         * Returns the underlying CXF message
058         * 
059         * @return the CXF message
060         */
061        public Message getMessage() {
062            return cxfMessage;
063        }
064    
065        public void setMessage(Message cxfMessage) {
066            this.cxfMessage = cxfMessage;
067        }
068    
069        public Object getHeader(String name) {
070            return cxfMessage.get(name);
071        }
072    
073        @Override
074        public void setHeader(String name, Object value) {
075            cxfMessage.put(name, value);
076        }
077    
078        @Override
079        public Map<String, Object> getHeaders() {
080            return cxfMessage;
081        }
082    
083        @Override
084        public CxfMessage newInstance() {
085            return new CxfMessage();
086        }
087    
088        @Override
089        protected Object createBody() {
090            return getExchange().getBinding().extractBodyFromCxf(getExchange(), cxfMessage);
091        }
092    }