gmunozfe commented on code in PR #4078:
URL:
https://github.com/apache/incubator-kie-kogito-runtimes/pull/4078#discussion_r2851758409
##########
kogito-codegen-modules/kogito-codegen-processes/src/main/resources/class-templates/RestResourceQuarkusTemplate.java:
##########
@@ -94,10 +100,32 @@ public class $Type$Resource {
}
@GET
- @Produces(MediaType.APPLICATION_JSON)
+ @Produces({MediaType.APPLICATION_JSON, MediaType.TEXT_HTML})
@Operation(operationId = "getAllProcessInstances_$name$", summary =
"$documentation$", description = "$processInstanceDescription$")
- public List<$Type$Output> getResources_$name$() {
- return processService.getProcessInstanceOutput(process);
+ public Response getResources_$name$(@Context HttpHeaders headers) {
+ List<$Type$Output> out =
processService.getProcessInstanceOutput(process);
+ boolean wantsHtml = headers.getAcceptableMediaTypes()
+ .stream()
+ .anyMatch(mt -> mt.isCompatible(MediaType.TEXT_HTML_TYPE) &&
!mt.isWildcardType());
Review Comment:
You could also cover the case when receiving "text/*", which with the
current proposal is considered as HTML. You could add an enforcement clause to
check a wildcard subtype like this:
```suggestion
.anyMatch(mt -> mt.isCompatible(MediaType.TEXT_HTML_TYPE) &&
!mt.isWildcardType() && !mt.isWildcardSubtype());
```
##########
kogito-codegen-modules/kogito-codegen-processes/src/main/resources/class-templates/RestResourceQuarkusTemplate.java:
##########
@@ -94,10 +100,32 @@ public class $Type$Resource {
}
@GET
- @Produces(MediaType.APPLICATION_JSON)
+ @Produces({MediaType.APPLICATION_JSON, MediaType.TEXT_HTML})
@Operation(operationId = "getAllProcessInstances_$name$", summary =
"$documentation$", description = "$processInstanceDescription$")
- public List<$Type$Output> getResources_$name$() {
- return processService.getProcessInstanceOutput(process);
+ public Response getResources_$name$(@Context HttpHeaders headers) {
+ List<$Type$Output> out =
processService.getProcessInstanceOutput(process);
+ boolean wantsHtml = headers.getAcceptableMediaTypes()
+ .stream()
+ .anyMatch(mt -> mt.isCompatible(MediaType.TEXT_HTML_TYPE) &&
!mt.isWildcardType());
+
+ if (wantsHtml) {
+ InputStream htmlStream =
getClass().getResourceAsStream("/META-INF/resources/index.html");
+ if (htmlStream == null) {
+ return Response.status(Response.Status.NOT_FOUND)
+ .entity("HTML resource not found")
+ .build();
+ }
+
+ StreamingOutput stream = os -> {
+ try (InputStream inputStream = htmlStream) {
Review Comment:
Why don't open the inputStream only when the body is actually written?
```suggestion
try (InputStream inputStream =
getClass().getResourceAsStream(path)) {
```
##########
kogito-codegen-modules/kogito-codegen-processes/src/main/resources/class-templates/RestResourceQuarkusTemplate.java:
##########
@@ -94,10 +100,32 @@ public class $Type$Resource {
}
@GET
- @Produces(MediaType.APPLICATION_JSON)
+ @Produces({MediaType.APPLICATION_JSON, MediaType.TEXT_HTML})
@Operation(operationId = "getAllProcessInstances_$name$", summary =
"$documentation$", description = "$processInstanceDescription$")
- public List<$Type$Output> getResources_$name$() {
- return processService.getProcessInstanceOutput(process);
+ public Response getResources_$name$(@Context HttpHeaders headers) {
+ List<$Type$Output> out =
processService.getProcessInstanceOutput(process);
+ boolean wantsHtml = headers.getAcceptableMediaTypes()
+ .stream()
+ .anyMatch(mt -> mt.isCompatible(MediaType.TEXT_HTML_TYPE) &&
!mt.isWildcardType());
+
+ if (wantsHtml) {
+ InputStream htmlStream =
getClass().getResourceAsStream("/META-INF/resources/index.html");
+ if (htmlStream == null) {
+ return Response.status(Response.Status.NOT_FOUND)
+ .entity("HTML resource not found")
+ .build();
+ }
Review Comment:
Check resource existence before creating the inputStream:
```
String path = "/META-INF/resources/index.html";
if (getClass().getResource(path) == null) {
return Response.status(Response.Status.NOT_FOUND)
.entity("HTML resource not found")
.build();
}
```
--
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]