Class MessageContext
- All Implemented Interfaces:
Externalizable,Serializable,SafeSerializable
Axis2 states are held in two information models, called description hierarchy and context hierarchy. Description hierarchy hold deployment configuration and it's values does not change unless deployment configuration change occurs where Context hierarchy hold run time information. Both hierarchies consists four levels, Global, Service Group, Operation and Message. Please look at "Information Model" section of "Axis2 Architecture Guide" for more information.
MessageContext hold run time information about one Message invocation. It hold reference to OperationContext, ServiceGroupContext, and Configuration Context tied with current message. For an example if you need accesses to other messages of the current invocation, you can get to them via OperationContext. Addition to class attributes define in Message context, message context stores the information as name value pairs. Those name value pairs,and class attributes tweak the execution behavior of message context and some of them can be find in org.apache.axis2.Constants class. (TODO we should provide list of supported options). You may set them at any level of context hierarchy and they will affect invocations related to their child elements.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionorg.apache.axiom.attachments.Attachmentsmessage attachments NOTE: Serialization of message attachments is handled as part of the overall message serialization.static final StringField CHARACTER_SET_ENCODINGstatic final StringTo invoke fireAndforget method we have to hand over transport sending logic to a thread other wise user has to wait till it get transport response (in the case of HTTP its HTTP 202) 202).static ThreadLocal<MessageContext>A place to store the current MessageContextstatic final StringField DEFAULT_CHAR_SET_ENCODING.static final StringThis property allows someone (e.g.intstatic final intstatic final intstatic final StringConstant used as the key for the property which stores the In MessageContext in the Out MessageContext/FaultMessageContext.protected Optionsstatic final intstatic final intbooleanstatic final Stringstatic final Stringstatic final Stringstatic final StringField TRANSPORT_INstatic final StringField TRANSPORT_OUTstatic final StringField TRANSPORT_SUCCEEDstatic final StringField UTF_16.static final StringField UTF_8.Fields inherited from class org.apache.axis2.context.AbstractContext
COPY_PROPERTIES, lastTouchedTime, parent, properties -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidThis method checks to see if additional work needs to be done in order to complete the object reconstitution.voidactivateWithOperationContext(OperationContext operationCtx) This method checks to see if additional work needs to be done in order to complete the object reconstitution.addAttachment(jakarta.activation.DataHandler dataHandler) Adds an attachment to the attachment Map of this message context.voidaddAttachment(String contentID, jakarta.activation.DataHandler dataHandler) Adds an attachment to the attachment Map of this message context.voidaddExecutedPhase(Handler phase) Add a Phase to the collection of executed phases for the path.voidaddRelatesTo(RelatesTo reference) Add a RelatesTobooleancontainsSelfManagedDataKey(Class clazz, Object key) Check to see if the key for the self managed data is availablestatic voidReturn a Read-Only copy of this message context that has been extracted from the object hierachy.jakarta.activation.DataHandlergetAttachment(String contentID) Access the DataHandler of the attachment contained in the map corresponding to the given content ID.org.apache.axiom.attachments.AttachmentsYou can directly access the attachment map of the message context from here.org.apache.axiom.attachments.AttachmentsgetAttachmentMap(boolean create) intstatic MessageContextintorg.apache.neethi.Policyorg.apache.axiom.soap.SOAPEnvelopeGet an iterator over the executed phase list.Obtain the Exception which caused the processing chain to halt.intgetFLOW()getFrom()getLocalProperty(String name) Retrieves a property value.getLocalProperty(String name, boolean searchOptions) Get a "raw" version of the logCorrelationID.Get a formatted version of the logCorrelationID.getModuleParameter(String key, String moduleName, HandlerDescription handler) Retrieves both module specific configuration parameters as well as other parameters.getParameter(String key) Retrieves configuration descriptor parameters at any level.Retrieves all property values.getProperty(String name) Retrieves a property value.getRelatesTo(String type) Get any RelatesTos of a particular type associated with this MessageContext TODO: Shouldn't this return a List?getSelfManagedData(Class clazz, Object key) Retrieve a value of self managed data previously saved with the specified key.getTo()booleanbooleanbooleanbooleanbooleanisFault()booleanDeprecated.The bonus you used to get from this is now built in to SOAPEnvelope.getHeader()booleanbooleanbooleanisPaused()booleanbooleanisPropertyTrue(String name) Check if a given property is true.booleanisPropertyTrue(String name, boolean defaultVal) Check if a given property is true.booleanbooleanbooleanisSOAP11()voidpause()Pause the execution of the current handler chainvoidreadExternal(ObjectInput inObject) Restore the contents of the MessageContext that was previously saved.voidremoveAttachment(String contentID) Removes the attachment with the given content ID from the Attachments Map Do nothing if a attachment cannot be found by the given content ID.voidRemove the first Phase in the collection of executed phasesvoidremoveSelfManagedData(Class clazz, Object key) Removes the mapping of the specified key if the specified key has been set for self managed datavoidReset the list of executed phases.voidsetAttachmentMap(org.apache.axiom.attachments.Attachments attachments) Setting of the attachments map should be performed at the receipt of a message only.voidsetAxisMessage(AxisMessage axisMessage) voidsetAxisOperation(AxisOperation axisOperation) voidsetAxisService(AxisService axisService) voidsetAxisServiceGroup(AxisServiceGroup axisServiceGroup) voidvoidsetCurrentHandlerIndex(int currentHandlerIndex) static voidvoidsetCurrentPhaseIndex(int currentPhaseIndex) voidsetDoingMTOM(boolean b) voidsetDoingREST(boolean b) voidsetDoingSwA(boolean b) voidsetEnvelope(org.apache.axiom.soap.SOAPEnvelope envelope) voidvoidsetExecutionChain(ArrayList<Handler> executionChain) Set the execution chain of Handler in this MessageContext.voidsetFailureReason(Exception failureReason) Set the failure reason.voidsetFaultTo(EndpointReference reference) voidsetFLOW(int FLOW) voidsetFrom(EndpointReference reference) voidsetIncomingTransportName(String incomingTransportName) voidsetIsSOAP11Explicit(boolean t) voidsetMessageID(String messageId) voidsetNewThreadRequired(boolean b) voidsetOperationContext(OperationContext context) voidsetOptions(Options options) Set the options for myself.voidvoidsetOutputWritten(boolean b) voidsetPaused(boolean paused) voidsetProcessingFault(boolean b) voidsetRelationships(RelatesTo[] list) voidsetReplyTo(EndpointReference reference) Set ReplyTo destinationvoidsetResponseWritten(boolean b) voidsetSelfManagedData(Class clazz, Object key, Object value) Add a key-value pair of self managed data to the set associated with this message context.voidvoidsetServerSide(boolean b) voidsetServiceContext(ServiceContext context) voidsetServiceContextID(String serviceContextID) Sets the service context id.voidsetServiceGroupContext(ServiceGroupContext serviceGroupContext) voidsetServiceGroupContextId(String serviceGroupContextId) voidsetSessionContext(SessionContext sessionContext) voidsetSoapAction(String soapAction) voidvoidvoidvoidsetWSAAction(String actionURI) setWSAActionvoidsetWSAMessageId(String messageID) toString()voidSave the contents of this MessageContext instance.Methods inherited from class org.apache.axis2.context.AbstractContext
clearPropertyDifferences, flush, getLastTouchedTime, getParent, getPropertyDifferences, getPropertyNames, getPropertyNonReplicable, isAncestor, mergeProperties, removeProperty, removePropertyNonReplicable, setLastTouchedTime, setNonReplicableProperty, setParent, setProperties, setProperty, touch
-
Field Details
-
currentMessageContext
A place to store the current MessageContext -
options
-
IN_FLOW
public static final int IN_FLOW- See Also:
-
IN_FAULT_FLOW
public static final int IN_FAULT_FLOW- See Also:
-
OUT_FLOW
public static final int OUT_FLOW- See Also:
-
OUT_FAULT_FLOW
public static final int OUT_FAULT_FLOW- See Also:
-
REMOTE_ADDR
- See Also:
-
TRANSPORT_ADDR
- See Also:
-
TRANSPORT_HEADERS
- See Also:
-
IN_MESSAGE_CONTEXT
Constant used as the key for the property which stores the In MessageContext in the Out MessageContext/FaultMessageContext. This is needed in cases where an OperationContext is not created, for example, since the request never gets dispatched to the service operation, either due to a security failure or a request coming in for a non-existing endpoint- See Also:
-
attachments
public transient org.apache.axiom.attachments.Attachments attachmentsmessage attachments NOTE: Serialization of message attachments is handled as part of the overall message serialization. If this needs to change, then investigate having the Attachment class implement the java.io.Externalizable interface. -
TRANSPORT_OUT
Field TRANSPORT_OUT- See Also:
-
TRANSPORT_IN
Field TRANSPORT_IN- See Also:
-
CHARACTER_SET_ENCODING
Field CHARACTER_SET_ENCODING- See Also:
-
UTF_8
Field UTF_8. This is the 'utf-8' value for CHARACTER_SET_ENCODING property.- See Also:
-
UTF_16
Field UTF_16. This is the 'utf-16' value for CHARACTER_SET_ENCODING property.- See Also:
-
TRANSPORT_SUCCEED
Field TRANSPORT_SUCCEED- See Also:
-
DEFAULT_CHAR_SET_ENCODING
Field DEFAULT_CHAR_SET_ENCODING. This is the default value for CHARACTER_SET_ENCODING property.- See Also:
-
FLOW
public int FLOW -
CLIENT_API_NON_BLOCKING
To invoke fireAndforget method we have to hand over transport sending logic to a thread other wise user has to wait till it get transport response (in the case of HTTP its HTTP 202) 202). This was eariler named TRANSPORT_NON_BLOCKING, but that name is wrong as transport non blocking is NIO, which has nothing to do with this property. See https://issues.apache.org/jira/browse/AXIS2-4196. Renaming this to CLIENT_API_NON_BLOCKING instead.- See Also:
-
DISABLE_ASYNC_CALLBACK_ON_TRANSPORT_ERROR
This property allows someone (e.g. RM) to disable an async callback from being invoked if a fault occurs during message transmission. If this is not set, it can be assumed that the fault will be delivered via Callback.onError(...).- See Also:
-
outputWritten
public boolean outputWritten
-
-
Constructor Details
-
MessageContext
public MessageContext()Constructor
-
-
Method Details
-
getCurrentMessageContext
-
destroyCurrentMessageContext
public static void destroyCurrentMessageContext() -
setCurrentMessageContext
-
toString
-
getLogCorrelationID
Get a "raw" version of the logCorrelationID. The logCorrelationID is guaranteed to be unique and may be persisted along with the rest of the message context.- Returns:
- A string that can be output to a log file as an identifier for this MessageContext. It is suitable for matching related log entries.
-
getLogIDString
Get a formatted version of the logCorrelationID.- Returns:
- A string that can be output to a log file as an identifier for this MessageContext. It is suitable for matching related log entries.
-
pause
public void pause()Pause the execution of the current handler chain -
getAxisOperation
-
getAxisService
-
getAxisServiceGroup
-
getConfigurationContext
-
getCurrentHandlerIndex
public int getCurrentHandlerIndex() -
getCurrentPhaseIndex
public int getCurrentPhaseIndex() -
getEnvelope
public org.apache.axiom.soap.SOAPEnvelope getEnvelope()- Returns:
- Returns SOAPEnvelope.
-
getExecutionChain
-
addExecutedPhase
Add a Phase to the collection of executed phases for the path. Phases will be inserted in a LIFO data structure.- Parameters:
phase- The phase to add to the list.
-
removeFirstExecutedPhase
public void removeFirstExecutedPhase()Remove the first Phase in the collection of executed phases -
getExecutedPhases
Get an iterator over the executed phase list.- Returns:
- An Iterator over the LIFO data structure.
-
resetExecutedPhases
public void resetExecutedPhases()Reset the list of executed phases. This is needed because the OutInAxisOperation currently invokes receive() even when a fault occurs, and we will have already executed the flowComplete on those before receiveFault() is called. -
getFaultTo
- Returns:
- Returns EndpointReference.
-
getFrom
- Returns:
- Returns EndpointReference.
-
getMessageID
- Returns:
- Returns message id.
-
getModuleParameter
Retrieves both module specific configuration parameters as well as other parameters. The order of search is as follows:- Search in module configurations inside corresponding operation description if its there
- Search in corresponding operation if its there
- Search in module configurations inside corresponding service description if its there
- Next search in Corresponding Service description if its there
- Next search in module configurations inside axisConfiguration
- Search in AxisConfiguration for parameters
- Next get the corresponding module and search for the parameters
- Search in HandlerDescription for the parameter
N/A - Parameters:
key- : Parameter NamemoduleName- : Name of the modulehandler-HandlerDescription- Returns:
- Parameter
Parameter
-
getOperationContext
-
getParameter
Retrieves configuration descriptor parameters at any level. The order of search is as follows:- Search in message description if it exists
- If parameter is not found or if axisMessage is null, search in AxisOperation
- If parameter is not found or if operationContext is null, search in AxisService
- If parameter is not found or if axisService is null, search in AxisConfiguration
- Parameters:
key- name of desired parameter- Returns:
- Parameter
Parameter
-
getLocalProperty
Retrieves a property value. The order of search is as follows: search in my own map and then look at my options. Does not search up the hierarchy.- Overrides:
getLocalPropertyin classAbstractContext- Parameters:
name- name of the property to search for- Returns:
- the value of the property, or null if the property is not found
-
getLocalProperty
-
getProperty
Retrieves a property value. The order of search is as follows: search in my own map and then look in my context hierarchy, and then in options. Since its possible that the entire hierarchy is not present, I will start at whatever level has been set.- Overrides:
getPropertyin classAbstractContext- Parameters:
name- name of the property to search for- Returns:
- the value of the property, or null if the property is not found
-
isPropertyTrue
Check if a given property is true. Will return false if the property does not exist or is not an explicit "true" value.- Parameters:
name- name of the property to check- Returns:
- true if the property exists and is Boolean.TRUE, "true", 1, etc.
-
isPropertyTrue
Check if a given property is true. Will return the passed default if the property does not exist.- Parameters:
name- name of the property to checkdefaultVal- the default value if the property doesn't exist- Returns:
- true if the property exists and is Boolean.TRUE, "true", 1, etc.
-
getProperties
Retrieves all property values. The order of search is as follows: search in my own options and then look in my context hierarchy. Since its possible that the entire hierarchy is not present, it will start at whatever level has been set and start there. The returned map is unmodifiable, so any changes to the properties have to be done by callingAbstractContext.setProperty(String,Object). In addition, any changes to the properties are not reflected on this map.- Overrides:
getPropertiesin classAbstractContext- Returns:
- An unmodifiable map containing the combination of all available properties or an empty map.
-
getRelationships
- Returns:
- Returns RelatesTo array.
-
getRelatesTo
Get any RelatesTos of a particular type associated with this MessageContext TODO: Shouldn't this return a List?- Parameters:
type- the relationship type- Returns:
- Returns RelatesTo.
-
getRelatesTo
- Returns:
- Returns RelatesTo.
-
getReplyTo
- Returns:
- Returns EndpointReference.
-
getServiceContext
- Returns:
- Returns ServiceContext.
-
getServiceContextID
- Returns:
- Returns the serviceContextID.
-
getServiceGroupContext
-
getServiceGroupContextId
-
getSessionContext
- Returns:
- Returns SessionContext.
-
setSessionContext
-
getSoapAction
- Returns:
- Returns soap action.
-
getTo
- Returns:
- Returns EndpointReference.
-
getTransportIn
- Returns:
- Returns TransportInDescription.
-
getTransportOut
- Returns:
- Returns TransportOutDescription.
-
getWSAAction
-
isDoingMTOM
public boolean isDoingMTOM()- Returns:
- Returns boolean.
-
isDoingREST
public boolean isDoingREST()- Returns:
- Returns boolean.
-
isDoingSwA
public boolean isDoingSwA()- Returns:
- Returns boolean.
-
isNewThreadRequired
public boolean isNewThreadRequired()- Returns:
- Returns boolean.
-
isOutputWritten
public boolean isOutputWritten()- Returns:
- Returns boolean.
-
isPaused
public boolean isPaused()- Returns:
- Returns boolean.
-
setPaused
public void setPaused(boolean paused) -
isProcessingFault
public boolean isProcessingFault()- Returns:
- Returns boolean.
-
isResponseWritten
public boolean isResponseWritten()- Returns:
- Returns boolean.
-
isSOAP11
public boolean isSOAP11() -
isServerSide
public boolean isServerSide()- Returns:
- Returns boolean.
-
getAxisMessage
-
setAxisMessage
-
setAxisOperation
-
setAxisService
-
setAxisServiceGroup
-
setConfigurationContext
- Parameters:
context-
-
setCurrentHandlerIndex
public void setCurrentHandlerIndex(int currentHandlerIndex) -
setCurrentPhaseIndex
public void setCurrentPhaseIndex(int currentPhaseIndex) -
setDoingMTOM
public void setDoingMTOM(boolean b) - Parameters:
b-
-
setDoingREST
public void setDoingREST(boolean b) - Parameters:
b-
-
setDoingSwA
public void setDoingSwA(boolean b) - Parameters:
b-
-
setEnvelope
- Parameters:
envelope-- Throws:
AxisFault
-
setExecutionChain
Set the execution chain of Handler in this MessageContext. Doing this causes the current handler/phase indexes to reset to 0, since we have new Handlers to execute (this usually only happens at initialization and when a fault occurs).- Parameters:
executionChain-
-
setFaultTo
- Parameters:
reference-
-
setFrom
- Parameters:
reference-
-
setMessageID
- Parameters:
messageId-
-
setNewThreadRequired
public void setNewThreadRequired(boolean b) - Parameters:
b-
-
setOperationContext
- Parameters:
context- The OperationContext
-
setOutputWritten
public void setOutputWritten(boolean b) - Parameters:
b-
-
setProcessingFault
public void setProcessingFault(boolean b) - Parameters:
b-
-
addRelatesTo
Add a RelatesTo- Parameters:
reference- RelatesTo describing how we relate to another message
-
setReplyTo
Set ReplyTo destination- Parameters:
reference- the ReplyTo EPR
-
setResponseWritten
public void setResponseWritten(boolean b) - Parameters:
b-
-
setServerSide
public void setServerSide(boolean b) - Parameters:
b-
-
setServiceContext
- Parameters:
context-
-
setServiceContextID
Sets the service context id.- Parameters:
serviceContextID-
-
setServiceGroupContext
-
setServiceGroupContextId
-
setSoapAction
- Parameters:
soapAction-
-
setTo
- Parameters:
to-
-
setTransportIn
- Parameters:
in-
-
setTransportOut
- Parameters:
out-
-
setWSAAction
setWSAAction -
setWSAMessageId
-
getFLOW
public int getFLOW() -
setFLOW
public void setFLOW(int FLOW) -
getOptions
-
setOptions
Set the options for myself. I make the given options my own options' parent so that that becomes the default. That allows the user to override specific options on a given message context and not affect the overall options.- Parameters:
options- the options to set
-
getIncomingTransportName
-
setIncomingTransportName
-
setRelationships
-
getEffectivePolicy
public org.apache.neethi.Policy getEffectivePolicy() -
isEngaged
-
isHeaderPresent
public boolean isHeaderPresent()Deprecated.The bonus you used to get from this is now built in to SOAPEnvelope.getHeader()Gets the first child of the envelope, check if it is a soap:Body, which means there is no header. We do this basically to make sure we don't parse and build the om tree of the whole envelope looking for the soap header. If this method returns true, there still is no guarantee that there is a soap:Header present, use getHeader() and also check for null on getHeader() to be absolutely sure.- Returns:
- boolean
-
setAttachmentMap
public void setAttachmentMap(org.apache.axiom.attachments.Attachments attachments) Setting of the attachments map should be performed at the receipt of a message only. This method is only meant to be used by the Axis2 internals.- Parameters:
attachments-
-
getAttachmentMap
public org.apache.axiom.attachments.Attachments getAttachmentMap()You can directly access the attachment map of the message context from here. Returned attachment map can be empty.- Returns:
- attachment
-
getAttachmentMap
public org.apache.axiom.attachments.Attachments getAttachmentMap(boolean create) -
addAttachment
Adds an attachment to the attachment Map of this message context. This attachment gets serialised as a MIME attachment when sending the message if SOAP with Attachments is enabled.- Parameters:
contentID- : will be the content ID of the MIME part (without the "cid:" prefix)dataHandler-
-
addAttachment
Adds an attachment to the attachment Map of this message context. This attachment gets serialised as a MIME attachment when sending the message if SOAP with Attachments is enabled. Content ID of the MIME part will be auto generated by Axis2.- Parameters:
dataHandler-- Returns:
- the auto generated content ID of the MIME attachment
-
getAttachment
Access the DataHandler of the attachment contained in the map corresponding to the given content ID. Returns "NULL" if a attachment cannot be found by the given content ID.- Parameters:
contentID- : Content ID of the MIME attachment (without the "cid:" prefix)- Returns:
- Data handler of the attachment
-
removeAttachment
Removes the attachment with the given content ID from the Attachments Map Do nothing if a attachment cannot be found by the given content ID.- Parameters:
contentID- of the attachment (without the "cid:" prefix)
-
setSelfManagedData
Add a key-value pair of self managed data to the set associated with this message context. This is primarily intended to allow handlers to manage their own message-specific data when the message context is saved/restored.- Parameters:
clazz- The class of the caller that owns the key-value pairkey- The key for this data objectvalue- The data object
-
getSelfManagedData
Retrieve a value of self managed data previously saved with the specified key.- Parameters:
clazz- The class of the caller that owns the key-value pairkey- The key for the data- Returns:
- The data object associated with the key, or NULL if not found
-
containsSelfManagedDataKey
Check to see if the key for the self managed data is available- Parameters:
clazz- The class of the caller that owns the key-value pairkey- The key to look for- Returns:
- TRUE if the key exists, FALSE otherwise
-
removeSelfManagedData
Removes the mapping of the specified key if the specified key has been set for self managed data- Parameters:
clazz- The class of the caller that owns the key-value pairkey- The key of the object to be removed
-
writeExternal
Save the contents of this MessageContext instance. NOTE: Transient fields and static fields are not saved. Also, objects that represent "static" data are not saved, except for enough information to be able to find matching objects when the message context is re-constituted.- Specified by:
writeExternalin interfaceExternalizable- Parameters:
o- The stream to write the object contents to- Throws:
IOException
-
readExternal
Restore the contents of the MessageContext that was previously saved. NOTE: The field data must read back in the same order and type as it was written. Some data will need to be validated when resurrected.- Specified by:
readExternalin interfaceExternalizable- Parameters:
inObject- The stream to read the object contents from- Throws:
IOExceptionClassNotFoundException
-
activate
This method checks to see if additional work needs to be done in order to complete the object reconstitution. Some parts of the object restored from the readExternal() cannot be completed until we have a configurationContext from the active engine. The configurationContext is used to help this object to plug back into the engine's configuration and deployment objects.- Parameters:
cc- The configuration context object representing the active configuration
-
activateWithOperationContext
This method checks to see if additional work needs to be done in order to complete the object reconstitution. Some parts of the object restored from the readExternal() cannot be completed until we have an object that gives us a view of the active object graph from the active engine. NOTE: when activating an object, you only need to call one of the activate methods (activate() or activateWithOperationContext()) but not both.- Parameters:
operationCtx- The operation context object that is a member of the active object graph
-
extractCopyMessageContext
Return a Read-Only copy of this message context that has been extracted from the object hierachy. In other words, the message context copy does not have links to the object graph. NOTE: The copy shares certain objects with the original. The intent is to use the copy to read values but not modify them, especially since the copy is not part of the normal *Context and Axis* object graph.- Returns:
- A copy of the message context that is not in the object graph
-
setIsSOAP11Explicit
public void setIsSOAP11Explicit(boolean t) -
setExecutedPhasesExplicit
-
setSelfManagedDataMapExplicit
-
setOptionsExplicit
-
getRootContext
- Specified by:
getRootContextin classAbstractContext
-
isFault
public boolean isFault() -
getFailureReason
Obtain the Exception which caused the processing chain to halt.- Returns:
- null, or an Exception.
-
setFailureReason
Set the failure reason. Only AxisEngine should ever do this.- Parameters:
failureReason- an Exception which caused processing to halt.
-
findEndpoint
- Returns:
- Identifies and returns the service endpoint for this message context. The method will
use the following steps to identify the endpoint:
- If a non-null
AxisEndpointinstance is set under theENDPOINT_LOCAL_NAMEmessage context property, return it - If a non-null
axisServiceinstance is set and it specifiesclientSide=true, retrieve the endpoint which matches itsenpointName - else, return
null
- If a non-null
-