[Inquiry] Cannot specify appropriate resource package using BeanConfig.setResourcePackage

726 views
Skip to first unread message

Kazuhiro Komoda

unread,
Aug 13, 2015, 11:04:00 AM8/13/15
to Swagger
Hello.
I have read through the Google group and have problems 
when setting resource package in (io.swagger.jaxrs.config.)BeanConfig under these environments.
  • Java EE 7
    • JAX-RS 2.x (jersey-common-2.1.jar)
  • NetBeans8.0.2
  • GlassFish4.1
  • swagger 1.5.0

I followed the project setup wiki but I failed to set resource package properly.
  1. When I specify a dummy string as an argument of BeanConfig.setResourcePackage, I can see swagger.json at the context root, but does NOT include my resource(s). (please refer to #1)
  2. When I specify the package (SimpleResource.class.getPackage().getName() or "simple.maven.glassfish.jaxrs.resource”), an error occurs and the war file cannot be deployed to Glassfish. (please refer to #2) 
    1. (The SimpleResource class has an @Api annotation and each method inside it has an @ApiOperation annotation)
Judging from the result of mvn dependency:list, I have included jackson 2.4.2 as required in swagger-core README. (please refer to #3)
   com.fasterxml.jackson.core:jackson-databind:jar:2.4.2:compile
(and this version seems to have a findPropertyIndex method )

All the modifications I added for enabling swagger are summarized in this commit on github.


Any advice would be deeply appreciated.
Thank you for your kind attention.

Best regards,
Kazuhiro Komoda


{
  "swagger": "2.0",
  "info": {
    "description": "A simple Maven Glassfish JAX-RS project.",
    "version": "1.0.2",
    "title": "simpleMavenGlassfishJaxrs"
  },
  "host": "localhost:8080/simpleMavenGlassfishJaxrs/webresources",
  "basePath": "/simple",
  "schemes": [
    "http"
  ]
}


(#2) 
This line 
   at simple.maven.glassfish.jaxrs.common.config.ApplicationConfig.<init>(ApplicationConfig.java:30)
corresponds to “beanConfig.setScan(true);” and this line
    at io.swagger.jaxrs.config.BeanConfig.setScan(BeanConfig.java:170)
corresponds to this line.

server.log output
Info:   Registering the Jersey servlet application, named simple.maven.glassfish.jaxrs.common.config.ApplicationConfig, at the servlet mapping /webresources/*, with the Application class of the same name.
Severe:   SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
Severe:   SLF4J: Defaulting to no-operation (NOP) logger implementation
Severe:   SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Severe:   WebModule[/simpleMavenGlassfishJaxrs]StandardWrapper.Throwable
MultiException stack 1 of 1
java.lang.NoSuchMethodError: com.fasterxml.jackson.databind.AnnotationIntrospector.findPropertyIndex(Lcom/fasterxml/jackson/databind/introspect/Annotated;)Ljava/lang/Integer;
    at io.swagger.jackson.ModelResolver.resolve(ModelResolver.java:372)
    at io.swagger.jackson.ModelResolver.resolve(ModelResolver.java:151)
    at io.swagger.converter.ModelConverterContextImpl.resolve(ModelConverterContextImpl.java:85)
    at io.swagger.jackson.ModelResolver.resolveProperty(ModelResolver.java:131)
    at io.swagger.jackson.ModelResolver.resolveProperty(ModelResolver.java:93)
    at io.swagger.converter.ModelConverterContextImpl.resolveProperty(ModelConverterContextImpl.java:65)
    at io.swagger.converter.ModelConverters.readAsProperty(ModelConverters.java:58)
    at io.swagger.jaxrs.Reader.parseMethod(Reader.java:768)
    at io.swagger.jaxrs.Reader.read(Reader.java:286)
    at io.swagger.jaxrs.Reader.read(Reader.java:169)
    at io.swagger.jaxrs.Reader.read(Reader.java:146)
    at io.swagger.jaxrs.config.BeanConfig.setScan(BeanConfig.java:170)
    at simple.maven.glassfish.jaxrs.common.config.ApplicationConfig.<init>(ApplicationConfig.java:30)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
    at org.glassfish.hk2.utilities.reflection.ReflectionHelper.makeMe(ReflectionHelper.java:1107)
    at org.jvnet.hk2.internal.Utilities.justCreate(Utilities.java:1011)
    at org.jvnet.hk2.internal.ServiceLocatorImpl.create(ServiceLocatorImpl.java:884)
    at org.jvnet.hk2.internal.ServiceLocatorImpl.createAndInitialize(ServiceLocatorImpl.java:976)
    at org.jvnet.hk2.internal.ServiceLocatorImpl.createAndInitialize(ServiceLocatorImpl.java:968)
    at org.glassfish.jersey.server.ApplicationHandler.createApplication(ApplicationHandler.java:336)
    at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:315)
    at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:285)
    at org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.java:310)
    at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:170)
    at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:358)
    at javax.servlet.GenericServlet.init(GenericServlet.java:244)
    at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1583)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1382)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5704)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:5946)
    at com.sun.enterprise.web.WebModule.start(WebModule.java:691)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:1041)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:1024)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:747)
    at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:2286)
    at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1932)
    at com.sun.enterprise.web.WebApplication.start(WebApplication.java:139)
    at org.glassfish.internal.data.EngineRef.start(EngineRef.java:122)
    at org.glassfish.internal.data.ModuleInfo.start(ModuleInfo.java:291)
    at org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:352)
    at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:500)
    at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:219)
    at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:491)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:539)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:535)
    at java.security.AccessController.doPrivileged(Native Method)
    at javax.security.auth.Subject.doAs(Subject.java:360)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$2.execute(CommandRunnerImpl.java:534)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$3.run(CommandRunnerImpl.java:565)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$3.run(CommandRunnerImpl.java:557)
    at java.security.AccessController.doPrivileged(Native Method)
    at javax.security.auth.Subject.doAs(Subject.java:360)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:556)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1464)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1300(CommandRunnerImpl.java:109)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1846)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1722)
    at org.glassfish.admin.rest.utils.ResourceUtil.runCommand(ResourceUtil.java:253)
    at org.glassfish.admin.rest.utils.ResourceUtil.runCommand(ResourceUtil.java:231)
    at org.glassfish.admin.rest.utils.ResourceUtil.runCommand(ResourceUtil.java:275)
    at org.glassfish.admin.rest.resources.TemplateListOfResource.createResource(TemplateListOfResource.java:133)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    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:151)
    at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:171)
    at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$ResponseOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:152)
    at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:104)
    at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:387)
    at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:331)
    at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:103)
    at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:271)
    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:297)
    at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:254)
    at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1028)
    at org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpContainer.service(GrizzlyHttpContainer.java:365)
    at org.glassfish.admin.rest.adapter.RestAdapter$2.service(RestAdapter.java:316)
    at org.glassfish.admin.rest.adapter.RestAdapter.service(RestAdapter.java:179)
    at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
    at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:201)
    at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:175)
    at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
    at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
    at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
    at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:561)
    at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:565)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
    at java.lang.Thread.run(Thread.java:745)


(#3) output of mvn dependency:list in NetBeans
The following files have been resolved:
   com.fasterxml.jackson.jaxrs:jackson-jaxrs-base:jar:2.4.2:compile
   com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:jar:2.4.2:compile
   com.fasterxml.jackson.core:jackson-databind:jar:2.4.2:compile
   com.fasterxml.jackson.module:jackson-module-jaxb-annotations:jar:2.4.2:compile
   com.google.code.findbugs:annotations:jar:2.0.1:compile
   javax:javaee-web-api:jar:7.0:provided
   org.javassist:javassist:jar:3.18.2-GA:compile
   org.glassfish.jersey.core:jersey-server:jar:2.1:compile
   org.glassfish.jersey.core:jersey-common:jar:2.1:compile
   org.apache.commons:commons-lang3:jar:3.2.1:compile
   org.glassfish.hk2:hk2-api:jar:2.2.0-b10:compile
   com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:jar:2.4.2:compile
   com.fasterxml.jackson.core:jackson-annotations:jar:2.4.0:compile
   org.glassfish.hk2.external:javax.inject:jar:2.2.0-b10:compile
   javax.ws.rs:javax.ws.rs-api:jar:2.0:compile
   io.swagger:swagger-models:jar:1.5.0:compile
   org.glassfish.jersey.core:jersey-client:jar:2.1:compile
   com.fasterxml.jackson.dataformat:jackson-dataformat-xml:jar:2.4.2:compile
   org.glassfish.jersey.media:jersey-media-multipart:jar:2.1:compile
   io.swagger:swagger-core:jar:1.5.0:compile
   io.swagger:swagger-jersey2-jaxrs:jar:1.5.0:compile
   com.google.guava:guava:jar:15.0:compile
   javax.annotation:javax.annotation-api:jar:1.2:compile
   joda-time:joda-time:jar:2.2:compile
   org.glassfish.hk2.external:asm-all-repackaged:jar:2.2.0-b10:compile
   org.glassfish.hk2:hk2-utils:jar:2.2.0-b10:compile
   org.glassfish.hk2:osgi-resource-locator:jar:1.0.1:compile
   com.fasterxml.jackson.core:jackson-core:jar:2.4.2:compile
   org.codehaus.woodstox:stax2-api:jar:3.1.4:compile
   io.swagger:swagger-annotations:jar:1.5.0:compile
   org.glassfish.hk2:hk2-locator:jar:2.2.0-b10:compile
   org.glassfish.jersey.containers:jersey-container-servlet-core:jar:2.1:compile
   junit:junit:jar:4.10:test
   org.reflections:reflections:jar:0.9.9:compile
   org.jvnet.mimepull:mimepull:jar:1.8:compile
   javax.validation:validation-api:jar:1.1.0.Final:compile
   org.glassfish.hk2.external:cglib:jar:2.2.0-b10:compile
   org.slf4j:slf4j-api:jar:1.6.3:compile
   com.fasterxml.jackson.datatype:jackson-datatype-joda:jar:2.4.2:compile
   org.hamcrest:hamcrest-core:jar:1.1:test
   io.swagger:swagger-jaxrs:jar:1.5.0:compile



Aki Yoshida

unread,
Aug 13, 2015, 11:46:59 AM8/13/15
to swagger-sw...@googlegroups.com
I think your GF4.1 is bringing its own jackson-databind which is an
older version (e.g., 2.3.2).
I don't know it how but you need to configure your GF to use your 2.4.2 version.
> --
> 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.

Ron Ratovsky

unread,
Aug 13, 2015, 2:10:20 PM8/13/15
to Swagger
That is correct, you to force GF to ignore its own Jackson dependency. There are new RC releases of GF that already include a newer version of Jackson, if I recall correctly.
--
-----------------------------------------
http://swagger.io
https://twitter.com/SwaggerApi
-----------------------------------------

Kazuhiro Komoda

unread,
Aug 13, 2015, 6:37:36 PM8/13/15
to Swagger
Aki, Ron

Thank you for your quick and precise reply. I didn't imagine the problems existed on the glassfish side...
These links (especially the quick hack which is mentioned in the second link) helped me to finally solve the problems.




2015年8月14日金曜日 3時10分20秒 UTC+9 Ron:

> 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-swaggersocket+unsub...@googlegroups.com.

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

Ron Ratovsky

unread,
Aug 13, 2015, 6:43:59 PM8/13/15
to Swagger
Thanks for sharing the details of what you found, I hope it helps others in the future too.


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



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

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