Skip to content

Conversation

@mcruzdev
Copy link
Contributor

Changes

  • Add a new RuntimeException the the serverlessworkflow-impl-http module called RedirectValidationException.
  • Add a new method into AbstractHttpExecutorBuilder responsible for applying redirect validation rules for the HTTP response. When the validation fails, it pass the response status code to the WorkflowError instance.

TODO

  • Add specific tests for redirect behavior (when the upstream server returns a 3XX status code)

Closes #959

Signed-off-by: Matheus Cruz <matheuscruz.dev@gmail.com>
Signed-off-by: Matheus Cruz <matheuscruz.dev@gmail.com>
Comment on lines +82 to +91
WorkflowError.communication(
response.getStatus(),
t,
new RedirectValidationException(
String.format(
"The property 'redirect' is %s but received status %d (%s); expected status in the %s range",
redirect,
response.getStatus(),
response.getStatusInfo().getReasonPhrase(),
expectedRange)))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
WorkflowError.communication(
response.getStatus(),
t,
new RedirectValidationException(
String.format(
"The property 'redirect' is %s but received status %d (%s); expected status in the %s range",
redirect,
response.getStatus(),
response.getStatusInfo().getReasonPhrase(),
expectedRange)))
WorkflowError.communication(
response.getStatus(),
t,
String.format(
"The property 'redirect' is %s but received status %d (%s); expected status in the %s range",
redirect,
response.getStatus(),
response.getStatusInfo().getReasonPhrase(),
expectedRange))

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think there is need to create a new exception, just the formated message within the error should suffice

Comment on lines +75 to +79
boolean isSuccess = statusFamily.equals(Response.Status.Family.SUCCESSFUL);
boolean isRedirect = statusFamily.equals(Response.Status.Family.REDIRECTION);

boolean valid = redirect ? (isSuccess || isRedirect) : isSuccess;
if (!valid) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets use import static for Response.Status.Family values

Suggested change
boolean isSuccess = statusFamily.equals(Response.Status.Family.SUCCESSFUL);
boolean isRedirect = statusFamily.equals(Response.Status.Family.REDIRECTION);
boolean valid = redirect ? (isSuccess || isRedirect) : isSuccess;
if (!valid) {
if (statusFamily != SUCCESSFUL || redirect && statusFamily != REDIRECTION) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add redirect for OpenAPI call

2 participants