[ 
https://issues.apache.org/jira/browse/CAMEL-22116?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17955485#comment-17955485
 ] 

Bjorn Beskow commented on CAMEL-22116:
--------------------------------------

Great, thanks! So the fix is 
[https://github.com/apache/camel-spring-boot/commit/f73942b48973eee325430e8db13bc5e1b2e1a893:]

 
{code:java}
    @Override
    protected String getRawPath(HttpServletRequest request) {
        String uri = request.getRequestURI();
        String contextPath = request.getContextPath() == null ? "" : 
request.getContextPath();
        String servletPath = request.getServletPath() == null ? "" : 
request.getServletPath();
        if (contextPath.isEmpty()) {
            return servletPath;
        }
        return uri.substring(contextPath.length() + servletPath.length());
    } {code}
 I'm however puzzled by the if statement. I can see how the fix solves the 
problem when contextPath is not used (i.e. is empty). But if context-path is 
non-empty, we however end up in the same behavior - rawPath evaluates to ''.

If getRawPath() is simplified like this:
{code:java}
@Override
protected String getRawPath(HttpServletRequest request) {
    String contextPath = request.getContextPath() == null ? "" : 
request.getContextPath();
    String servletPath = request.getServletPath() == null ? "" : 
request.getServletPath();
    return contextPath + servletPath;
} {code}
it works correctly for both with and without a server.servlet.context-path set.

> camel-openapi-validator doesn't work for contract-first api's with Spring Boot
> ------------------------------------------------------------------------------
>
>                 Key: CAMEL-22116
>                 URL: https://issues.apache.org/jira/browse/CAMEL-22116
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-spring-boot, rest
>    Affects Versions: 4.10.4, 4.11.0
>            Reporter: Bjorn Beskow
>            Assignee: Claus Ibsen
>            Priority: Minor
>             Fix For: 4.8.8, 4.10.6, 4.13.0
>
>
> Using camel-openapi-validator with an contract-first api such as 
> [https://github.com/apache/camel-spring-boot-examples/openapi-contract-first] 
> results in an HTTP 400 for all endpoints:
>  
> {code:java}
> > curl http://localhost:8080/api/v3/pet/1
> Validation failed.
> [ERROR][GET ] No API path found that matches request ''.{code}
> This is caused by the CamelHttpPath set to '' by camel-platform-http, which 
> is used to select endpoint from the openapi specification.
> The "CamelPlatformHttpContextPath" is however correctly set by 
> SpringBootPlatformHttpConsumer, and hence the correct value for path can be 
> calculated:
> {code:java}
> String path = exchange.getMessage().getHeader(Exchange.HTTP_PATH, 
> String.class);
> // Workaround for camel-platform-http which does not properly set HTTP_PATH 
> header
> if (StringUtils.isEmpty(path)) {
>     String uri = exchange.getMessage().getHeader(Exchange.HTTP_URI, 
> String.class);
>     String contextPath = 
> exchange.getMessage().getHeader("CamelPlatformHttpContextPath", String.class);
>     if (StringUtils.isNotEmpty(contextPath) && uri.startsWith(contextPath)) {
>         path = uri.substring(contextPath.length());
>     }
> } {code}
> With path correctly set, the corresponding endpoint can be found in the 
> openapi specification, which corrects the problem.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to