how to debug swagger api-docs not found error?

2,709 views
Skip to first unread message

Xiaozhong Tony Ge

unread,
Sep 9, 2014, 3:21:38 PM9/9/14
to swagger-sw...@googlegroups.com
I'm using the swagger-jaxrs_2.10-1.3.7 with jeresy 2.9 and tomcat 7. I can see the api-docs resource in jeresy wadl file when my rest service is running, but when I try the http://local-host:8080/rest/api-docs, it always returns 404? any suggestions how I debug the problem?
 
Thanks,
 
Tony

Ron

unread,
Sep 9, 2014, 3:25:26 PM9/9/14
to swagger-sw...@googlegroups.com
Hi Tony,

Unrelated to the issue, you'd want to use swagger-jersey2-jaxrs_2.10 as the dependency.
Can you share how you configured swagger (either web.xml or programmatically)?

--
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.

Xiaozhong Tony Ge

unread,
Sep 9, 2014, 7:55:06 PM9/9/14
to swagger-sw...@googlegroups.com
Hi Ron,
Thank you for your respnse. I use ant build env, not maven, not sure how to add the dependency in my build script. I manually downloaded the jars from the maven repository. Here is my web.xml, Thanks
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="xwebService_ID">
    <display-name>MyRestService</display-name>
    <context-param>
        <param-name>log4jConfigLocation</param-name>
        <param-value>classpath:log4j.xml</param-value>
    </context-param>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            classpath:applicationContext.xml
        </param-value>
    </context-param>

    <listener>
        <listener-class>
            org.springframework.web.context.ContextLoaderListener
        </listener-class>
    </listener>
    <listener>
        <listener-class>
            org.springframework.security.web.session.HttpSessionEventPublisher
        </listener-class>
    </listener>
    <servlet>
        <servlet-name>RestService</servlet-name>
        <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
        <init-param>
            <param-name>jersey.config.server.provider.classnames</param-name>
            <param-value>
                com.wordnik.swagger.jaxrs.listing.ApiListingResourceJSON,
                com.wordnik.swagger.jaxrs.listing.JerseyApiDeclarationProvider,
                com.wordnik.swagger.jaxrs.listing.JerseyResourceListingProvider
            </param-value>
        </init-param>
        <init-param>
            <param-name>jersey.api.json.POJOMappingFeature</param-name>
            <param-value>true</param-value>
        </init-param>
        <init-param>
            <param-name>jersey.config.server.provider.packages</param-name>
            <param-value>com.oce.ocsdm.ws.rest.resources.v0_0;com.wordnik.swagger.jaxrs.json</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>RestService</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
    <servlet>
        <servlet-name>DefaultJaxrsConfig</servlet-name>
        <servlet-class>com.wordnik.swagger.jaxrs.config.DefaultJaxrsConfig</servlet-class>
        <init-param>
            <param-name>api.version</param-name>
            <param-value>0.0</param-value>
        </init-param>
        <init-param>
            <param-name>swagger.api.basepath</param-name>
            <param-value>http://localhost:8080/rest/</param-value>
        </init-param>
        <load-on-startup>2</load-on-startup>
    </servlet>
    <servlet>
        <servlet-name>Bootstrap</servlet-name>
        <servlet-class>com.oce.ocsdm.ws.rest.swagger.Bootstrap</servlet-class>
        <load-on-startup>2</load-on-startup>
    </servlet>
    <error-page>
        <error-code>404</error-code>
        <location>/404error.html</location>
    </error-page>
    <error-page>
        <error-code>500</error-code>
        <location>/500error.html</location>
    </error-page>
</web-app>
 

Ron

unread,
Sep 10, 2014, 12:13:33 AM9/10/14
to swagger-sw...@googlegroups.com
Okay, since you mentioned that you're using ant and you said you manually downloaded the dependency - are you sure you added all the dependencies required by swagger-core? It's a bit of a long list. If you added a few libraries, can you list your dependencies?
You can also check your tomcat's start up logs to see if there are any errors (either on startup or when accessing /api-docs).

