Cannot get JAX-RS Jersey Resource working with Proguard-obfuscated REST service

Sorry for the length of this post. I try to get all the useful information in it and anticipate questions that people may have.

I have a series of RESTful web services that were implemented in Jersey and run on Jetty. Everything works fine with the un-obfuscated version of the jar file. But when I mess up Proguard, I get a 500 message with a message

The ResourceConfig instance does not contain any root resource classes.

As part of my package, I have an extremely simple ping service, so I can check the connection and basic configuration of Jersey.

My code that launches the berth with knitwear looks like this:

ServletHolder sh = new ServletHolder(ServletContainer.class);
sh.setInitParameter("com.sun.jersey.config.property.packages", "com.sw.pr.hq");
sh.setInitParameter("com.sun.jersey.config.property.resourceConfigClass",
            "com.sun.jersey.api.core.PackagesResourceConfig");
ServletContextHandler sch = new ServletContextHandler(server, "/pr");
sch.addServlet(sh, "/");

When I try to hit my ping url from the browser, the debug log shows the following lines:

Jan 13, 2011 9:33:35 AM com.sun.jersey.api.core.PackagesResourceConfig init
[java] INFO: Scanning for root resource and provider classes in the packages:
[java]   com.sw.pr.hq

, , . , .

, , ping, , :

[java] SEVERE: The ResourceConfig instance does not contain any root resource classes.
[java] 2011-01-13 09:33:35.585:WARN:/pr:unavailable

proguard ( ). , jar -tvf obfuscated.jar, com.sw.pr.HQServerResource.class.

-dontskipnonpubliclibraryclasses
-renamesourcefileattribute SourceFile
-keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,*Annotation*,EnclosingMethod
-overloadaggressively
-repackageclasses com.sw.rtm
-adaptresourcefilenames    **.properties,**.png,**.css
-adaptresourcefilecontents **.properties,META-INF/MANIFEST.MF
-keep public class * {
    public *;
}
-keepclassmembernames class * {
    java.lang.Class class$(java.lang.String);
    java.lang.Class class$(java.lang.String, boolean);
}
-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

ping :

@Path("/")
public class HQServerResource {
    @GET
    @Produces(MediaType.APPLICATION_XML)
    @Path("/ping")
    public PingResponse pingGet(@Context HttpServletRequest httpRequest) {
        LOGGER.debug("pingGet()");
        return getPingResponse(httpRequest);
    }
}

- Proguard.

, , Proguard @Path . (-keepattributes Annotation) proguard. .

.

STACK TRACE:

[java] com.sun.jersey.api.container.ContainerException: ResourceConfig root.  [java] com.sun.jersey.server.impl.application.RootResourceUriRules. (RootResourceUriRules.java:103)  [java] com.sun.jersey.server.impl.application.WebApplicationImpl._initiate (WebApplicationImpl.java:1182)  [java] com.sun.jersey.server.impl.application.WebApplicationImpl.access $600 (WebApplicationImpl.java:161)  [java] com.sun.jersey.server.impl.application.WebApplicationImpl $12.f(WebApplicationImpl.java:698)  [java] com.sun.jersey.server.impl.application.WebApplicationImpl $12.f(WebApplicationImpl.java:695)  [java] com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:197)  [java] com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:695)  [java] com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:690)  [java] at com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:438)  [java] com.sun.jersey.spi.container.servlet.ServletContainer $InternalWebComponent.initiate(ServletContainer.java:287)  [java] com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:587)  [java] at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:213)  [java] com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:342)  [java] com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:516)  [java] javax.servlet.GenericServlet.init(GenericServlet.java:211)  [java] org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:431)  [java] org.eclipse.jetty.servlet.ServletHolder.getServlet(ServletHolder.java:330)  [java] org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:510)

+3
1

, , . , proguard jar.

, jar .

com/sw/pr/hq/HQServerResource.class
com/sw/pr/hq/a.class
com/sw/pr/hq/a.class

, .

-keepdirectories proguard, jar .

com/
com/sw/
com/sw/pr/
com/sw/pr/hq/
com/sw/pr/hq/HQServerResource.class
com/sw/pr/hq/a.class
com/sw/pr/hq/a.class

, Servlet , @Path.

, .

+8

Source: https://habr.com/ru/post/1785234/


All Articles