New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding Swagger-JAX-RS library breaks discovery of my ContextResolver<ObjectMapper> #862
Comments
Which version of swagger-core do you use? What does your Application class look like? |
Here is list of my dependencies "org.glassfish.jersey.containers" % "jersey-container-servlet" % "2.15",
"org.glassfish.jersey.media" % "jersey-media-json-jackson" % "2.15",
"com.fasterxml.jackson.core" % "jackson-databind" % "2.5.0",
"com.fasterxml.jackson.core" % "jackson-core" % "2.5.0",
"com.fasterxml.jackson.core" % "jackson-annotations" % "2.5.0",
"com.wordnik" % "swagger-jersey2-jaxrs_2.11" % "1.3.12", I don't have application class. Interestingly enough all my |
Okay, that's interesting. As for the second method, I suspect your provider isn't picked up because you didn't include it in the |
Yeah, I thought that too and tried adding it after I posted this issue but strangely it didn't help. I'm investigating it right now. As per Swagger I can't come up with working solution for now :( |
I can come up with a solution, but you may not like it :) The set up guide in the wiki provides several alternatives, one of which would be to use the Application class, but that would require you to manually set to classes. With Jersey 2 you can also use the ResourceConfig which can help by only going over the packages instead of explicit classes. |
He he :) Could you please give me ResourceConfig version of the solution ? By the way, why do you need UPDATE: Ah damn, it's because of |
the jersey2 module extends the jaxrs module. Unfortunately, I don't have a specific usage example of ResourceConfig. However, I think if you look both here and in the ResourceConfig section here you'd be able to combine the two into a working example. Basically, the |
Could you decouple these two libraries instead so that there are no duplicating JAX-RS provides in the classpath ? |
They use different packages, which is what is meant to isolate them. And at the moment, there won't be an easy way to decouple them. |
I see. So I'm still fighting with it here here is what I found.
If I have Swaggers providers in classpath my |
Sadly I couldn't figure out why it's happening. If you find root cause please update this issue. I only found this. In your public MAPPER locateMapper(Class<?> type, MediaType mediaType)
{
// First: were we configured with a specific instance?
MAPPER m = _mapperConfig.getConfiguredMapper();
if (m == null) {
// If not, maybe we can get one configured via context?
m = _locateMapperViaProvider(type, mediaType);
if (m == null) {
// If not, let's get the fallback default instance
m = _mapperConfig.getDefaultMapper();
}
}
return m;
} in correct code-flow I'll try to create small isolated sample project in few days that reproduces the issue and will post it on GitHub. In the mean time I'll have to maintain API documentation manually :( |
Are you sure its docs are right? I get 404 for pretty much any URL. |
Oops. I accidentally left wrong webroot from my big project. Please update. |
Okay, that works. To be clear, you changed the issue being described here? Technically, even with that sample, you don't get proper API documentation. |
Another thing, will you be able to try using 1.5.0-M1 instead? Testing it, it seems the API call that doesn't work with the older dependency works with the newer one. |
I changed description of the issue as I discovered real cause of it. Initially I thought problem lies in how I enable Jersey in Yep, I intentionally simplified example project. In my real project API documentation is working. Yes, I tested 1.5.0-M1 as well. Web-service doesn't give error about missing serializer but returns empty json instead. |
Okay, that's at least some progress. @fehguy would have to jump in here now. |
Thank you, guys ! If we fix it I'll be tremendously happy.Let me know if I can help somehow. |
will be looking in a bit. |
@CPPExpert - well, if it makes you happy, it makes us happy. |
I am running up against the same thing. Adding swagger breaks my perfectly good service thanks to it's dependencies on out dated JSR-311 implementations. Caused by: java.lang.NoSuchMethodError: javax.ws.rs.core.Response.hasEntity()Z |
@steowens - I don't see how those two issues are related (the one you're talking about and the one the OP is). Do you also have your own ObjectMapper? |
jersey (1) or jersey 2? Can you share your pom.xml? |
I managed to fix the problem. In my case I am using JSR-339, and all of the features that it entails. Swagger pulls in a compile time dependency on JSR-311. By adding an exclude for the compile time dendency to the swagger dependency I was able to resolve my issue. |
Thanks, I will keep this open to look at the dependencies. |
@steowens you should not need to exclude the JSR-311 as it's already excluded by the |
@CPPExpert I've been looking at this and have some thoughts. (kudos for being the first person I've seen using sbt for a non-play java project!)
I believe that the issue isn't swagger, but a library incompatibility and configuration settings. I've sent a PR for the following:
I've sent a PR to your repo with the changes, Please check it out. |
Guys, I just tried switching to new 1.5.0 Sadly I can't have it get initialized now. I get following exception {
"error": {
"type": "GenericException",
"message": "NotFoundException: HTTP 404 Not Found",
"stackTrace": "javax.ws.rs.NotFoundException: HTTP 404 Not Found\r\n\tat org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:305)\r\n\tat org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)\r\n\tat org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)\r\n\tat org.glassfish.jersey.internal.Errors.process(Errors.java:315)\r\n\tat org.glassfish.jersey.internal.Errors.process(Errors.java:297)\r\n\tat org.glassfish.jersey.internal.Errors.process(Errors.java:267)\r\n\tat org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317)\r\n\tat org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:291)\r\n\tat org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1140)\r\n\tat org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:403)\r\n\tat org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:386)\r\n\tat org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:334)\r\n\tat org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:221)\r\n\tat org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:751)\r\n\tat org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1666)\r\n\tat org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:176)\r\n\tat org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:145)\r\n\tat org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:92)\r\n\tat org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:381)\r\n\tat org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1636)\r\n\tat org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:564)\r\n\tat org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)\r\n\tat org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:578)\r\n\tat org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:221)\r\n\tat org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1111)\r\n\tat org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:498)\r\n\tat org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:183)\r\n\tat org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1045)\r\n\tat org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)\r\n\tat org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:199)\r\n\tat org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:109)\r\n\tat org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:98)\r\n\tat org.eclipse.jetty.server.Server.handle(Server.java:461)\r\n\tat org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:284)\r\n\tat org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:244)\r\n\tat org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:534)\r\n\tat org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:607)\r\n\tat org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:536)\r\n\tat java.lang.Thread.run(Thread.java:745)\r\n"
}
} Also I see in the debugger that this class My <servlet>
<servlet-name>DefaultJaxrsConfig</servlet-name>
<servlet-class>io.swagger.jaxrs.config.DefaultJaxrsConfig</servlet-class>
<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> and packages("com.company.api2", "io.swagger.jaxrs.listing"); |
I have problem initializing Swagger using Jersey 2.
Here is how my
web.xml
looks likeOn server start I get
[FATAL] A resource model has ambiguous (sub-)resource method for HTTP method GET and input mime-types as defined by"@Consumes" and "@Produces" annotations at Java methods public javax.ws.rs.core.Response com.wordnik.swagger.jaxrs.listing.ApiListingResource.resourceListing(javax.ws.rs.core.Application,javax.servlet.ServletConfig,javax.ws.rs.core.HttpHeaders,javax.ws.rs.core.UriInfo) and public javax.ws.rs.core.Response com.wordnik.swagger.jersey.listing.ApiListingResource.resourceListing(javax.ws.rs.core.Application,org.glassfish.jersey.servlet.WebConfig,javax.ws.rs.core.HttpHeaders,javax.ws.rs.core.UriInfo) at matching regular expression /api\-docs. These two methods produces and consumes exactly the same mime-types and therefore their invocation as a resource methods will always fail.; source='org.glassfish.jersey.server.model.RuntimeResource@3d13bf1a',
which expected considering there are two classes mapping to the same endpoint:
com.wordnik.swagger.jersey.listing.ApiListingResource
andcom.wordnik.swagger.jaxrs.listing.ApiListingCache
.Why do we have jersey listener in jaxrs module jar ?
Is there way to make it work ?
I also tried using example from your tutorial which is
Sadly this version ignores my other provider located in
com.mycompany.api2.serialization
.Thanks!
The text was updated successfully, but these errors were encountered: