davsclaus commented on code in PR #26203:
URL: https://github.com/apache/camel/pull/26203#discussion_r4136511273
##########
components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/RestOpenApiProcessor.java:
##########
@@ -130,18 +161,60 @@ public boolean process(Exchange exchange, AsyncCallback
callback) {
final String contextPath = path;
List<String> allow = METHODS.stream()
.filter(v -> RestConsumerContextPathMatcher.matchBestPath(v,
contextPath, paths) != null).toList();
- if (allow.isEmpty()) {
- exchange.getMessage().setHeader(Exchange.HTTP_RESPONSE_CODE, 404);
- } else {
- exchange.getMessage().setHeader(Exchange.HTTP_RESPONSE_CODE, 405);
- // include list of allowed VERBs
- exchange.getMessage().setHeader("Allow", String.join(", ", allow));
- }
+ return answerUnmatchedRequest(exchange, callback, allow.isEmpty() ?
404 : 405, allow);
+ }
+
+ /**
+ * Lets the resolved (default or custom) {@link
RestUnmatchedRequestHandler} answer a request that Camel must not
+ * process, such as requests that match no operation of the OpenAPI
specification or requests failing
+ * Content-Type/Accept negotiation when server request validation is
enabled.
+ */
+ private boolean answerUnmatchedRequest(
+ Exchange exchange, AsyncCallback callback, int statusCode,
+ List<String> allowedMethods) {
+ unmatchedRequestHandler.handle(exchange, statusCode, allowedMethods);
exchange.setRouteStop(true);
callback.done(true);
return true;
}
+ /**
+ * Whether the given Content-Type or Accept header value matches the
consumes/produces of the operation. Unlike
+ * RestUtil#isValidOrAcceptedContentType, the parameters of each part are
stripped and subtype wildcards are
+ * supported.
+ */
+ static boolean isValidOrAcceptedContentType(String valid, String target) {
Review Comment:
Understood on keeping this separate from `RestUtil`. FYI, CAMEL-25046
(#26927, merged yesterday) already changed
`RestUtil.isValidOrAcceptedContentType` on main to strip parameters per
comma-separated part, so after a rebase the only difference left is the
`type/*` wildcard. Not blocking: a follow-up could add the wildcard to
`RestUtil` and drop this copy.
--
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]