oEscal commented on code in PR #3939:
URL:
https://github.com/apache/incubator-kie-kogito-runtimes/pull/3939#discussion_r2946288022
##########
quarkus/addons/knative/serving/runtime/src/main/java/org/kie/kogito/addons/quarkus/knative/serving/customfunctions/PlainJsonKnativeParamsDecorator.java:
##########
@@ -37,12 +45,44 @@ public void decorate(KogitoWorkItem workItem, Map<String,
Object> parameters, Ht
if
(isCloudEvent(KnativeFunctionPayloadSupplier.getPayload(parameters))) {
throw new
IllegalArgumentException(CLOUDEVENT_SENT_AS_PLAIN_JSON_ERROR_MESSAGE);
}
-
- super.decorate(workItem, parameters, request);
+ buildFromParams(workItem, parameters, request);
}
private static boolean isCloudEvent(Map<String, Object> payload) {
List<String> cloudEventMissingAttributes =
CloudEventUtils.getMissingAttributes(payload);
return !payload.isEmpty() && (cloudEventMissingAttributes.isEmpty() ||
(cloudEventMissingAttributes.size() == 1 &&
cloudEventMissingAttributes.contains(ID)));
}
+
+ private void buildFromParams(KogitoWorkItem workItem, Map<String, Object>
parameters, HttpRequest<?> request) {
+ Map<String, Object> inputModel = new HashMap<>();
+
+ Object inputModelObject = parameters.get(MODEL_WORKFLOW_VAR);
+
+ ObjectNode inputModelCopy = null;
+ if (inputModelObject instanceof ObjectNode objectNode) {
+ ObjectMapper mapper = new ObjectMapper();
+ objectNode.fields().forEachRemaining(entry -> {
+ JsonNode value = entry.getValue();
+ Object rawValue = mapper.convertValue(value, Object.class);
+ inputModel.put(entry.getKey(), rawValue);
+ });
+
+ try {
+ inputModelCopy = (ObjectNode)
mapper.readTree(objectNode.toString());
+ } catch (JsonProcessingException e) {
+ throw new RuntimeException("Failed to copy
MODEL_WORKFLOW_VAR", e);
+ }
+ }
+
+ Set<String> paramsRemove = super.extractHeadersQueries(workItem,
inputModel, request);
+ super.decorate(workItem, parameters, request);
+
+ if (inputModelCopy != null) {
+ // mutate the safe copy
+ inputModelCopy.remove(paramsRemove);
+
+ // replace the original entry in parameters with the copy
+ parameters.put(MODEL_WORKFLOW_VAR, inputModelCopy);
+ }
Review Comment:
I implemented this a long time ago. But from what I remember, this was to
avoid sending the headers and queries from the params (HEADER_* and QUERY_*) as
arguments to the service when they are already processed as headers and
queries. But yes, I agree with you; this is too confusing at the moment. I will
find another way of doing this more cleanly.
--
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]