--

Xiaozhong Tony Ge

unread,
Sep 10, 2014, 7:59:05 AM9/10/14
to swagger-sw...@googlegroups.com
Ok,  I will check the dependencies.  I had checked the tomcat's log, it has no errors, but I didn't see any logging messages from the swagger, how can I turn on the swagger logging? or any other ways to debug the swagger? Thanks.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.

Ron

unread,
Sep 10, 2014, 8:09:43 AM9/10/14
to swagger-sw...@googlegroups.com
I don't expect the errors to come from swagger but rather then jersey tries loading them or when you try accessing /api-docs.

The https://github.com/wordnik/swagger-core/tree/master/samples have swagger logging set to them, at various levels. You can check them out and bump up the logging level.

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.

Xiaozhong Tony Ge

unread,
Sep 10, 2014, 2:08:02 PM9/10/14
to swagger-sw...@googlegroups.com
Here is the logging messages when I do http://localhost:8080/rest/api-docs. Any ideas what went wrong for my issue? Thanks, -Tony
 
13:59:01.437 [ajp-bio-8009-exec-6] DEBUG c.w.s.jaxrs.listing.ApiListingCache$ - cache has Set(/v0.0/ocao/vmImages, /v0.0/admin, /v0.0/ocao/vdus, /v0.0/ocao/logs, /api-docs, /v0.0/configs, /v0.0/ocao/nfGroups, /v0.0/ocao/dataCenters, /v0.0/ocao/vims) keys
13:59:01.438 [ajp-bio-8009-exec-6] DEBUG c.w.swagger.core.filter.SpecFilter - requiredModels: ListBuffer()
13:59:01.438 [ajp-bio-8009-exec-6] DEBUG c.w.swagger.core.filter.SpecFilter - existingModels: List()
13:59:01.439 [ajp-bio-8009-exec-6] DEBUG c.w.swagger.core.filter.SpecFilter - requiredModels: ListBuffer(Session, Session, Session)
13:59:01.439 [ajp-bio-8009-exec-6] DEBUG c.w.swagger.core.filter.SpecFilter - existingModels: List(Session, Session, Session, long, string)
13:59:01.440 [ajp-bio-8009-exec-6] DEBUG c.w.s.c.ModelInheritenceUtil$ - expanding Session
13:59:01.440 [ajp-bio-8009-exec-6] DEBUG c.w.s.c.ModelInheritenceUtil$ - got a base model from Session
13:59:01.440 [ajp-bio-8009-exec-6] DEBUG c.w.s.c.ModelInheritenceUtil$ - skipping java.lang.Void
13:59:01.440 [ajp-bio-8009-exec-6] DEBUG c.w.s.c.ModelInheritenceUtil$ - basePropNames: Set()
13:59:01.440 [ajp-bio-8009-exec-6] DEBUG c.w.s.c.ModelInheritenceUtil$ - inspecting userName
13:59:01.440 [ajp-bio-8009-exec-6] DEBUG c.w.s.c.ModelInheritenceUtil$ - inspecting password
13:59:01.440 [ajp-bio-8009-exec-6] DEBUG c.w.s.c.ModelInheritenceUtil$ - inspecting userGroup
13:59:01.440 [ajp-bio-8009-exec-6] DEBUG c.w.s.c.ModelInheritenceUtil$ - inspecting sessionId
13:59:01.440 [ajp-bio-8009-exec-6] DEBUG c.w.s.c.ModelInheritenceUtil$ - inspecting idleTimeout
13:59:01.441 [ajp-bio-8009-exec-6] DEBUG c.w.swagger.core.filter.SpecFilter - requiredModels: ListBuffer()
13:59:01.441 [ajp-bio-8009-exec-6] DEBUG c.w.swagger.core.filter.SpecFilter - existingModels: List()
13:59:01.442 [ajp-bio-8009-exec-6] DEBUG c.w.swagger.core.filter.SpecFilter - requiredModels: ListBuffer()
13:59:01.442 [ajp-bio-8009-exec-6] DEBUG c.w.swagger.core.filter.SpecFilter - existingModels: List()
13:59:01.442 [ajp-bio-8009-exec-6] DEBUG c.w.swagger.core.filter.SpecFilter - requiredModels: ListBuffer()
13:59:01.442 [ajp-bio-8009-exec-6] DEBUG c.w.swagger.core.filter.SpecFilter - existingModels: List()
13:59:01.443 [ajp-bio-8009-exec-6] DEBUG c.w.swagger.core.filter.SpecFilter - requiredModels: ListBuffer()
13:59:01.443 [ajp-bio-8009-exec-6] DEBUG c.w.swagger.core.filter.SpecFilter - existingModels: List()
13:59:01.444 [ajp-bio-8009-exec-6] DEBUG c.w.swagger.core.filter.SpecFilter - requiredModels: ListBuffer()
13:59:01.444 [ajp-bio-8009-exec-6] DEBUG c.w.swagger.core.filter.SpecFilter - existingModels: List()
13:59:01.445 [ajp-bio-8009-exec-6] DEBUG c.w.swagger.core.filter.SpecFilter - requiredModels: ListBuffer()
13:59:01.445 [ajp-bio-8009-exec-6] DEBUG c.w.swagger.core.filter.SpecFilter - existingModels: List()
13:59:01.445 [ajp-bio-8009-exec-6] DEBUG c.w.swagger.core.filter.SpecFilter - requiredModels: ListBuffer()
13:59:01.445 [ajp-bio-8009-exec-6] DEBUG c.w.swagger.core.filter.SpecFilter - existingModels: List()
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsubscri...@googlegroups.com.

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

