element.addAttribute(fac.createOMAttribute(
"encoding", null, endpointDefinition.getCharSetEncoding()));
}
if (endpointDefinition.isAddressingOn()) {
OMElement addressing = fac.createOMElement(
"enableAddressing", SynapseConstants.SYNAPSE_OMNAMESPACE);
if (endpointDefinition.getAddressingVersion() != null) {
addressing.addAttribute(fac.createOMAttribute(
"version", null, endpointDefinition.getAddressingVersion()));
}
if (endpointDefinition.isUseSeparateListener()) {
addressing.addAttribute(fac.createOMAttribute("separateListener", null, "true"));
}
element.addChild(addressing);
}
if (endpointDefinition.isReliableMessagingOn()) {
OMElement rm = fac.createOMElement("enableRM", SynapseConstants.SYNAPSE_OMNAMESPACE);
if (endpointDefinition.getWsRMPolicyKey() != null) {
rm.addAttribute(fac.createOMAttribute(
"policy", null, endpointDefinition.getWsRMPolicyKey()));
}
element.addChild(rm);
}
if (endpointDefinition.isSecurityOn()) {
OMElement sec = fac.createOMElement("enableSec", SynapseConstants.SYNAPSE_OMNAMESPACE);
if (endpointDefinition.getWsSecPolicyKey() != null) {
sec.addAttribute(fac.createOMAttribute(
"policy", null, endpointDefinition.getWsSecPolicyKey()));
} else {
if (endpointDefinition.getInboundWsSecPolicyKey() != null) {
sec.addAttribute(fac.createOMAttribute(
"inboundPolicy", null, endpointDefinition.getInboundWsSecPolicyKey()));
}
if (endpointDefinition.getOutboundWsSecPolicyKey() != null) {
sec.addAttribute(fac.createOMAttribute("outboundPolicy",
null, endpointDefinition.getOutboundWsSecPolicyKey()));
}
}
element.addChild(sec);
}
if (endpointDefinition.getTimeoutAction() != SynapseConstants.NONE ||
endpointDefinition.getTimeoutDuration() > 0) {
OMElement timeout = fac.createOMElement(
"timeout", SynapseConstants.SYNAPSE_OMNAMESPACE);
element.addChild(timeout);
OMElement duration = fac.createOMElement(
"duration", SynapseConstants.SYNAPSE_OMNAMESPACE);
duration.setText(Long.toString(endpointDefinition.getTimeoutDuration()));
timeout.addChild(duration);
OMElement action = fac.createOMElement("responseAction", SynapseConstants.SYNAPSE_OMNAMESPACE);
if (endpointDefinition.getTimeoutAction() == SynapseConstants.DISCARD) {
action.setText("discard");
timeout.addChild(action);
} else if (endpointDefinition.getTimeoutAction()
== SynapseConstants.DISCARD_AND_FAULT) {
action.setText("fault");
timeout.addChild(action);
} else if (endpointDefinition.getTimeoutAction()
== SynapseConstants.NONE) {
// if the action is not given, it is set to fault
action.setText("fault");
timeout.addChild(action);
}
}
if (endpointDefinition.getInitialSuspendDuration() != -1 ||
!endpointDefinition.getSuspendErrorCodes().isEmpty()) {
OMElement suspendOnFailure = fac.createOMElement(
org.apache.synapse.config.xml.XMLConfigConstants.SUSPEND_ON_FAILURE,
SynapseConstants.SYNAPSE_OMNAMESPACE);
if (!endpointDefinition.getSuspendErrorCodes().isEmpty()) {
OMElement errorCodes = fac.createOMElement(
org.apache.synapse.config.xml.XMLConfigConstants.ERROR_CODES,
SynapseConstants.SYNAPSE_OMNAMESPACE);
errorCodes.setText(endpointDefinition.getSuspendErrorCodes().
toString().replaceAll("[\\[\\] ]", ""));
suspendOnFailure.addChild(errorCodes);
}
if (endpointDefinition.getInitialSuspendDuration() != -1) {
OMElement initialDuration = fac.createOMElement(
org.apache.synapse.config.xml.XMLConfigConstants.SUSPEND_INITIAL_DURATION,
SynapseConstants.SYNAPSE_OMNAMESPACE);
initialDuration.setText(Long.toString(endpointDefinition.getInitialSuspendDuration()));
suspendOnFailure.addChild(initialDuration);
}
if (endpointDefinition.getSuspendProgressionFactor() != -1) {
OMElement progressionFactor = fac.createOMElement(
org.apache.synapse.config.xml.XMLConfigConstants.SUSPEND_PROGRESSION_FACTOR,
SynapseConstants.SYNAPSE_OMNAMESPACE);
progressionFactor.setText(Float.toString(endpointDefinition.getSuspendProgressionFactor()));
suspendOnFailure.addChild(progressionFactor);
}
if (endpointDefinition.getSuspendMaximumDuration() != -1 &&
endpointDefinition.getSuspendMaximumDuration() != Long.MAX_VALUE) {
OMElement suspendMaximum = fac.createOMElement(
org.apache.synapse.config.xml.XMLConfigConstants.SUSPEND_MAXIMUM_DURATION,
SynapseConstants.SYNAPSE_OMNAMESPACE);
suspendMaximum.setText(Long.toString(endpointDefinition.getSuspendMaximumDuration()));
suspendOnFailure.addChild(suspendMaximum);
}
element.addChild(suspendOnFailure);
}
if (endpointDefinition.getRetryDurationOnTimeout() > 0 ||
!endpointDefinition.getTimeoutErrorCodes().isEmpty()) {
OMElement markAsTimedout = fac.createOMElement(
org.apache.synapse.config.xml.XMLConfigConstants.MARK_FOR_SUSPENSION,
SynapseConstants.SYNAPSE_OMNAMESPACE);
if (!endpointDefinition.getTimeoutErrorCodes().isEmpty()) {
OMElement errorCodes = fac.createOMElement(
org.apache.synapse.config.xml.XMLConfigConstants.ERROR_CODES,
SynapseConstants.SYNAPSE_OMNAMESPACE);
errorCodes.setText(endpointDefinition.getTimeoutErrorCodes().
toString().replaceAll("[\\[\\] ]", ""));
markAsTimedout.addChild(errorCodes);
}
if (endpointDefinition.getRetriesOnTimeoutBeforeSuspend() > 0) {
OMElement retries = fac.createOMElement(
org.apache.synapse.config.xml.XMLConfigConstants.RETRIES_BEFORE_SUSPENSION,
SynapseConstants.SYNAPSE_OMNAMESPACE);
retries.setText(Long.toString(endpointDefinition.getRetriesOnTimeoutBeforeSuspend()));
markAsTimedout.addChild(retries);
}
if (endpointDefinition.getRetryDurationOnTimeout() > 0) {
OMElement retryDelay = fac.createOMElement(
org.apache.synapse.config.xml.XMLConfigConstants.RETRY_DELAY,
SynapseConstants.SYNAPSE_OMNAMESPACE);
retryDelay.setText(Long.toString(endpointDefinition.getRetryDurationOnTimeout()));
markAsTimedout.addChild(retryDelay);
}
element.addChild(markAsTimedout);
}
if (!endpointDefinition.getRetryDisabledErrorCodes().isEmpty()) {
OMElement retryConfig = fac.createOMElement(XMLConfigConstants.RETRY_CONFIG,
SynapseConstants.SYNAPSE_OMNAMESPACE);
OMElement errorCodes = fac.createOMElement("disabledErrorCodes",
SynapseConstants.SYNAPSE_OMNAMESPACE);
errorCodes.setText(endpointDefinition.getRetryDisabledErrorCodes().
toString().replaceAll("[\\[\\] ]", ""));
retryConfig.addChild(errorCodes);
element.addChild(retryConfig);
}
}