Swagger 1.5.3 not able to read the JSON for Jersey2.17

174 views
Skip to first unread message

vishak v

unread,
Oct 9, 2015, 3:29:25 AM10/9/15
to Swagger
Hi Team,

    I have configured the Swagger1.5.3 and i configured the application. Please find the information below

1] Added the gradle download 'io.swagger:swagger-jaxrs:1.5.3'

2] Added all the jars and dependents listed below
a) Jackson Libraries
b)swagger-jersey2-jaxrs-1.5.3
c)swagger-annotations-1.5.3
d)swagger-core-1.5.3
e)swagger-jaxrs-1.5.3
f)swagger-models-1.5.3
g)reflections-0.9.9

No Scala libraries as the dependencies are removed.
3] In Web.xml configured the following properties

<servlet>
    <servlet-name>Jersey2Config</servlet-name>
    <servlet-class>io.swagger.jersey.config.JerseyJaxrsConfig</servlet-class>
    <init-param>
      <param-name>api.version</param-name>
      <param-value>1.0</param-value>
    </init-param>
    <init-param>
      <param-name>swagger.api.basepath</param-name>
      <param-value>http://localhost/swagger/api/1.0</param-value>
    </init-param>
  </servlet>

<servlet>
   <servlet-name>Jersey REST Service</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
        <init-param>
            <param-name>jersey.config.server.provider.packages</param-name>
            <param-value>io.swagger.jaxrs.listing</param-value>
        </init-param>
        <init-param>
            <param-name>jersey.config.server.provider.classnames</param-name>
            <param-value>org.glassfish.jersey.media.multipart.MultiPartFeature</param-value>
        </init-param>
</servlet>

When i try to access http://localhost/swagger/index.html "swagger" is my context root.

I get the error Can't read swagger JSON from http://localhost/swagger/api/1.0/api-docs

However if i try http://localhost/swagger/sample.json  it loads the static JSON.

Can anyone please help me in this context.

Regards
Vishak

 

Saad Mufti

unread,
Oct 9, 2015, 10:47:53 AM10/9/15
to Swagger
Your basepath servlet init parameter should be just "/swagger" with no http://localhost and nothing after "/swagger". The basepath is basicaly just the webapp context path of your webapp. If you need the host to be set also, that is a separate init parameter called "host", otherwise the UI will point relative to where the Swagger UI is served from.

----
Saad

Ron Ratovsky

unread,
Oct 9, 2015, 1:19:24 PM10/9/15
to Swagger
Vishak,

It sounds like you migrated from 1.3 to 1.5. One of the changes in 1.5 is that the Swagger definition is no longer hosted under /api-docs but rather under /swagger.json - give it and try and it should work if everything is configured properly.


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



--
-----------------------------------------
http://swagger.io
https://twitter.com/SwaggerApi
-----------------------------------------

vishak v

unread,
Oct 12, 2015, 3:14:56 AM10/12/15
to swagger-sw...@googlegroups.com
Thanks Ron,

  It really worked for me, but currently i'm getting this error below. Can you please tell me how to resolve it
