You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@camel.apache.org by "Zoran Regvart (JIRA)" <ji...@apache.org> on 2018/10/05 09:57:00 UTC

[jira] [Commented] (CAMEL-12855) camel-swagger-java not honoring the x-forwarded-[host,proto,prefix] headers.

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

Zoran Regvart commented on CAMEL-12855:
---------------------------------------

[~thiagolocatelli] I think this is a valid approach, please if you can submit the PR. I'm only wondering if this behaviour should be always on, but I guess if this behaviour is unwanted then those {{X-Forwarded}} headers can be removed before this code path. Thank you for your detailed report and analysis.

> camel-swagger-java not honoring the x-forwarded-[host,proto,prefix] headers.
> ----------------------------------------------------------------------------
>
>                 Key: CAMEL-12855
>                 URL: https://issues.apache.org/jira/browse/CAMEL-12855
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-swagger
>    Affects Versions: 2.22.1
>            Reporter: Thiago Locatelli
>            Priority: Major
>
> We have a camel spring boot application sitting behind an api gateway with a Swagger page for accessing the documentation for all of our services (created with Spring Boot and Zuul Proxy, Consul as service discovery). The Swagger gateway sends three headers to the camel application to retrieve the swagger docs, but camel-swagger-java is not honoring those headers, thus the attributes host, basePath and schemes remain the same as if the swagger documentation was being acessed directly.
> Example, when trying to get the swagger docs for our customer-service camel application:
> [https://api-gateway.dev-internal.io/api-gateway/customer-service/v2/api-docs]
>  
> {code:java}
> x-forwarded-prefix: /api-gateway/
> x-forwarded-host: api-gateway.dev-internal.io
> x-forwarded-proto: https,http{code}
>  
> The expected results should be
> {code:java}
> {
>     "swagger": "2.0",
>     ...
>     "host": "api-gateway.dev-internal.io",
>     "basePath": "/api-gateway/customer-service",
>     "schemes": [ "https", "http" ]
>     ...
> }{code}
> Current results:
> {code:java}
> {
>     "swagger": "2.0",
>     ...
>     "host": "",
>     "basePath": "/customer-service",
>     "schemes": [ "http" ]
>     ...
> }{code}
>  
> we had a simple solution, which might not be the correct one. We changed the RestSwaggerSupport.java:
>  
> {code:java}
> public class RestSwaggerSupport {
>     private static final String X_FORWARDED_PREFIX = "X-Forwarded-Prefix";     
>     private static final String X_FORWARDED_HOST = "X-Forwarded-Host";
>     public void renderResourceListing(RestApiResponseAdapter response, BeanConfig swaggerConfig, String contextId, String route, boolean json, boolean yaml, Exchange exchange, ClassResolver classResolver, RestConfiguration configuration, String prefix) throws Exception {
>     ...
>         Swagger swagger = reader.read(rests, route, swaggerConfig, contextId, exchange == null ? classResolver : exchange.getContext().getClassResolver());   
>         setupXForwardedHeaders(swagger, exchange);
>     ...
>     }
>     private void setupXForwardedHeaders(Swagger swagger, Exchange exchange) {
>         if (exchange.getIn().getHeaders().containsKey(X_FORWARDED_PREFIX)) {
>             String prefix = exchange.getIn().getHeader(X_FORWARDED_PREFIX, String.class);
>             prefix = prefix.replace("/", "");
>             if (prefix != null) {
>                 String path = swagger.getBasePath();
>                 path = "/" + prefix + path;
>                 swagger.setBasePath(path);
>             }
>         }
>         if(exchange.getIn().getHeaders().containsKey(X_FORWARDED_HOST)) {
>             String host = exchange.getIn().getHeader(X_FORWARDED_HOST, String.class);
>             if(host != null && host.length() > 0) {
>                 swagger.setHost(host);
>             }
>         }
>     ...
> }
> {code}
>  
> If this is a valid approach, I will submit a PR. 
>  
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)