Hi,

I think the most common way to get the host and port in servlet based
frameworks is to use the servlet HTTP request object.

This also allows for the container to handle the situation when it runs
behind a loadbalancer that sets the X-Forward headers.

As such I think it would be good to set these values for each request and
not just on startup since two different clients might use different
hostnames or even ports to call the same service.

Just my €0.02

Best regards
Pontus Ullgren

On Tue, 17 Jul 2018, 21:47 Claus Ibsen, <claus.ib...@gmail.com> wrote:

> Hi
>
> We can possible look at allowing to plugin a custom host name
> resolver, so you can use your own implementation, or we can provide a
> "none" that dont set one, and then possible swagger wont output it.
>
> For getting port number from servlet then AFAIR its not easy. Not sure
> if you can get some details from ENV or JMX to find out which servlet
> engine is running and get details to get port number. Or use some kind
> of initial http request that calls the servlet and then you can maybe
> get the port via some servlet request information. Its been a while
> since I was working with the servlet api, so cant remember on top of
> my head.
>
> But for making camel-swagger not output hostname then we can maybe add
> a "none" implementation. You are welcome to log a JIRA and attempt to
> implement this and provide a PR. We love contributions
> http://camel.apache.org/contributing
>
> On Tue, Jul 17, 2018 at 9:08 PM, Martin Lichtin
> <lich...@yahoo.com.invalid> wrote:
> > Thanks Rafael and Daniel
> >
> > Both of your <restConfiguration> examples don't quite solve the 0.0.0.0
> > issue, setting an empty "host" unfortunately does not help.
> >
> > However, I learned about "hostNameResolver", so at least I can provide an
> > actual IP address.
> >
> >     <restConfiguration component="servlet" bindingMode="json"
> > contextPath="/rest" apiContextPath="doc" enableCORS="true"
> > hostNameResolver="localIp"
> >       port="{{port}}">
> >
> > Still the problem is with the port number. Ideally the RestConfiguration
> > would get the port from the servlet, but not sure how that could work.
> >
> > - Martin
> >
> >
> >
> > On 12.07.2018 22:10, Rafael Soares wrote:
> >>
> >> Hi!
> >> Try the following conf:
> >>
> >>
> >> * <restConfiguration     apiContextPath="api-docs"
>  component="servlet"
> >>      enableCORS="true"     host="">            <camel:apiProperty
> >> key="api.title" value="myAPI"/>            <camel:apiProperty
> >> key="api.version" value="1.0.0"/>            <camel:apiProperty
> key="cors"
> >> value="true"/>            <camel:apiProperty key="host" value=""/>
> >> </restConfiguration>*
> >>
> >> Regards.
> >> ________________________
> >> Rafael Torres Coelho Soares
> >>
> >>
> >> On Thu, Jul 12, 2018 at 4:55 PM Martin Lichtin
> <lich...@yahoo.com.invalid>
> >> wrote:
> >>>
> >>> Anyone know how I can configure <restconfiguration> so the generated
> >>> swagger.json does not set host: "0.0.0.0"?
> >>>
> >>> With this 0.0.0.0 I cannot, for example, import the Swagger directly
> into
> >>> Postman and make calls to the API.
> >>> https://swagger.io/docs/specification/2-0/api-host-and-base-path/ says
> >>> the "host" can be omitted for a more dynamic association.
> >>>
> >>>
> >
>
>
>
> --
> Claus Ibsen
> -----------------
> http://davsclaus.com @davsclaus
> Camel in Action 2: https://www.manning.com/ibsen2
>

Reply via email to