During Jersey Upgrade lot of apis from com.sun.jersey is not supported in the Jersey 2.29 which supports Java11. What should be the alternatives for below APIs ?
ServletHolder sh = new ServletHolder(ServletContainer.class);
sh.setInitParameter("com.sun.jersey.config.property.resourceConfigClass",
"com.sun.jersey.api.core.PackagesResourceConfig");
sh.setInitParameter(PackagesResourceConfig.PROPERTY_PACKAGES,
String.format("%s;%s", ThrowableMapper.class.getPackage().getName(), packageName));
sh.setInitParameter("com.sun.jersey.api.json.POJOMappingFeature", Boolean.TRUE.toString());
ServletContextHandler context = new ServletContextHandler();
if (contextPath.indexOf("/") == 0) {
contextPath = contextPath.substring(1);
}
context.setContextPath(String.format("/api/mid/%s", contextPath));
context.addServlet(sh, "/*");
is used to provide a POJO Support whereas in 2.x, Jersey has few of the auto discoverable features like JSON Binding where we just have to add the dependency in the pom so that they get loaded in the classpath.
is used to create an instance of resourceConfigClass. Although in few of the forums it is mentioned that even if it's not instantiated it would create an instance on a fly to add resources. Now in 2.x if ServerProperties.PROVIDER_PACKAGES is used then source code of ServletContainer also confirms the same so we should not need to instantiate resourceConfigClass separately. So, this parameter can easily be removed.
ServerProperties.PROVIDER_PACKAGES should be used for above code instead of PackagesResourceConfig.PROPERTY_PACKAGES.