2015-10-12 12:37:49,342 DEBUG [TP-Processor3] io.swagger.jackson.ModelResolver [ModelResolver.java:204] @javax.xml.bind.annotation.XmlRootElement(name=assigneditem, namespace=##default)
2015-10-12 12:37:49,342 DEBUG [TP-Processor3] io.swagger.jackson.ModelResolver [ModelResolver.java:312] overriding datatype from [simple type, class long] to java.lang.long
2015-10-12 12:37:49,373 DEBUG [TP-Processor3] i.s.c.ModelConverterContextImpl [ModelConverterContextImpl.java:74] resolveProperty null

Vishak.V

--
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/O5iCIVOMWLI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to swagger-swaggers...@googlegroups.com.

vishak v

unread,
Oct 12, 2015, 6:01:23 AM10/12/15
to Swagger
Current error i'm getting
java.lang.IllegalArgumentException: Unrecognized Type: [null]
    at com.fasterxml.jackson.databind.type.TypeFactory._constructType(TypeFactory.java:405)
    at com.fasterxml.jackson.databind.type.TypeFactory.constructType(TypeFactory.java:354)
    at com.fasterxml.jackson.databind.ObjectMapper.constructType(ObjectMapper.java:1330)
    at io.swagger.jackson.ModelResolver.resolveProperty(ModelResolver.java:94)
    at io.swagger.converter.ModelConverterContextImpl.resolveProperty(ModelConverterContextImpl.java:79)
    at io.swagger.jackson.ModelResolver.resolve(ModelResolver.java:345)
    at io.swagger.jackson.ModelResolver.resolve(ModelResolver.java:149)
    at io.swagger.converter.ModelConverterContextImpl.resolve(ModelConverterContextImpl.java:99)
    at io.swagger.jackson.ModelResolver.resolveProperty(ModelResolver.java:129)
    at io.swagger.jackson.ModelResolver.resolveProperty(ModelResolver.java:94)
    at io.swagger.converter.ModelConverterContextImpl.resolveProperty(ModelConverterContextImpl.java:79)
    at io.swagger.converter.ModelConverters.readAsProperty(ModelConverters.java:58)
    at io.swagger.jaxrs.Reader.parseMethod(Reader.java:765)
    at io.swagger.jaxrs.Reader.read(Reader.java:263)
    at io.swagger.jaxrs.Reader.read(Reader.java:167)
    at io.swagger.jaxrs.Reader.read(Reader.java:144)
    at io.swagger.jaxrs.listing.ApiListingResource.scan(ApiListingResource.java:64)
    at io.swagger.jaxrs.listing.ApiListingResource.process(ApiListingResource.java:90)
    at io.swagger.jaxrs.listing.ApiListingResource.getListingJson(ApiListingResource.java:129)
    at io.swagger.jaxrs.listing.ApiListingResource.getListing(ApiListingResource.java:116)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory$1.invoke(ResourceMethodInvocationHandlerFactory.java:81)
    at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:164)
    at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:181)
    at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$ResponseOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:158)
    at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:101)
    at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:389)
    at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:347)
    at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:102)
    at org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:305)
    at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
    at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:267)
    at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317)
    at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:288)
    at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1110)
    at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:401)
    at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:386)
    at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:335)
    at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:222)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at com.xxx.xxx.xxx.swagger.SwaggerApiFilter.doFilter(SwaggerApiFilter.java:21)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
    at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:190)
    at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:291)
    at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:774)
    at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:703)
    at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:896)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:690)
    at java.lang.Thread.run(Thread.java:722)

Filter code is below

public void doFilter(ServletRequest request, ServletResponse response,
            FilterChain chain) throws IOException, ServletException {
        HttpServletResponse res = (HttpServletResponse) response;
        res.addHeader("Access-Control-Allow-Origin", "*");
        res.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT");
        res.addHeader("Access-Control-Allow-Headers", "Content-Type");
        chain.doFilter(request, response);
    }

I'm completely struck.

Regards
Vishak.V

Vishak.V

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

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



--
-----------------------------------------
http://swagger.io
https://twitter.com/SwaggerApi
-----------------------------------------

--
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/O5iCIVOMWLI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to swagger-swaggersocket+unsub...@googlegroups.com.

Ron Ratovsky

unread,
Oct 12, 2015, 5:45:36 PM10/12/15
to Swagger
We're handling the same issue here and in the github ticket, so let's keep it there.


Vishak.V

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.



--
-----------------------------------------
http://swagger.io
https://twitter.com/SwaggerApi
-----------------------------------------

--
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/O5iCIVOMWLI/unsubscribe.
To unsubscribe from this group and all its topics, 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 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.
Reply all
Reply to author
Forward
0 new messages