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 12:37:09 UTC

Incorrect context path in camel-swagger-java swagger servlet?

Hi,

I have an application deployed at
"http://server:port/some/context/path", with a REST api at
"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

Re: Incorrect context path in camel-swagger-java swagger servlet?

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

Because of the environment our application is deployed to, we are stuck at
JDK 7, and therefore at camel 2.17.x.

I will test locally if this problem still exists in camel 2.18.0, though,
and will let you know the result.

Kind regards,

Joans

Op ma 7 nov. 2016 om 12:31 schreef Claus Ibsen <cl...@gmail.com>:

Hi

Can you try with Camel 2.18.0 release.

On Wed, Nov 2, 2016 at 1:37 PM, Jonas Koperdraat
<jo...@jonaskoperdraat.nl> wrote:
> Hi,
>
> I have an application deployed at
> "http://server:port/some/context/path", with a REST api at
> "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



--
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 Claus Ibsen <cl...@gmail.com>.
Hi

Can you try with Camel 2.18.0 release.

On Wed, Nov 2, 2016 at 1:37 PM, Jonas Koperdraat
<jo...@jonaskoperdraat.nl> wrote:
> Hi,
>
> I have an application deployed at
> "http://server:port/some/context/path", with a REST api at
> "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



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