Package org.apache.synapse.endpoints
Class AbstractEndpoint
- java.lang.Object
-
- org.apache.synapse.FaultHandler
-
- org.apache.synapse.endpoints.AbstractEndpoint
-
- All Implemented Interfaces:
Endpoint
,ManagedLifecycle
,Nameable
,PropertyInclude
,SynapseArtifact
- Direct Known Subclasses:
AddressEndpoint
,ClassEndpoint
,DefaultEndpoint
,FailoverEndpoint
,HTTPEndpoint
,IndirectEndpoint
,LoadbalanceEndpoint
,RecipientListEndpoint
,ResolvingEndpoint
,TemplateEndpoint
,WSDLEndpoint
public abstract class AbstractEndpoint extends FaultHandler implements Endpoint, PropertyInclude
An abstract base class for all Endpoint implementations
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
anonymous
protected String
artifactContainerName
static String
CHILDREN_JSON_ATT
protected String
errorHandler
The Sequence name associated with the endpointprotected String
fileName
The name of the file where this endpoint is definedprotected boolean
initialized
Has this endpoint been initialized ?protected Boolean
isClusteringEnabled
Is clustering enabledprotected org.apache.commons.logging.Log
log
static String
NAME_JSON_ATT
Attributes for json representationprotected static org.apache.commons.logging.Log
trace
static String
TYPE_JSON_ATT
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractEndpoint()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
addProperties(Collection<MediatorProperty> mediatorProperties)
Add all the properties to the endpointvoid
addProperty(MediatorProperty property)
Add a property to the endpoint.protected abstract void
createJsonRepresentation()
void
destroy()
This method should implement the destroying of the implemented parts of the configuration.protected void
evaluateProperties(MessageContext synCtx)
Evaluates the endpoint properties based on the current message context and set the properties to the message context appropriatelyvoid
executeEpTypeSpecificFunctions(MessageContext synCtx)
String
getArtifactContainerName()
Get the car File name which this endpoint deployed fromList<Endpoint>
getChildren()
Get the children of this endpointList<String>
getCommentsList()
EndpointContext
getContext()
Get the EndpointContext that has the run-time state of this endpointEndpointDefinition
getDefinition()
String
getDescription()
Retrieves the description of the artifactprotected org.json.JSONArray
getEndpointChildrenAsJson(List<Endpoint> children)
String
getErrorHandler()
Get the MessageStore name associated with the EndpointString
getFileName()
Get the filename from which this endpoint is loaded,null
if it is an anonymous endpointboolean
getIsEdited()
Get the edit state of the endpointorg.json.JSONObject
getJsonRepresentation()
Get the json representation of the endpoint.EndpointView
getMetricsMBean()
Get a reference to the metrics MBean for this endpointString
getName()
Get the name of an abstractionEndpoint
getParentEndpoint()
Collection<MediatorProperty>
getProperties()
Return theCollection
of properties specifiedMediatorProperty
getProperty(String name)
Get a property with the given nameString
getReportingName()
protected void
handleException(String msg)
Helper methods to handle errors.protected void
handleException(String msg, Exception e)
Helper methods to handle errors.protected void
handleException(String msg, Exception e, MessageContext msgCtx)
Helper methods to handle errors.protected void
informFailure(MessageContext synCtx, int errorCode, String errorMsg)
void
init(SynapseEnvironment synapseEnvironment)
This method should implement the initialization of the implemented parts of the configuration.boolean
isAnonymous()
boolean
isInitialized()
Has this Endpoint initialized?boolean
isLeafEndpoint()
Is this a leaf level endpoint? or parent endpoint that has children?protected boolean
isRetry(MessageContext synCtx)
protected boolean
isSuspendFault(MessageContext synCtx)
Is this a fault that should put the endpoint on SUSPEND? or is this a fault to ignore?protected boolean
isTimeout(MessageContext synCtx)
Is this [fault] message a timeout?protected boolean
isTraceOn(MessageContext msgCtx)
Should this mediator perform tracing? True if its explicitly asked to trace, or its parent has been asked to trace and it does not reject itprotected boolean
isTraceOrDebugOn(boolean isTraceOn)
Is tracing or debug logging on?protected void
logOnChildEndpointFail(Endpoint endpoint, MessageContext synMessageContext)
void
logSetter()
void
onChildEndpointFail(Endpoint endpoint, MessageContext synMessageContext)
Endpoints that contain other endpoints should implement this method.void
onFault(MessageContext synCtx)
On a fault, propagate to parent if any, or call into the fault handlervoid
onSuccess()
The SynapseCallback Receiver notifies an endpoint, if a message was successfully processed to give it a chance to clear up or reset its state to activeprotected void
prepareForEndpointStatistics(MessageContext synCtx)
Process statistics for this messageboolean
readyToSend()
Returns true to indicate that the endpoint is ready to service requestsMediatorProperty
removeProperty(String name)
Remove a property with the given namevoid
send(MessageContext synCtx)
Sends the message context according to an endpoint specific behavior.protected void
setAdvancedProperties()
Set advanced properties of the endpoint to json object.void
setAnonymous(boolean anonymous)
void
setArtifactContainerName(String name)
Set the car File name which this endpoint deployed fromvoid
setChildren(List<Endpoint> children)
void
setCommentsList(List<String> commentsList)
void
setComponentStatisticsId(ArtifactHolder holder)
void
setContentAware(boolean contentAware)
void
setDefinition(EndpointDefinition definition)
void
setDescription(String description)
Set the description of the artifactvoid
setEnableMBeanStats(boolean flag)
set whether this endpoint needs to be registered for JMX MBeans.void
setErrorHandler(String errorHandler)
Set the Message Store name associated with the Endpointprotected void
setErrorOnMessage(MessageContext synCtx, Integer errorCode, String errorMsg)
void
setFileName(String fileName)
Set the filename from which the endpoint is loadedvoid
setForceBuildMC(boolean forceBuildMC)
void
setIsEdited(boolean isEdited)
Set the edit state of the endpointvoid
setName(String endpointName)
Set the name of an abstractionvoid
setParentEndpoint(Endpoint parentEndpoint)
Sets the parent endpoint for the current endpoint.String
toString()
protected void
traceOrDebug(boolean traceOn, String msg)
Perform Trace and Debug logging of a message @INFO (trace) and DEBUG (log)-
Methods inherited from class org.apache.synapse.FaultHandler
executeExtendedSynapseHandlerOnFault, getStackTrace, handleFault, handleFault
-
-
-
-
Field Detail
-
log
protected org.apache.commons.logging.Log log
-
trace
protected static final org.apache.commons.logging.Log trace
-
initialized
protected volatile boolean initialized
Has this endpoint been initialized ?
-
isClusteringEnabled
protected Boolean isClusteringEnabled
Is clustering enabled
-
fileName
protected String fileName
The name of the file where this endpoint is defined
-
anonymous
protected boolean anonymous
-
errorHandler
protected String errorHandler
The Sequence name associated with the endpoint
-
artifactContainerName
protected String artifactContainerName
-
NAME_JSON_ATT
public static final String NAME_JSON_ATT
Attributes for json representation- See Also:
- Constant Field Values
-
TYPE_JSON_ATT
public static final String TYPE_JSON_ATT
- See Also:
- Constant Field Values
-
CHILDREN_JSON_ATT
public static final String CHILDREN_JSON_ATT
- See Also:
- Constant Field Values
-
-
Method Detail
-
getMetricsMBean
public EndpointView getMetricsMBean()
Description copied from interface:Endpoint
Get a reference to the metrics MBean for this endpoint- Specified by:
getMetricsMBean
in interfaceEndpoint
- Returns:
- EndpointView instance
-
getContext
public EndpointContext getContext()
Description copied from interface:Endpoint
Get the EndpointContext that has the run-time state of this endpoint- Specified by:
getContext
in interfaceEndpoint
- Returns:
- the runtime context
-
getName
public String getName()
Description copied from interface:Nameable
Get the name of an abstraction
-
isInitialized
public boolean isInitialized()
Description copied from interface:Endpoint
Has this Endpoint initialized?- Specified by:
isInitialized
in interfaceEndpoint
- Returns:
- true if the endpoint is initialized
-
getDefinition
public EndpointDefinition getDefinition()
-
setDefinition
public void setDefinition(EndpointDefinition definition)
-
getParentEndpoint
public Endpoint getParentEndpoint()
-
setParentEndpoint
public void setParentEndpoint(Endpoint parentEndpoint)
Description copied from interface:Endpoint
Sets the parent endpoint for the current endpoint.- Specified by:
setParentEndpoint
in interfaceEndpoint
- Parameters:
parentEndpoint
- parent endpoint containing this endpoint. It should handle the onChildEndpointFail(...) callback.
-
getChildren
public List<Endpoint> getChildren()
Description copied from interface:Endpoint
Get the children of this endpoint- Specified by:
getChildren
in interfaceEndpoint
- Returns:
- the child endpoints
-
getFileName
public String getFileName()
Description copied from interface:Endpoint
Get the filename from which this endpoint is loaded,null
if it is an anonymous endpoint- Specified by:
getFileName
in interfaceEndpoint
- Returns:
- String file name
-
setFileName
public void setFileName(String fileName)
Description copied from interface:Endpoint
Set the filename from which the endpoint is loaded- Specified by:
setFileName
in interfaceEndpoint
- Parameters:
fileName
- from which the endpoint is loaded
-
isAnonymous
public boolean isAnonymous()
-
setAnonymous
public void setAnonymous(boolean anonymous)
-
setDescription
public void setDescription(String description)
Description copied from interface:SynapseArtifact
Set the description of the artifact- Specified by:
setDescription
in interfaceSynapseArtifact
- Parameters:
description
- tobe set to the artifact
-
getDescription
public String getDescription()
Description copied from interface:SynapseArtifact
Retrieves the description of the artifact- Specified by:
getDescription
in interfaceSynapseArtifact
- Returns:
- description of the artifact
-
setName
public void setName(String endpointName)
Description copied from interface:Nameable
Set the name of an abstraction
-
setArtifactContainerName
public void setArtifactContainerName(String name)
Set the car File name which this endpoint deployed from- Specified by:
setArtifactContainerName
in interfaceEndpoint
- Parameters:
name
-
-
getArtifactContainerName
public String getArtifactContainerName()
Get the car File name which this endpoint deployed from- Specified by:
getArtifactContainerName
in interfaceEndpoint
- Returns:
- artifactContainerName
-
getIsEdited
public boolean getIsEdited()
Get the edit state of the endpoint- Specified by:
getIsEdited
in interfaceEndpoint
- Returns:
-
setIsEdited
public void setIsEdited(boolean isEdited)
Set the edit state of the endpoint- Specified by:
setIsEdited
in interfaceEndpoint
- Parameters:
isEdited
-
-
setEnableMBeanStats
public void setEnableMBeanStats(boolean flag)
set whether this endpoint needs to be registered for JMX MBeans. some endpoints may not need to register under MBean and setting false will cut the additional overhead.- Parameters:
flag
- set true/false
-
init
public void init(SynapseEnvironment synapseEnvironment)
Description copied from interface:ManagedLifecycle
This method should implement the initialization of the implemented parts of the configuration.- Specified by:
init
in interfaceManagedLifecycle
- Parameters:
synapseEnvironment
- SynapseEnvironment to be used for initialization
-
readyToSend
public boolean readyToSend()
Description copied from interface:Endpoint
Returns true to indicate that the endpoint is ready to service requests- Specified by:
readyToSend
in interfaceEndpoint
- Returns:
- true if endpoint is ready to service requests
-
send
public void send(MessageContext synCtx)
Description copied from interface:Endpoint
Sends the message context according to an endpoint specific behavior.
-
isLeafEndpoint
public boolean isLeafEndpoint()
Is this a leaf level endpoint? or parent endpoint that has children?- Returns:
- true if there is no children - a leaf endpoint
-
onChildEndpointFail
public void onChildEndpointFail(Endpoint endpoint, MessageContext synMessageContext)
Description copied from interface:Endpoint
Endpoints that contain other endpoints should implement this method. It will be called if a child endpoint causes an exception. Action to be taken on such failure is up to the implementation. But it is good practice to first try addressing the issue. If it can't be addressed propagate the exception to parent endpoint by calling parent endpoint's onChildEndpointFail(...) method.- Specified by:
onChildEndpointFail
in interfaceEndpoint
- Parameters:
endpoint
- The child endpoint which caused the exception.synMessageContext
- MessageContext that was used in the failed attempt.
-
executeEpTypeSpecificFunctions
public void executeEpTypeSpecificFunctions(MessageContext synCtx)
-
isTimeout
protected boolean isTimeout(MessageContext synCtx)
Is this [fault] message a timeout?- Parameters:
synCtx
- the current fault message- Returns:
- true if this is defined as a timeout
-
isRetry
protected boolean isRetry(MessageContext synCtx)
-
isSuspendFault
protected boolean isSuspendFault(MessageContext synCtx)
Is this a fault that should put the endpoint on SUSPEND? or is this a fault to ignore?- Parameters:
synCtx
- the current fault message- Returns:
- true if this fault should suspend the endpoint
-
onFault
public void onFault(MessageContext synCtx)
On a fault, propagate to parent if any, or call into the fault handler- Specified by:
onFault
in classFaultHandler
- Parameters:
synCtx
- the message at hand
-
onSuccess
public void onSuccess()
The SynapseCallback Receiver notifies an endpoint, if a message was successfully processed to give it a chance to clear up or reset its state to active
-
isTraceOn
protected boolean isTraceOn(MessageContext msgCtx)
Should this mediator perform tracing? True if its explicitly asked to trace, or its parent has been asked to trace and it does not reject it- Parameters:
msgCtx
- the current message- Returns:
- true if tracing should be performed
-
isTraceOrDebugOn
protected boolean isTraceOrDebugOn(boolean isTraceOn)
Is tracing or debug logging on?- Parameters:
isTraceOn
- is tracing known to be on?- Returns:
- true, if either tracing or debug logging is on
-
traceOrDebug
protected void traceOrDebug(boolean traceOn, String msg)
Perform Trace and Debug logging of a message @INFO (trace) and DEBUG (log)- Parameters:
traceOn
- is runtime trace on for this message?msg
- the message to log/trace
-
prepareForEndpointStatistics
protected void prepareForEndpointStatistics(MessageContext synCtx)
Process statistics for this message- Parameters:
synCtx
- the current message
-
handleException
protected void handleException(String msg)
Helper methods to handle errors.- Parameters:
msg
- The error message
-
handleException
protected void handleException(String msg, Exception e)
Helper methods to handle errors.- Parameters:
msg
- The error messagee
- The exception
-
handleException
protected void handleException(String msg, Exception e, MessageContext msgCtx)
Helper methods to handle errors.- Parameters:
msg
- The error messagee
- The exceptionmsgCtx
- The message context
-
logOnChildEndpointFail
protected void logOnChildEndpointFail(Endpoint endpoint, MessageContext synMessageContext)
-
informFailure
protected void informFailure(MessageContext synCtx, int errorCode, String errorMsg)
-
setErrorOnMessage
protected void setErrorOnMessage(MessageContext synCtx, Integer errorCode, String errorMsg)
-
destroy
public void destroy()
Description copied from interface:ManagedLifecycle
This method should implement the destroying of the implemented parts of the configuration.- Specified by:
destroy
in interfaceManagedLifecycle
-
addProperty
public void addProperty(MediatorProperty property)
Add a property to the endpoint.- Specified by:
addProperty
in interfacePropertyInclude
- Parameters:
property
- property to be added
-
getProperty
public MediatorProperty getProperty(String name)
Get a property with the given name- Specified by:
getProperty
in interfacePropertyInclude
- Parameters:
name
- name of the property- Returns:
- a property with the given name
-
getProperties
public Collection<MediatorProperty> getProperties()
Return theCollection
of properties specified- Specified by:
getProperties
in interfacePropertyInclude
- Returns:
Collection
of properties
-
removeProperty
public MediatorProperty removeProperty(String name)
Remove a property with the given name- Specified by:
removeProperty
in interfacePropertyInclude
- Parameters:
name
- name of the property to be removed- Returns:
- the remove property or
null
if a property doesn't exists
-
addProperties
public void addProperties(Collection<MediatorProperty> mediatorProperties)
Add all the properties to the endpoint- Specified by:
addProperties
in interfacePropertyInclude
- Parameters:
mediatorProperties
-Collection
of properties to be added
-
getErrorHandler
public String getErrorHandler()
Description copied from interface:Endpoint
Get the MessageStore name associated with the Endpoint- Specified by:
getErrorHandler
in interfaceEndpoint
- Returns:
- String message store name
-
setErrorHandler
public void setErrorHandler(String errorHandler)
Description copied from interface:Endpoint
Set the Message Store name associated with the Endpoint- Specified by:
setErrorHandler
in interfaceEndpoint
- Parameters:
errorHandler
- , name of the message store
-
setContentAware
public void setContentAware(boolean contentAware)
-
setForceBuildMC
public void setForceBuildMC(boolean forceBuildMC)
-
evaluateProperties
protected void evaluateProperties(MessageContext synCtx)
Evaluates the endpoint properties based on the current message context and set the properties to the message context appropriately- Parameters:
synCtx
- the current message context
-
logSetter
public void logSetter()
-
getReportingName
public String getReportingName()
-
setComponentStatisticsId
public void setComponentStatisticsId(ArtifactHolder holder)
- Specified by:
setComponentStatisticsId
in interfaceEndpoint
-
setAdvancedProperties
protected void setAdvancedProperties()
Set advanced properties of the endpoint to json object.
-
getEndpointChildrenAsJson
protected org.json.JSONArray getEndpointChildrenAsJson(List<Endpoint> children)
-
getJsonRepresentation
public org.json.JSONObject getJsonRepresentation()
Description copied from interface:Endpoint
Get the json representation of the endpoint.- Specified by:
getJsonRepresentation
in interfaceEndpoint
- Returns:
- JSONObject
-
createJsonRepresentation
protected abstract void createJsonRepresentation()
-
-