<restconfiguration> swagger.json generation without host set to 0.0.0.0

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

<restconfiguration> swagger.json generation without host set to 0.0.0.0

Martin Lichtin-2
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.

Reply | Threaded
Open this post in threaded view
|

Re: <restconfiguration> swagger.json generation without host set to 0.0.0.0

rafaeltuelho
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 <[hidden email]>
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.
>
>
Reply | Threaded
Open this post in threaded view
|

Rép. : <restconfiguration> swagger.json generation without host set to 0.0.0.0

angelwine
In reply to this post by Martin Lichtin-2
Hi,

here the way i use it

<restConfiguration bindingMode="off" component="servlet" port="8181"
                   contextPath="/XXXX/*"
                   apiContextPath="/api-doc" apiContextListing="false"
                   enableCORS="true">
  <endpointProperty key="servletName" value="XXXXCamelServlet" />
  <dataFormatProperty key="prettyPrint" value="true"/>
  <apiProperty key="base.path" value="/XXXX"/>
  <apiProperty key="api.description" value="{{XXXX.ENV}} - DOCUMENTATION OF REST SERVICES XXXX"/>
  <apiProperty key="api.title" value="System XXXX" />
  <apiProperty key="api.version" value="1.0.0" />
  <apiProperty key="api.contact.name" value="XXXXXXXXXXXXXXXXXXXX / YYYYYYYYYYYYYYYYYYY"/>
  <apiProperty key="api.contact.email" value="[hidden email]"/>
  <apiProperty key="api.termsOfService" value="(C) XXXX 2018"/>
</restConfiguration>

<!-- <rest path="/echo" consumes="application/text" produces="application/text"> -->
<rest path="/echo" consumes="text/html" produces="text/html">
 <description>Echo rest service</description>
 <get uri="ping">
    <description>Connectivity test</description>
    <route id="echo.xxxx">
        <transform>
           <constant>pong</constant>
        </transform>
    </route>
 </get>
</rest>


<rest path="/Service1" produces="application/json">
 <description>Summary of service1 </description>
 <get uri="/{xxxxIdService1}">
    <description>Description Id Service1</description>
      <param name="xxxxIdService1" type="path" description="Id Of Service1 description" />
      <route id="direct.xxxxService1">
         <to pattern="InOut" uri="direct:xxxxService1" />
      </route>
 </get>
</rest>





>>> Martin Lichtin <[hidden email]> 2018-07-12 15:55 >>>
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.




"Le présent courriel peut contenir des renseignements confidentiels et ne s'adresse qu'au destinataire dont le nom apparaît ci-dessus. Si ce courriel vous est parvenu par mégarde, veuillez le supprimer et nous en aviser aussitôt."
Daniel Langevin
System Administrator
Reply | Threaded
Open this post in threaded view
|

Re: <restconfiguration> swagger.json generation without host set to 0.0.0.0

Martin Lichtin-2
In reply to this post by rafaeltuelho
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 <[hidden email]>
> 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.
>>
>>

Reply | Threaded
Open this post in threaded view
|

Re: <restconfiguration> swagger.json generation without host set to 0.0.0.0

Claus Ibsen-2
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
<[hidden email]> 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 <[hidden email]>
>> 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 | Threaded
Open this post in threaded view
|

Re: <restconfiguration> swagger.json generation without host set to 0.0.0.0

pontus.ullgren
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, <[hidden email]> 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
> <[hidden email]> 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
> <[hidden email]>
> >> 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 | Threaded
Open this post in threaded view
|

Re: <restconfiguration> swagger.json generation without host set to 0.0.0.0

Claus Ibsen-2
Hi

Yeah we can maybe add an option to allow setting the hostname from
data via the HttpRequest.
Pontus you are welcome to log a JIRA with details.



On Wed, Jul 18, 2018 at 10:18 AM, Pontus Ullgren <[hidden email]> wrote:

> 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, <[hidden email]> 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
>> <[hidden email]> 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
>> <[hidden email]>
>> >> 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
>>



--
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2