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; 019 020 import java.util.Map; 021 022 /** 023 * Implements the <a href="http://activemq.apache.org/camel/message.html">Message</a> 024 * pattern and represents an inbound or outbound message as part of an {@link Exchange} 025 * 026 * @version $Revision: 540152 $ 027 */ 028 public interface Message { 029 030 /** 031 * @return the id of the message 032 */ 033 String getMessageId(); 034 035 /** 036 * set the id of the message 037 * @param messageId 038 */ 039 void setMessageId(String messageId); 040 041 /** 042 * Returns the exchange this message is related to 043 * 044 * @return 045 */ 046 Exchange getExchange(); 047 048 /** 049 * Accesses a specific header 050 * 051 * @param name 052 * @return object header associated with the name 053 */ 054 Object getHeader(String name); 055 056 /** 057 * Returns a header associated with this message by name and specifying the type required 058 * 059 * @param name the name of the header 060 * @param type the type of the header 061 * @return the value of the given header or null if there is no property for the given name or it cannot be 062 * converted to the given type 063 */ 064 <T> T getHeader(String name, Class<T> type); 065 066 /** 067 * Sets a header on the message 068 * 069 * @param name of the header 070 * @param value to associate with the name 071 */ 072 void setHeader(String name, Object value); 073 074 /** 075 * Returns all of the headers associated with the message 076 * 077 * @return all the headers in a Map 078 */ 079 Map<String, Object> getHeaders(); 080 081 /** 082 * Set all the headers associated with this message 083 * @param headers 084 */ 085 void setHeaders(Map<String,Object> headers); 086 087 /** 088 * Returns the body of the message as a POJO 089 * 090 * @return the body of the message 091 */ 092 public Object getBody(); 093 094 /** 095 * Returns the body as the specified type 096 * 097 * @param type the type that the body 098 * @return the body of the message as the specified type 099 */ 100 public <T> T getBody(Class<T> type); 101 102 /** 103 * Sets the body of the message 104 */ 105 public void setBody(Object body); 106 107 /** 108 * Sets the body of the message as a specific type 109 */ 110 public <T> void setBody(Object body, Class<T> type); 111 112 /** 113 * Creates a copy of this message so that it can be used and possibly modified further in another exchange 114 * 115 * @return a new message instance copied from this message 116 */ 117 Message copy(); 118 119 }