diff --git a/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointDefinitionFactory.java b/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointDefinitionFactory.java index eee1c45fa7..b3685893c8 100644 --- a/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointDefinitionFactory.java +++ b/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointDefinitionFactory.java @@ -29,6 +29,7 @@ import org.apache.synapse.config.xml.ValueFactory; import org.apache.synapse.config.xml.XMLConfigConstants; import org.apache.synapse.endpoints.EndpointDefinition; +import org.apache.synapse.mediators.Value; import org.apache.synapse.util.xpath.SynapseXPath; import org.jaxen.JaxenException; @@ -161,12 +162,11 @@ public EndpointDefinition createDefinition(OMElement elem) { String d = duration.getText(); if (d != null) { try { - if (isExpression(d)) { - definition.setDynamicTimeoutExpression(valueFactory.createTextValue(duration)); - } else { - long timeoutMilliSeconds = Long.parseLong(d.trim()); - definition.setTimeoutDuration(timeoutMilliSeconds); + Value timeoutDurationValue = valueFactory.createTextValue(duration); + if (timeoutDurationValue.getKeyValue() != null) { + Long.parseLong(timeoutDurationValue.getKeyValue()); } + definition.setTimeoutDuration(valueFactory.createTextValue(duration)); } catch (NumberFormatException e) { handleException("Endpoint timeout duration expected as a " + "number but was not a number"); @@ -177,19 +177,12 @@ public EndpointDefinition createDefinition(OMElement elem) { OMElement action = timeout.getFirstChildWithName( new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "responseAction")); if (action != null && action.getText() != null) { - String actionString = action.getText().trim(); - if (isExpression(actionString)) { - definition.setDynamicTimeoutAction(valueFactory.createTextValue(action)); - } else { - if ("discard".equalsIgnoreCase(actionString)) { - definition.setTimeoutAction(SynapseConstants.DISCARD); - } else if ("fault".equalsIgnoreCase(actionString)) { - definition.setTimeoutAction(SynapseConstants.DISCARD_AND_FAULT); - } else { - handleException("Invalid timeout action, action : " - + actionString + " is not supported"); - } + Value timeoutActionValue = valueFactory.createTextValue(action); + + if (timeoutActionValue.getKeyValue() != null && !timeoutActionValue.getKeyValue().equals("discard") && !timeoutActionValue.getKeyValue().equals("fault")) { + handleException("Invalid timeout action, action : " + timeoutActionValue.getKeyValue() + " is not supported"); } + definition.setTimeoutAction(timeoutActionValue); } } @@ -203,21 +196,20 @@ public EndpointDefinition createDefinition(OMElement elem) { SynapseConstants.SYNAPSE_NAMESPACE, XMLConfigConstants.ERROR_CODES)); if (timeoutCodes != null && timeoutCodes.getText() != null) { - String trimmedTimeoutCodes = timeoutCodes.getText().trim(); - if (isExpression(trimmedTimeoutCodes)) { - definition.setDynamicTimeoutErrorCodes(valueFactory.createTextValue(timeoutCodes)); - } else { + Value timeoutErrorCodesValue = valueFactory.createTextValue(timeoutCodes); + if (timeoutErrorCodesValue.getKeyValue() != null) { StringTokenizer st = new StringTokenizer(timeoutCodes.getText().trim(), ", "); while (st.hasMoreTokens()) { String s = st.nextToken(); try { - definition.addTimeoutErrorCode(Integer.parseInt(s)); + Integer.parseInt(s); } catch (NumberFormatException e) { handleException("The timeout error codes should be specified " + "as valid numbers separated by commas : " + timeoutCodes.getText(), e); } } } + definition.setTimeoutErrorCodes(timeoutErrorCodesValue); } OMElement retriesBeforeSuspend = markAsTimedOut.getFirstChildWithName(new QName( @@ -225,13 +217,11 @@ public EndpointDefinition createDefinition(OMElement elem) { XMLConfigConstants.RETRIES_BEFORE_SUSPENSION)); if (retriesBeforeSuspend != null && retriesBeforeSuspend.getText() != null) { try { - String trimmedRetriesBeforeSuspend = retriesBeforeSuspend.getText().trim(); - if (isExpression(trimmedRetriesBeforeSuspend)) { - definition.setDynamicRetriesOnTimeoutBeforeSuspend(valueFactory.createTextValue(retriesBeforeSuspend)); - } else { - definition.setRetriesOnTimeoutBeforeSuspend( - Integer.parseInt(trimmedRetriesBeforeSuspend)); + Value retriesBeforeSuspendValue = valueFactory.createTextValue(retriesBeforeSuspend); + if (retriesBeforeSuspendValue.getKeyValue() != null) { + Integer.parseInt(retriesBeforeSuspendValue.getKeyValue()); } + definition.setRetriesOnTimeoutBeforeSuspend(retriesBeforeSuspendValue); } catch (NumberFormatException e) { handleException("The retries before suspend [for timeouts] should be " + "specified as a valid number : " + retriesBeforeSuspend.getText(), e); @@ -243,13 +233,11 @@ public EndpointDefinition createDefinition(OMElement elem) { XMLConfigConstants.RETRY_DELAY)); if (retryDelay != null && retryDelay.getText() != null) { try { - String trimmedRetryDelay = retryDelay.getText().trim(); - if (isExpression(trimmedRetryDelay)) { - definition.setDynamicRetryDurationOnTimeout(valueFactory.createTextValue(retryDelay)); - } else { - definition.setRetryDurationOnTimeout( - Integer.parseInt(trimmedRetryDelay)); + Value retryDelayValue = valueFactory.createTextValue(retryDelay); + if (retryDelayValue.getKeyValue() != null) { + Integer.parseInt(retryDelayValue.getKeyValue()); } + definition.setRetryDurationOnTimeout(valueFactory.createTextValue(retryDelay)); } catch (NumberFormatException e) { handleException("The retry delay for timeouts should be specified " + "as a valid number : " + retryDelay.getText(), e); @@ -264,9 +252,9 @@ public EndpointDefinition createDefinition(OMElement elem) { log.warn("Configuration uses deprecated style for endpoint 'suspendDurationOnFailure'"); try { - definition.setInitialSuspendDuration( - 1000 * Long.parseLong(suspendDurationOnFailure.getText().trim())); - definition.setSuspendProgressionFactor((float) 1.0); + long suspendDurationValue = 1000 * Long.parseLong(suspendDurationOnFailure.getText().trim()); + definition.setInitialSuspendDuration(new Value(String.valueOf(suspendDurationValue))); + definition.setSuspendProgressionFactor(new Value(String.valueOf((float) 1.0))); } catch (NumberFormatException e) { handleException("The initial suspend duration should be specified " + "as a valid number : " + suspendDurationOnFailure.getText(), e); @@ -283,21 +271,20 @@ public EndpointDefinition createDefinition(OMElement elem) { SynapseConstants.SYNAPSE_NAMESPACE, XMLConfigConstants.ERROR_CODES)); if (suspendCodes != null && suspendCodes.getText() != null) { - String trimmedSuspendCodes = suspendCodes.getText().trim(); - if (isExpression(trimmedSuspendCodes)) { - definition.setDynamicSuspendErrorCodes(valueFactory.createTextValue(suspendCodes)); - } else { - StringTokenizer st = new StringTokenizer(trimmedSuspendCodes, ", "); + Value suspendErrorCodesValue = valueFactory.createTextValue(suspendCodes); + if (suspendErrorCodesValue.getKeyValue() != null) { + StringTokenizer st = new StringTokenizer(suspendCodes.getText().trim(), ", "); while (st.hasMoreTokens()) { String s = st.nextToken(); try { - definition.addSuspendErrorCode(Integer.parseInt(s)); + Integer.parseInt(s); } catch (NumberFormatException e) { handleException("The suspend error codes should be specified " + "as valid numbers separated by commas : " + suspendCodes.getText(), e); } } } + definition.setSuspendErrorCodes(valueFactory.createTextValue(suspendCodes)); } OMElement initialDuration = suspendOnFailure.getFirstChildWithName(new QName( @@ -305,13 +292,11 @@ public EndpointDefinition createDefinition(OMElement elem) { XMLConfigConstants.SUSPEND_INITIAL_DURATION)); if (initialDuration != null && initialDuration.getText() != null) { try { - String initialDurationTrimmed = initialDuration.getText().trim(); - if (isExpression(initialDurationTrimmed)) { - definition.setDynamicInitialSuspendDuration(valueFactory.createTextValue(initialDuration)); - } else { - definition.setInitialSuspendDuration( - Integer.parseInt(initialDurationTrimmed)); + Value initialSuspendDurationValue = valueFactory.createTextValue(initialDuration); + if (initialSuspendDurationValue.getKeyValue() != null) { + Integer.parseInt(initialSuspendDurationValue.getKeyValue()); } + definition.setInitialSuspendDuration(initialSuspendDurationValue); } catch (NumberFormatException e) { handleException("The initial suspend duration should be specified " + "as a valid number : " + initialDuration.getText(), e); @@ -323,13 +308,11 @@ public EndpointDefinition createDefinition(OMElement elem) { XMLConfigConstants.SUSPEND_PROGRESSION_FACTOR)); if (progressionFactor != null && progressionFactor.getText() != null) { try { - String trimmedProgressionFactor = progressionFactor.getText().trim(); - if (isExpression(trimmedProgressionFactor)) { - definition.setDynamicSuspendProgressionFactor(valueFactory.createTextValue(progressionFactor)); - } else { - definition.setSuspendProgressionFactor( - Float.parseFloat(trimmedProgressionFactor)); + Value progressionFactorValue = valueFactory.createTextValue(progressionFactor); + if (progressionFactorValue.getKeyValue() != null) { + Float.parseFloat(progressionFactorValue.getKeyValue()); } + definition.setSuspendProgressionFactor(progressionFactorValue); } catch (NumberFormatException e) { handleException("The suspend duration progression factor should be specified " + "as a valid float : " + progressionFactor.getText(), e); @@ -341,13 +324,11 @@ public EndpointDefinition createDefinition(OMElement elem) { XMLConfigConstants.SUSPEND_MAXIMUM_DURATION)); if (maximumDuration != null && maximumDuration.getText() != null) { try { - String trimmedMaximumDuration = maximumDuration.getText().trim(); - if (isExpression(trimmedMaximumDuration)) { - definition.setDynamicSuspendMaximumDuration(valueFactory.createTextValue(maximumDuration)); - } else { - definition.setSuspendMaximumDuration( - Long.parseLong(maximumDuration.getText().trim())); + Value suspendMaximumDurationValue = valueFactory.createTextValue(maximumDuration); + if (suspendMaximumDurationValue.getKeyValue() != null) { + Long.parseLong(suspendMaximumDurationValue.getKeyValue()); } + definition.setSuspendMaximumDuration(suspendMaximumDurationValue); } catch (NumberFormatException e) { handleException("The maximum suspend duration should be specified " + "as a valid number : " + maximumDuration.getText(), e); @@ -403,14 +384,6 @@ public EndpointDefinition createDefinition(OMElement elem) { return definition; } - private boolean isExpression(String expressionStr) { - Pattern pattern = Pattern.compile("\\{.*\\}"); - if (pattern.matcher(expressionStr).matches()) { - return true; - } - return false; - } - protected static void handleException(String msg) { log.error(msg); throw new SynapseException(msg); diff --git a/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointDefinitionSerializer.java b/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointDefinitionSerializer.java index 1b41e6e280..b3a7390e59 100644 --- a/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointDefinitionSerializer.java +++ b/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointDefinitionSerializer.java @@ -102,33 +102,32 @@ public void serializeEndpointDefinition(EndpointDefinition endpointDefinition, element.addChild(sec); } - if (endpointDefinition.getTimeoutAction() != SynapseConstants.NONE || endpointDefinition.getDynamicTimeoutAction() != null || - endpointDefinition.getTimeoutDuration() > 0 || endpointDefinition.isDynamicTimeoutEndpoint()) { + if (!endpointDefinition.getTimeoutAction().equals("none") || endpointDefinition.isTimeoutActionDynamic() || + isStringPositiveNumber(endpointDefinition.getTimeoutDuration()) || endpointDefinition.isDynamicTimeoutEndpoint()) { OMElement timeout = fac.createOMElement( "timeout", SynapseConstants.SYNAPSE_OMNAMESPACE); element.addChild(timeout); - if (endpointDefinition.getTimeoutDuration() > 0 || endpointDefinition.isDynamicTimeoutEndpoint()) { + if (isStringPositiveNumber(endpointDefinition.getTimeoutDuration()) || endpointDefinition.isDynamicTimeoutEndpoint()) { OMElement duration = fac.createOMElement( "duration", SynapseConstants.SYNAPSE_OMNAMESPACE); if (!endpointDefinition.isDynamicTimeoutEndpoint()) { - duration.setText(Long.toString(endpointDefinition.getTimeoutDuration())); + duration.setText(endpointDefinition.getTimeoutDuration()); } else { - duration.setText('{' + endpointDefinition.getDynamicTimeoutExpression().getExpression() + '}'); + duration.setText('{' + endpointDefinition.getTimeoutDuration() + '}'); } timeout.addChild(duration); } - if (endpointDefinition.getTimeoutAction() != SynapseConstants.NONE || endpointDefinition.getDynamicTimeoutAction() != null) { + if (!endpointDefinition.getTimeoutAction().equals("none") || endpointDefinition.isTimeoutActionDynamic()) { OMElement action = fac.createOMElement("responseAction", SynapseConstants.SYNAPSE_OMNAMESPACE); if (endpointDefinition.isTimeoutActionDynamic()) { - action.setText('{' + endpointDefinition.getDynamicTimeoutAction().getExpression() + '}'); + action.setText('{' + endpointDefinition.getTimeoutAction() + '}'); } else { - if (endpointDefinition.getTimeoutAction() == SynapseConstants.DISCARD) { + if (endpointDefinition.getTimeoutAction().equals("discard")) { action.setText("discard"); - } else if (endpointDefinition.getTimeoutAction() - == SynapseConstants.DISCARD_AND_FAULT) { + } else if (endpointDefinition.getTimeoutAction().equals("fault")) { action.setText("fault"); } } @@ -136,7 +135,7 @@ public void serializeEndpointDefinition(EndpointDefinition endpointDefinition, } } - if (endpointDefinition.getInitialSuspendDuration() != -1 || endpointDefinition.isInitialSuspendDurationDynamic() || + if (!endpointDefinition.getInitialSuspendDuration().equals(String.valueOf(-1)) || endpointDefinition.isInitialSuspendDurationDynamic() || !endpointDefinition.getSuspendErrorCodes().isEmpty() || endpointDefinition.isSuspendErrorCodesDynamic()) { OMElement suspendOnFailure = fac.createOMElement( @@ -148,7 +147,7 @@ public void serializeEndpointDefinition(EndpointDefinition endpointDefinition, org.apache.synapse.config.xml.XMLConfigConstants.ERROR_CODES, SynapseConstants.SYNAPSE_OMNAMESPACE); if (endpointDefinition.isSuspendErrorCodesDynamic()) { - errorCodes.setText('{' + endpointDefinition.getDynamicSuspendErrorCodes().getExpression() + '}'); + errorCodes.setText('{' + endpointDefinition.getSuspendErrorCodes() + '}'); } else { errorCodes.setText(endpointDefinition.getSuspendErrorCodes(). toString().replaceAll("[\\[\\] ]", "")); @@ -156,39 +155,39 @@ public void serializeEndpointDefinition(EndpointDefinition endpointDefinition, suspendOnFailure.addChild(errorCodes); } - if (endpointDefinition.getInitialSuspendDuration() != -1 || endpointDefinition.isInitialSuspendDurationDynamic()) { + if (!endpointDefinition.getInitialSuspendDuration().equals(String.valueOf(-1)) || endpointDefinition.isInitialSuspendDurationDynamic()) { OMElement initialDuration = fac.createOMElement( org.apache.synapse.config.xml.XMLConfigConstants.SUSPEND_INITIAL_DURATION, SynapseConstants.SYNAPSE_OMNAMESPACE); if (!endpointDefinition.isInitialSuspendDurationDynamic()){ - initialDuration.setText(Long.toString(endpointDefinition.getInitialSuspendDuration())); + initialDuration.setText(endpointDefinition.getInitialSuspendDuration()); } else { - initialDuration.setText('{' + endpointDefinition.getDynamicInitialSuspendDuration().getExpression() + '}'); + initialDuration.setText('{' + endpointDefinition.getInitialSuspendDuration() + '}'); } suspendOnFailure.addChild(initialDuration); } - if (endpointDefinition.getSuspendProgressionFactor() != -1 || endpointDefinition.isSuspendProgressionFactorDynamic()) { + if (!endpointDefinition.getSuspendProgressionFactor().equals(String.valueOf(-1)) || endpointDefinition.isSuspendProgressionFactorDynamic()) { OMElement progressionFactor = fac.createOMElement( org.apache.synapse.config.xml.XMLConfigConstants.SUSPEND_PROGRESSION_FACTOR, SynapseConstants.SYNAPSE_OMNAMESPACE); if (endpointDefinition.isSuspendProgressionFactorDynamic()) { - progressionFactor.setText('{' + endpointDefinition.getDynamicSuspendProgressionFactor().getExpression() + '}'); + progressionFactor.setText('{' + endpointDefinition.getSuspendProgressionFactor() + '}'); } else { - progressionFactor.setText(Float.toString(endpointDefinition.getSuspendProgressionFactor())); + progressionFactor.setText(endpointDefinition.getSuspendProgressionFactor()); } suspendOnFailure.addChild(progressionFactor); } - if ((endpointDefinition.getSuspendMaximumDuration() != -1 && - endpointDefinition.getSuspendMaximumDuration() != Long.MAX_VALUE) || endpointDefinition.isSuspendMaximumDurationDynamic()) { + if ((!endpointDefinition.getSuspendMaximumDuration().equals(String.valueOf(-1)) && + !endpointDefinition.getSuspendMaximumDuration().equals(String.valueOf(Long.MAX_VALUE))) || endpointDefinition.isSuspendMaximumDurationDynamic()) { OMElement suspendMaximum = fac.createOMElement( org.apache.synapse.config.xml.XMLConfigConstants.SUSPEND_MAXIMUM_DURATION, SynapseConstants.SYNAPSE_OMNAMESPACE); if (endpointDefinition.isSuspendMaximumDurationDynamic()) { - suspendMaximum.setText('{' + endpointDefinition.getDynamicSuspendMaximumDuration().getExpression() + '}'); + suspendMaximum.setText('{' + endpointDefinition.getSuspendMaximumDuration() + '}'); } else { - suspendMaximum.setText(Long.toString(endpointDefinition.getSuspendMaximumDuration())); + suspendMaximum.setText(endpointDefinition.getSuspendMaximumDuration()); } suspendOnFailure.addChild(suspendMaximum); } @@ -196,7 +195,7 @@ public void serializeEndpointDefinition(EndpointDefinition endpointDefinition, element.addChild(suspendOnFailure); } - if (endpointDefinition.getRetryDurationOnTimeout() > 0 || endpointDefinition.isRetryDurationOnTimeoutDynamic() || + if (isStringPositiveNumber(endpointDefinition.getRetryDurationOnTimeout()) || endpointDefinition.isRetryDurationOnTimeoutDynamic() || !endpointDefinition.getTimeoutErrorCodes().isEmpty() || endpointDefinition.isTimeoutErrorCodesDynamic()) { OMElement markAsTimedout = fac.createOMElement( @@ -208,7 +207,7 @@ public void serializeEndpointDefinition(EndpointDefinition endpointDefinition, org.apache.synapse.config.xml.XMLConfigConstants.ERROR_CODES, SynapseConstants.SYNAPSE_OMNAMESPACE); if (endpointDefinition.isTimeoutErrorCodesDynamic()) { - errorCodes.setText('{' + endpointDefinition.getDynamicTimeoutErrorCodes().getExpression() + '}'); + errorCodes.setText('{' + endpointDefinition.getTimeoutErrorCodes() + '}'); } else { errorCodes.setText(endpointDefinition.getTimeoutErrorCodes(). toString().replaceAll("[\\[\\] ]", "")); @@ -216,26 +215,26 @@ public void serializeEndpointDefinition(EndpointDefinition endpointDefinition, markAsTimedout.addChild(errorCodes); } - if (endpointDefinition.getRetriesOnTimeoutBeforeSuspend() > 0 || endpointDefinition.isRetriesOnTimeoutBeforeSuspendDynamic()) { + if (isStringPositiveNumber(endpointDefinition.getRetriesOnTimeoutBeforeSuspend()) || endpointDefinition.isRetriesOnTimeoutBeforeSuspendDynamic()) { OMElement retries = fac.createOMElement( org.apache.synapse.config.xml.XMLConfigConstants.RETRIES_BEFORE_SUSPENSION, SynapseConstants.SYNAPSE_OMNAMESPACE); if (endpointDefinition.isRetriesOnTimeoutBeforeSuspendDynamic()) { - retries.setText('{' + endpointDefinition.getDynamicRetriesOnTimeoutBeforeSuspend().getExpression() + '}'); + retries.setText('{' + endpointDefinition.getRetriesOnTimeoutBeforeSuspend() + '}'); } else { - retries.setText(Long.toString(endpointDefinition.getRetriesOnTimeoutBeforeSuspend())); + retries.setText(endpointDefinition.getRetriesOnTimeoutBeforeSuspend()); } markAsTimedout.addChild(retries); } - if (endpointDefinition.getRetryDurationOnTimeout() > 0 || endpointDefinition.isRetryDurationOnTimeoutDynamic()) { + if (isStringPositiveNumber(endpointDefinition.getRetryDurationOnTimeout()) || endpointDefinition.isRetryDurationOnTimeoutDynamic()) { OMElement retryDelay = fac.createOMElement( org.apache.synapse.config.xml.XMLConfigConstants.RETRY_DELAY, SynapseConstants.SYNAPSE_OMNAMESPACE); if (endpointDefinition.isRetryDurationOnTimeoutDynamic()) { - retryDelay.setText('{' + endpointDefinition.getDynamicRetryDurationOnTimeout().getExpression() + '}'); + retryDelay.setText('{' + endpointDefinition.getRetryDurationOnTimeout() + '}'); } else { - retryDelay.setText(Long.toString(endpointDefinition.getRetryDurationOnTimeout())); + retryDelay.setText(endpointDefinition.getRetryDurationOnTimeout()); } markAsTimedout.addChild(retryDelay); } @@ -263,4 +262,16 @@ public void serializeEndpointDefinition(EndpointDefinition endpointDefinition, element.addChild(retryConfig); } } + + private boolean isStringPositiveNumber(String input) { + if (input == null || input.isEmpty()) { + return false; + } + try { + float number = Float.parseFloat(input); + return number > 0; + } catch (NumberFormatException e) { + return false; + } + } } diff --git a/modules/core/src/main/java/org/apache/synapse/endpoints/DynamicLoadbalanceEndpoint.java b/modules/core/src/main/java/org/apache/synapse/endpoints/DynamicLoadbalanceEndpoint.java index df16a85f48..13ecce36aa 100755 --- a/modules/core/src/main/java/org/apache/synapse/endpoints/DynamicLoadbalanceEndpoint.java +++ b/modules/core/src/main/java/org/apache/synapse/endpoints/DynamicLoadbalanceEndpoint.java @@ -40,6 +40,7 @@ import org.apache.synapse.endpoints.dispatch.HttpSessionDispatcher; import org.apache.synapse.endpoints.dispatch.SALSessions; import org.apache.synapse.endpoints.dispatch.SessionInformation; +import org.apache.synapse.mediators.Value; import org.apache.synapse.transport.nhttp.NhttpConstants; import java.net.MalformedURLException; @@ -456,7 +457,7 @@ private Endpoint getEndpoint(EndpointReference to, Member member, MessageContext endpoint.setName("DLB:" + member.getHostName() + ":" + member.getPort() + ":" + UUID.randomUUID()); EndpointDefinition definition = new EndpointDefinition(); - definition.setSuspendMaximumDuration(10000); + definition.setSuspendMaximumDuration(new Value("10000")); definition.setReplicationDisabled(true); definition.setAddress(to.getAddress()); endpoint.setDefinition(definition); diff --git a/modules/core/src/main/java/org/apache/synapse/endpoints/EndpointDefinition.java b/modules/core/src/main/java/org/apache/synapse/endpoints/EndpointDefinition.java index ab72d5c995..4dbbea3b29 100755 --- a/modules/core/src/main/java/org/apache/synapse/endpoints/EndpointDefinition.java +++ b/modules/core/src/main/java/org/apache/synapse/endpoints/EndpointDefinition.java @@ -132,11 +132,6 @@ public class EndpointDefinition implements AspectConfigurable { */ private String charSetEncoding; - /** - * The expression to evaluate dynamic timeout. - */ - private Value dynamicTimeout = null; - /** * Whether endpoint state replication should be disabled or not (only valid in clustered setups) */ @@ -148,7 +143,8 @@ public class EndpointDefinition implements AspectConfigurable { * not set any timeout configuration, default timeout action is set to NONE, which won't do * anything for timeouts. */ - private long timeoutDuration = 0; + private final long defaultTimeoutDuration = 0; + private Value timeoutDuration = new Value(String.valueOf(defaultTimeoutDuration)); /** * Effective timeout interval for the endpoint @@ -158,41 +154,36 @@ public class EndpointDefinition implements AspectConfigurable { /** * action to perform when a timeout occurs (NONE | DISCARD | DISCARD_AND_FAULT) * */ - private int timeoutAction = SynapseConstants.NONE; - /** The expression to evaluate dynamic timeout action */ - private Value dynamicTimeoutAction = null; + private final int defaultTimeoutAction = SynapseConstants.NONE; + private Value timeoutAction = new Value("none"); /** The initial suspend duration when an endpoint is marked inactive */ - private long initialSuspendDuration = -1; + private final long defaultInitialSuspendDuration = -1; + private Value initialSuspendDuration = new Value(String.valueOf(defaultInitialSuspendDuration)); + /** - * The expression to evaluate dynamic initial suspend duration. + * The suspend duration ratio for the next duration - this is the geometric series multipler */ - private Value dynamicInitialSuspendDuration = null; - /** The suspend duration ratio for the next duration - this is the geometric series multipler */ - private float suspendProgressionFactor = 1; - /** The expression to evaluate dynamic suspend progression factor */ - private Value dynamicSuspendProgressionFactor = null; + private final float defaultSuspendProgressionFactor = 1; + private Value suspendProgressionFactor = new Value(String.valueOf(defaultSuspendProgressionFactor)); + /** This is the maximum duration for which a node will be suspended */ - private long suspendMaximumDuration = Long.MAX_VALUE; - /** The expression to maximum duration for which a node will be suspended */ - private Value dynamicSuspendMaximumDuration = null; + private final long defaultSuspendMaximumDuration = Long.MAX_VALUE; + private Value suspendMaximumDuration = new Value(String.valueOf(defaultSuspendMaximumDuration)); + /** A list of error codes, which directly puts an endpoint into suspend mode */ - private final List suspendErrorCodes = new ArrayList(); - /** The expression to evaluate dynamic suspend error codes */ - private Value dynamicSuspendErrorCodes = null; + private Value suspendErrorCodes = new Value(""); /** No of retries to attempt on timeout, before an endpoint is makred inactive */ - private int retriesOnTimeoutBeforeSuspend = 0; - /** The expression to evaluate dynamic retries on timeout before suspend */ - private Value dynamicRetriesOnTimeoutBeforeSuspend = null; + private final int defaultRetriesOnTimeOutBeforeSuspend = 0; + private Value retriesOnTimeoutBeforeSuspend = new Value(String.valueOf(defaultRetriesOnTimeOutBeforeSuspend)); + /** The delay between retries for a timeout out endpoint */ - private int retryDurationOnTimeout = 0; - /** The expression to evaluate dynamic retry duration on timeout */ - private Value dynamicRetryDurationOnTimeout = null; + private final int defaultRetryDurationOnTimeout = 0; + private Value retryDurationOnTimeout = new Value(String.valueOf(defaultRetryDurationOnTimeout)); + /** A list of error codes which puts the endpoint into timeout mode */ - private final List timeoutErrorCodes = new ArrayList(); - /** The expression to evaluate dynamic timeout error codes */ - private Value dynamicTimeoutErrorCodes = null; + private Value timeoutErrorCodes = new Value(""); private AspectConfiguration aspectConfiguration; @@ -221,29 +212,16 @@ public EndpointDefinition() { } } - public void setDynamicTimeoutExpression(Value expression) { - this.dynamicTimeout = expression; - } - - public SynapsePath getDynamicTimeoutExpression() { - if (dynamicTimeout == null) { - return null; - } - return this.dynamicTimeout.getExpression(); - } - public boolean isDynamicTimeoutEndpoint() { - if (this.dynamicTimeout != null) { - return true; - } else { - return false; - } + + return timeoutDuration.getExpression() != null; } public long evaluateDynamicEndpointTimeout(MessageContext synCtx) { + long timeoutMilliSeconds; try { - String stringValue = dynamicTimeout.evaluateValue(synCtx); + String stringValue = timeoutDuration.evaluateValue(synCtx); if (stringValue != null) { timeoutMilliSeconds = Long.parseLong(stringValue.trim()); } else { @@ -559,8 +537,12 @@ public void setUseSwa(boolean useSwa) { this.useSwa = useSwa; } - public long getTimeoutDuration() { - return timeoutDuration; + public String getTimeoutDuration() { + + if (timeoutDuration.getKeyValue() != null) { + return timeoutDuration.getKeyValue(); + } + return timeoutDuration.getExpression().getExpression(); } /** @@ -580,64 +562,49 @@ public long getEffectiveTimeout() { * * @param timeoutDuration a duration in milliseconds */ - public void setTimeoutDuration(long timeoutDuration) { + public void setTimeoutDuration(Value timeoutDuration) { + this.timeoutDuration = timeoutDuration; - this.effectiveTimeout = timeoutDuration; + if (timeoutDuration.getKeyValue() != null) { + this.effectiveTimeout = Long.parseLong(timeoutDuration.getKeyValue()); + } this.endpointTimeoutType = SynapseConstants.ENDPOINT_TIMEOUT_TYPE.ENDPOINT_TIMEOUT; } - public int getTimeoutAction() { - return timeoutAction; - } + public String getTimeoutAction() { - public void setTimeoutAction(int timeoutAction) { - this.timeoutAction = timeoutAction; - } - - public SynapsePath getDynamicTimeoutAction() { - - if (dynamicTimeoutAction == null) { - return null; + if (timeoutAction.getKeyValue() != null) { + return timeoutAction.getKeyValue(); } - return dynamicTimeoutAction.getExpression(); + return timeoutAction.getExpression().getExpression(); } - public void setDynamicTimeoutAction(Value dynamicTimeoutAction) { + public void setTimeoutAction(Value timeoutAction) { - this.dynamicTimeoutAction = dynamicTimeoutAction; + this.timeoutAction = timeoutAction; } public boolean isTimeoutActionDynamic() { - return dynamicTimeoutAction != null; + return timeoutAction.getExpression() != null; } - public int evaluateDynamicTimeoutAction(MessageContext synCtx) { + public int getResolvedTimeoutAction(MessageContext synCtx) { - int result = timeoutAction; - try { - String timeoutActionStr = dynamicTimeoutAction.evaluateValue(synCtx); - if (timeoutActionStr != null) { - if (EPConstants.DISCARD.equalsIgnoreCase(timeoutActionStr)) { - result = SynapseConstants.DISCARD; - } else if (EPConstants.FAULT.equalsIgnoreCase(timeoutActionStr)) { - result = SynapseConstants.DISCARD_AND_FAULT; - } + int result = defaultTimeoutAction; + String timeoutActionStr = timeoutAction.evaluateValue(synCtx); + if (timeoutActionStr != null) { + if (EPConstants.DISCARD.equalsIgnoreCase(timeoutActionStr)) { + result = SynapseConstants.DISCARD; + } else if (EPConstants.FAULT.equalsIgnoreCase(timeoutActionStr)) { + result = SynapseConstants.DISCARD_AND_FAULT; + } else { + log.warn("Invalid timeout action, action : '" + timeoutActionStr + "' is not supported."); } - } catch (NumberFormatException e) { - log.warn("Error while evaluating dynamic endpoint timeout action."); } return result; } - public int getResolvedTimeoutAction(MessageContext messageContext) { - - if (isTimeoutActionDynamic()) { - return evaluateDynamicTimeoutAction(messageContext); - } - return timeoutAction; - } - public String getFormat() { return format; } @@ -669,8 +636,12 @@ public void setCharSetEncoding(String charSetEncoding) { * * @return suspendOnFailDuration */ - public long getInitialSuspendDuration() { - return initialSuspendDuration; + public String getInitialSuspendDuration() { + + if (initialSuspendDuration.getKeyValue() != null) { + return initialSuspendDuration.getKeyValue(); + } + return initialSuspendDuration.getExpression().getExpression(); } /** @@ -678,253 +649,182 @@ public long getInitialSuspendDuration() { * * @param initialSuspendDuration a duration in milliseconds */ - public void setInitialSuspendDuration(long initialSuspendDuration) { + public void setInitialSuspendDuration(Value initialSuspendDuration) { + this.initialSuspendDuration = initialSuspendDuration; } - public SynapsePath getDynamicInitialSuspendDuration() { + public boolean isInitialSuspendDurationDynamic() { - if (dynamicInitialSuspendDuration == null) { - return null; - } - return dynamicInitialSuspendDuration.getExpression(); + return initialSuspendDuration.getExpression() != null; } - public void setDynamicInitialSuspendDuration(Value dynamicInitialSuspendDuration) { - - this.dynamicInitialSuspendDuration = dynamicInitialSuspendDuration; - } + public long getResolvedInitialSuspendDuration(MessageContext synCtx) { - public boolean isInitialSuspendDurationDynamic() { - if (dynamicInitialSuspendDuration != null) { - return true; - } else { - return false; - } - } - - public long evaluateDynamicInitialSuspendDuration(MessageContext synCtx) { - long result = initialSuspendDuration; + long result = defaultInitialSuspendDuration; + String stringValue = ""; try { - String stringValue = dynamicInitialSuspendDuration.evaluateValue(synCtx); + stringValue = initialSuspendDuration.evaluateValue(synCtx); if (stringValue != null) { result = Long.parseLong(stringValue.trim()); } } catch (NumberFormatException e) { - log.warn("Error while evaluating dynamic initial suspend duration."); + log.warn("Error while evaluating initial suspend duration. The resolved value '" + stringValue + "' should be a valid number. Hence the default value '" + defaultInitialSuspendDuration + "' is used."); } return result; } - public long getResolvedInitialSuspendDuration(MessageContext messageContext) { - if (isInitialSuspendDurationDynamic()) { - return evaluateDynamicInitialSuspendDuration(messageContext); - } - return initialSuspendDuration; - } - -// public int getTraceState() { -// return traceState; -// } -// -// public void setTraceState(int traceState) { -// this.traceState = traceState; -// } - - public float getSuspendProgressionFactor() { - return suspendProgressionFactor; - } - - public void setSuspendProgressionFactor(float suspendProgressionFactor) { - this.suspendProgressionFactor = suspendProgressionFactor; - } - - public SynapsePath getDynamicSuspendProgressionFactor() { + public String getSuspendProgressionFactor() { - if (dynamicSuspendProgressionFactor == null) { - return null; + if (suspendProgressionFactor.getKeyValue() != null) { + return suspendProgressionFactor.getKeyValue(); } - return dynamicSuspendProgressionFactor.getExpression(); + return suspendProgressionFactor.getExpression().getExpression(); } - public void setDynamicSuspendProgressionFactor(Value dynamicSuspendProgressionFactor) { + public void setSuspendProgressionFactor(Value suspendProgressionFactor) { - this.dynamicSuspendProgressionFactor = dynamicSuspendProgressionFactor; + this.suspendProgressionFactor = suspendProgressionFactor; } public boolean isSuspendProgressionFactorDynamic() { - return dynamicSuspendProgressionFactor != null; + return suspendProgressionFactor.getExpression() != null; } - public float evaluateDynamicSuspendProgressionFactor(MessageContext messageContext) { + public float getResolvedSuspendProgressionFactor(MessageContext messageContext) { - float result = suspendProgressionFactor; + float result = defaultSuspendProgressionFactor; + String stringValue = ""; try { - String stringValue = dynamicSuspendProgressionFactor.evaluateValue(messageContext); + stringValue = suspendProgressionFactor.evaluateValue(messageContext); if (stringValue != null) { result = Float.parseFloat(stringValue); } } catch (NumberFormatException e) { - log.warn("Error while evaluating dynamic endpoint timeout expression."); + log.warn("Error while evaluating suspend duration progression factor. The resolved value '" + stringValue + "' should be a valid float. Hence the default value '" + defaultSuspendProgressionFactor + "' is used."); } return result; } - public float getResolvedSuspendProgressionFactor(MessageContext messageContext) { - if (isSuspendProgressionFactorDynamic()) { - return evaluateDynamicSuspendProgressionFactor(messageContext); - } - return suspendProgressionFactor; - } - - public long getSuspendMaximumDuration() { - return suspendMaximumDuration; - } + public String getSuspendMaximumDuration() { - public void setSuspendMaximumDuration(long suspendMaximumDuration) { - this.suspendMaximumDuration = suspendMaximumDuration; - } - - public SynapsePath getDynamicSuspendMaximumDuration() { - - if (dynamicSuspendMaximumDuration == null) { - return null; + if (suspendMaximumDuration.getKeyValue() != null) { + return suspendMaximumDuration.getKeyValue(); } - return dynamicSuspendMaximumDuration.getExpression(); + return suspendMaximumDuration.getExpression().getExpression(); } - public void setDynamicSuspendMaximumDuration(Value dynamicSuspendMaximumDuration) { + public void setSuspendMaximumDuration(Value suspendMaximumDuration) { - this.dynamicSuspendMaximumDuration = dynamicSuspendMaximumDuration; + this.suspendMaximumDuration = suspendMaximumDuration; } public boolean isSuspendMaximumDurationDynamic() { - return dynamicSuspendMaximumDuration != null; + return suspendMaximumDuration.getExpression() != null; } - public long evaluateDynamicSuspendMaximumDuration(MessageContext messageContext) { + public long getResolvedSuspendMaximumDuration(MessageContext messageContext) { - long result = suspendMaximumDuration; + long result = defaultSuspendMaximumDuration; + String stringValue = ""; try { - String stringValue = dynamicSuspendMaximumDuration.evaluateValue(messageContext); + stringValue = suspendMaximumDuration.evaluateValue(messageContext); if (stringValue != null) { result = Long.parseLong(stringValue); } } catch (NumberFormatException e) { - log.warn("Error while evaluating dynamic endpoint timeout expression."); + log.warn("Error while evaluating suspend maximum duration. The resolved value '" + stringValue + "' should be a valid number. Hence the default value '" + defaultSuspendMaximumDuration + "' is used."); } return result; } - public long getResolvedSuspendMaximumDuration(MessageContext messageContext) { - if (isSuspendMaximumDurationDynamic()) { - return evaluateDynamicSuspendMaximumDuration(messageContext); - } - return suspendMaximumDuration; - } - - public int getRetriesOnTimeoutBeforeSuspend() { - return retriesOnTimeoutBeforeSuspend; - } - - public void setRetriesOnTimeoutBeforeSuspend(int retriesOnTimeoutBeforeSuspend) { - this.retriesOnTimeoutBeforeSuspend = retriesOnTimeoutBeforeSuspend; - } - - public SynapsePath getDynamicRetriesOnTimeoutBeforeSuspend() { + public String getRetriesOnTimeoutBeforeSuspend() { - if (dynamicRetriesOnTimeoutBeforeSuspend == null) { - return null; + if (retriesOnTimeoutBeforeSuspend.getKeyValue() != null) { + return retriesOnTimeoutBeforeSuspend.getKeyValue(); } - return dynamicRetriesOnTimeoutBeforeSuspend.getExpression(); + return retriesOnTimeoutBeforeSuspend.getExpression().getExpression(); } - public void setDynamicRetriesOnTimeoutBeforeSuspend(Value dynamicRetriesOnTimeoutBeforeSuspend) { + public void setRetriesOnTimeoutBeforeSuspend(Value retriesOnTimeoutBeforeSuspend) { - this.dynamicRetriesOnTimeoutBeforeSuspend = dynamicRetriesOnTimeoutBeforeSuspend; + this.retriesOnTimeoutBeforeSuspend = retriesOnTimeoutBeforeSuspend; } public boolean isRetriesOnTimeoutBeforeSuspendDynamic() { - return dynamicRetriesOnTimeoutBeforeSuspend != null; + return retriesOnTimeoutBeforeSuspend.getExpression() != null; } - public int evaluateDynamicRetriesOnTimeoutBeforeSuspend(MessageContext messageContext) { + public int getResolvedRetriesOnTimeoutBeforeSuspend(MessageContext messageContext) { - int result = retriesOnTimeoutBeforeSuspend; + int result = defaultRetriesOnTimeOutBeforeSuspend; + String stringValue = ""; try { - String stringValue = dynamicRetriesOnTimeoutBeforeSuspend.evaluateValue(messageContext); + stringValue = retriesOnTimeoutBeforeSuspend.evaluateValue(messageContext); if (stringValue != null) { result = Integer.parseInt(stringValue); } } catch (NumberFormatException e) { - log.warn("Error while evaluating dynamic endpoint timeout expression."); + log.warn("Error while evaluating retries before suspend [for timeouts]. The resolved value '" + stringValue + "' should be a valid number. Hence the default value '" + defaultRetriesOnTimeOutBeforeSuspend + "' is used."); } return result; } - public int getResolvedRetriesOnTimeoutBeforeSuspend(MessageContext messageContext) { - if (isRetriesOnTimeoutBeforeSuspendDynamic()) { - return evaluateDynamicRetriesOnTimeoutBeforeSuspend(messageContext); - } - return retriesOnTimeoutBeforeSuspend; - } + public String getRetryDurationOnTimeout() { - public int getRetryDurationOnTimeout() { - return retryDurationOnTimeout; - } - - public void setRetryDurationOnTimeout(int retryDurationOnTimeout) { - this.retryDurationOnTimeout = retryDurationOnTimeout; - } - - public SynapsePath getDynamicRetryDurationOnTimeout() { - - if (dynamicRetryDurationOnTimeout == null) { - return null; + if (retryDurationOnTimeout.getKeyValue() != null) { + return retryDurationOnTimeout.getKeyValue(); } - return dynamicRetryDurationOnTimeout.getExpression(); + return retryDurationOnTimeout.getExpression().getExpression(); } - public void setDynamicRetryDurationOnTimeout(Value dynamicRetryDurationOnTimeout) { + public void setRetryDurationOnTimeout(Value retryDurationOnTimeout) { - this.dynamicRetryDurationOnTimeout = dynamicRetryDurationOnTimeout; + this.retryDurationOnTimeout = retryDurationOnTimeout; } public boolean isRetryDurationOnTimeoutDynamic() { - return dynamicRetryDurationOnTimeout != null; + return retryDurationOnTimeout.getExpression() != null; } - public int evaluateDynamicRetryDurationOnTimeout(MessageContext messageContext) { + public int getResolvedRetryDurationOnTimeout(MessageContext messageContext) { - int result = retryDurationOnTimeout; + int result = defaultRetryDurationOnTimeout; + String stringValue = ""; try { - String stringValue = dynamicRetryDurationOnTimeout.evaluateValue(messageContext); + stringValue = retryDurationOnTimeout.evaluateValue(messageContext); if (stringValue != null) { result = Integer.parseInt(stringValue); } } catch (NumberFormatException e) { - log.warn("Error while evaluating dynamic endpoint timeout expression."); + log.warn("Error while evaluating retry delay for timeouts. The resolved value '" + stringValue + "' should be a valid number. Hence the default value '" + defaultRetryDurationOnTimeout + "' is used."); } return result; } - public int getResolvedRetryDurationOnTimeout(MessageContext messageContext) { - if (isRetryDurationOnTimeoutDynamic()) { - return evaluateDynamicRetryDurationOnTimeout(messageContext); + public String getSuspendErrorCodes() { + + if (suspendErrorCodes.getKeyValue() != null) { + return suspendErrorCodes.getKeyValue(); } - return retryDurationOnTimeout; + return suspendErrorCodes.getExpression().getExpression(); } - public List getSuspendErrorCodes() { - return suspendErrorCodes; + public boolean isSuspendErrorCodesDynamic() { + + return suspendErrorCodes.getExpression() != null; } - public List getTimeoutErrorCodes() { - return timeoutErrorCodes; + public String getTimeoutErrorCodes() { + + if (timeoutErrorCodes.getKeyValue() != null) { + return timeoutErrorCodes.getKeyValue(); + } + return timeoutErrorCodes.getExpression().getExpression(); } public List getRetryDisabledErrorCodes() { @@ -943,33 +843,24 @@ public void setReplicationDisabled(boolean replicationDisabled) { this.replicationDisabled = replicationDisabled; } - public void addSuspendErrorCode(int code) { - suspendErrorCodes.add(code); - } + public void setSuspendErrorCodes(Value suspendErrorCodes) { - public SynapsePath getDynamicSuspendErrorCodes() { - - if (dynamicSuspendErrorCodes == null) { - return null; - } - return dynamicSuspendErrorCodes.getExpression(); - } - - public void setDynamicSuspendErrorCodes(Value dynamicSuspendErrorCodes) { - - this.dynamicSuspendErrorCodes = dynamicSuspendErrorCodes; + this.suspendErrorCodes = suspendErrorCodes; } - public boolean isSuspendErrorCodesDynamic() { + public void addSuspendErrorCode(int code) { - return dynamicSuspendErrorCodes != null; + if (suspendErrorCodes.getKeyValue() != null) { + suspendErrorCodes = new Value(suspendErrorCodes.getKeyValue() + "," + code); + } } - public List evaluateDynamicSuspendErrorCodes(MessageContext messageContext) { + public List getResolvedSuspendErrorCodes(MessageContext messageContext) { - List result = suspendErrorCodes; + List result = new ArrayList<>(); + String stringValue = ""; try { - String stringValue = dynamicSuspendErrorCodes.evaluateValue(messageContext); + stringValue = suspendErrorCodes.evaluateValue(messageContext); if (stringValue != null) { String[] errorCodes = stringValue.split(","); result = new ArrayList(); @@ -978,45 +869,34 @@ public List evaluateDynamicSuspendErrorCodes(MessageContext messageCont } } } catch (NumberFormatException e) { - log.warn("Error while evaluating dynamic endpoint timeout expression."); + log.warn("Error while evaluating suspend error codes. The resolved value '" + stringValue + "' should be valid numbers separated by commas."); } return result; } - public List getResolvedSuspendErrorCodes(MessageContext messageContext) { - if (isSuspendErrorCodesDynamic()) { - return evaluateDynamicSuspendErrorCodes(messageContext); - } - return suspendErrorCodes; - } + public void setTimeoutErrorCodes(Value timeoutErrorCodes) { - public void addTimeoutErrorCode(int code) { - timeoutErrorCodes.add(code); + this.timeoutErrorCodes = timeoutErrorCodes; } - public SynapsePath getDynamicTimeoutErrorCodes() { + public void addTimeoutErrorCode(int code) { - if (dynamicTimeoutErrorCodes == null) { - return null; + if (timeoutErrorCodes.getKeyValue() != null) { + timeoutErrorCodes = new Value(timeoutErrorCodes.getKeyValue() + "," + code); } - return dynamicTimeoutErrorCodes.getExpression(); - } - - public void setDynamicTimeoutErrorCodes(Value dynamicTimeoutErrorCodes) { - - this.dynamicTimeoutErrorCodes = dynamicTimeoutErrorCodes; } public boolean isTimeoutErrorCodesDynamic() { - return dynamicTimeoutErrorCodes != null; + return timeoutErrorCodes.getExpression() != null; } - public List evaluateDynamicTimeoutErrorCodes(MessageContext messageContext) { + public List getResolvedTimeoutErrorCodes(MessageContext messageContext) { - List result = timeoutErrorCodes; + List result = new ArrayList<>(); + String stringValue = ""; try { - String stringValue = dynamicTimeoutErrorCodes.evaluateValue(messageContext); + stringValue = timeoutErrorCodes.evaluateValue(messageContext); if (stringValue != null) { String[] errorCodes = stringValue.split(","); result = new ArrayList(); @@ -1025,18 +905,11 @@ public List evaluateDynamicTimeoutErrorCodes(MessageContext messageCont } } } catch (NumberFormatException e) { - log.warn("Error while evaluating dynamic endpoint timeout expression."); + log.warn("Error while evaluating timeout error codes. The resolved value '" + stringValue + "' should be valid numbers separated by commas."); } return result; } - public List getResolvedTimeoutErrorCodes(MessageContext messageContext) { - if (isTimeoutErrorCodesDynamic()) { - return evaluateDynamicTimeoutErrorCodes(messageContext); - } - return timeoutErrorCodes; - } - public void addRetryDisabledErrorCode(int code) { retryDisabledErrorCodes.add(code); } diff --git a/modules/core/src/test/java/org/apache/synapse/endpoints/HttpEndpointTest.java b/modules/core/src/test/java/org/apache/synapse/endpoints/HttpEndpointTest.java index d99d6ee521..6b2edb80b5 100644 --- a/modules/core/src/test/java/org/apache/synapse/endpoints/HttpEndpointTest.java +++ b/modules/core/src/test/java/org/apache/synapse/endpoints/HttpEndpointTest.java @@ -178,8 +178,8 @@ public void testSetSuspendOnFailureInitialDuration() throws XMLStreamException, OMElement omElement = AXIOMUtil.stringToOM( "10100010"); EndpointDefinition ep1 = httpEndpointFactory.createEndpointDefinition(omElement); - Assert.assertEquals(ep1.getRetriesOnTimeoutBeforeSuspend(), 0); - Assert.assertEquals(ep1.getInitialSuspendDuration(), 1000); + Assert.assertEquals(ep1.getRetriesOnTimeoutBeforeSuspend(), "0"); + Assert.assertEquals(ep1.getInitialSuspendDuration(), "1000"); } @Test diff --git a/modules/core/src/test/java/org/apache/synapse/endpoints/dynamic/DynamicEndpointTest.java b/modules/core/src/test/java/org/apache/synapse/endpoints/dynamic/DynamicEndpointTest.java index a2e4b101c0..0010f054a5 100644 --- a/modules/core/src/test/java/org/apache/synapse/endpoints/dynamic/DynamicEndpointTest.java +++ b/modules/core/src/test/java/org/apache/synapse/endpoints/dynamic/DynamicEndpointTest.java @@ -26,7 +26,6 @@ import org.apache.synapse.endpoints.AbstractEndpoint; import org.apache.synapse.endpoints.AddressEndpoint; import org.apache.synapse.endpoints.EndpointDefinition; -import org.apache.synapse.util.xpath.SynapseXPath; import java.util.ArrayList; import java.util.List; @@ -39,7 +38,7 @@ public void testContextProperties() throws Exception { AbstractEndpoint endpoint = new AddressEndpoint(); EndpointDefinition definition = new EndpointDefinition(); endpoint.setDefinition(definition); - definition.setDynamicTimeoutExpression(new ValueFactory().createTextValue(omElement)); + definition.setTimeoutDuration(new ValueFactory().createTextValue(omElement)); MessageContext synCtx = new TestMessageContext(); synCtx.setProperty("timeout", "90000"); assertEquals(90000, @@ -52,7 +51,7 @@ public void testContextPropertiesForInitialSuspendDuration() throws Exception { AbstractEndpoint endpoint = new AddressEndpoint(); EndpointDefinition definition = new EndpointDefinition(); endpoint.setDefinition(definition); - definition.setDynamicInitialSuspendDuration(new ValueFactory().createTextValue(omElement)); + definition.setInitialSuspendDuration(new ValueFactory().createTextValue(omElement)); MessageContext synCtx = new TestMessageContext(); synCtx.setProperty("suspendInitialDuration", "90000"); assertEquals(endpoint.getDefinition().getResolvedInitialSuspendDuration(synCtx), 90000); @@ -64,7 +63,7 @@ public void testContextPropertiesForNoInitialSuspendDuration() throws Exception AbstractEndpoint endpoint = new AddressEndpoint(); EndpointDefinition definition = new EndpointDefinition(); endpoint.setDefinition(definition); - definition.setDynamicInitialSuspendDuration(new ValueFactory().createTextValue(omElement)); + definition.setInitialSuspendDuration(new ValueFactory().createTextValue(omElement)); MessageContext synCtx = new TestMessageContext(); assertEquals(-1, endpoint.getDefinition().getResolvedInitialSuspendDuration(synCtx)); } @@ -75,7 +74,7 @@ public void testContextPropertiesForSuspendMaximumDuration() throws Exception { AbstractEndpoint endpoint = new AddressEndpoint(); EndpointDefinition definition = new EndpointDefinition(); endpoint.setDefinition(definition); - definition.setDynamicSuspendMaximumDuration(new ValueFactory().createTextValue(omElement)); + definition.setSuspendMaximumDuration(new ValueFactory().createTextValue(omElement)); MessageContext synCtx = new TestMessageContext(); synCtx.setProperty("suspendMaximumDuration", "90000"); assertEquals(endpoint.getDefinition().getResolvedSuspendMaximumDuration(synCtx), 90000); @@ -87,7 +86,7 @@ public void testContextPropertiesForNoSuspendMaximumDuration() throws Exception AbstractEndpoint endpoint = new AddressEndpoint(); EndpointDefinition definition = new EndpointDefinition(); endpoint.setDefinition(definition); - definition.setDynamicSuspendMaximumDuration(new ValueFactory().createTextValue(omElement)); + definition.setSuspendMaximumDuration(new ValueFactory().createTextValue(omElement)); MessageContext synCtx = new TestMessageContext(); assertEquals(Long.MAX_VALUE, endpoint.getDefinition().getResolvedSuspendMaximumDuration(synCtx)); } @@ -98,7 +97,7 @@ public void testContextPropertiesForSuspendProgressionFactor() throws Exception AbstractEndpoint endpoint = new AddressEndpoint(); EndpointDefinition definition = new EndpointDefinition(); endpoint.setDefinition(definition); - definition.setDynamicSuspendProgressionFactor(new ValueFactory().createTextValue(omElement)); + definition.setSuspendProgressionFactor(new ValueFactory().createTextValue(omElement)); MessageContext synCtx = new TestMessageContext(); synCtx.setProperty("suspendProgressionFactor", "2"); assertEquals(endpoint.getDefinition().getResolvedSuspendProgressionFactor(synCtx), 2.0f); @@ -110,7 +109,7 @@ public void testContextPropertiesForNoSuspendProgressionFactor() throws Exceptio AbstractEndpoint endpoint = new AddressEndpoint(); EndpointDefinition definition = new EndpointDefinition(); endpoint.setDefinition(definition); - definition.setDynamicSuspendProgressionFactor(new ValueFactory().createTextValue(omElement)); + definition.setSuspendProgressionFactor(new ValueFactory().createTextValue(omElement)); MessageContext synCtx = new TestMessageContext(); assertEquals(1.0f, endpoint.getDefinition().getResolvedSuspendProgressionFactor(synCtx)); } @@ -121,7 +120,7 @@ public void testContextPropertiesForRetriesOnTimeoutBeforeSuspend() throws Excep AbstractEndpoint endpoint = new AddressEndpoint(); EndpointDefinition definition = new EndpointDefinition(); endpoint.setDefinition(definition); - definition.setDynamicRetriesOnTimeoutBeforeSuspend(new ValueFactory().createTextValue(omElement)); + definition.setRetriesOnTimeoutBeforeSuspend(new ValueFactory().createTextValue(omElement)); MessageContext synCtx = new TestMessageContext(); synCtx.setProperty("retriesOnTimeoutBeforeSuspend", "3"); assertEquals(endpoint.getDefinition().getResolvedRetriesOnTimeoutBeforeSuspend(synCtx), 3); @@ -133,7 +132,7 @@ public void testContextPropertiesForNoRetriesOnTimeoutBeforeSuspend() throws Exc AbstractEndpoint endpoint = new AddressEndpoint(); EndpointDefinition definition = new EndpointDefinition(); endpoint.setDefinition(definition); - definition.setDynamicRetriesOnTimeoutBeforeSuspend(new ValueFactory().createTextValue(omElement)); + definition.setRetriesOnTimeoutBeforeSuspend(new ValueFactory().createTextValue(omElement)); MessageContext synCtx = new TestMessageContext(); assertEquals(0, endpoint.getDefinition().getResolvedRetriesOnTimeoutBeforeSuspend(synCtx)); } @@ -141,11 +140,10 @@ public void testContextPropertiesForNoRetriesOnTimeoutBeforeSuspend() throws Exc public void testContextPropertiesForRetryDurationOnTimeout() throws Exception { OMElement omElement = AXIOMUtil.stringToOM("{$ctx:retryDurationOnTimeout}"); - SynapseXPath xpath = new SynapseXPath("$ctx:retryDurationOnTimeout"); AbstractEndpoint endpoint = new AddressEndpoint(); EndpointDefinition definition = new EndpointDefinition(); endpoint.setDefinition(definition); - definition.setDynamicRetryDurationOnTimeout(new ValueFactory().createTextValue(omElement)); + definition.setRetryDurationOnTimeout(new ValueFactory().createTextValue(omElement)); MessageContext synCtx = new TestMessageContext(); synCtx.setProperty("retryDurationOnTimeout", "90000"); assertEquals(endpoint.getDefinition().getResolvedRetryDurationOnTimeout(synCtx), 90000); @@ -157,7 +155,7 @@ public void testContextPropertiesForNoRetryDurationOnTimeout() throws Exception AbstractEndpoint endpoint = new AddressEndpoint(); EndpointDefinition definition = new EndpointDefinition(); endpoint.setDefinition(definition); - definition.setDynamicRetryDurationOnTimeout(new ValueFactory().createTextValue(omElement)); + definition.setRetryDurationOnTimeout(new ValueFactory().createTextValue(omElement)); MessageContext synCtx = new TestMessageContext(); assertEquals(0, endpoint.getDefinition().getResolvedRetryDurationOnTimeout(synCtx)); } @@ -168,7 +166,7 @@ public void testContextPropertiesForTimeoutActionFault() throws Exception { AbstractEndpoint endpoint = new AddressEndpoint(); EndpointDefinition definition = new EndpointDefinition(); endpoint.setDefinition(definition); - definition.setDynamicTimeoutAction(new ValueFactory().createTextValue(omElement)); + definition.setTimeoutAction(new ValueFactory().createTextValue(omElement)); MessageContext synCtx = new TestMessageContext(); synCtx.setProperty("timeoutAction", "fault"); assertEquals(endpoint.getDefinition().getResolvedTimeoutAction(synCtx), SynapseConstants.DISCARD_AND_FAULT); @@ -180,7 +178,7 @@ public void testContextPropertiesForTimeoutActionDiscard() throws Exception { AbstractEndpoint endpoint = new AddressEndpoint(); EndpointDefinition definition = new EndpointDefinition(); endpoint.setDefinition(definition); - definition.setDynamicTimeoutAction(new ValueFactory().createTextValue(omElement)); + definition.setTimeoutAction(new ValueFactory().createTextValue(omElement)); MessageContext synCtx = new TestMessageContext(); synCtx.setProperty("timeoutAction", "discard"); assertEquals(endpoint.getDefinition().getResolvedTimeoutAction(synCtx), SynapseConstants.DISCARD); @@ -192,7 +190,7 @@ public void testContextPropertiesForNoTimeoutAction() throws Exception { AbstractEndpoint endpoint = new AddressEndpoint(); EndpointDefinition definition = new EndpointDefinition(); endpoint.setDefinition(definition); - definition.setDynamicTimeoutAction(new ValueFactory().createTextValue(omElement)); + definition.setTimeoutAction(new ValueFactory().createTextValue(omElement)); MessageContext synCtx = new TestMessageContext(); assertEquals(endpoint.getDefinition().getResolvedTimeoutAction(synCtx), SynapseConstants.NONE); } @@ -203,7 +201,7 @@ public void testContextPropertiesForSuspendErrorCodes() throws Exception { AbstractEndpoint endpoint = new AddressEndpoint(); EndpointDefinition definition = new EndpointDefinition(); endpoint.setDefinition(definition); - definition.setDynamicSuspendErrorCodes(new ValueFactory().createTextValue(omElement)); + definition.setSuspendErrorCodes(new ValueFactory().createTextValue(omElement)); MessageContext synCtx = new TestMessageContext(); synCtx.setProperty("suspendErrorCodes", "101503,101504"); @@ -220,7 +218,7 @@ public void testContextPropertiesForEmptySuspendErrorCodes() throws Exception { AbstractEndpoint endpoint = new AddressEndpoint(); EndpointDefinition definition = new EndpointDefinition(); endpoint.setDefinition(definition); - definition.setDynamicSuspendErrorCodes(new ValueFactory().createTextValue(omElement)); + definition.setSuspendErrorCodes(new ValueFactory().createTextValue(omElement)); MessageContext synCtx = new TestMessageContext(); synCtx.setProperty("suspendErrorCodes", ""); @@ -235,7 +233,7 @@ public void testContextPropertiesForNoSuspendErrorCodes() throws Exception { AbstractEndpoint endpoint = new AddressEndpoint(); EndpointDefinition definition = new EndpointDefinition(); endpoint.setDefinition(definition); - definition.setDynamicSuspendErrorCodes(new ValueFactory().createTextValue(omElement)); + definition.setSuspendErrorCodes(new ValueFactory().createTextValue(omElement)); MessageContext synCtx = new TestMessageContext(); List expectedSuspendErrorCodes = endpoint.getDefinition().getResolvedSuspendErrorCodes(synCtx); assertTrue(expectedSuspendErrorCodes.isEmpty()); @@ -247,7 +245,7 @@ public void testContextPropertiesForTimeoutErrorCodes() throws Exception { AbstractEndpoint endpoint = new AddressEndpoint(); EndpointDefinition definition = new EndpointDefinition(); endpoint.setDefinition(definition); - definition.setDynamicTimeoutErrorCodes(new ValueFactory().createTextValue(omElement)); + definition.setTimeoutErrorCodes(new ValueFactory().createTextValue(omElement)); MessageContext synCtx = new TestMessageContext(); synCtx.setProperty("timeoutErrorCodes", "101503,101504"); @@ -264,7 +262,7 @@ public void testContextPropertiesForEmptyTimeoutErrorCodes() throws Exception { AbstractEndpoint endpoint = new AddressEndpoint(); EndpointDefinition definition = new EndpointDefinition(); endpoint.setDefinition(definition); - definition.setDynamicTimeoutErrorCodes(new ValueFactory().createTextValue(omElement)); + definition.setTimeoutErrorCodes(new ValueFactory().createTextValue(omElement)); MessageContext synCtx = new TestMessageContext(); synCtx.setProperty("timeoutErrorCodes", ""); @@ -279,7 +277,7 @@ public void testContextPropertiesForNoTimeoutErrorCodes() throws Exception { AbstractEndpoint endpoint = new AddressEndpoint(); EndpointDefinition definition = new EndpointDefinition(); endpoint.setDefinition(definition); - definition.setDynamicTimeoutErrorCodes(new ValueFactory().createTextValue(omElement)); + definition.setTimeoutErrorCodes(new ValueFactory().createTextValue(omElement)); MessageContext synCtx = new TestMessageContext(); List expectedTimeoutErrorCodes = endpoint.getDefinition().getResolvedTimeoutErrorCodes(synCtx); assertTrue(expectedTimeoutErrorCodes.isEmpty());