camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jonas Koperdraat <jo...@jonaskoperdraat.nl>
Subject Incorrect context path in camel-swagger-java swagger servlet?
Date Wed, 02 Nov 2016 12:37:09 GMT
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

Mime
View raw message