Fuse 6 is no longer supported
As of February 2025, Red Hat Fuse 6 is no longer supported. If you are using Fuse 6, please upgrade to Red Hat build of Apache Camel.Ce contenu n'est pas disponible dans la langue sélectionnée.
Chapter 4. Implementing the Interceptors Processing Logic
Abstract
handleMessage()
method. This method receives the message data and manipulates it as needed. Developers may also want to add some special logic to handle fault processing cases.
Figure 4.1. Flow through an interceptor
handleMessage()
method is called. The handleMessage()
method is where the interceptor's message processing logic is placed.
handleMessage()
method of the interceptor, or any subsequent interceptor in the interceptor chain, the handleFault()
method is called. The handleFault()
method is useful for cleaning up after an interceptor in the event of an error. It can also be used to alter the fault message.
4.1. Processing messages Copier lienLien copié sur presse-papiers!
Overview Copier lienLien copié sur presse-papiers!
handleMessage()
method is invoked. It receives that message data as a Message
object. Along with the actual contents of the message, the Message
object may contain a number of properties related to the message or the message processing state. The exact contents of the Message
object depends on the interceptors preceding the current interceptor in the chain.
Getting the message contents Copier lienLien copié sur presse-papiers!
Message
interface provides two methods that can be used in extracting the message contents:
public <T> T getContent(java.lang.Class<T> format);
ThegetContent()
method returns the content of the message in an object of the specified class. If the contents are not available as an instance of the specified class, null is returned. The list of available content types is determined by the interceptor's location on the interceptor chain and the direction of the interceptor chain.public Collection<Attachment> getAttachments();
ThegetAttachments()
method returns a JavaCollection
object containing any binary attachments associated with the message. The attachments are stored inorg.apache.cxf.message.Attachment
objects.Attachment
objects provide methods for managing the binary data.ImportantAttachments are only available after the attachment processing interceptors have executed.
Determining the message's direction Copier lienLien copié sur presse-papiers!
getExchange()
method. As shown in Example 4.1, “Getting the message exchange”, getExchange()
does not take any parameters and returns the message exchange as a org.apache.cxf.message.Exchange
object.
Example 4.1. Getting the message exchange
Exchange getExchange();
Exchange
object has four methods, shown in Example 4.2, “Getting messages from a message exchange”, for getting the messages associated with an exchange. Each method will either return the message as a org.apache.cxf.Message
object or it will return null if the message does not exist.
Example 4.2. Getting messages from a message exchange
Message getInMessage();
Message getInFaultMessage();
Message getOutMessage();
Message getOutFaultMessage();
Example 4.3. Checking the direction of a message chain
Example Copier lienLien copié sur presse-papiers!
Example 4.4. Example message processing method