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