Skip to content
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

RESTEASY003880: Unable to find contextual data of type: javax.servlet.ServletConfig #1691

Closed
natros opened this issue Mar 2, 2016 · 10 comments · Fixed by #1692
Closed

RESTEASY003880: Unable to find contextual data of type: javax.servlet.ServletConfig #1691

natros opened this issue Mar 2, 2016 · 10 comments · Fixed by #1692
Milestone

Comments

@natros
Copy link

natros commented Mar 2, 2016

This is happening after updating from swagger 1.5.6 to 1.5.6. I'm using jetty-maven-plugin with resteasy 3.0.16

15:03:27.900 ERROR [qtp2034546868-30] i18n: RESTEASY002005: Failed executing GET /swagger.json
org.jboss.resteasy.spi.LoggableFailure: RESTEASY003880: Unable to find contextual data of type: javax.servlet.ServletConfig
    at org.jboss.resteasy.core.ContextParameterInjector$GenericDelegatingProxy.invoke(ContextParameterInjector.java:55)
    at com.sun.proxy.$Proxy61.getInitParameter(Unknown Source)
    at io.swagger.jaxrs.config.SwaggerContextService.getConfigOrSwagger(SwaggerContextService.java:126)
    at io.swagger.jaxrs.config.SwaggerContextService.getSwagger(SwaggerContextService.java:146)
    at io.swagger.jaxrs.listing.ApiListingResource.process(ApiListingResource.java:99)
    at io.swagger.jaxrs.listing.ApiListingResource.getListingJson(ApiListingResource.java:154)
    at io.swagger.jaxrs.listing.ApiListingResource.getListing(ApiListingResource.java:141)
    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:498)
    at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:139)
    at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:295)
    at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:249)
    at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:236)
    at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:395)
    at org.jboss.resteasy.core.SynchronousDispatcher.invokePropagateNotFound(SynchronousDispatcher.java:240)
    at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:225)
    at org.jboss.resteasy.plugins.server.servlet.FilterDispatcher.doFilter(FilterDispatcher.java:62)
    at com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:82)
    at com.google.inject.servlet.ManagedFilterPipeline.dispatch(ManagedFilterPipeline.java:120)
    at com.google.inject.servlet.GuiceFilter.doFilter(GuiceFilter.java:135)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1668)
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:581)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
    at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:548)
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:226)
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1158)
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:511)
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1090)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
    at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:213)
    at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:109)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:119)
    at org.eclipse.jetty.server.Server.handle(Server.java:517)
    at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:308)
    at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:242)
    at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:273)
    at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:95)
    at org.eclipse.jetty.io.SelectChannelEndPoint$2.run(SelectChannelEndPoint.java:75)
    at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.produceAndRun(ExecuteProduceConsume.java:213)
    at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.run(ExecuteProduceConsume.java:147)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:654)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:572)
    at java.lang.Thread.run(Thread.java:745)
@frantuma
Copy link
Member

frantuma commented Mar 2, 2016

@natros this is possibly related to #1491, could you specify old and new version, and possibly share configuration?

@natros
Copy link
Author

natros commented Mar 2, 2016

I think I know what the problem is. I'm bootstrapping resteasy with a filter dispatcher rather than a servlet dispatcher, so the ServletConfig is not available in this case. Apparently this last version of swagger is using getInitParameter from ServletConfig that restasy can not provide.

@frantuma
Copy link
Member

frantuma commented Mar 2, 2016

last version uses indeed ServletConfig if not null, also previous versions do actually in some configurations like the ones affected by #1491. as you said in your case ServletConfig is not available, but it's not null and I would say possibly this is related to solution mentioned in #1491. This will need some investigation, as workaround you could change resteasy bootstrap or try #1491 solution

@natros
Copy link
Author

natros commented Mar 2, 2016

I don't think it's related to #1491. In my case the ServletContext is set and is valid, but the same does not happen with ServletConfig. IIRC, the ServletConfig is one for each servlet while the ServletContext is for all servlets.
For now I cannot change the bootstrap.

