You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Claus Ibsen <cl...@gmail.com> on 2018/02/01 16:54:43 UTC
Re: Incorrect context path in camel-swagger-java swagger servlet?
Hi
Just a word that this servlet has been deprecated.
However we could maybe improve this code, so you can configure the
context path as servlet configuration so it knows this, and can use
that to clip the url correctly. You are welcome to dive into the
source code and work on a patch for that.
http://camel.apache.org/contributing
On Wed, Jan 31, 2018 at 6:57 PM, Darius Cooper <da...@gmail.com> wrote:
> We're seeing the same thing with Camel v2.19.3
>
>
> With a Context root of /a/b, the last part (i.e. b) is dropped.
>
> The code is looking for the last backslash in the context-root?
> https://github.com/apache/camel/blob/master/components/camel-swagger-java/src/main/java/org/apache/camel/swagger/servlet/RestSwaggerServlet.java#L235
>
>
>
>>> Hi
>>>
>>> Can you try with Camel 2.18.0 release.
>>>
>>> On Wed, Nov 2, 2016 at 1:37 PM, Jonas Koperdraat
>>> <[hidden email]> wrote:
>>>
>>> > Hi,
>>> >
>>> > I have an application deployed at
>>> > "<a href="http://server:port/some/context/path">http://server:port/some/context/path",
> with a REST api at
>>> > "<a href="http://server:port
> /some/context/path/rest">http://server:port/some/context/path/rest".
>>> >
>>> > According to http://camel.apache.org/swagger-java.html, I should
>>> > configure the 'base.path' and 'api.path' relative to the context
> path.
>>> > However, I find that I have to include the final part of the context
>>> > path in 'base.path' and 'api.path' for the swagger servlet to work,
>>> > like so:
>>> >
>>> > <init-param>
>>> > <param-name>base.path</param-name>
>>> > <param-value>path/rest</param-value>
>>> > </init-param>
>>> > <init-param>
>>> > <param-name>api.path</param-name>
>>> > <param-value>path/rest-docs</param-value>
>>> > </init-param>
>>> >
>>> > Debugging the code, I noticed in
>>> >
> org.apache.camel.swagger.servlet.RestSwaggerServlet#translateContextPath,
>>> > that the context path being returned is stripped from the last
>>> > segment. The responsible piece of code is:
>>> >
>>> > /**
>>> > * We do only want the base context-path and not sub paths
>>> > */
>>> > private String translateContextPath(HttpServletRequest request) {
>>> > String path = request.getContextPath();
>>> > if (path.isEmpty() || path.equals("/")) {
>>> > return "";
>>> > } else {
>>> > int idx = path.lastIndexOf("/");
>>> > if (idx > 0) {
>>> > return path.substring(0, idx);
>>> > }
>>> > }
>>> > return path;
>>> > }
>>> >
>>> > When debugging I can see that 'path' contains the entire context
> path:
>>> > "/some/context/path", which gets reduced to "/some/context". This
>>> > results in an incorrect basePath and non-working swagger servlet if I
>>> > don't add the "path" in the servlet configuration for 'api.path' and
>>> > 'base.path'
>>> >
>>> > Is this a bug or a feature? And in the latter case, how should I then
>>> > configure my application, such that I can configure the swagger
>>> > servlet independent of the context path (e.g. without "path" in
>>> > 'api.path' and 'base.path')?
>>> >
>>> > Im using java 7, camel(-swagger-java) v2.17.0, serlvet spec v3.0 and
>>> > am deploying to tomcat 7
>>> >
>>> > Kind regards,
>>> >
>>> > Jonas
>>> « [hide part of quote]
>>>
>>>
>>>
>>> --
>>> 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
Re: Incorrect context path in camel-swagger-java swagger servlet?
Posted by Darius Cooper <da...@gmail.com>.
The reason we configured this using Swagger servlet was that it picks up
the host name and context dynamically from the incoming HttpRequest.
Is there a way to do this with RestConfiguration?
For instance, people can hit our Swagger using two slightly different
hostnames, and the REST endpoint appear (to each of them) like they're on
different hosts. Similarly, the same Servlet configuration code could be
re-used in different microservices, which ahd different context roots.
Is there are way to set up the RestConfiguration so that the host name
would be "whatever hostname is being used to hit the '/api-docs' endpoint?
From what I can tell, setting the HostnameResolver would not do this; or
would it?
On Thu, Feb 1, 2018 at 11:54 AM, Claus Ibsen <cl...@gmail.com> wrote:
> Hi
>
> Just a word that this servlet has been deprecated.
>
> However we could maybe improve this code, so you can configure the
> context path as servlet configuration so it knows this, and can use
> that to clip the url correctly. You are welcome to dive into the
> source code and work on a patch for that.
>
> http://camel.apache.org/contributing
>
> On Wed, Jan 31, 2018 at 6:57 PM, Darius Cooper <da...@gmail.com>
> wrote:
> > We're seeing the same thing with Camel v2.19.3
> >
> >
> > With a Context root of /a/b, the last part (i.e. b) is dropped.
> >
> > The code is looking for the last backslash in the context-root?
> > https://github.com/apache/camel/blob/master/components/
> camel-swagger-java/src/main/java/org/apache/camel/swagger/
> servlet/RestSwaggerServlet.java#L235
> >
> >
> >
> >>> Hi
> >>>
> >>> Can you try with Camel 2.18.0 release.
> >>>
> >>> On Wed, Nov 2, 2016 at 1:37 PM, Jonas Koperdraat
> >>> <[hidden email]> wrote:
> >>>
> >>> > Hi,
> >>> >
> >>> > I have an application deployed at
> >>> > "<a href="http://server:port/some/context/path">http://server:
> port/some/context/path",
> > with a REST api at
> >>> > "<a href="http://server:port
> > /some/context/path/rest">http://server:port/some/context/path/rest".
> >>> >
> >>> > According to http://camel.apache.org/swagger-java.html, I should
> >>> > configure the 'base.path' and 'api.path' relative to the context
> > path.
> >>> > However, I find that I have to include the final part of the context
> >>> > path in 'base.path' and 'api.path' for the swagger servlet to work,
> >>> > like so:
> >>> >
> >>> > <init-param>
> >>> > <param-name>base.path</param-name>
> >>> > <param-value>path/rest</param-value>
> >>> > </init-param>
> >>> > <init-param>
> >>> > <param-name>api.path</param-name>
> >>> > <param-value>path/rest-docs</param-value>
> >>> > </init-param>
> >>> >
> >>> > Debugging the code, I noticed in
> >>> >
> > org.apache.camel.swagger.servlet.RestSwaggerServlet#
> translateContextPath,
> >>> > that the context path being returned is stripped from the last
> >>> > segment. The responsible piece of code is:
> >>> >
> >>> > /**
> >>> > * We do only want the base context-path and not sub paths
> >>> > */
> >>> > private String translateContextPath(HttpServletRequest request) {
> >>> > String path = request.getContextPath();
> >>> > if (path.isEmpty() || path.equals("/")) {
> >>> > return "";
> >>> > } else {
> >>> > int idx = path.lastIndexOf("/");
> >>> > if (idx > 0) {
> >>> > return path.substring(0, idx);
> >>> > }
> >>> > }
> >>> > return path;
> >>> > }
> >>> >
> >>> > When debugging I can see that 'path' contains the entire context
> > path:
> >>> > "/some/context/path", which gets reduced to "/some/context". This
> >>> > results in an incorrect basePath and non-working swagger servlet if
> I
> >>> > don't add the "path" in the servlet configuration for 'api.path' and
> >>> > 'base.path'
> >>> >
> >>> > Is this a bug or a feature? And in the latter case, how should I
> then
> >>> > configure my application, such that I can configure the swagger
> >>> > servlet independent of the context path (e.g. without "path" in
> >>> > 'api.path' and 'base.path')?
> >>> >
> >>> > Im using java 7, camel(-swagger-java) v2.17.0, serlvet spec v3.0 and
> >>> > am deploying to tomcat 7
> >>> >
> >>> > Kind regards,
> >>> >
> >>> > Jonas
> >>> « [hide part of quote]
> >>>
> >>>
> >>>
> >>> --
> >>> 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
>