Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add expression support to endpoint definition attributes for handling endpoints in the HTTP connector. #2238

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
9f36f1d
add expression for suspend initial duration attribute without create …
chathuranga-jayanath-99 Oct 3, 2024
261b0f4
add expression for suspend maximum duration attribute without set sus…
chathuranga-jayanath-99 Oct 4, 2024
704a8da
add expression for suspend progression factor
chathuranga-jayanath-99 Oct 4, 2024
26ff0b4
add expression for retries on timeout before suspend without set time…
chathuranga-jayanath-99 Oct 4, 2024
64aab6c
add expression for retry duration on timeout
chathuranga-jayanath-99 Oct 4, 2024
1ba5ad2
add tests to check added expressions
chathuranga-jayanath-99 Oct 5, 2024
ea622f3
add expression for timeout action
chathuranga-jayanath-99 Oct 5, 2024
9e371ab
fix expression check pattern
chathuranga-jayanath-99 Oct 5, 2024
7178623
add expression for suspend error codes without setSuspendStateProperties
chathuranga-jayanath-99 Oct 7, 2024
67e5592
add expression for timeout error codes without setTimeoutStateProperties
chathuranga-jayanath-99 Oct 7, 2024
65fd4d2
add tests for error codes
chathuranga-jayanath-99 Oct 7, 2024
e19e5d4
parse message context for createJsonRepresentation
chathuranga-jayanath-99 Oct 8, 2024
81b9899
handle timeout action value "never"
chathuranga-jayanath-99 Nov 25, 2024
e27203b
remove log warns where unnecessary
chathuranga-jayanath-99 Nov 25, 2024
2a5cb16
add new tests handling value not defined scenarios
chathuranga-jayanath-99 Nov 25, 2024
5d0d62f
Merge branch 'refs/heads/add-expression' into integrate-new-expressions
chathuranga-jayanath-99 Nov 25, 2024
1b00df2
remove handling timeout action value "never"
chathuranga-jayanath-99 Nov 26, 2024
2df1a58
add synapse expression support
chathuranga-jayanath-99 Nov 26, 2024
3c782b1
Revert "parse message context for createJsonRepresentation"
chathuranga-jayanath-99 Nov 28, 2024
4a99054
introduce value to handle endpoint definition attributes
chathuranga-jayanath-99 Nov 28, 2024
4383df8
add 'never' as default value of timeoutAction
chathuranga-jayanath-99 Dec 6, 2024
80a2d64
change delimiter ", " to ","
chathuranga-jayanath-99 Dec 6, 2024
b1367aa
add tests to check endpoint definition
chathuranga-jayanath-99 Dec 7, 2024
9d29be9
address reviewed changes
chathuranga-jayanath-99 Dec 8, 2024
c88988f
add serializer tests
chathuranga-jayanath-99 Dec 8, 2024
68cf96d
add method overload for onSuccess, onFault, onTimeout
chathuranga-jayanath-99 Dec 9, 2024
213b9ec
update print endpoint address
chathuranga-jayanath-99 Dec 9, 2024
e79f395
address reviewed changes
chathuranga-jayanath-99 Dec 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public static void setSpanTags(SpanWrapper spanWrapper, MessageContext synCtx) {
}
if (openStatisticsLog.getEndpoint() != null) {
span.setAttribute(TelemetryConstants.ENDPOINT_ATTRIBUTE_KEY,
String.valueOf(openStatisticsLog.getEndpoint().getJsonRepresentation()));
String.valueOf(openStatisticsLog.getEndpoint().getJsonRepresentation(synCtx)));
}
if (synCtx.getProperty(CorrelationConstants.CORRELATION_ID) != null) {
span.setAttribute(TelemetryConstants.CORRELATION_ID_ATTRIBUTE_KEY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,24 @@ 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();
if ("discard".equalsIgnoreCase(actionString.trim())) {
definition.setTimeoutAction(SynapseConstants.DISCARD);
} else if ("fault".equalsIgnoreCase(actionString.trim())) {
definition.setTimeoutAction(SynapseConstants.DISCARD_AND_FAULT);
String actionString = action.getText().trim();
if (isExpression(actionString)) {
try {
String expressionStr = actionString.substring(1, actionString.length() - 1);
SynapseXPath expressionXPath = new SynapseXPath(expressionStr);
chathuranga-jayanath-99 marked this conversation as resolved.
Show resolved Hide resolved
chathuranga-jayanath-99 marked this conversation as resolved.
Show resolved Hide resolved
definition.setDynamicTimeoutAction(expressionXPath);
} catch (JaxenException e) {
handleException("Couldn't assign dynamic timeout action as Synapse expression");
chathuranga-jayanath-99 marked this conversation as resolved.
Show resolved Hide resolved
}
} else {
handleException("Invalid timeout action, action : "
+ actionString + " is not supported");
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");
}
}
}
}
Expand All @@ -202,14 +212,25 @@ public EndpointDefinition createDefinition(OMElement elem) {
SynapseConstants.SYNAPSE_NAMESPACE,
XMLConfigConstants.ERROR_CODES));
if (timeoutCodes != null && timeoutCodes.getText() != null) {
StringTokenizer st = new StringTokenizer(timeoutCodes.getText().trim(), ", ");
while (st.hasMoreTokens()) {
String s = st.nextToken();
String trimmedTimeoutCodes = timeoutCodes.getText().trim();
if (isExpression(trimmedTimeoutCodes)) {
try {
definition.addTimeoutErrorCode(Integer.parseInt(s));
} catch (NumberFormatException e) {
handleException("The timeout error codes should be specified " +
"as valid numbers separated by commas : " + timeoutCodes.getText(), e);
String expressionStr = trimmedTimeoutCodes.substring(1, trimmedTimeoutCodes.length() - 1);
SynapseXPath expressionXPath = new SynapseXPath(expressionStr);
definition.setDynamicTimeoutErrorCodes(expressionXPath);
} catch (JaxenException e) {
handleException("Couldn't assign dynamic timeout error codes as Synapse expression");
}
} else {
StringTokenizer st = new StringTokenizer(timeoutCodes.getText().trim(), ", ");
chathuranga-jayanath-99 marked this conversation as resolved.
Show resolved Hide resolved
while (st.hasMoreTokens()) {
String s = st.nextToken();
try {
definition.addTimeoutErrorCode(Integer.parseInt(s));
} catch (NumberFormatException e) {
handleException("The timeout error codes should be specified " +
"as valid numbers separated by commas : " + timeoutCodes.getText(), e);
}
}
}
}
Expand All @@ -219,11 +240,20 @@ public EndpointDefinition createDefinition(OMElement elem) {
XMLConfigConstants.RETRIES_BEFORE_SUSPENSION));
if (retriesBeforeSuspend != null && retriesBeforeSuspend.getText() != null) {
try {
definition.setRetriesOnTimeoutBeforeSuspend(
Integer.parseInt(retriesBeforeSuspend.getText().trim()));
String trimmedRetriesBeforeSuspend = retriesBeforeSuspend.getText().trim();
if (isExpression(trimmedRetriesBeforeSuspend)) {
String expressionStr = trimmedRetriesBeforeSuspend.substring(1, trimmedRetriesBeforeSuspend.length() - 1);
SynapseXPath expressionXPath = new SynapseXPath(expressionStr);
definition.setDynamicRetriesOnTimeoutBeforeSuspend(expressionXPath);
} else {
definition.setRetriesOnTimeoutBeforeSuspend(
Integer.parseInt(trimmedRetriesBeforeSuspend));
}
} catch (NumberFormatException e) {
handleException("The retries before suspend [for timeouts] should be " +
"specified as a valid number : " + retriesBeforeSuspend.getText(), e);
} catch (JaxenException e) {
handleException("Couldn't assign dynamic retries before suspend [for timeouts] as Synapse expression");
}
}

