[ 
https://issues.apache.org/jira/browse/CAMEL-12855?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Zoran Regvart updated CAMEL-12855:
----------------------------------
    Issue Type: New Feature  (was: Bug)

> 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: New Feature
>          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)

Reply via email to