code: public static Application getWrappedApplication(Application app) {
          while (app instanceof ResourceConfig) {
              final Application wrappedApplication = ((ResourceConfig) app).getApplication();
              if (wrappedApplication == app) {
                  break;
              }
              app = wrappedApplication;
          }
          return app;
      }
docs: Gets the most internal wrapped {@link Application application} class. This method is similar to
  {@link org.glassfish.jersey.server.ResourceConfig#getApplication()} except if provided application was created by wrapping multiple
  {@link org.glassfish.jersey.server.ResourceConfig} instances this method returns the original application and not a resource config wrapper.
  
  @param app jax-rs application
  @return the original {@link javax.ws.rs.core.Application} subclass.