1 /* 2 * $Id: MuleMessage.java 22749 2011-08-26 00:41:12Z mike.schilling $ 3 * -------------------------------------------------------------------------------------- 4 * Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com 5 * 6 * The software in this package is published under the terms of the CPAL v1.0 7 * license, a copy of which has been included with this distribution in the 8 * LICENSE.txt file. 9 */ 10 11 package org.mule.api; 12 13 import org.mule.api.transformer.DataType; 14 import org.mule.api.transformer.Transformer; 15 import org.mule.api.transformer.TransformerException; 16 import org.mule.api.transport.PropertyScope; 17 18 import java.io.Serializable; 19 import java.util.List; 20 import java.util.Map; 21 import java.util.Set; 22 23 import javax.activation.DataHandler; 24 25 /** 26 * <code>MuleMessage</code> represents a message payload. The Message comprises of 27 * the payload itself and properties associated with the payload. 28 */ 29 30 public interface MuleMessage extends Serializable 31 { 32 /** 33 * Adds a map of properties to be associated with this message 34 * 35 * @param properties the properties add to this message 36 * @deprecated use {@link #addProperties(java.util.Map, org.mule.api.transport.PropertyScope)} instead 37 */ 38 @Deprecated 39 void addProperties(Map<String, Object> properties); 40 41 /** 42 * Adds a map of properties to be associated with this message 43 * 44 * @param properties the properties add to this message 45 * @param scope the scope in which the properties should be added 46 */ 47 void addProperties(Map<String, Object> properties, PropertyScope scope); 48 49 /** 50 * Removes all properties on this message in the {@link org.mule.api.transport.PropertyScope#INVOCATION} and 51 * {@link org.mule.api.transport.PropertyScope#OUTBOUND}. 52 * @deprecated use {@link #clearProperties(org.mule.api.transport.PropertyScope)} instead 53 */ 54 @Deprecated 55 void clearProperties(); 56 57 /** 58 * Removes all properties on this message in the given scope. Note that the INBOUND scope is 59 * read-only, so attempting to clear this scopee will result in an UnsupportedOperationException. 60 * 61 * @param scope the property scope to clear 62 * @throws UnsupportedOperationException if scope specified is {@link org.mule.api.transport.PropertyScope#INBOUND} 63 */ 64 void clearProperties(PropertyScope scope); 65 /** 66 /** 67 * 68 * @deprecated use the overloaded version with an explicit lookup scope. This method will 69 * now use only the outbound scope. 70 * @see #getInboundProperty(String) 71 * @see #getOutboundProperty(String) 72 * @see #getInvocationProperty(String) 73 * @see #getSessionProperty(String) 74 */ 75 @Deprecated 76 Object getProperty(String key); 77 78 /** 79 * Set a property on the message. This method will now set a value on the outbound scope only. 80 * @deprecated use {@link #setProperty(String, Object, org.mule.api.transport.PropertyScope)} or 81 * preferrably any of the scope-specific set methods. 82 * 83 * @param key the key on which to associate the value 84 * @param value the property value 85 * @see #setInvocationProperty(String, Object) 86 * @see #setOutboundProperty(String, Object) 87 * @see #setSessionProperty(String, Object) 88 */ 89 @Deprecated 90 void setProperty(String key, Object value); 91 92 /** 93 * @see #setProperty(String, Object, org.mule.api.transport.PropertyScope) 94 */ 95 void setInvocationProperty(String key, Object value); 96 97 /** 98 * @see #setProperty(String, Object, org.mule.api.transport.PropertyScope) 99 */ 100 void setOutboundProperty(String key, Object value); 101 102 /** 103 * Set a property on the message. End-users should prefer more 104 * scope-specific methods for readability. This one is more intended for programmatic 105 * scope manipulation and Mule internal use. 106 * 107 * @param key the key on which to associate the value 108 * @param value the property value 109 * @param scope The scope at which to set the property at 110 * @see PropertyScope 111 * @see #setInvocationProperty(String, Object) 112 * @see #setOutboundProperty(String, Object) 113 * @see #setSessionProperty(String, Object) 114 */ 115 void setProperty(String key, Object value, PropertyScope scope); 116 117 /** 118 * Removes a property on this message. 119 * 120 * @param key the property key to remove 121 * @return the removed property value or null if the property did not exist 122 * @deprecated use {@link #removeProperty(String, org.mule.api.transport.PropertyScope)} 123 */ 124 @Deprecated 125 Object removeProperty(String key); 126 127 /** 128 * Removes a property on this message from the specified scope only. 129 * 130 * @param key the property key to remove 131 * @param scope The scope at which to set the property at 132 * @return the removed property value or null if the property did not exist 133 */ 134 Object removeProperty(String key, PropertyScope scope); 135 136 /** 137 * @return all property keys on this message. 138 * @since 3.0 only the outbound scope properties are returned 139 * @deprecated use {@link #getPropertyNames(org.mule.api.transport.PropertyScope)} 140 */ 141 @Deprecated 142 Set<String> getPropertyNames(); 143 144 /** 145 * Gets all property names in a given scope. Prefer using one of the convenience 146 * scope-aware methods instead, this one is meant for internal access mostly. 147 * @param scope the scope of property names 148 * @return all property keys on this message in the given scope 149 * @see #getInvocationPropertyNames() 150 * @see #getInboundPropertyNames() 151 * @see #getOutboundPropertyNames() 152 * @see #getSessionPropertyNames() 153 */ 154 Set<String> getPropertyNames(PropertyScope scope); 155 156 Set<String> getInvocationPropertyNames(); 157 Set<String> getInboundPropertyNames(); 158 Set<String> getOutboundPropertyNames(); 159 Set<String> getSessionPropertyNames(); 160 161 162 /** 163 * @return the current message 164 */ 165 Object getPayload(); 166 167 /** 168 * gets the unique identifier for the message. It's up to the implementation to 169 * ensure a unique id 170 * 171 * @return a unique message id. The Id should never be null. If the underlying 172 * transport does not have the notion of a message Id, one should be 173 * generated. The generated Id should be a UUID. 174 */ 175 String getUniqueId(); 176 177 /** 178 * gets an identifier that is the same among parent and child messages 179 * 180 * @return a message id for the group of descendant messages. The Id should never be null. 181 */ 182 String getMessageRootId(); 183 184 /** 185 * set the root ID for the message 186 */ 187 void setMessageRootId(String rootId); 188 189 /** 190 * copy the message root id from parent to child 191 */ 192 void propagateRootId(MuleMessage parent); 193 194 /** 195 * Gets a property from the message 196 * 197 * @param name the name or key of the property. This must be non-null. 198 * @param defaultValue a default value if the property doesn't exist in the event. This can be null. 199 * @return the property value or the defaultValue if the property does not exist 200 * @deprecated use scope-aware methods instead 201 * @see #getInboundProperty(String) 202 * @see #getOutboundProperty(String) 203 * @see #getInvocationProperty(String) 204 * @see #getSessionProperty(String) 205 */ 206 @Deprecated 207 Object getProperty(String name, Object defaultValue); 208 209 /** 210 * Gets a property from the message with a given scope. End-users should prefer more 211 * scope-specific methods for readability. This one is more intended for programmatic 212 * scope manipulation and Mule internal use. 213 * 214 * @param name the name or key of the property. This must be non-null. 215 * @param scope The scope of the property to retrieve. This must be non-null. 216 * @return the property value or null if the property does not exist in the specified scope 217 * @see #getInboundProperty(String) 218 * @see #getOutboundProperty(String) 219 * @see #getInvocationProperty(String) 220 * @see #getSessionProperty(String) 221 */ 222 <T> T getProperty(String name, PropertyScope scope); 223 224 /** 225 * @see #getProperty(String, org.mule.api.transport.PropertyScope, Object) 226 */ 227 <T> T getInboundProperty(String name, T defaultValue); 228 229 /** 230 * @see #getProperty(String, org.mule.api.transport.PropertyScope, Object) 231 */ 232 <T> T getInboundProperty(String name); 233 234 /** 235 * @see #getProperty(String, org.mule.api.transport.PropertyScope, Object) 236 */ 237 <T> T getInvocationProperty(String name, T defaultValue); 238 239 /** 240 * @see #getProperty(String, org.mule.api.transport.PropertyScope, Object) 241 */ 242 <T> T getInvocationProperty(String name); 243 244 /** 245 * @see #getProperty(String, org.mule.api.transport.PropertyScope, Object) 246 */ 247 <T> T getOutboundProperty(String name, T defaultValue); 248 249 /** 250 * @see #getProperty(String, org.mule.api.transport.PropertyScope, Object) 251 */ 252 <T> T getOutboundProperty(String name); 253 254 /** 255 * This method was added with the introduction of Property scopes. However, this method should 256 * rarely be used. Instead, the scoped accessors should be used. Mule does not use this method internally 257 * and may be deprecated in future versions 258 * 259 * The Scopes will be checked in the following order, with the first match being returned - 260 * <ul> 261 * <li>Outbound</li> 262 * <li>Invocation</li> 263 * <li>Session</li> 264 * <li>Inbound</li> 265 * </ul> 266 * 267 * @param name the name of the property to look for 268 * @param defaultValue the default value that will be returned if the property is not found 269 * @param <T> The Type of the property value that will be returned 270 * @return TThe property value from the first scope that had the property set, or the 'defaultValue' if the property was 271 * not found in any scope 272 * @since 3.0 273 */ 274 <T> T findPropertyInAnyScope(String name, T defaultValue); 275 276 /** 277 * Gets a property from the message with a given scope and provides a default value if the property is not 278 * present on the message in the scope specified. The method will also type check against the default value 279 * to ensure that the value is of the correct type. If null is used for the default value no type checking is 280 * done. 281 * @param name the name or key of the property. This must be non-null. 282 * @param scope The scope of the property to retrieve. This must be non-null. 283 * @param defaultValue the value to return if the property is not in the scope provided. Can be null 284 * @param <T> the defaultValue type ,this is used to validate the property value type 285 * @return the property value or the defaultValue if the property does not exist in the specified scope 286 * @throws IllegalArgumentException if the value for the property key is not assignable from the defaultValue type 287 */ 288 <T> T getProperty(String name, PropertyScope scope, T defaultValue); 289 290 /** 291 * Gets an integer property from the message 292 * 293 * @param name the name or key of the property 294 * @param defaultValue a default value if the property doesn't exist in the event 295 * @return the property value or the defaultValue if the property does not exist 296 * @deprecated use {@link #getInboundProperty(String, Object)} instead 297 */ 298 @Deprecated 299 int getIntProperty(String name, int defaultValue); 300 301 /** 302 * Gets a long property from the message 303 * 304 * @param name the name or key of the property 305 * @param defaultValue a default value if the property doesn't exist in the event 306 * @return the property value or the defaultValue if the property does not exist 307 * @deprecated use {@link #getInboundProperty(String, Object)} instead 308 */ 309 @Deprecated 310 long getLongProperty(String name, long defaultValue); 311 312 /** 313 * Gets a double property from the message 314 * 315 * @param name the name or key of the property 316 * @param defaultValue a default value if the property doesn't exist in the event 317 * @return the property value or the defaultValue if the property does not exist 318 * @deprecated use {@link #getInboundProperty(String, Object)} instead 319 */ 320 @Deprecated 321 double getDoubleProperty(String name, double defaultValue); 322 323 /** 324 * Gets a String property from the message 325 * 326 * @param name the name or key of the property 327 * @param defaultValue a default value if the property doesn't exist in the event 328 * @return the property value or the defaultValue if the property does not exist 329 * @deprecated use {@link #getInboundProperty(String, Object)} instead 330 */ 331 @Deprecated 332 String getStringProperty(String name, String defaultValue); 333 334 /** 335 * Gets a boolean property from the message 336 * 337 * @param name the name or key of the property 338 * @param defaultValue a default value if the property doesn't exist in the event 339 * @return the property value or the defaultValue if the property does not exist 340 * @deprecated use {@link #getInboundProperty(String, Object)} instead 341 */ 342 @Deprecated 343 boolean getBooleanProperty(String name, boolean defaultValue); 344 345 /** 346 * Sets a boolean property on the message 347 * 348 * @param name the property name or key 349 * @param value the property value 350 * @deprecated use {@link #setOutboundProperty(String, Object)} instead 351 */ 352 @Deprecated 353 void setBooleanProperty(String name, boolean value); 354 355 /** 356 * Sets a integer property on the message 357 * 358 * @param name the property name or key 359 * @param value the property value 360 * @deprecated use {@link #setOutboundProperty(String, Object)} instead 361 */ 362 @Deprecated 363 void setIntProperty(String name, int value); 364 365 /** 366 * Sets a long property on the message 367 * 368 * @param name the property name or key 369 * @param value the property value 370 * @deprecated use {@link #setOutboundProperty(String, Object)} instead 371 */ 372 @Deprecated 373 void setLongProperty(String name, long value); 374 375 /** 376 * Sets a double property on the message 377 * 378 * @param name the property name or key 379 * @param value the property value 380 * @deprecated use {@link #setOutboundProperty(String, Object)} instead 381 */ 382 @Deprecated 383 void setDoubleProperty(String name, double value); 384 385 /** 386 * Sets a String property on the message 387 * 388 * @param name the property name or key 389 * @param value the property value 390 * @deprecated use {@link #setOutboundProperty(String, Object)} instead 391 */ 392 @Deprecated 393 void setStringProperty(String name, String value); 394 395 396 397 398 /** 399 * Sets a correlationId for this message. The correlation Id can be used by 400 * components in the system to manage message relations <p/> transport protocol. 401 * As such not all messages will support the notion of a correlationId i.e. tcp 402 * or file. In this situation the correlation Id is set as a property of the 403 * message where it's up to developer to keep the association with the message. 404 * For example if the message is serialised to xml the correlationId will be 405 * available in the message. 406 * 407 * @param id the Id reference for this relationship 408 */ 409 void setCorrelationId(String id); 410 411 /** 412 * Sets a correlationId for this message. The correlation Id can be used by 413 * components in the system to manage message relations. <p/> The correlationId 414 * is associated with the message using the underlying transport protocol. As 415 * such not all messages will support the notion of a correlationId i.e. tcp or 416 * file. In this situation the correlation Id is set as a property of the message 417 * where it's up to developer to keep the association with the message. For 418 * example if the message is serialised to xml the correlationId will be 419 * available in the message. 420 * 421 * @return the correlationId for this message or null if one hasn't been set 422 */ 423 String getCorrelationId(); 424 425 /** 426 * Gets the sequence or ordering number for this message in the the correlation 427 * group (as defined by the correlationId) 428 * 429 * @return the sequence number or -1 if the sequence is not important 430 */ 431 int getCorrelationSequence(); 432 433 /** 434 * Gets the sequence or ordering number for this message in the the correlation 435 * group (as defined by the correlationId) 436 * 437 * @param sequence the sequence number or -1 if the sequence is not important 438 */ 439 void setCorrelationSequence(int sequence); 440 441 /** 442 * Determines how many messages are in the correlation group 443 * 444 * @return total messages in this group or -1 if the size is not known 445 */ 446 int getCorrelationGroupSize(); 447 448 /** 449 * Determines how many messages are in the correlation group 450 * 451 * @param size the total messages in this group or -1 if the size is not known 452 */ 453 void setCorrelationGroupSize(int size); 454 455 /** 456 * Sets a replyTo address for this message. This is useful in an asynchronous 457 * environment where the caller doesn't wait for a response and the response 458 * needs to be routed somewhere for further processing. The value of this field 459 * can be any valid endpointUri url. 460 * 461 * @param replyTo the endpointUri url to reply to 462 */ 463 void setReplyTo(Object replyTo); 464 465 /** 466 * Returns a replyTo address for this message. This is useful in an asynchronous 467 * environment where the caller doesn't wait for a response and the response 468 * needs to be routed somewhere for further processing. The value of this field 469 * can be any valid endpointUri url. 470 * 471 * @return the endpointUri url to reply to or null if one has not been set 472 */ 473 Object getReplyTo(); 474 475 /** 476 * If an error occurred during the processing of this message this will return a 477 * ErrorPayload that contains the root exception and Mule error code, plus any 478 * other releated info 479 * 480 * @return The exception payload (if any) attached to this message 481 */ 482 ExceptionPayload getExceptionPayload(); 483 484 /** 485 * If an error occurs while processing this message, a ErrorPayload is attached 486 * which contains the root exception and Mule error code, plus any other releated 487 * info. 488 * 489 * @param payload The exception payload to attach to this message 490 */ 491 void setExceptionPayload(ExceptionPayload payload); 492 493 /** 494 * Allows for arbitrary data attachments to be associated with the Message. These 495 * attachments work in the same way that email attachments work. Attachments can 496 * be binary or text 497 * 498 * @param name the name to associate with the attachment 499 * @param dataHandler The attachment datahandler to use. This will be used to 500 * interact with the attachment data. 501 * @throws Exception if the attachment cannot be added for any reason 502 * @see javax.activation.DataHandler 503 * @deprecated use 504 * {@link #addOutboundAttachment(java.lang.String, javax.activation.DataHandler)} 505 * instead 506 */ 507 @Deprecated 508 void addAttachment(String name, DataHandler dataHandler) throws Exception; 509 510 /** 511 * Allows for arbitrary data attachments to be associated with the Message. These attachments work in the 512 * same way that email attachments work. Attachments can be binary or text 513 * @param name the name to associate with the attachment 514 * @param dataHandler The attachment {@link javax.activation.DataHandler} to use. This will be used to interact with the attachment data 515 * @throws Exception if the attachment cannot be added for any reason 516 * @see javax.activation.DataHandler 517 * @since 3.0 518 */ 519 void addOutboundAttachment(String name, DataHandler dataHandler) throws Exception; 520 521 /** 522 * Adds an outgoing attachment to the message 523 * @param object the input stream to the contents of the attachment. This object can either be a {@link java.net.URL}, which will construct a URL data source, or 524 * a {@link java.io.File}, which will construct a file data source. Any other object will be used as the raw contents of the attachment 525 * @param contentType the content type of the attachment. Note that the charset attribute can be specifed too i.e. text/plain;charset=UTF-8 526 * @param name the name to associate with the attachments 527 * @throws Exception if the attachment cannot be read or created 528 * @since 3.0 529 */ 530 void addOutboundAttachment(String name, Object object, String contentType) throws Exception; 531 532 /** 533 * Remove an attachment form this message with the specified name 534 * @param name the name of the attachment to remove. If the attachment does not exist, the request may be ignored 535 * @throws Exception different messaging systems handle attachments differently, as such some will throw an exception 536 * if an attachment does dot exist. 537 * @deprecated use {@link #removeOutboundAttachment(java.lang.String)} instead 538 */ 539 @Deprecated 540 void removeAttachment(String name) throws Exception; 541 542 /** 543 * Remove an attachment form this message with the specified name 544 * @param name the name of the attachment to remove. If the attachment does not exist, the request may be ignored 545 * @throws Exception different messaging systems handle attachments differently, as such some will throw an exception 546 * if an attachment does dot exist. 547 * @since 3.0 548 */ 549 void removeOutboundAttachment(String name) throws Exception; 550 551 /** 552 * Retrieve an attachment with the given name. If the attachment does not exist, null will be returned 553 * @param name the name of the attachment to retrieve 554 * @return the attachment with the given name or null if the attachment does not exist 555 * @see javax.activation.DataHandler 556 * @deprecated use {@link #getInboundAttachment(String)} instead 557 */ 558 @Deprecated 559 DataHandler getAttachment(String name); 560 561 /** 562 * Retrieve an attachment with the given name. If the attachment does not exist, null will be returned 563 * @param name the name of the attachment to retrieve 564 * @return the attachment with the given name or null if the attachment does not exist 565 * @see javax.activation.DataHandler 566 * @since 3.0 567 */ 568 DataHandler getInboundAttachment(String name); 569 570 /** 571 * Retrieve an attachment with the given name. If the attachment does not exist, null will be returned 572 * @param name the name of the attachment to retrieve 573 * @return the attachment with the given name or null if the attachment does not exist 574 * @see javax.activation.DataHandler 575 * @since 3.0 576 */ 577 DataHandler getOutboundAttachment(String name); 578 579 /** 580 * @return a set of the names of the attachments on this message. If there are no attachments an empty set will be 581 * returned. 582 * @deprecated use {@link #getInboundAttachmentNames()} 583 */ 584 @Deprecated 585 Set<String> getAttachmentNames(); 586 587 /** 588 * @return a set of the names of the attachments on this message. If there are no attachments an empty set will be 589 * returned. 590 * @since 3.0 591 */ 592 Set<String> getInboundAttachmentNames(); 593 594 /** 595 * @return a set of the names of the attachments on this message. If there are no attachments an empty set will be 596 * returned. 597 * @since 3.0 598 */ 599 Set<String> getOutboundAttachmentNames(); 600 601 /** 602 * Gets the encoding for the current message. For potocols that send encoding 603 * information with the message, this method should be overriden to expose the 604 * transport encoding, otherwise the default encoding in the Mule configuration 605 * will be used. 606 * 607 * @return the encoding for this message. This method must never return null 608 */ 609 String getEncoding(); 610 611 /** 612 * Sets the encoding for this message 613 * 614 * @param encoding the encoding to use 615 */ 616 void setEncoding(String encoding); 617 618 /** 619 * Perform any clean up operations on the message resource. 620 */ 621 void release(); 622 623 /** 624 * Will apply a list of transformers to the payload of the message. This *Will* change the payload of the 625 * message. This method provides the only way to alter the paylaod of this message without recreating a 626 * copy of the message 627 * @param event the event being processed 628 * @param transformers the transformers to apply to the message payload 629 * @throws TransformerException if a transformation error occurs or one or more of the transformers passed in a 630 * are incompatible with the message payload 631 */ 632 void applyTransformers(MuleEvent event, List<? extends Transformer> transformers) throws MuleException; 633 634 /** 635 * Will apply a list of transformers to the payload of the message. This *Will* change the payload of the 636 * message. This method provides the only way to alter the paylaod of this message without recreating a 637 * copy of the message 638 * @param event the event being processed 639 * @param transformers the transformers to apply to the message payload 640 * @throws TransformerException if a transformation error occurs or one or more of the transformers passed in a 641 * are incompatible with the message payload 642 */ 643 void applyTransformers(MuleEvent event, Transformer... transformers) throws MuleException; 644 645 /** 646 * Will apply a list of transformers to the payload of the message. This *Will* change the payload of the 647 * message. This method provides the only way to alter the paylaod of this message without recreating a 648 * copy of the message 649 * @param event the event being processed 650 * @param transformers the transformers to apply to the message payload 651 * @param outputType the required output type for this transformation. by adding this parameter some additional 652 * transformations will occur on the message payload to ensure that the final payload is of the specified type. 653 * If no transformers can be found in the registry that can transform from the return type of the transformation 654 * list to the outputType and exception will be thrown 655 * @throws TransformerException if a transformation error occurs or one or more of the transformers passed in a 656 * are incompatible with the message payload 657 */ 658 void applyTransformers(MuleEvent event, List<? extends Transformer> transformers, Class<?> outputType) throws MuleException; 659 660 /** 661 * Update the message payload. This is typically only called if the 662 * payload was originally an InputStream. In which case, if the InputStream 663 * is consumed, it needs to be replaced for future access. 664 * 665 * @param payload the object to assign as the message payload 666 */ 667 void setPayload(Object payload); 668 669 /** 670 * Will attempt to obtain the payload of this message with the desired Class type. This will 671 * try and resolve a transformer that can do this transformation. If a transformer cannot be found 672 * an exception is thrown. Any transformers added to the registry will be checked for compatibility 673 * @param outputType the desired return type 674 * @return The converted payload of this message. Note that this method will not alter the payload of this 675 * message *unless* the payload is an InputStream in which case the stream will be read and the payload will become 676 * the fully read stream. 677 * @throws TransformerException if a transformer cannot be found or there is an error during transformation of the 678 * payload 679 */ 680 <T> T getPayload(Class<T> outputType) throws TransformerException; 681 682 /** 683 * Will attempt to obtain the payload of this message with the desired Class type. This will 684 * try and resolve a transformer that can do this transformation. If a transformer cannot be found 685 * an exception is thrown. Any transformers added to the registry will be checked for compatability 686 * @param outputType the desired return type 687 * @return The converted payload of this message. Note that this method will not alter the payload of this 688 * message *unless* the payload is an InputStream in which case the stream will be read and the payload will become 689 * the fully read stream. 690 * @throws TransformerException if a transformer cannot be found or there is an error during transformation of the 691 * payload 692 */ 693 <T> T getPayload(DataType<T> outputType) throws TransformerException; 694 695 696 /** 697 * Converts the message implementation into a String representation 698 * 699 * @param encoding The encoding to use when transforming the message (if 700 * necessary). The parameter is used when converting from a byte array 701 * @return String representation of the message payload 702 * @throws Exception Implementation may throw an endpoint specific exception 703 */ 704 String getPayloadAsString(String encoding) throws Exception; 705 706 /** 707 * Converts the message implementation into a String representation. If encoding 708 * is required it will use the encoding set on the message 709 * 710 * @return String representation of the message payload 711 * @throws Exception Implementation may throw an endpoint specific exception 712 * 713 */ 714 String getPayloadAsString() throws Exception; 715 716 /** 717 * Converts the message implementation into a byte array representation 718 * 719 * @return byte array of the message 720 * @throws Exception Implemetation may throw an endpoint specific exception 721 * 722 */ 723 byte[] getPayloadAsBytes() throws Exception; 724 725 /** 726 * Returns the original payload used to create this message. The payload of the message can change 727 * if {@link #applyTransformers(MuleEvent,java.util.List)} or 728 * {@link #applyTransformers(MuleEvent, java.util.List, Class)} is called. 729 * @return the original payload used to create this message 730 */ 731 Object getOriginalPayload(); 732 733 /** 734 * Get the message payload for logging without throwing exception 735 * Converts the message implementation into a String representation. 736 * 737 * @return message payload as object 738 */ 739 String getPayloadForLogging(); 740 741 /** 742 * Get the message payload for logging without throwing exception 743 * Converts the message implementation into a String representation. If encoding 744 * is required it will use the encoding set on the message 745 * 746 * @return message payload as object 747 */ 748 String getPayloadForLogging(String encoding); 749 750 MuleContext getMuleContext(); 751 752 /** 753 * Returns the data type (if any) associated with the message's payload. 754 */ 755 DataType<?> getDataType(); 756 757 <T> T getSessionProperty(String name, T defaultValue); 758 759 <T> T getSessionProperty(String name); 760 761 void setSessionProperty(String key, Object value); 762 763 /** 764 * Copy an inbound message to an outbound one, moving all message properties and attachments 765 * @return the inbound message 766 */ 767 MuleMessage createInboundMessage() throws Exception; 768 }