public class DefaultMuleEventContext extends Object implements MuleEventContext
DefaultMuleEventContext
is the context object for the current
request. Using the context, developers can send/dispatch/receive events
programmatically as well as manage transactions.Modifier and Type | Field and Description |
---|---|
protected static Log |
logger
logger used by this class
|
Constructor and Description |
---|
DefaultMuleEventContext(MuleEvent event) |
Modifier and Type | Method and Description |
---|---|
void |
dispatchEvent(MuleMessage message)
This will dispatch an event asynchronously via the configured outbound
endpoint on the service for this session
|
void |
dispatchEvent(MuleMessage message,
EndpointURI endpointUri)
Depending on the session state this methods either Passes an event
asynchronously to the next available Mule component in the pool or via the
endpointUri configured for the event
|
void |
dispatchEvent(MuleMessage message,
OutboundEndpoint endpoint)
Depending on the session state this methods either Passes an event
asynchronously to the next available Mule component in the pool or via the
endpoint configured for the event
|
void |
dispatchEvent(MuleMessage message,
String endpointName)
Depending on the session state this methods either Passes an event
asynchronously to the next available Mule component in the pool or via the
endpoint configured for the event
|
void |
dispatchEvent(Object message)
This will dispatch an event asynchronously via the configured outbound
endpoint on the service for this session
|
Transaction |
getCurrentTransaction()
Returns the current transaction (if any) for the session
|
String |
getEncoding()
Gets the encoding for the current message.
|
URI |
getEndpointURI()
Returns a reference to the Endpoint Uri for this context This is the endpoint
on which the event was received
|
MessageExchangePattern |
getExchangePattern() |
FlowConstruct |
getFlowConstruct() |
MuleMessage |
getMessage()
Returns the message payload for this event
|
byte[] |
getMessageAsBytes()
Reterns the conents of the message as a byte array.
|
String |
getMessageAsString()
Returns the message contents as a string This method will use the default
encoding on the event
|
String |
getMessageAsString(String encoding)
Returns the message contents as a string
|
MuleContext |
getMuleContext() |
OutputStream |
getOutputStream()
An outputstream the can optionally be used write response data to an incoming
message.
|
MuleSession |
getSession() |
int |
getTimeout()
Get the timeout value associated with the event
|
Transaction |
getTransaction()
Returns the transaction for the current event or null if there is no
transaction in progresss
|
boolean |
isStopFurtherProcessing()
Determines whether the default processing for this event will be executed.
|
void |
markTransactionForRollback()
Mark the current transaction (if any) for rollback
|
MuleMessage |
requestEvent(EndpointURI endpointUri,
long timeout)
Requests a synchronous receive of an event on the service
|
MuleMessage |
requestEvent(InboundEndpoint endpoint,
long timeout)
Requests a synchronous receive of an event on the service
|
MuleMessage |
requestEvent(String endpointName,
long timeout)
Requests a synchronous receive of an event on the service
|
MuleMessage |
sendEvent(MuleMessage message)
Depending on the session state this methods either Passes an event
synchronously to the next available Mule component in the pool or via the
endpoint configured for the event
|
MuleMessage |
sendEvent(MuleMessage message,
EndpointURI endpointUri)
Depending on the session state this methods either Passes an event
synchronously to the next available Mule component in the pool or via the
endpointUri configured for the event
|
MuleMessage |
sendEvent(MuleMessage message,
OutboundEndpoint endpoint)
Depending on the session state this methods either Passes an event
synchronously to the next available Mule component in the pool or via the
endpoint configured for the event
|
MuleMessage |
sendEvent(MuleMessage message,
String endpointName)
Depending on the session state this methods either Passes an event
synchronously to the next available Mule component in the pool or via the
endpoint configured for the event
|
MuleMessage |
sendEvent(Object message)
This will send an event via the configured outbound router on the service
|
FutureMessageResult |
sendEventAsync(MuleMessage message,
EndpointURI endpointUri,
int timeout)
sends an event request via the configured outbound router for this service.
|
FutureMessageResult |
sendEventAsync(MuleMessage message,
int timeout)
sends an event request via the configured outbound router for this service.
|
FutureMessageResult |
sendEventAsync(MuleMessage message,
String endpointName,
int timeout)
sends an event request via the configured outbound router for this service.
|
FutureMessageResult |
sendEventAsync(Object message,
int timeout)
sends an event request via the configured outbound router for this service.
|
void |
setStopFurtherProcessing(boolean stopFurtherProcessing)
Determines whether the default processing for this event will be executed.
|
String |
toString() |
Object |
transformMessage(Class expectedType)
Returns the message transformed into its recognised or expected format.
|
Object |
transformMessage(DataType dataType)
Returns the message transformed into its recognised or expected format.
|
byte[] |
transformMessageToBytes()
Deprecated.
|
String |
transformMessageToString()
Returns the message transformed into it's recognised or expected format and
then into a String.
|
protected static final Log logger
public DefaultMuleEventContext(MuleEvent event)
public MuleMessage getMessage()
getMessage
in interface MuleEventContext
public byte[] getMessageAsBytes() throws MuleException
getMessageAsBytes
in interface MuleEventContext
MuleException
- if the message cannot be converted into an
array of bytespublic Object transformMessage(DataType dataType) throws TransformerException
transformMessage
in interface MuleEventContext
dataType
- The dataType required for the return object. This param
just provides a convienient way to manage type casting of
transformed objectsTransformerException
- if a failure occurs or
if the return type is not the same as the expected type in the
transformerTransformer
public Object transformMessage(Class expectedType) throws TransformerException
transformMessage
in interface MuleEventContext
expectedType
- The class type required for the return object. This param
just provides a convienient way to manage type casting of
transformed objectsTransformerException
- if a failure occurs or
if the return type is not the same as the expected type in the
transformerTransformer
@Deprecated public byte[] transformMessageToBytes() throws TransformerException
transformMessage(org.mule.api.transformer.DataType)
insteadtransformMessageToBytes
in interface MuleEventContext
TransformerException
- if a failure occurs in
the transformerTransformer
public String getMessageAsString(String encoding) throws MuleException
getMessageAsString
in interface MuleEventContext
encoding
- The encoding to use when transforming the messageMuleException
- if the message cannot be converted into a
stringpublic String transformMessageToString() throws TransformerException
transformMessageToString
in interface MuleEventContext
TransformerException
- if a failure occurs in
the transformerTransformer
public String getMessageAsString() throws MuleException
getMessageAsString
in interface MuleEventContext
MuleException
- if the message cannot be converted into a
stringpublic Transaction getCurrentTransaction()
getCurrentTransaction
in interface MuleEventContext
public void markTransactionForRollback() throws TransactionException
MuleEventContext
markTransactionForRollback
in interface MuleEventContext
TransactionException
- if operation failedpublic MuleMessage sendEvent(Object message) throws MuleException
sendEvent
in interface MuleEventContext
message
- the message to sendMuleException
- if there is no outbound endpoint configured
on the service or the events fails during dispatchpublic MuleMessage sendEvent(MuleMessage message, OutboundEndpoint endpoint) throws MuleException
sendEvent
in interface MuleEventContext
message
- the event message payload to sendendpoint
- The endpoint to disptch the event through.MuleException
- if the event fails to be processed by the
service or the transport for the endpointpublic MuleMessage sendEvent(MuleMessage message) throws MuleException
sendEvent
in interface MuleEventContext
message
- the message payload to sendMuleException
- if the event fails to be processed by the
service or the transport for the endpointpublic MuleMessage sendEvent(MuleMessage message, EndpointURI endpointUri) throws MuleException
sendEvent
in interface MuleEventContext
message
- the event message payload to sendendpointUri
- The endpointUri to disptch the event throughMuleException
- if the event fails to be processed by the
service or the transport for the endpointUripublic FutureMessageResult sendEventAsync(Object message, int timeout) throws MuleException
sendEventAsync
in interface MuleEventContext
message
- the object that is the payload of the eventtimeout
- how long to block in milliseconds waiting for a resultMuleException
- if the dispatch fails or the components or
transfromers cannot be foundFutureMessageResult
public FutureMessageResult sendEventAsync(MuleMessage message, int timeout) throws MuleException
sendEventAsync
in interface MuleEventContext
message
- the MuleMessage of the eventtimeout
- how long to block in milliseconds waiting for a resultMuleException
- if the dispatch fails or the components or
transfromers cannot be foundFutureMessageResult
public FutureMessageResult sendEventAsync(MuleMessage message, EndpointURI endpointUri, int timeout) throws MuleException
sendEventAsync
in interface MuleEventContext
message
- the MuleMessage of the eventendpointUri
- the endpointUri to dispatch totimeout
- how long to block in milliseconds waiting for a resultMuleException
- if the dispatch fails or the components or
transfromers cannot be foundFutureMessageResult
public FutureMessageResult sendEventAsync(MuleMessage message, String endpointName, int timeout) throws MuleException
sendEventAsync
in interface MuleEventContext
message
- the MuleMessage of the eventendpointName
- The endpoint name to disptch the event through. This will
be looked up first on the service configuration and then on the
mule manager configurationtimeout
- how long to block in milliseconds waiting for a resultMuleException
- if the dispatch fails or the components or
transfromers cannot be foundFutureMessageResult
public MuleMessage sendEvent(MuleMessage message, String endpointName) throws MuleException
sendEvent
in interface MuleEventContext
message
- the event message payload to sendendpointName
- The endpoint name to disptch the event through. This will
be looked up first on the service configuration and then on the
mule manager configurationMuleException
- if the event fails to be processed by the
service or the transport for the endpointpublic void dispatchEvent(Object message) throws MuleException
dispatchEvent
in interface MuleEventContext
message
- payload to dispatchMuleException
- if there is no outbound endpoint configured
on the service or the events fails during dispatchpublic void dispatchEvent(MuleMessage message) throws MuleException
dispatchEvent
in interface MuleEventContext
message
- the message to sendMuleException
- if there is no outbound endpoint configured
on the service or the events fails during dispatchpublic void dispatchEvent(MuleMessage message, EndpointURI endpointUri) throws MuleException
dispatchEvent
in interface MuleEventContext
message
- the event message payload to sendendpointUri
- the endpointUri to dispatc the event to first on the
service configuration and then on the mule manager configurationMuleException
- if the event fails to be processed by the
service or the transport for the endpointUripublic void dispatchEvent(MuleMessage message, String endpointName) throws MuleException
dispatchEvent
in interface MuleEventContext
message
- the event message payload to sendendpointName
- The endpoint name to disptch the event through. This will
be looked up first on the service configuration and then on the
mule manager configurationMuleException
- if the event fails to be processed by the
service or the transport for the endpointpublic void dispatchEvent(MuleMessage message, OutboundEndpoint endpoint) throws MuleException
dispatchEvent
in interface MuleEventContext
message
- the event message payload to sendendpoint
- The endpoint name to disptch the event through.MuleException
- if the event fails to be processed by the
service or the transport for the endpointpublic MuleMessage requestEvent(InboundEndpoint endpoint, long timeout) throws MuleException
requestEvent
in interface MuleEventContext
endpoint
- the endpoint identifing the endpointUri on ewhich the event
will be receivedtimeout
- time in milliseconds before the request timesoutMuleException
- if the request operation failspublic MuleMessage requestEvent(String endpointName, long timeout) throws MuleException
requestEvent
in interface MuleEventContext
endpointName
- the endpoint identifing the endpointUri on ewhich the
event will be receivedtimeout
- time in milliseconds before the request timesoutMuleException
- if the request operation failspublic MuleMessage requestEvent(EndpointURI endpointUri, long timeout) throws MuleException
requestEvent
in interface MuleEventContext
endpointUri
- the endpointUri on which the event will be receivedtimeout
- time in milliseconds before the request timesoutMuleException
- if the request operation failspublic FlowConstruct getFlowConstruct()
getFlowConstruct
in interface MuleEventContext
public boolean isStopFurtherProcessing()
org.mule.api.lifecycle.Callable
or calling
RequestContext.getEventContext
to obtain the MuleEventContext for
the current thread. The user can programmatically control how events are
dispatched.isStopFurtherProcessing
in interface MuleEventContext
MuleEventContext
,
Callable
public void setStopFurtherProcessing(boolean stopFurtherProcessing)
org.mule.api.lifecycle.Callable
or calling
RequestContext.getEventContext
to obtain the MuleEventContext for
the current thread. The user can programmatically control how events are
dispached.setStopFurtherProcessing
in interface MuleEventContext
stopFurtherProcessing
- the value to set.public OutputStream getOutputStream()
getOutputStream
in interface MuleEventContext
public URI getEndpointURI()
MuleEventContext
getEndpointURI
in interface MuleEventContext
public MessageExchangePattern getExchangePattern()
getExchangePattern
in interface MuleEventContext
public Transaction getTransaction()
getTransaction
in interface MuleEventContext
public int getTimeout()
getTimeout
in interface MuleEventContext
public String getEncoding()
getEncoding
in interface MuleEventContext
public MuleSession getSession()
getSession
in interface MuleEventContext
public MuleContext getMuleContext()
getMuleContext
in interface MuleEventContext
Copyright © 2003–2016 MuleSoft, Inc.. All rights reserved.