Expand All @@ -232,11 +262,20 @@ public EndpointDefinition createDefinition(OMElement elem) {
XMLConfigConstants.RETRY_DELAY));
if (retryDelay != null && retryDelay.getText() != null) {
try {
definition.setRetryDurationOnTimeout(
Integer.parseInt(retryDelay.getText().trim()));
String trimmedRetryDelay = retryDelay.getText().trim();
if (isExpression(trimmedRetryDelay)) {
String expressionStr = trimmedRetryDelay.substring(1, trimmedRetryDelay.length() - 1);
SynapseXPath expressionXPath = new SynapseXPath(expressionStr);
definition.setDynamicRetryDurationOnTimeout(expressionXPath);
} else {
definition.setRetryDurationOnTimeout(
Integer.parseInt(trimmedRetryDelay));
}
} catch (NumberFormatException e) {
handleException("The retry delay for timeouts should be specified " +
"as a valid number : " + retryDelay.getText(), e);
} catch (JaxenException e) {
handleException("Couldn't assign dynamic retry delay for timeouts as Synapse expression");
}
}
}
Expand Down Expand Up @@ -267,15 +306,25 @@ public EndpointDefinition createDefinition(OMElement elem) {
SynapseConstants.SYNAPSE_NAMESPACE,
XMLConfigConstants.ERROR_CODES));
if (suspendCodes != null && suspendCodes.getText() != null) {

StringTokenizer st = new StringTokenizer(suspendCodes.getText().trim(), ", ");
while (st.hasMoreTokens()) {
String s = st.nextToken();
String trimmedSuspendCodes = suspendCodes.getText().trim();
if (isExpression(trimmedSuspendCodes)) {
try {
definition.addSuspendErrorCode(Integer.parseInt(s));
} catch (NumberFormatException e) {
handleException("The suspend error codes should be specified " +
"as valid numbers separated by commas : " + suspendCodes.getText(), e);
String expressionStr = trimmedSuspendCodes.substring(1, trimmedSuspendCodes.length() - 1);
SynapseXPath expressionXPath = new SynapseXPath(expressionStr);
definition.setDynamicSuspendErrorCodes(expressionXPath);
} catch (JaxenException e) {
handleException("Couldn't assign dynamic suspend error codes as Synapse expression");
}
} else {
StringTokenizer st = new StringTokenizer(trimmedSuspendCodes, ", ");
while (st.hasMoreTokens()) {
String s = st.nextToken();
try {
definition.addSuspendErrorCode(Integer.parseInt(s));
} catch (NumberFormatException e) {
handleException("The suspend error codes should be specified " +
"as valid numbers separated by commas : " + suspendCodes.getText(), e);
}
}
}
}
Expand All @@ -285,11 +334,20 @@ public EndpointDefinition createDefinition(OMElement elem) {
XMLConfigConstants.SUSPEND_INITIAL_DURATION));
if (initialDuration != null && initialDuration.getText() != null) {
try {
definition.setInitialSuspendDuration(
Integer.parseInt(initialDuration.getText().trim()));
String initialDurationTrimmed = initialDuration.getText().trim();
if (isExpression(initialDurationTrimmed)) {
String expressionStr = initialDurationTrimmed.substring(1, initialDurationTrimmed.length() - 1);
SynapseXPath expressionXPath = new SynapseXPath(expressionStr);
definition.setDynamicInitialSuspendDuration(expressionXPath);
} else {
definition.setInitialSuspendDuration(
Integer.parseInt(initialDurationTrimmed));
}
} catch (NumberFormatException e) {
handleException("The initial suspend duration should be specified " +
"as a valid number : " + initialDuration.getText(), e);
} catch (JaxenException e) {
handleException("Couldn't assign dynamic initial suspend duration as Synapse expression");
}
}