Ron

unread,
Sep 10, 2014, 2:13:58 PM9/10/14
to swagger-sw...@googlegroups.com
I think I've made a wrong assumption. What's the context root of your application?
If you're not sure, can you paste a sample URL of one of the API operations you expose?

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.

tony tam

unread,
Sep 10, 2014, 2:16:38 PM9/10/14
to swagger-sw...@googlegroups.com

Xiaozhong Tony Ge

unread,
Sep 10, 2014, 2:22:36 PM9/10/14
to swagger-sw...@googlegroups.com
here is an URL example for my login resource:  "http://localhost:8080/rest/v0.0/admin/login"
 
Also, here is the generated wadl from jersey:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<application xmlns="http://wadl.dev.java.net/2009/02">
    <doc xmlns:jersey="http://jersey.java.net/" jersey:generatedBy="Jersey: 2.9 2014-05-22 05:12:10"/>
    <doc xmlns:jersey="http://jersey.java.net/" jersey:hint="This is simplified WADL with user and core resources only. To get full WADL with ext
ended resources use the query parameter detail. Link: http://localhost:8080/rest/application.wadl?detail=false&amp;detail=true"/>
    <grammars>
        <include href="application.wadl/xsd0.xsd">
            <doc title="Generated" xml:lang="en"/>
        </include>
    </grammars>
    <resources base="http://localhost:8080/rest/">
        <resource path="/v0.0/admin">
            <resource path="/logout">
                <method id="logout" name="POST">
                    <response>
                        <representation mediaType="*/*"/>
                    </response>
                </method>
            </resource>
            <resource path="/login">
                <method id="login" name="POST">
                    <request>
                        <ns2:representation xmlns:ns2="http://wadl.dev.java.net/2009/02" xmlns="" element="session" mediaType="application/xml"/>
                        <ns2:representation xmlns:ns2="http://wadl.dev.java.net/2009/02" xmlns="" element="session" mediaType="application/json"/
>
                    </request>
                    <response>
                        <ns2:representation xmlns:ns2="http://wadl.dev.java.net/2009/02" xmlns="" element="session" mediaType="application/xml"/>
                        <ns2:representation xmlns:ns2="http://wadl.dev.java.net/2009/02" xmlns="" element="session" mediaType="application/json"/
