Resteasy/Guice Unable to find contextual data of type: javax.servlet.ServletConfig
See original GitHub issueI don’t use the default implementation of resteasy servlet dispatcher. I use filter dispatcher, so i need change how the api’s are read.
Here are how my filter dispatcher works: https://gist.github.com/stickfigure/5ff4b814b8a08e4e1f57
Here the code:
@Path("/swagger.{type:json}")
public class SwaggerResource extends BaseApiListingResource {
@Context
ServletContext context;
@GET
@Produces({MediaType.APPLICATION_JSON})
@ApiOperation(value = "The swagger definition in either JSON", hidden = true)
public Response getListing(
@Context Application app,
@Context ServletConfig sc,
@Context FilterConfig fc,
@Context HttpHeaders headers,
@Context UriInfo uriInfo,
@PathParam("type") String type) {
return getListingJsonResponse(app, context, mergeConfig(sc, fc), headers, uriInfo);
}
private ServletConfig mergeConfig(ServletConfig sc, FilterConfig fc) {
try {
sc.getInitParameter("test");
} catch (Exception e) {
return new ServletConfigWrapper(fc);
}
return sc;
}
private static class ServletConfigWrapper implements ServletConfig {
private FilterConfig fc;
public ServletConfigWrapper(FilterConfig fc) {
this.fc = fc;
}
@Override
public String getServletName() {
return fc.getFilterName();
}
@Override
public ServletContext getServletContext() {
return fc.getServletContext();
}
@Override
public String getInitParameter(String name) {
return fc.getInitParameter(name);
}
@Override
public Enumeration<String> getInitParameterNames() {
return fc.getInitParameterNames();
}
}
}
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:8 (3 by maintainers)
Top Results From Across the Web
Unable to find contextual data of type: javax.servlet.http ...
In my experience the @Context is set on a per method basis. More like: @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.
Read more >Unable to find contextual data of type: javax.servlet ...
It seems the new io.swagger.jaxrs.listing.ApiListingResource causes RestEasy 3.0.9 to require a ThreadLocal reference to ServletContext which ...
Read more >Unable to find contextual data of type: javax.ws.rs.ext.Providers
Just using a library doing a ClientBuilder.newClient, the following occurs: org.jboss.resteasy.spi.LoggableFailure: Unable to find contextual data of type: ...
Read more >Throws "Unable to find contextual data of type: javax.servlet ...
Throws "Unable to find contextual data of type: javax.servlet.ServletContext " Jboss, RestEasy, Swagger.
Read more >Full text of "resteasy-reference-guide-en-US" - Internet Archive
Text media types and character sets. ... See Chapter 20, JAX-RS Content Negotiation for more details. resteasy. media, ... ServletConfig • javax.servlet.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Same thing for Tapestry5 that runs as a filter. As an answer to @frantuma, it’ll basically happen in any environment where ServletConfig isn’t available (but injects a proxy for the ServletConfig to ApiListingResource). Figured I’ll do the same as @niom and create my own subclass instead.
I had a similar problem with our project.
We are using Jersey JAX-RS configuration and using pure filter based configuration. When using pure filter based configuration there is no ServletConfig but instead of FilterConfig that can be injected.
Swagger has a class: ApiListingResource that is used as the listing client.
now with pure filter configuration the injection of the ServletConfig will fail because there is no such thing.
So what would need to happen is that swagger should provide a proper ResourceListing file that would contain FilterConfig as an alternative for the ServletConfig parameter.
So we ended up creating a own FilterApiListingResource that would work something like this:
in this way have the FilterConfig. ServletContext will be null because one does not exist.
what we are not sure is what information is missing when the ServletContext is null in BaseApiListingResource.