Expand All @@ -298,11 +356,20 @@ public EndpointDefinition createDefinition(OMElement elem) {
XMLConfigConstants.SUSPEND_PROGRESSION_FACTOR));
if (progressionFactor != null && progressionFactor.getText() != null) {
try {
definition.setSuspendProgressionFactor(
Float.parseFloat(progressionFactor.getText().trim()));
String trimmedProgressionFactor = progressionFactor.getText().trim();
if (isExpression(trimmedProgressionFactor)) {
String expressionStr = trimmedProgressionFactor.substring(1, trimmedProgressionFactor.length() - 1);
SynapseXPath expressionXPath = new SynapseXPath(expressionStr);
definition.setDynamicSuspendProgressionFactor(expressionXPath);
} else {
definition.setSuspendProgressionFactor(
Float.parseFloat(trimmedProgressionFactor));
}
} catch (NumberFormatException e) {
handleException("The suspend duration progression factor should be specified " +
"as a valid float : " + progressionFactor.getText(), e);
} catch (JaxenException e) {
handleException("Couldn't assign dynamic suspend duration progression factor as Synapse expression");
}
}

Expand All @@ -311,11 +378,20 @@ public EndpointDefinition createDefinition(OMElement elem) {
XMLConfigConstants.SUSPEND_MAXIMUM_DURATION));
if (maximumDuration != null && maximumDuration.getText() != null) {
try {
definition.setSuspendMaximumDuration(
Long.parseLong(maximumDuration.getText().trim()));
String trimmedMaximumDuration = maximumDuration.getText().trim();
if (isExpression(trimmedMaximumDuration)) {
String expressionStr = trimmedMaximumDuration.substring(1, trimmedMaximumDuration.length() - 1);
SynapseXPath expressionXPath = new SynapseXPath(expressionStr);
definition.setDynamicSuspendMaximumDuration(expressionXPath);
} else {
definition.setSuspendMaximumDuration(
Long.parseLong(maximumDuration.getText().trim()));
}
} catch (NumberFormatException e) {
handleException("The maximum suspend duration should be specified " +
"as a valid number : " + maximumDuration.getText(), e);
} catch (JaxenException e) {
handleException("Couldn't assign dynamic maximum suspend duration as Synapse expression");
}
}
}
Expand Down Expand Up @@ -368,6 +444,14 @@ public EndpointDefinition createDefinition(OMElement elem) {
return definition;
}

private boolean isExpression(String expressionStr) {
Pattern pattern = Pattern.compile("\\{.*\\}");
if (pattern.matcher(expressionStr).matches()) {
chathuranga-jayanath-99 marked this conversation as resolved.
Show resolved Hide resolved
return true;
}
return false;
}

protected static void handleException(String msg) {
log.error(msg);
throw new SynapseException(msg);
Expand Down
Loading
Loading