Swagger + Servlet on Tomcat

1,034 views
Skip to first unread message

Ioannis Kavvouras

unread,
Apr 16, 2014, 6:02:07 AM4/16/14
to swagger-sw...@googlegroups.com
Hello, I have a similar problem as:
https://groups.google.com/forum/#!searchin/swagger-swaggersocket/servlet/swagger-swaggersocket/2BjFWm1ufGY/n-mzu9SwOqgJ

what I get from http://localhost:8080/ServicesCatalogManagerServlet/api-docs is:
{"apiVersion":"1.0.0","swaggerVersion":"1.2"}
I have the following annotations in my servlet:
@Api(value = "/WCSCatalogManagerServlet", description = "requests on WCSCatalogManager")
@WebServlet("/WCSCatalogManagerServlet")
public class WCSCatalogManagerServlet extends HttpServlet {...}


this is my web.xml on tomcat
   <!-- swagger -->
<servlet>
  <servlet-name>DefaultServletReaderConfig</servlet-name>
  <servlet-class>com.wordnik.swagger.servlet.config.DefaultServletReaderConfig</servlet-class>
  <load-on-startup>2</load-on-startup>
  <init-param>
    <param-name>swagger.resource.package</param-name>
    <param-value>gr.uoa.di.madgik.servicescatalogmanager.servlet</param-value>
  </init-param>
  <init-param>
    <param-name>swagger.api.basepath</param-name>
    <param-value>http://localhost:8080/api-docs</param-value>
  </init-param>
  <init-param>
    <param-name>api.version</param-name>
    <param-value>1.0.0</param-value>
  </init-param>
