Re: [PR] Issue-3936 Upgrade the REST custom functions to have visibility over the returned status code and headers [incubator-kie-kogito-runtimes]
fjtirado merged PR #3937: URL: https://github.com/apache/incubator-kie-kogito-runtimes/pull/3937 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] - To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Re: [PR] Issue-3936 Upgrade the REST custom functions to have visibility over the returned status code and headers [incubator-kie-kogito-runtimes]
oEscal commented on code in PR #3937:
URL:
https://github.com/apache/incubator-kie-kogito-runtimes/pull/3937#discussion_r2445059237
##
kogito-serverless-workflow/kogito-serverless-workflow-rest-runtime/src/main/java/org/kie/kogito/serverless/workflow/rest/JsonNodeResultHandler.java:
##
@@ -33,18 +34,27 @@
public class JsonNodeResultHandler implements RestWorkItemHandlerResult {
-static final String STATUS_CODE = "statusCode";
-static final String STATUS_MESSAGE = "statusMessage";
+public static final String FAIL_ON_STATUS_ERROR = "failOnStatusCode";
+public static final String STATUS_CODE = "statusCode";
+public static final String STATUS_MESSAGE = "statusMessage";
+public static final String RESPONSE_HEADERS = "responseHeaders";
@Override
public Object apply(HttpResponse t, Class u,
KogitoProcessContext context) {
Map metadata =
context.getNodeInstance().getNode().getMetaData();
-if (metadata == null ||
toBoolean(metadata.getOrDefault("failOnStatusCode", Boolean.TRUE))) {
+if (metadata == null ||
toBoolean(metadata.getOrDefault(FAIL_ON_STATUS_ERROR, Boolean.TRUE))) {
checkStatusCode(t);
} else {
context.setVariable(STATUS_CODE, t.statusCode());
context.setVariable(STATUS_MESSAGE, t.statusMessage());
}
+
+if (metadata != null) {
+Map headersMap = new HashMap<>();
+t.headers().forEach(entry -> headersMap.put(entry.getKey(),
entry.getValue()));
+context.setVariable(RESPONSE_HEADERS, headersMap);
+}
Review Comment:
You are right, the verification of metadata was a remaining from the
previous implementation I did
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
Re: [PR] Issue-3936 Upgrade the REST custom functions to have visibility over the returned status code and headers [incubator-kie-kogito-runtimes]
fjtirado commented on code in PR #3937:
URL:
https://github.com/apache/incubator-kie-kogito-runtimes/pull/3937#discussion_r2444671058
##
kogito-serverless-workflow/kogito-serverless-workflow-rest-runtime/src/main/java/org/kie/kogito/serverless/workflow/rest/JsonNodeResultHandler.java:
##
@@ -33,18 +34,27 @@
public class JsonNodeResultHandler implements RestWorkItemHandlerResult {
-static final String STATUS_CODE = "statusCode";
-static final String STATUS_MESSAGE = "statusMessage";
+public static final String FAIL_ON_STATUS_ERROR = "failOnStatusCode";
+public static final String STATUS_CODE = "statusCode";
+public static final String STATUS_MESSAGE = "statusMessage";
+public static final String RESPONSE_HEADERS = "responseHeaders";
@Override
public Object apply(HttpResponse t, Class u,
KogitoProcessContext context) {
Map metadata =
context.getNodeInstance().getNode().getMetaData();
-if (metadata == null ||
toBoolean(metadata.getOrDefault("failOnStatusCode", Boolean.TRUE))) {
+if (metadata == null ||
toBoolean(metadata.getOrDefault(FAIL_ON_STATUS_ERROR, Boolean.TRUE))) {
checkStatusCode(t);
} else {
context.setVariable(STATUS_CODE, t.statusCode());
context.setVariable(STATUS_MESSAGE, t.statusMessage());
}
+
+if (metadata != null) {
+Map headersMap = new HashMap<>();
+t.headers().forEach(entry -> headersMap.put(entry.getKey(),
entry.getValue()));
+context.setVariable(RESPONSE_HEADERS, headersMap);
+}
Review Comment:
I think this can be done in just one line, since there is not need to check
metadata (you always add the reponse headers) and the map can be generated
using functional approach.
```suggestion
context.setVariable(RESPONSE_HEADERS,
t.headers().entries().stream().collect(Collectors.toMap(Map.Entry::getKey,
Map.Entry::getValue)));
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
Re: [PR] Issue-3936 Upgrade the REST custom functions to have visibility over the returned status code and headers [incubator-kie-kogito-runtimes]
oEscal commented on PR #3937: URL: https://github.com/apache/incubator-kie-kogito-runtimes/pull/3937#issuecomment-3405208263 @fjtirado, before creating the IT tests, was it something like this that you were looking for? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] - To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Re: [PR] Issue-3936 Upgrade the REST custom functions to have visibility over the returned status code and headers [incubator-kie-kogito-runtimes]
oEscal commented on PR #3937: URL: https://github.com/apache/incubator-kie-kogito-runtimes/pull/3937#issuecomment-3401254070 > @oEscal Thats precisely what Im suggesting to do, you can access the last headers the same way you can access the last error code, through the WORKFLOW context, which is usable in expressions (so you can add them to the model if you want) That will only require changes in two classes, which is far more aligned with the current design. Ok, after taking a better look at the PR you mentioned, I think I am now getting the picture. I thought that the WORKFLOW.statusCode could only be obtained after the execution of the overall workflow. When I get some time in my hands, I will do as you advised, thank you @fjtirado -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] - To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Re: [PR] Issue-3936 Upgrade the REST custom functions to have visibility over the returned status code and headers [incubator-kie-kogito-runtimes]
kie-ci3 commented on PR #3937:
URL:
https://github.com/apache/incubator-kie-kogito-runtimes/pull/3937#issuecomment-3406737386
**PR job** `#23` was: **UNSTABLE**
Possible explanation: This should be test failures
Reproducer
build-chain build full_downstream -f
'https://raw.githubusercontent.com/${AUTHOR:apache}/incubator-kie-kogito-pipelines/${BRANCH:main}/.ci/buildchain-config-pr-cdb.yaml'
-o 'bc' -p apache/incubator-kie-kogito-runtimes -u
https://github.com/apache/incubator-kie-kogito-runtimes/pull/3937
--skipParallelCheckout
NOTE: To install the build-chain tool, please refer to
https://github.com/kiegroup/github-action-build-chain#local-execution
Please look here:
https://ci-builds.apache.org/job/KIE/job/kogito/job/main/job/pullrequest_jobs/job/kogito-runtimes-pr/job/PR-3937/23/display/redirect
**Test results:**
- PASSED: 3644
- FAILED: 3
Those are the test failures:
https://ci-builds.apache.org/job/KIE/job/kogito/job/main/job/pullrequest_jobs/job/kogito-runtimes-pr/job/PR-3937/23/testReport/org.kie.kogito.addons.quarkus.knative.serving.customfunctions.it/KnativeServingAddonIT/___/";>org.kie.kogito.addons.quarkus.knative.serving.customfunctions.it.KnativeServingAddonIT.(?)
java.lang.RuntimeException: io.quarkus.builder.BuildException: Build
failure: Build failed due to errors [error]: Build step
io.quarkus.devservices.keycloak.KeycloakDevServicesProcessor#startKeycloakContainer
threw an exception: java.lang.RuntimeException:
org.testcontainers.containers.ContainerLaunchException: Container startup
failed for image quay.io/keycloak/keycloak:26.1.3 at
io.quarkus.devservices.keycloak.KeycloakDevServicesProcessor.startKeycloakContainer(KeycloakDevServicesProcessor.java:250)
at
java.base/java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:732)
at
io.quarkus.deployment.ExtensionLoader$3.execute(ExtensionLoader.java:856)
at io.quarkus.builder.BuildContext.run(BuildContext.java:255) at
org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18) at
org.jboss.threads.EnhancedQueueExecutor$Task.doRunWith(EnhancedQueueExecutor.java:2675)
at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQu
eueExecutor.java:2654) at
org.jboss.threads.EnhancedQueueExecutor.runThreadBody(EnhancedQueueExecutor.java:1627)
at
org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1594)
at java.base/java.lang.Thread.run(Thread.java:840) at
org.jboss.threads.JBossThread.run(JBossThread.java:499)Caused by:
org.testcontainers.containers.ContainerLaunchException: Container startup
failed for image quay.io/keycloak/keycloak:26.1.3 at
org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:351)
at
org.testcontainers.containers.GenericContainer.start(GenericContainer.java:322)
at
io.quarkus.devservices.keycloak.KeycloakDevServicesProcessor.lambda$startContainer$4(KeycloakDevServicesProcessor.java:421)
at java.base/java.util.Optional.orElseGet(Optional.java:364) at
io.quarkus.devservices.keycloak.KeycloakDevServicesProcessor.startContainer(KeycloakDevServicesProcessor.java:447)
at io.quarkus.devser
vices.keycloak.KeycloakDevServicesProcessor.startKeycloakContainer(KeycloakDevServicesProcessor.java:200)
... 10 moreCaused by: org.rnorth.ducttape.RetryCountExceededException:
Retry limit hit with exception at
org.rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess(Unreliables.java:88)
at
org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:336)
... 15 moreCaused by:
org.testcontainers.containers.ContainerLaunchException: Could not create/start
container at
org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:556)
at
org.testcontainers.containers.GenericContainer.lambda$doStart$0(GenericContainer.java:346)
at
org.rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess(Unreliables.java:81)
... 16 moreCaused by:
org.testcontainers.containers.ContainerLaunchException: Timed out waiting for
log output matching '.*Keycloak.*started.*' at
org.testcontainers.containers.wait
.strategy.LogMessageWaitStrategy.waitUntilReady(LogMessageWaitStrategy.java:47)
at
org.testcontainers.containers.wait.strategy.AbstractWaitStrategy.waitUntilReady(AbstractWaitStrategy.java:52)
at
org.testcontainers.containers.GenericContainer.waitUntilContainerStarted(GenericContainer.java:909)
at
org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:492)
... 18 more
https://ci-builds.apache.org/job/KIE/job/kogito/job/main/job/pullrequest_jobs/job/kogito-runtimes-pr/job/PR-3937/23/testReport/org.kie.kogito.addons.quarkus.kubernetes/ConfigValueExpanderIT/test/";>org.kie.kogito.addons.quarkus.kubernetes.ConfigValueExpanderIT.test
java.lang.RuntimeException: io.quarkus.builder.BuildException: Build
failure: Build failed due to errors [error]: Build step
Re: [PR] Issue-3936 Upgrade the REST custom functions to have visibility over the returned status code and headers [incubator-kie-kogito-runtimes]
kie-ci3 commented on PR #3937:
URL:
https://github.com/apache/incubator-kie-kogito-runtimes/pull/3937#issuecomment-3403656704
**PR job** `#19` was: **UNSTABLE**
Possible explanation: This should be test failures
Reproducer
build-chain build full_downstream -f
'https://raw.githubusercontent.com/${AUTHOR:apache}/incubator-kie-kogito-pipelines/${BRANCH:main}/.ci/buildchain-config-pr-cdb.yaml'
-o 'bc' -p apache/incubator-kie-kogito-runtimes -u
https://github.com/apache/incubator-kie-kogito-runtimes/pull/3937
--skipParallelCheckout
NOTE: To install the build-chain tool, please refer to
https://github.com/kiegroup/github-action-build-chain#local-execution
Please look here:
https://ci-builds.apache.org/job/KIE/job/kogito/job/main/job/pullrequest_jobs/job/kogito-runtimes-pr/job/PR-3937/19/display/redirect
**Test results:**
- PASSED: 2722
- FAILED: 1
Those are the test failures:
https://ci-builds.apache.org/job/KIE/job/kogito/job/main/job/pullrequest_jobs/job/kogito-runtimes-pr/job/PR-3937/19/testReport/org.kie.kogito.addon.quarkus.messaging.common/QuarkusEventThreadPoolTest/testQuarkusEventThreadPoolMultiThreadTest/";>org.kie.kogito.addon.quarkus.messaging.common.QuarkusEventThreadPoolTest.testQuarkusEventThreadPoolMultiThreadTest
expected: <100> but was: <99>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
Re: [PR] Issue-3936 Upgrade the REST custom functions to have visibility over the returned status code and headers [incubator-kie-kogito-runtimes]
kie-ci3 commented on PR #3937:
URL:
https://github.com/apache/incubator-kie-kogito-runtimes/pull/3937#issuecomment-3417689482
**PR job** `#25` was: **UNSTABLE**
Possible explanation: This should be test failures
Reproducer
build-chain build full_downstream -f
'https://raw.githubusercontent.com/${AUTHOR:apache}/incubator-kie-kogito-pipelines/${BRANCH:main}/.ci/buildchain-config-pr-cdb.yaml'
-o 'bc' -p apache/incubator-kie-kogito-runtimes -u
https://github.com/apache/incubator-kie-kogito-runtimes/pull/3937
--skipParallelCheckout
NOTE: To install the build-chain tool, please refer to
https://github.com/kiegroup/github-action-build-chain#local-execution
Please look here:
https://ci-builds.apache.org/job/KIE/job/kogito/job/main/job/pullrequest_jobs/job/kogito-runtimes-pr/job/PR-3937/25/display/redirect
**Test results:**
- PASSED: 3657
- FAILED: 4
Those are the test failures:
https://ci-builds.apache.org/job/KIE/job/kogito/job/main/job/pullrequest_jobs/job/kogito-runtimes-pr/job/PR-3937/25/testReport/org.kie.kogito.serverless.workflow.executor/StaticFluentWorkflowApplicationTest/testEventPubSub/";>org.kie.kogito.serverless.workflow.executor.StaticFluentWorkflowApplicationTest.testEventPubSub
No value present
https://ci-builds.apache.org/job/KIE/job/kogito/job/main/job/pullrequest_jobs/job/kogito-runtimes-pr/job/PR-3937/25/testReport/org.kie.kogito.addons.quarkus.knative.serving.customfunctions.it/KnativeServingAddonIT/___/";>org.kie.kogito.addons.quarkus.knative.serving.customfunctions.it.KnativeServingAddonIT.(?)
java.lang.RuntimeException: io.quarkus.builder.BuildException: Build
failure: Build failed due to errors [error]: Build step
io.quarkus.devservices.keycloak.KeycloakDevServicesProcessor#startKeycloakContainer
threw an exception: java.lang.RuntimeException:
org.testcontainers.containers.ContainerLaunchException: Container startup
failed for image quay.io/keycloak/keycloak:26.1.3 at
io.quarkus.devservices.keycloak.KeycloakDevServicesProcessor.startKeycloakContainer(KeycloakDevServicesProcessor.java:250)
at
java.base/java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:732)
at
io.quarkus.deployment.ExtensionLoader$3.execute(ExtensionLoader.java:856)
at io.quarkus.builder.BuildContext.run(BuildContext.java:255) at
org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18) at
org.jboss.threads.EnhancedQueueExecutor$Task.doRunWith(EnhancedQueueExecutor.java:2675)
at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQu
eueExecutor.java:2654) at
org.jboss.threads.EnhancedQueueExecutor.runThreadBody(EnhancedQueueExecutor.java:1627)
at
org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1594)
at java.base/java.lang.Thread.run(Thread.java:840) at
org.jboss.threads.JBossThread.run(JBossThread.java:499)Caused by:
org.testcontainers.containers.ContainerLaunchException: Container startup
failed for image quay.io/keycloak/keycloak:26.1.3 at
org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:351)
at
org.testcontainers.containers.GenericContainer.start(GenericContainer.java:322)
at
io.quarkus.devservices.keycloak.KeycloakDevServicesProcessor.lambda$startContainer$4(KeycloakDevServicesProcessor.java:421)
at java.base/java.util.Optional.orElseGet(Optional.java:364) at
io.quarkus.devservices.keycloak.KeycloakDevServicesProcessor.startContainer(KeycloakDevServicesProcessor.java:447)
at io.quarkus.devser
vices.keycloak.KeycloakDevServicesProcessor.startKeycloakContainer(KeycloakDevServicesProcessor.java:200)
... 10 moreCaused by: org.rnorth.ducttape.RetryCountExceededException:
Retry limit hit with exception at
org.rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess(Unreliables.java:88)
at
org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:336)
... 15 moreCaused by:
org.testcontainers.containers.ContainerLaunchException: Could not create/start
container at
org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:556)
at
org.testcontainers.containers.GenericContainer.lambda$doStart$0(GenericContainer.java:346)
at
org.rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess(Unreliables.java:81)
... 16 moreCaused by:
org.testcontainers.containers.ContainerLaunchException: Timed out waiting for
log output matching '.*Keycloak.*started.*' at
org.testcontainers.containers.wait
.strategy.LogMessageWaitStrategy.waitUntilReady(LogMessageWaitStrategy.java:47)
at
org.testcontainers.containers.wait.strategy.AbstractWaitStrategy.waitUntilReady(AbstractWaitStrategy.java:52)
at
org.testcontainers.containers.GenericContainer.waitUntilContainerStarted(GenericContainer.java:909)
at
org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:492)
... 18 more
https://ci-builds.apache.org/job/KIE/job/ko
Re: [PR] Issue-3936 Upgrade the REST custom functions to have visibility over the returned status code and headers [incubator-kie-kogito-runtimes]
oEscal commented on PR #3937: URL: https://github.com/apache/incubator-kie-kogito-runtimes/pull/3937#issuecomment-3348051045 > @oEscal You need to take into account [PR](https://github.com/apache/incubator-kie-kogito-runtimes/pull/4014) which I bet you did not know it exist. > > This PR added support for $WORKFLOW.statusCode and $WORKFLOW.statusMessage. > > So, since there is already a way to access error status and error message, we just need to add access to response headers following a similar approach; by specifying metadata in the workflow definition file, , the response headers are made accesible through new $WORKFLOW context variable (rather than including them in the model directly) > > Unfortunately, This implies basically reimplementing the PR. RestWorkItemHandler and RestTypeHandler does not need to be modified, but JsonNodeResultHandler to check the new metadata and RestKogitoProcessContextResolver to add the context. Once you have that, you add a IT test with a new WorkflowDefinition using that metadata. Sorry about this and thanks for the efffort! @fjtirado yes, I later noticed that PR when fixing merge conflicts (because this PR was older). However, I think this PR is a bit different. Because the idea is not to access the headers or status code of the overall workflow, but instead to access the previously running function, so that the workflow and its actions and functions can use that data in their logic. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] - To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Re: [PR] Issue-3936 Upgrade the REST custom functions to have visibility over the returned status code and headers [incubator-kie-kogito-runtimes]
fjtirado commented on code in PR #3937:
URL:
https://github.com/apache/incubator-kie-kogito-runtimes/pull/3937#discussion_r2439423728
##
kogito-serverless-workflow/kogito-serverless-workflow-rest-runtime/src/main/java/org/kie/kogito/serverless/workflow/rest/RestKogitoProcessContextResolver.java:
##
@@ -24,13 +24,25 @@
import org.kie.kogito.internal.process.runtime.KogitoProcessContext;
import
org.kie.kogito.serverless.workflow.utils.KogitoProcessContextResolverExtension;
+import static
org.kie.kogito.serverless.workflow.rest.JsonNodeResultHandler.FAIL_ON_STATUS_ERROR;
+import static
org.kie.kogito.serverless.workflow.rest.JsonNodeResultHandler.RESPONSE_HEADERS;
+import static
org.kie.kogito.serverless.workflow.rest.JsonNodeResultHandler.RETURN_HEADERS;
+import static
org.kie.kogito.serverless.workflow.rest.JsonNodeResultHandler.RETURN_STATUS_CODE;
+import static
org.kie.kogito.serverless.workflow.rest.JsonNodeResultHandler.RETURN_STATUS_MESSAGE;
import static
org.kie.kogito.serverless.workflow.rest.JsonNodeResultHandler.STATUS_CODE;
import static
org.kie.kogito.serverless.workflow.rest.JsonNodeResultHandler.STATUS_MESSAGE;
public class RestKogitoProcessContextResolver implements
KogitoProcessContextResolverExtension {
+
@Override
public Map>
getKogitoProcessContextResolver() {
-return Map.of(JsonNodeResultHandler.STATUS_CODE, k ->
k.getVariable(STATUS_CODE),
-JsonNodeResultHandler.STATUS_MESSAGE, k ->
k.getVariable(STATUS_MESSAGE));
+return Map.of(
+JsonNodeResultHandler.RETURN_HEADERS, k ->
k.getVariable(RETURN_HEADERS),
+JsonNodeResultHandler.RETURN_STATUS_CODE, k ->
k.getVariable(RETURN_STATUS_CODE),
+JsonNodeResultHandler.RETURN_STATUS_MESSAGE, k ->
k.getVariable(RETURN_STATUS_MESSAGE),
+JsonNodeResultHandler.FAIL_ON_STATUS_ERROR, k ->
k.getVariable(FAIL_ON_STATUS_ERROR),
+JsonNodeResultHandler.STATUS_CODE, k ->
k.getVariable(STATUS_CODE),
+JsonNodeResultHandler.STATUS_MESSAGE, k ->
k.getVariable(STATUS_MESSAGE),
+JsonNodeResultHandler.RESPONSE_HEADERS, k ->
k.getVariable(RESPONSE_HEADERS));
Review Comment:
The only one that you need to add is RESPONSE_HEADERS
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
Re: [PR] Issue-3936 Upgrade the REST custom functions to have visibility over the returned status code and headers [incubator-kie-kogito-runtimes]
fjtirado commented on code in PR #3937:
URL:
https://github.com/apache/incubator-kie-kogito-runtimes/pull/3937#discussion_r2439423728
##
kogito-serverless-workflow/kogito-serverless-workflow-rest-runtime/src/main/java/org/kie/kogito/serverless/workflow/rest/RestKogitoProcessContextResolver.java:
##
@@ -24,13 +24,25 @@
import org.kie.kogito.internal.process.runtime.KogitoProcessContext;
import
org.kie.kogito.serverless.workflow.utils.KogitoProcessContextResolverExtension;
+import static
org.kie.kogito.serverless.workflow.rest.JsonNodeResultHandler.FAIL_ON_STATUS_ERROR;
+import static
org.kie.kogito.serverless.workflow.rest.JsonNodeResultHandler.RESPONSE_HEADERS;
+import static
org.kie.kogito.serverless.workflow.rest.JsonNodeResultHandler.RETURN_HEADERS;
+import static
org.kie.kogito.serverless.workflow.rest.JsonNodeResultHandler.RETURN_STATUS_CODE;
+import static
org.kie.kogito.serverless.workflow.rest.JsonNodeResultHandler.RETURN_STATUS_MESSAGE;
import static
org.kie.kogito.serverless.workflow.rest.JsonNodeResultHandler.STATUS_CODE;
import static
org.kie.kogito.serverless.workflow.rest.JsonNodeResultHandler.STATUS_MESSAGE;
public class RestKogitoProcessContextResolver implements
KogitoProcessContextResolverExtension {
+
@Override
public Map>
getKogitoProcessContextResolver() {
-return Map.of(JsonNodeResultHandler.STATUS_CODE, k ->
k.getVariable(STATUS_CODE),
-JsonNodeResultHandler.STATUS_MESSAGE, k ->
k.getVariable(STATUS_MESSAGE));
+return Map.of(
+JsonNodeResultHandler.RETURN_HEADERS, k ->
k.getVariable(RETURN_HEADERS),
+JsonNodeResultHandler.RETURN_STATUS_CODE, k ->
k.getVariable(RETURN_STATUS_CODE),
+JsonNodeResultHandler.RETURN_STATUS_MESSAGE, k ->
k.getVariable(RETURN_STATUS_MESSAGE),
+JsonNodeResultHandler.FAIL_ON_STATUS_ERROR, k ->
k.getVariable(FAIL_ON_STATUS_ERROR),
+JsonNodeResultHandler.STATUS_CODE, k ->
k.getVariable(STATUS_CODE),
+JsonNodeResultHandler.STATUS_MESSAGE, k ->
k.getVariable(STATUS_MESSAGE),
+JsonNodeResultHandler.RESPONSE_HEADERS, k ->
k.getVariable(RESPONSE_HEADERS));
Review Comment:
The only one that you need to add is RESPONSE_HEADERS (so there are three
variables that the user will check, status_code, status_mesage (already
present) and the response headers (added by this PR)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
Re: [PR] Issue-3936 Upgrade the REST custom functions to have visibility over the returned status code and headers [incubator-kie-kogito-runtimes]
fjtirado commented on code in PR #3937:
URL:
https://github.com/apache/incubator-kie-kogito-runtimes/pull/3937#discussion_r2439418785
##
kogito-serverless-workflow/kogito-serverless-workflow-rest-runtime/src/main/java/org/kie/kogito/serverless/workflow/rest/JsonNodeResultHandler.java:
##
@@ -33,18 +33,35 @@
public class JsonNodeResultHandler implements RestWorkItemHandlerResult {
-static final String STATUS_CODE = "statusCode";
-static final String STATUS_MESSAGE = "statusMessage";
+public static final String RETURN_HEADERS = "returnHeaders";
+public static final String RETURN_STATUS_CODE = "returnStatusCode";
+public static final String RETURN_STATUS_MESSAGE = "returnStatusMessage";
+public static final String FAIL_ON_STATUS_ERROR = "failOnStatusCode";
+public static final String STATUS_CODE = "statusCode";
+public static final String STATUS_MESSAGE = "statusMessage";
+public static final String RESPONSE_HEADERS = "responseHeaders";
@Override
public Object apply(HttpResponse t, Class u,
KogitoProcessContext context) {
Map metadata =
context.getNodeInstance().getNode().getMetaData();
-if (metadata == null ||
toBoolean(metadata.getOrDefault("failOnStatusCode", Boolean.TRUE))) {
+if (metadata == null ||
toBoolean(metadata.getOrDefault(FAIL_ON_STATUS_ERROR, Boolean.TRUE))) {
checkStatusCode(t);
-} else {
-context.setVariable(STATUS_CODE, t.statusCode());
-context.setVariable(STATUS_MESSAGE, t.statusMessage());
}
+
+if (metadata != null) {
+if (toBoolean(metadata.getOrDefault(RETURN_STATUS_CODE,
Boolean.TRUE))) {
Review Comment:
I do not think this check is needed at all, failOnstatusCode check is needed
because default behaviour when there is an error is to throw an exception, but
headers can be added to context outside the if-else, without need to check for
metadata
and setVariable status_code and setVariable status:message should remain as
they were (only added when failOnStatusCode is set to false)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
Re: [PR] Issue-3936 Upgrade the REST custom functions to have visibility over the returned status code and headers [incubator-kie-kogito-runtimes]
fjtirado commented on PR #3937: URL: https://github.com/apache/incubator-kie-kogito-runtimes/pull/3937#issuecomment-3361109813 @oEscal Thats precisely what Im suggesting to do, you can access the last headers the same way you can access the last error code, thourh the WORKFLOW context. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] - To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Re: [PR] Issue-3936 Upgrade the REST custom functions to have visibility over the returned status code and headers [incubator-kie-kogito-runtimes]
fjtirado commented on code in PR #3937:
URL:
https://github.com/apache/incubator-kie-kogito-runtimes/pull/3937#discussion_r2379192188
##
kogito-workitems/kogito-rest-workitem/src/main/java/org/kogito/workitem/rest/resulthandlers/DefaultRestWorkItemHandlerResult.java:
##
@@ -18,18 +18,100 @@
*/
package org.kogito.workitem.rest.resulthandlers;
+import java.util.HashMap;
import java.util.Map;
+import java.util.Spliterators;
+import java.util.stream.Collectors;
+import java.util.stream.StreamSupport;
+import org.kogito.workitem.rest.decorators.PrefixParamsDecorator;
+
+import com.fasterxml.jackson.databind.JsonNode;
+
+import io.vertx.core.json.DecodeException;
import io.vertx.mutiny.core.buffer.Buffer;
import io.vertx.mutiny.ext.web.client.HttpResponse;
import static
org.kogito.workitem.rest.RestWorkItemHandlerUtils.checkStatusCode;
public class DefaultRestWorkItemHandlerResult implements
RestWorkItemHandlerResult {
+public static final String STATUS_CODE_PARAM = "STATUS_CODE";
+
+private boolean returnHeaders = false;
+private boolean returnStatusCode = false;
+private boolean failOnStatusError = true;
+
Review Comment:
You need to keep the empty parametes constructor for compatibility. Declare
the three new fields as final and initilizaze them to defaults in the empty
parameter constructor
##
kogito-workitems/kogito-rest-workitem/src/main/java/org/kogito/workitem/rest/resulthandlers/DefaultRestWorkItemHandlerResult.java:
##
@@ -18,18 +18,100 @@
*/
package org.kogito.workitem.rest.resulthandlers;
+import java.util.HashMap;
import java.util.Map;
+import java.util.Spliterators;
+import java.util.stream.Collectors;
+import java.util.stream.StreamSupport;
+import org.kogito.workitem.rest.decorators.PrefixParamsDecorator;
+
+import com.fasterxml.jackson.databind.JsonNode;
+
+import io.vertx.core.json.DecodeException;
import io.vertx.mutiny.core.buffer.Buffer;
import io.vertx.mutiny.ext.web.client.HttpResponse;
import static
org.kogito.workitem.rest.RestWorkItemHandlerUtils.checkStatusCode;
public class DefaultRestWorkItemHandlerResult implements
RestWorkItemHandlerResult {
+public static final String STATUS_CODE_PARAM = "STATUS_CODE";
+
+private boolean returnHeaders = false;
+private boolean returnStatusCode = false;
+private boolean failOnStatusError = true;
+
+public DefaultRestWorkItemHandlerResult(boolean returnHeaders, boolean
returnStatusCode, boolean failOnStatusError) {
+this.returnHeaders = returnHeaders;
+this.returnStatusCode = returnStatusCode;
+this.failOnStatusError = failOnStatusError;
+}
+
@Override
public Object apply(HttpResponse response, Class target) {
-checkStatusCode(response);
-return target == null ? response.bodyAsJson(Map.class) :
response.bodyAsJson(target);
+if (this.failOnStatusError) {
+checkStatusCode(response);
+}
+
+Map result = new HashMap<>();
+
+try {
+Object body = target == null ? response.bodyAsJson(Map.class) :
response.bodyAsJson(target);
+
+if (!this.returnHeaders && !this.returnStatusCode) {
+return body;
+}
+
+if (body instanceof Map) {
+((Map) body).forEach((key, value) ->
result.put(String.valueOf(key), value));
+} else if (body instanceof JsonNode && ((JsonNode)
body).isObject()) {
+JsonNode node = (JsonNode) body;
Review Comment:
Here you should use the utility method I mentiones in another comment
##
kogito-workitems/kogito-rest-workitem/src/main/java/org/kogito/workitem/rest/resulthandlers/DefaultRestWorkItemHandlerResult.java:
##
@@ -18,18 +18,100 @@
*/
package org.kogito.workitem.rest.resulthandlers;
+import java.util.HashMap;
import java.util.Map;
+import java.util.Spliterators;
+import java.util.stream.Collectors;
+import java.util.stream.StreamSupport;
+import org.kogito.workitem.rest.decorators.PrefixParamsDecorator;
+
+import com.fasterxml.jackson.databind.JsonNode;
+
+import io.vertx.core.json.DecodeException;
import io.vertx.mutiny.core.buffer.Buffer;
import io.vertx.mutiny.ext.web.client.HttpResponse;
import static
org.kogito.workitem.rest.RestWorkItemHandlerUtils.checkStatusCode;
public class DefaultRestWorkItemHandlerResult implements
RestWorkItemHandlerResult {
+public static final String STATUS_CODE_PARAM = "STATUS_CODE";
+
+private boolean returnHeaders = false;
+private boolean returnStatusCode = false;
+private boolean failOnStatusError = true;
+
+public DefaultRestWorkItemHandlerResult(boolean returnHeaders, boolean
returnStatusCode, boolean failOnStatusError) {
+this.returnHeaders = returnHeaders;
+this.returnStatusCode = returnStatusCode;
+this.failOnStatusError = failOnStatusError;
+}
+
@Override
public Object appl
Re: [PR] Issue-3936 Upgrade the REST custom functions to have visibility over the returned status code and headers [incubator-kie-kogito-runtimes]
fjtirado commented on code in PR #3937:
URL:
https://github.com/apache/incubator-kie-kogito-runtimes/pull/3937#discussion_r2379185211
##
kogito-workitems/kogito-rest-workitem/src/main/java/org/kogito/workitem/rest/resulthandlers/DefaultRestWorkItemHandlerResult.java:
##
@@ -18,18 +18,100 @@
*/
package org.kogito.workitem.rest.resulthandlers;
+import java.util.HashMap;
import java.util.Map;
+import java.util.Spliterators;
+import java.util.stream.Collectors;
+import java.util.stream.StreamSupport;
+import org.kogito.workitem.rest.decorators.PrefixParamsDecorator;
+
+import com.fasterxml.jackson.databind.JsonNode;
+
+import io.vertx.core.json.DecodeException;
import io.vertx.mutiny.core.buffer.Buffer;
import io.vertx.mutiny.ext.web.client.HttpResponse;
import static
org.kogito.workitem.rest.RestWorkItemHandlerUtils.checkStatusCode;
public class DefaultRestWorkItemHandlerResult implements
RestWorkItemHandlerResult {
+public static final String STATUS_CODE_PARAM = "STATUS_CODE";
+
+private boolean returnHeaders = false;
+private boolean returnStatusCode = false;
+private boolean failOnStatusError = true;
+
+public DefaultRestWorkItemHandlerResult(boolean returnHeaders, boolean
returnStatusCode, boolean failOnStatusError) {
+this.returnHeaders = returnHeaders;
+this.returnStatusCode = returnStatusCode;
+this.failOnStatusError = failOnStatusError;
+}
+
@Override
public Object apply(HttpResponse response, Class target) {
-checkStatusCode(response);
-return target == null ? response.bodyAsJson(Map.class) :
response.bodyAsJson(target);
+if (this.failOnStatusError) {
+checkStatusCode(response);
+}
+
+Map result = new HashMap<>();
+
+try {
+Object body = target == null ? response.bodyAsJson(Map.class) :
response.bodyAsJson(target);
+
+if (!this.returnHeaders && !this.returnStatusCode) {
+return body;
+}
+
+if (body instanceof Map) {
+((Map) body).forEach((key, value) ->
result.put(String.valueOf(key), value));
+} else if (body instanceof JsonNode && ((JsonNode)
body).isObject()) {
+JsonNode node = (JsonNode) body;
+node.fields().forEachRemaining(entry ->
result.put(entry.getKey(), extractJsonNodeValue(entry.getValue(;
+} else {
+result.put("body", body);
+}
+} catch (DecodeException e) {
+result.put("body", response.bodyAsString());
+}
+
+if (this.returnHeaders) {
+response.headers().forEach(entry ->
result.put(PrefixParamsDecorator.HEADER_PREFIX + entry.getKey(),
entry.getValue()));
+}
+if (this.returnStatusCode) {
+result.put(STATUS_CODE_PARAM, response.statusCode());
+}
+
+return result;
+}
+
+private static Object extractJsonNodeValue(JsonNode node) {
+if (node.isTextual())
+return node.textValue();
+if (node.isInt())
+return node.intValue();
+if (node.isLong())
+return node.longValue();
+if (node.isDouble())
+return node.doubleValue();
+if (node.isBoolean())
+return node.booleanValue();
+if (node.isNull())
+return null;
+if (node.isArray()) {
+// Wrap the Iterator in a Spliterator and create a Stream
+return StreamSupport.stream(
+Spliterators.spliteratorUnknownSize(node.elements(), 0),
+false)
+
.map(DefaultRestWorkItemHandlerResult::extractJsonNodeValue)
+.collect(Collectors.toList());
+}
+if (node.isObject()) {
+// Handle objects by recursively processing each field
+Map result = new HashMap<>();
+node.fields().forEachRemaining(entry -> result.put(entry.getKey(),
extractJsonNodeValue(entry.getValue(;
+return result;
+}
+return node.toString();
}
Review Comment:
Better to reuse this function
https://github.com/apache/incubator-kie-kogito-runtimes/blob/main/kogito-workitems/kogito-jackson-utils/src/main/java/org/kie/kogito/jackson/utils/JsonObjectUtils.java#L112
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
Re: [PR] Issue-3936 Upgrade the REST custom functions to have visibility over the returned status code and headers [incubator-kie-kogito-runtimes]
oEscal commented on PR #3937: URL: https://github.com/apache/incubator-kie-kogito-runtimes/pull/3937#issuecomment-3328672079 @ricardozanini @gmunozfe @wmedvede @fjtirado could you take a look into this PR when you have the time? :) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] - To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Re: [PR] Issue-3936 Upgrade the REST custom functions to have visibility over the returned status code and headers [incubator-kie-kogito-runtimes]
kie-ci3 commented on PR #3937:
URL:
https://github.com/apache/incubator-kie-kogito-runtimes/pull/3937#issuecomment-2905018647
**PR job** `#2` was: **UNSTABLE**
Possible explanation: This should be test failures
Reproducer
build-chain build full_downstream -f
'https://raw.githubusercontent.com/${AUTHOR:apache}/incubator-kie-kogito-pipelines/${BRANCH:main}/.ci/buildchain-config-pr-cdb.yaml'
-o 'bc' -p apache/incubator-kie-kogito-runtimes -u
https://github.com/apache/incubator-kie-kogito-runtimes/pull/3937
--skipParallelCheckout
NOTE: To install the build-chain tool, please refer to
https://github.com/kiegroup/github-action-build-chain#local-execution
Please look here:
https://ci-builds.apache.org/job/KIE/job/kogito/job/main/job/pullrequest_jobs/job/kogito-runtimes-pr/job/PR-3937/2/display/redirect
**Test results:**
- PASSED: 2252
- FAILED: 1
Those are the test failures:
https://ci-builds.apache.org/job/KIE/job/kogito/job/main/job/pullrequest_jobs/job/kogito-runtimes-pr/job/PR-3937/2/testReport/org.kie.kogito.codegen.rules/PublishEventBusinessRuleIT/testBusinessRuleProcessStartToEndWithVariableTracked/";>org.kie.kogito.codegen.rules.PublishEventBusinessRuleIT.testBusinessRuleProcessStartToEndWithVariableTracked
Expected size: 10 but was: 21 in:[ProcessInstanceStateDataEvent
{specVersion=1.0, id='d1609528-6f1d-4f88-978e-1207fa6253de',
source=http://myhost/TimerProcess, type='ProcessInstanceStateDataEvent',
time=2025-05-23T12:05:41.075679929-04:00, subject='null',
dataContentType='application/json', dataSchema=null,
data=ProcessInstanceStateEventBody [eventDate=Fri May 23 12:05:41 EDT 2025,
eventUser=null, eventType=1, processId=defaultPackage.TimerProcess,
processVersion=1.0, processType=BPMN,
processInstanceId=3e524fb4-c2d8-4f23-8252-48d29fec7fb4, businessKey=null,
processName=TimerProcess, parentInstanceId=null, rootProcessId=null,
rootProcessInstanceId=null, state=1, roles=null, cloudEventId=null
,cloudEventSource=null],
kogitoProcessInstanceId='3e524fb4-c2d8-4f23-8252-48d29fec7fb4',
kogitoRootProcessInstanceId='null',
kogitoProcessId='defaultPackage.TimerProcess', kogitoRootProcessId='null',
kogitoAddons='test', kogitoIdentity='null',
extensionAttributes={kogitoproctype=BPMN
, kogitoprocinstanceid=3e524fb4-c2d8-4f23-8252-48d29fec7fb4, kogitoprocist=1,
kogitoprocversion=1.0, kogitoprocid=defaultPackage.TimerProcess,
kogitoaddons=test}},ProcessInstanceNodeDataEvent {specVersion=1.0,
id='d0c6ad3e-b908-4a49-82dd-33524219f26a', source=http://myhost/TimerProcess,
type='ProcessInstanceNodeDataEvent', time=2025-05-23T12:05:41.069769043-04:00,
subject='null', dataContentType='application/json', dataSchema=null,
data=ProcessInstanceNodeEventBody [eventDate=Fri May 23 12:05:41 EDT 2025,
eventUser=null, eventType=1, processId=defaultPackage.TimerProcess,
processVersion=1.0, processInstanceId=3e524fb4-c2d8-4f23-8252-48d29fec7fb4,
connectionNodeInstanceId=null,
nodeDefinitionId=_F9AC8B12-8E75-49B5-B799-292F66270627, nodeName=start,
nodeType=StartNode, nodeInstanceId=057bbb5b-a938-4dc3-8428-7ff9144ac57a,
data={}], kogitoProcessInstanceId='3e524fb4-c2d8-4f23-8252-48d29fec7fb4',
kogitoRootProcessInstanceId='null',
kogitoProcessId='defaultPackage.TimerProcess',
kogitoRootProcessId='null', kogitoAddons='test', kogitoIdentity='null',
extensionAttributes={kogitoproctype=BPMN,
kogitoprocinstanceid=3e524fb4-c2d8-4f23-8252-48d29fec7fb4, kogitoprocist=1,
kogitoprocversion=1.0, kogitoprocid=defaultPackage.TimerProcess,
kogitoaddons=test}},ProcessInstanceNodeDataEvent {specVersion=1.0,
id='7c0862ce-a6a0-42b7-975e-38e465454037', source=http://myhost/TimerProcess,
type='ProcessInstanceNodeDataEvent', time=2025-05-23T12:05:41.070106988-04:00,
subject='null', dataContentType='application/json', dataSchema=null,
data=ProcessInstanceNodeEventBody [eventDate=Fri May 23 12:05:41 EDT 2025,
eventUser=null, eventType=1, processId=defaultPackage.TimerProcess,
processVersion=1.0, processInstanceId=3e524fb4-c2d8-4f23-8252-48d29fec7fb4,
connectionNodeInstanceId=SequenceFlow_2,
nodeDefinitionId=_E76AD186-6FA6-4378-B45B-C8F73E2C497C, nodeName=timer fired,
nodeType=ActionNode, nodeInstanceId=38f58dbd-179a-4849-b5c6-9cb665be0e6d,
data={}], kogitoProcessInsta
nceId='3e524fb4-c2d8-4f23-8252-48d29fec7fb4',
kogitoRootProcessInstanceId='null',
kogitoProcessId='defaultPackage.TimerProcess', kogitoRootProcessId='null',
kogitoAddons='test', kogitoIdentity='null',
extensionAttributes={kogitoproctype=BPMN,
kogitoprocinstanceid=3e524fb4-c2d8-4f23-8252-48d29fec7fb4, kogitoprocist=1,
kogitoprocversion=1.0, kogitoprocid=defaultPackage.TimerProcess,
kogitoaddons=test}},ProcessInstanceNodeDataEvent {specVersion=1.0,
id='ab214405-a58d-4da9-8796-61a06862f577', source=http://myhost/TimerProcess,
type='ProcessInstanceNodeDataEvent', time=2025-05-23T12:05:41.070645548-04:00,
subject='null', dataCo
Re: [PR] Issue-3936 Upgrade the REST custom functions to have visibility over the returned status code and headers [incubator-kie-kogito-runtimes]
oEscal commented on PR #3937: URL: https://github.com/apache/incubator-kie-kogito-runtimes/pull/3937#issuecomment-2904796429 This implementation is still a draft as I think some tests should be created. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] - To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
