I have a Jersey 1 ContainerResponseFilter in a shared library, which I register in Jersey 1 web services by specifying the package this filter exists in inside the web.xml eg.
<servlet>
<servlet-name>ServletAdaptor</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>
com.xxx.utils.jersey
</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.spi.container.ContainerResponseFilters</param-name>
<param-value>com.xxx.utils.jersey.CrossDomainFilter</param-value>
</init-param>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.xxx.utils.jersey</param-value>
</init-param>
...
</servlet>
I am now trying to use this shared library in a Jersey 2 web service which instead of using the web.xml to configure Jersey uses a class annotated with @ApplicationPath
and extending the Jersey ResourceConfig
. Inside this class I am not specifying the package of this Jersey 1 filter anywhere.
The problem I am getting is because this Jersey 2 web service doesn't include any Jersey 1 dependencies in the war I am getting a ClassNotFoundException
during deployment of the webservice for com.sun.jersey.spi.container.ContainerResponseFilter
Here is an example of how I am creating my config
@ApplicationPath("/")
public class AppConfig extends ResourceConfig
{
private static final String RESOURCE_PACKAGE = "com.xxx.services.rest";
public AppConfig()
{
packages(RESOURCE_PACKAGE);
register(ApiListingResource.class);
register(SwaggerSerializers.class);
BeanConfig beanConfig = new BeanConfig();
beanConfig.setVersion("1.0.0");
beanConfig.setResourcePackage(RESOURCE_PACKAGE);
beanConfig.setSchemes(new String[]{"http"});
beanConfig.setHost("localhost:7001");
beanConfig.setBasePath("/usr/");
beanConfig.setScan(true);
}
}
Is there a way I can make sure this Jersey 1 class is not loaded from the shared library, can I explicitly exclude the package?
EDIT:
A bit more investigation seems to imply it's something to do with CDI, the ContainerResponseFilter
is annotated as a @Producer
. If I remove the annotation from the class then I no longer receive the exception.
The container I am using is weblogic 12.2.1 which I believe uses Weld as its CDI provider. So I created a beans.xml with the following as indicated by this bit of Weld documentation
<beans xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:weld="http://jboss.org/schema/weld/beans">
<weld:scan>
<weld:exclude name="com.xxx.utils.jersey.**"/>
</weld:scan>
</beans>
But it doesn't seem to solve the issue. Any ideas?