</servlet>
<servlet>
    <servlet-name>ApiDeclarationServlet</servlet-name>
    <servlet-class>com.wordnik.swagger.servlet.listing.ApiDeclarationServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>ApiDeclarationServlet</servlet-name>
    <url-pattern>/api-docs/*</url-pattern>
</servlet-mapping>
<filter>
  <filter-name>CorsFilter</filter-name>
  <filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
</filter>
<filter-mapping>
  <filter-name>CorsFilter</filter-name>
  <url-pattern>/*</url-pattern>
</filter-mapping>


I have also added the following dependencies on tomcat 'lib' directory:
commons-lang-2.4.jar
jackson-module-jsonSchema-2.1.0.jar
json4s-jackson_2.9.1-1-3.2.4.jar
scalap-2.9.1-1.jar
dom4j-1.6.1.jar
jackson-module-scala_2.9.1-2.1.5.jar
json4s-native_2.9.1-1-3.2.4.jar  
slf4j-api-1.6.3.jar
guava-11.0.2.jar                         
javassist-3.12.1.GA.jar              
jsr305-1.3.9.jar                 
swagger-annotations-1.3.1.jar
jackson-annotations-2.1.5.jar             
joda-convert-1.2.jar                 
jsr311-api-1.1.1.jar             
swagger-core_2.9.1-1.3.1.jar
jackson-core-2.1.5.jar                    
joda-time-2.1.jar                    
paranamer-2.3.jar                
swagger-servlet_2.9.1-1.3.1.jar
jackson-databind-2.1.5.jar                
json4s-ast_2.9.1-1-3.2.4.jar         
reflections-0.9.8.jar            
xml-apis-1.0.b2.jar
jackson-jaxrs-json-provider-2.0.0.jar     
json4s-core_2.9.1-1-3.2.4.jar        
scala-compiler-2.9.1-1.jar
jackson-module-jaxb-annotations-2.0.0.jar 
json4s-ext_2.9.1-1-3.2.4.jar         
scala-library-2.9.1-1.jar



Could you please help me?

Regards
Yannis

Ron

unread,
Apr 16, 2014, 6:45:55 AM4/16/14
to swagger-sw...@googlegroups.com
Hi Yannis,

Following what Tony replied in the other issue you referred to, it seems that it may be a dependency issue.
Are you also not using a dependency manager?
It looks like you're using an old version of Swagger - you should definitely upgrade to the latest (1.3.4) with its current dependencies.


--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ioannis Kavvouras

unread,
Apr 16, 2014, 7:06:09 AM4/16/14
to swagger-sw...@googlegroups.com
Hi Ron,

My project is developed using maven. I have this in my pom file
<dependencies>
        <dependency>
            <groupId>com.wordnik</groupId>
            <artifactId>swagger-servlet_2.9.1</artifactId>
            <version>[1.3.1, 2.0)</version>
        </dependency>
....
</dependencies>

I copied all the dependencies into tomcat lib using: "mvn dependency:copy-dependencies"
Should I include any other dependency in my pom file?

Thanks
Yannis
You received this message because you are subscribed to a topic in the Google Groups "Swagger" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/swagger-swaggersocket/s5gNVKeRB3A/unsubscribe.
To unsubscribe from this group and all its topics, send an email to swagger-swaggers...@googlegroups.com.

Ron

unread,
Apr 16, 2014, 7:13:14 AM4/16/14
to swagger-sw...@googlegroups.com
Please change the artifactId to swagger-servlet_2.10 - I imagine it'll pull in the latest version 1.3.4 but please make sure that it does.

Normally, I'm used to having the maven project produce a war file which includes all the dependencies rather than copying the dependencies to the web container. That said, it doesn't mean your method shouldn't work.

Keep me posted please.

Ioannis Kavvouras

unread,
Apr 16, 2014, 7:32:27 AM4/16/14
to swagger-sw...@googlegroups.com
I 've tried 2 scenarios:
  1. web.xml config on tomcat conf/web.xml: I copied all the dependencies of swagger-servlet_2.10 into tomcat lib directory and it didn't work.
  2. web.xml config on project/.../web.xml: I deployed the war which includes the dependencies of swagger-servlet_2.10 and it didn't work too. http://localhost:8080/ServicesCatalogManagerServlet/api-docs continues returning
  1. {"apiVersion":"1.0.0","swaggerVersion":"1.2"}

On both cases I don't get any exception on tomcat logs.

Thanks
Yannis

Ron

unread,
Apr 16, 2014, 7:45:31 AM4/16/14
to swagger-sw...@googlegroups.com
While a scala sample and not a java one, can you try cloning and running the war file on Tomcat and see if it works? Just trying to isolate the problem - https://github.com/wordnik/swagger-core/tree/master/samples/scala-servlet



Ioannis Kavvouras

unread,
Apr 16, 2014, 8:20:51 AM4/16/14
to swagger-sw...@googlegroups.com
It works :/
You received this message because you are subscribed to a topic in the Google Groups "Swagger" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/swagger-swaggersocket/s5gNVKeRB3A/unsubscribe.
To unsubscribe from this group and all its topics, send an email to swagger-swaggers...@googlegroups.com.

Ron

unread,
Apr 16, 2014, 9:02:23 AM4/16/14
to swagger-sw...@googlegroups.com
That's actually a good thing - it's means we have something to compare with.

Can you compare both web.xml?

The main issue is that Swagger doesn't perform the annotation scanning, and I'm not entirely sure why.

Ioannis Kavvouras

unread,
Apr 16, 2014, 9:28:33 AM4/16/14
to swagger-sw...@googlegroups.com
the web.xml is almost identical with the one of the scala-sample

<web-app id="WebApp_ID" version="2.4"
    xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <display-name>Harvester REST Service</display-name>

    <!-- sample servlet -->
    <servlet>
        <servlet-name>WCSCatalogManagerServlet</servlet-name>
        <servlet-class>gr.uoa.di.madgik.servicescatalogmanager.servlet.WCSCatalogManagerServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>WCSCatalogManagerServlet</servlet-name>
        <url-pattern>/sample/users</url-pattern>
    </servlet-mapping>

    <!-- swagger servlet reader -->

    <servlet>
        <servlet-name>DefaultServletReaderConfig</servlet-name>
        <servlet-class>com.wordnik.swagger.servlet.config.DefaultServletReaderConfig</servlet-class>
        <init-param>
            <param-name>swagger.resource.package</param-name>
            <param-value>gr.uoa.di.madgik.servicescatalogmanager.servlet</param-value>
        </init-param>
        <init-param>
            <param-name>swagger.api.basepath</param-name>
            <param-value>http://localhost:8002</param-value>

        </init-param>
        <init-param>
            <param-name>api.version</param-name>
            <param-value>1.0.0</param-value>
        </init-param>
        <load-on-startup>2</load-on-startup>
    </servlet>

    <!-- swagger api declaration -->

    <servlet>
        <servlet-name>ApiDeclarationServlet</servlet-name>
        <servlet-class>com.wordnik.swagger.servlet.listing.ApiDeclarationServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>ApiDeclarationServlet</servlet-name>
        <url-pattern>/api-docs/*</url-pattern>
    </servlet-mapping>

    <filter>
        <filter-name>ApiFilter</filter-name>
        <filter-class>gr.uoa.di.madgik.servicescatalogmanager.servlet.utils.ApiFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>ApiFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
</web-app>

Ron

unread,
Apr 16, 2014, 9:38:05 AM4/16/14
to swagger-sw...@googlegroups.com
I assume ApiFilter is the CORS filter?

Also, even though it's quite unlikely that this is the issue, I imagine your tomcat doesn't run on port 8002?

Ioannis Kavvouras

unread,
Apr 16, 2014, 9:41:10 AM4/16/14
to swagger-sw...@googlegroups.com
ApiFilter is the CORS filter. It's the same as the one implemented in Scala.

My tomcat runs on 8080.

Yannis

Ron

unread,
Apr 16, 2014, 9:42:26 AM4/16/14
to swagger-sw...@googlegroups.com
Well, first thing to test/change is the swagger.api.basepath property value accordingly then.


--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.

Ioannis Kavvouras

unread,
Apr 16, 2014, 9:47:58 AM4/16/14
to swagger-sw...@googlegroups.com
I tried both:
http://localhost:8080
and
http://localhost:8080/ServicesCatalogManagerServlet

it didn;t work :/ http://localhost:8080/ServicesCatalogManagerServlet/api-docs returns {"apiVersion":"1.0.0","swaggerVersion":"1.2"}

On 04/16/2014 04:42 PM, Ron wrote:
Well, first thing to test/change is the swagger.api.basepath property value accordingly then.
On Wed, Apr 16, 2014 at 4:41 PM, Ioannis Kavvouras <jhk...@gmail.com> wrote:
ApiFilter is the CORS filter. It's the same as the one implemented in Scala.

My tomcat runs on 8080.

Yannis


On 04/16/2014 04:38 PM, Ron wrote:
I assume ApiFilter is the CORS filter?

Also, even though it's quite unlikely that this is the issue, I imagine your tomcat doesn't run on port 8002?



--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "Swagger" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/swagger-swaggersocket/s5gNVKeRB3A/unsubscribe.
To unsubscribe from this group and all its topics, send an email to swagger-swaggers...@googlegroups.com.

Ron

unread,
Apr 16, 2014, 9:50:14 AM4/16/14
to swagger-sw...@googlegroups.com
Any chance you could hop in our IRC channel? It would probably be easier to talk since we're both online. I'm sure we can find the issue - #swagger @ irc.freenode.net.
If you don't have an IRC channel or if it's generally blocked in your network, you can use the web client provided by freenode at https://webchat.freenode.net/

Ioannis Kavvouras

unread,
Apr 17, 2014, 3:37:30 AM4/17/14
to swagger-sw...@googlegroups.com
Hello, do you have any news about this issue?

Yannis

Ron

unread,
Apr 17, 2014, 6:40:52 AM4/17/14
to swagger-sw...@googlegroups.com
I will have another look at it later today, hope to get something to you by tomorrow.


Lars Pan

unread,
May 13, 2014, 7:47:00 AM5/13/14
to swagger-sw...@googlegroups.com
I am suffering from the exact same problem. Have you found a solution to this problem yet? If so, could I ask you to post it here, please?

Best regards
/Lars

Ron

unread,
May 13, 2014, 8:06:34 AM5/13/14
to swagger-sw...@googlegroups.com
My apologies, it completely slipped my mind.
Unfortunately, I won't be able to take a look at it again today, but tomorrow I should be available. Feel free to remind me about it.


--

Lars Pan

unread,
May 13, 2014, 8:29:49 AM5/13/14
to swagger-sw...@googlegroups.com
Np. Thanks for taking the time. :)

I'll give you a poke sometime tomorrow if need be.

/Lars

Ron

unread,
May 19, 2014, 2:32:10 PM5/19/14
to swagger-sw...@googlegroups.com
Lars, are you also running your project on Tomcat?


--

Ron

unread,
May 21, 2014, 7:55:35 AM5/21/14
to swagger-sw...@googlegroups.com
Please make sure that your doGet/doPost methods are public and not protected.
Reply all
Reply to author
Forward
0 new messages