如何在JavaQuarkus

问题描述 投票:0回答:1
@GET @Path(API_RESOURCE_IMAGE_REPORT) @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.TEXT_HTML) @Operation(summary = "", description = "") @APIResponses( value = { @APIResponse( responseCode = "200", description = "Request successful", content = @Content(mediaType = MediaType.TEXT_HTML)), @APIResponse( responseCode = "404", description = "Resource not found ", content = @Content( mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = NotFoundException.class))), }) public Response getReport(@Parameter( description = "", required = true) @PathParam("imageName") final String imageName, @Parameter(description = "", required = true) @PathParam("tag") final String tag, @Parameter(description = "") @PathParam("type") String type ) { InputStream report = jenkinsClient.getReport(imageName, tag, type); return Response.status(HttpURLConnection.HTTP_ACCEPTED).entity(report).build(); }

Jenkinsclient:

public InputStream getReport(final String imageName, final String tag, final String type) throws NotFoundException { try { final int lastSuccessfulBuildnumber = jenkinsClient.api().jobsApi().jobInfo(imageName, tag).lastSuccessfulBuild().number(); LOG.info("Last successful buildnumber: " + lastSuccessfulBuildnumber); final InputStream report = jenkinsClient.api().jobsApi().artifact(imageName, tag, lastSuccessfulBuildnumber, Objects.equals(type, "image") ? "trivy_image_report.html" : "trivy_Dockerfile_report.html"); if (report == null) { throw new NotFoundException("No dockerfile or image report found"); } return report; } catch (Exception e) { throw new NotFoundException("No dockerfile or image scan report found"); } }

I期望有404个消息,并带有“未找到的dockerfile或图像扫描报告”。但是当我找不到人工制品时,我只得到了404个没有消息的404。我将“ javax.ws.rs.notfoundexception”用于NotFoundException.

感谢您的帮助
    

在评论中感谢Nikos Paraskevopoulos。 我在这样的例外添加了响应状态:

throw new NotFoundException(Response.status(HttpURLConnection.HTTP_NOT_FOUND).entity("your message").build());

这个工作正常,我在响应主体中有信息

java http-status-code-404 response quarkus
1个回答
0
投票


最新问题
© www.soinside.com 2019 - 2025. All rights reserved.