You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Jonas Koperdraat <jo...@jonaskoperdraat.nl> on 2016/11/02 13:57:10 UTC

'host' configuration param not used by servlet

I have a REST API for which I am exposing a swagger definitiion using
camel-swagger-java. The application is deployed behind a proxy,
because of which I need to change host used in the generated swagger
documentation. Currently, the internal hostname of the actual machine
is being used, based on the host in the request. Because I want to
make the swagger api public, I need this to be the public hostname,
that which is configured in the proxy.

According to the documentation of camel-swagger-java
(http://camel.apache.org/swagger-java.html), the 'host' option allows
me to do just that; "To setup the hostname." However, this seems not
to be working. I have looked ad the code, and it seems to me, that
there is something wrong with the implementation of the
RestSwaggerServlet:

In org.apache.camel.swagger.servlet.RestSwaggerServlet, there's the
method doGet, which is called for each request. The first time this is
called, 'initBaseAndApiPaths' is called to do some initialization.
Debugging shows that when entering this method, the 'host'
configuration is propertly set to the value specified in my web.xml
file. However, the logic in this method is such that the host will
always be overridden with the host of the request url, thereby
rendering the 'host' configuration parameter useless.

It seems to me that this is a bug, but I might be mistaken, Is anyone
else familiar with this problem and aware of a solution/workaround?

Kind regards,

Jonas

Re: 'host' configuration param not used by servlet

Posted by Pontus Ullgren <ul...@gmail.com>.
I agree with Jonas original comment.

Since camel-swagger-java allows for explicitly setting a hostname it should
have precedence over the hostname taken from the servlet context
(regardless if it in turn is taken from 'X-Forwarded-Host' or 'Host').

@Jonas: I would suggest that you log a Jira with your findings.

// Pontus


On Fri, 11 Nov 2016 at 03:26 Vitalii Tymchyshyn <vi...@tym.im> wrote:

> In Tomcat you can add
>
> https://tomcat.apache.org/tomcat-7.0-doc/api/org/apache/catalina/valves/RemoteIpValve.html
>
> Ср, 2 лист. 2016 о 13:51 Jonas Koperdraat <jo...@jonaskoperdraat.nl> пише:
>
> > Hi Zoran,
> >
> > I've checked and the proxy sets the 'X-Forwarded-Host' header and this
> > contains the 'correct' host. The 'Host' header is also present on the
> > request and this contains the hostname of the actual machine the servlet
> is
> > running on. I'm not sure if we have the option to set it, but seeing as
> we
> > already have the desired hostname available in de 'X-Forwarded-Host'
> option
> > I'm not going to investigate that further ;-)
> >
> > But I guess our servlet container, which indeed is Tomcat, doesn't take
> the
> > X-Forwarded-Host header into consideration when constructing the
> requestUrl
> > parameter of the SerlvetRequest. So we'll have to manually insert the
> > desired hostname into the request url.
> >
> > Kind regards,
> >
> > Jonas
> >
> > Op wo 2 nov. 2016 om 16:33 schreef Zoran Regvart <zr...@redhat.com>:
> >
> > > Hi Jonas,
> > >
> > > On Wed, Nov 2, 2016 at 4:25 PM, Jonas Koperdraat
> > > <jo...@jonaskoperdraat.nl> wrote:
> > > > I don't know whether that header is being sent by the proxy. Should
> > that
> > > > impact the behavior I am seeing (e.g. should does that influence the
> > > result
> > > > of getRequestURL)?
> > >
> > > It does on some Servlet engines / middlewares, it might not in your
> > > case, especially if you're using Tomcat.
> > >
> > > Another header that you might want to investigate is the `Host`
> > > header, it's used for virtual hosts, and you might have an option to
> > > set it in your proxy (on the request sent to the backend).
> > >
> > > zoran
> > > --
> > > Zoran Regvart
> > > zregvart@redhat.com
> > >
> >
>

Re: 'host' configuration param not used by servlet

Posted by Vitalii Tymchyshyn <vi...@tym.im>.
In Tomcat you can add
https://tomcat.apache.org/tomcat-7.0-doc/api/org/apache/catalina/valves/RemoteIpValve.html

Ср, 2 лист. 2016 о 13:51 Jonas Koperdraat <jo...@jonaskoperdraat.nl> пише:

> Hi Zoran,
>
> I've checked and the proxy sets the 'X-Forwarded-Host' header and this
> contains the 'correct' host. The 'Host' header is also present on the
> request and this contains the hostname of the actual machine the servlet is
> running on. I'm not sure if we have the option to set it, but seeing as we
> already have the desired hostname available in de 'X-Forwarded-Host' option
> I'm not going to investigate that further ;-)
>
> But I guess our servlet container, which indeed is Tomcat, doesn't take the
> X-Forwarded-Host header into consideration when constructing the requestUrl
> parameter of the SerlvetRequest. So we'll have to manually insert the
> desired hostname into the request url.
>
> Kind regards,
>
> Jonas
>
> Op wo 2 nov. 2016 om 16:33 schreef Zoran Regvart <zr...@redhat.com>:
>
> > Hi Jonas,
> >
> > On Wed, Nov 2, 2016 at 4:25 PM, Jonas Koperdraat
> > <jo...@jonaskoperdraat.nl> wrote:
> > > I don't know whether that header is being sent by the proxy. Should
> that
> > > impact the behavior I am seeing (e.g. should does that influence the
> > result
> > > of getRequestURL)?
> >
> > It does on some Servlet engines / middlewares, it might not in your
> > case, especially if you're using Tomcat.
> >
> > Another header that you might want to investigate is the `Host`
> > header, it's used for virtual hosts, and you might have an option to
> > set it in your proxy (on the request sent to the backend).
> >
> > zoran
> > --
> > Zoran Regvart
> > zregvart@redhat.com
> >
>

Re: 'host' configuration param not used by servlet

Posted by Jonas Koperdraat <jo...@jonaskoperdraat.nl>.
Hi Zoran,

I've checked and the proxy sets the 'X-Forwarded-Host' header and this
contains the 'correct' host. The 'Host' header is also present on the
request and this contains the hostname of the actual machine the servlet is
running on. I'm not sure if we have the option to set it, but seeing as we
already have the desired hostname available in de 'X-Forwarded-Host' option
I'm not going to investigate that further ;-)

But I guess our servlet container, which indeed is Tomcat, doesn't take the
X-Forwarded-Host header into consideration when constructing the requestUrl
parameter of the SerlvetRequest. So we'll have to manually insert the
desired hostname into the request url.

Kind regards,

Jonas

Op wo 2 nov. 2016 om 16:33 schreef Zoran Regvart <zr...@redhat.com>:

> Hi Jonas,
>
> On Wed, Nov 2, 2016 at 4:25 PM, Jonas Koperdraat
> <jo...@jonaskoperdraat.nl> wrote:
> > I don't know whether that header is being sent by the proxy. Should that
> > impact the behavior I am seeing (e.g. should does that influence the
> result
> > of getRequestURL)?
>
> It does on some Servlet engines / middlewares, it might not in your
> case, especially if you're using Tomcat.
>
> Another header that you might want to investigate is the `Host`
> header, it's used for virtual hosts, and you might have an option to
> set it in your proxy (on the request sent to the backend).
>
> zoran
> --
> Zoran Regvart
> zregvart@redhat.com
>

Re: 'host' configuration param not used by servlet

Posted by Zoran Regvart <zr...@redhat.com>.
Hi Jonas,

On Wed, Nov 2, 2016 at 4:25 PM, Jonas Koperdraat
<jo...@jonaskoperdraat.nl> wrote:
> I don't know whether that header is being sent by the proxy. Should that
> impact the behavior I am seeing (e.g. should does that influence the result
> of getRequestURL)?

It does on some Servlet engines / middlewares, it might not in your
case, especially if you're using Tomcat.

Another header that you might want to investigate is the `Host`
header, it's used for virtual hosts, and you might have an option to
set it in your proxy (on the request sent to the backend).

zoran
-- 
Zoran Regvart
zregvart@redhat.com

Re: 'host' configuration param not used by servlet

Posted by Jonas Koperdraat <jo...@jonaskoperdraat.nl>.
Hi Zoran,

I don't know whether that header is being sent by the proxy. Should that
impact the behavior I am seeing (e.g. should does that influence the result
of getRequestURL)?

I was considering a filter that alters the resulting swagger documentation,
but a filter that overrides getRequestURL is a more elegant approach, so
thanks for that suggestion!

Kind regards,

Jonas

Op wo 2 nov. 2016 om 15:42 schreef Zoran Regvart <zr...@redhat.com>:

> Hi Jonas,
>
> On Wed, Nov 2, 2016 at 2:57 PM, Jonas Koperdraat
> <jo...@jonaskoperdraat.nl> wrote:
> > It seems to me that this is a bug, but I might be mistaken, Is anyone
> > else familiar with this problem and aware of a solution/workaround?
>
> is your proxy sending the X-Forwarded-Host header to the servlet
> engine (watchout for Tomcat [1])? You can always implement a Servlet
> filter that would override the getRequestURL using
> HttpServletRequestWrapper or (if using) Tomcat Valve that would do the
> same.
>
> zoran
>
> [1] https://bz.apache.org/bugzilla/show_bug.cgi?id=57665
> --
> Zoran Regvart
> zregvart@redhat.com
>

Re: 'host' configuration param not used by servlet

Posted by Zoran Regvart <zr...@redhat.com>.
Hi Jonas,

On Wed, Nov 2, 2016 at 2:57 PM, Jonas Koperdraat
<jo...@jonaskoperdraat.nl> wrote:
> It seems to me that this is a bug, but I might be mistaken, Is anyone
> else familiar with this problem and aware of a solution/workaround?

is your proxy sending the X-Forwarded-Host header to the servlet
engine (watchout for Tomcat [1])? You can always implement a Servlet
filter that would override the getRequestURL using
HttpServletRequestWrapper or (if using) Tomcat Valve that would do the
same.

zoran

[1] https://bz.apache.org/bugzilla/show_bug.cgi?id=57665
-- 
Zoran Regvart
zregvart@redhat.com