>
                    </response>
                </method>
            </resource>
        </resource>
        <resource path="/api-docs">
            <method id="resourceListing" name="GET">
                <response>
                    <representation mediaType="application/json; charset=utf-8"/>
                </response>
            </method>
            <resource path="/{route: .+}">
                <param xmlns:xs="http://www.w3.org/2001/XMLSchema" name="route" style="template" type="xs:string"/>
                <method id="apiDeclaration" name="GET">
                    <response>
                        <representation mediaType="application/json; charset=utf-8"/>
                    </response>
                </method>
            </resource>
        </resource>
    </resources>
</application>

Ron

unread,
Sep 10, 2014, 2:26:00 PM9/10/14
to swagger-sw...@googlegroups.com
Okay, that's a bit odd. Based on the logs and what you wrote you should get a response from http://localhost:8080/rest/api-docs.
Are you sure you're getting 404 and not what may seem like an empty response?

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.

Xiaozhong Tony Ge

unread,
Sep 10, 2014, 2:30:10 PM9/10/14
to swagger-sw...@googlegroups.com
The HTTP response code is 404, I have the same result  from both browser and cURL command. I wonder if I'm missing some jars or any suggestions to debug this? Thanks, -Tony

Ron

unread,
Sep 10, 2014, 2:36:33 PM9/10/14
to swagger-sw...@googlegroups.com

I don't think it's related to a missing library since you'd have seen more explicit exceptions on the log.

I know this may be sensitive, but is there any way you can share your code? You can send it to me directly and not in the group.

If not, maybe you can write a sample project that reproduces the issue? I may need some assistance since my ant knowledge is rusty.

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.

Xiaozhong Tony Ge

unread,
Sep 10, 2014, 3:13:20 PM9/10/14
to swagger-sw...@googlegroups.com

It is going to be very difficult to create an isolated small sample project to reproduce the problem.  Is anything else I can try?

Ron

unread,
Sep 10, 2014, 3:25:19 PM9/10/14
to swagger-sw...@googlegroups.com
Okay, based on your logs, your /api-docs is being accessed properly. What I suspect now is that there's some kind of a filter the blocks the access.
Your web.xml doesn't include any filters, but you may have classes annotated by @WebFilter.

Another possible issue is the HttpSessionEventPublisher spring listener. I'm not that familiar with it, but it seems it is part of spring-security. Is it possible you need to configure it to not block certain URLs?
I'm not sure if that configuration would be in the core your applicationContext.xml (or some other configuration file).

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.

Xiaozhong Tony Ge

unread,
Sep 11, 2014, 8:10:29 AM9/11/14
to swagger-sw...@googlegroups.com

I made a little bit progress. It seems that there are some conflicts between the jars for MOXy  json support in my rest service and Jackson jars for swagger json support. I temporarily  remove all the jars for the MOXy json in my rest service. No http://localhost:8080/rest/api-docs returns HTTP 200(ok), but the result is empty{}. Any ideas why the result is empty? Thanks, -Tony

Ron

unread,
Sep 11, 2014, 8:38:19 AM9/11/14
to swagger-sw...@googlegroups.com
A completely empty result is odd.
Can you please list the current dependencies you have and their versions?

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.

Xiaozhong Tony Ge

unread,
Sep 11, 2014, 9:47:43 AM9/11/14
to swagger-sw...@googlegroups.com
Ron,
does any swagger versions support jersey 2.9 with jersey-media-json-jackson-2.9.jar ? (the jersey 2.9 json representation needs the jersay-media-json-jackson-2.9.jar, which depend on jackson 2.3.2 version jars). The swagger version 2.10-1.3.7 I used seems  requires jackson 2.1.0 level.  I think there are some conflicts between the two jackson versions.
 
Thanks,
 
Tony
Reply all
Reply to author
Forward
0 new messages