public User getMessage(@Context ServletContext ctx, @Context ServletConfig cfg) {
}

The debugger shows me this

cfg = {$Proxy62@8445} Method threw 'org.jboss.resteasy.spi.LoggableFailure' exception. Cannot evaluate com.sun.proxy.$Proxy62.toString()
ctx = {$Proxy59@8444} "ServletContext@o.e.j.m.p.JettyWebAppContext@9accff0{/,[file:///Users/fsousa/Projects/demo/swagger2-demo/src/main/webapp/, jar:file:///Users/fsousa/.m2/repository/org/webjars/swagger-ui/2.1.4/swagger-ui-2.1.4.jar!/META-INF/resources],AVAILABLE}{file:///Users/fsousa/Projects/demo/swagger2-demo/src/main/webapp/}"

@frantuma
Copy link
Member

frantuma commented Mar 2, 2016

@natros, yep issue is with servletConfig being not null but "invalid" in RESTEasy filter based; a fix is available in PR #1692 and will be available soon in 1.5.8-SNAPSHOT and in next release v1.5.8

@natros
Copy link
Author

natros commented Mar 2, 2016

I'll try as soon as possible.

Thank you.

On 02/03/2016, at 21:49, Francesco Tumanischvili notifications@github.com wrote:

@natros https://github.com/natros, yep issue is with servletConfig being not null but "invalid" in RESTEasy filter based; a fix is available in PR #1692 #1692 and will be available soon in 1.5.8-SNAPSHOT and in next release v1.5.8


Reply to this email directly or view it on GitHub #1691 (comment).

frantuma added a commit that referenced this issue Mar 5, 2016
Fix #1691 - fixes ServletConfig related error in RESTEasy Filter based config
@afredlyj
Copy link

The exception still exist since I change to 1.5.8:

        <dependency>
            <groupId>io.swagger</groupId>
            <artifactId>swagger-jaxrs</artifactId>
            <version>1.5.8</version>
        </dependency>

and the error log :

12:50:08.441 [pool-3-thread-3] INFO  i.s.j.config.SwaggerContextService 69 - Exception caught testing servletConfig. see https://github.com/swagger-api/swagger-core/issues/1691 
12:50:08.441 [pool-3-thread-3] INFO  i.s.j.config.SwaggerContextService 69 - Exception caught testing servletConfig. see https://github.com/swagger-api/swagger-core/issues/1691 
12:50:08.441 [pool-3-thread-3] INFO  i.s.j.config.SwaggerContextService 69 - Exception caught testing servletConfig. see https://github.com/swagger-api/swagger-core/issues/1691 
1

@frantuma
Copy link
Member

@afredlyj log seems to be correct (INFO level) it just signals the "invalid" servlet config, and adopts appropriate behavior; previously you would get a blocking error instead

@afredlyj
Copy link

I use netty + resteasy + swagger, but still something is wrong when request http://127.0.0.1:12345/swagger.son, the response from server is :

RESTEASY003880: Unable to find contextual data of type: javax.servlet.ServletContext

this is my spring xml :

    <bean id="apiListingResourceJSON" class="io.swagger.jaxrs.listing.ApiListingResource"/>
    <bean id="apiDeclarationProvider" class="io.swagger.jaxrs.listing.SwaggerSerializers"/>

    <bean id="beanConfig" class="io.swagger.jaxrs.config.BeanConfig" lazy-init="false">
        <property name="title" value="Swagger Sample App"/>
        <property name="version" value="1.0.0" />
        <property name="schemes" value="http" />
        <property name="host" value="localhost:12345" />
        <property name="basePath" value="/"/>
        <property name="resourcePackage" value="io.swagger.resources,afred.javademo.dispatcher"/>
        <property name="scan" value="true"/>
    </bean>

@weisebrazil
Copy link

I opened a new issue, because I use resteasy with google guice and I dont use the default implementation of resteasy servlet dispatcher. You can see how I resolved this in #2239

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants