1

I'm using jersey 2. This is an app I did not set up myself. I followed the instructions in this answer: https://stackoverflow.com/a/33271754

But, this isn't doing anything. I put breakpoints on every method and none of them are ever called whether on startup or on thrown exceptions. I googled a bit and read that I need to register it in the web.xml with a line like this:

  <servlet>
        <servlet-name>jersey-serlvet</servlet-name>
        <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
        <init-param>
             <param-name>jersey.config.server.provider.packages</param-name>
             <param-value>com.mypackage.rest</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

But, my ExceptionLogger is already in that package. Official docs give examples with a ResourceConfig class, but that class doesn't exist in my project (despite the fact that the app runs fine).

I'm not necessarily asking what I'm doing wrong, I want to know how to get some information out of Jersey 2 so that I can troubleshoot what I'm doing wrong. It doesn't spit out any logs on startup, but the app appears to be running fine when I hit it. Is there a property I can set to that it will print debugging information about how it's searching for things like ApplicationEventListener?

Update

I figured out how to solve it. I needed to add this to my web.xml:

  <init-param>
      <param-name>jersey.config.server.provider.classnames</param-name>
      <param-value>org.glassfish.jersey.filter.LoggingFilter;com.mypackage.rest.ExceptionLogger</param-value>
  </init-param>

Can someone explain to me why the .packages param wouldn't make the .classnames redundant?

Daniel Kaplan
  • 62,768
  • 50
  • 234
  • 356
  • @CassioMazzochiMolin it's not the answer I'm looking for. I don't know why this works or how to troubleshoot the issue. – Daniel Kaplan Jan 19 '18 at 23:38

1 Answers1

1

The listener needs to be annotated with @Provider. That's what the package scan is looking for: classes annotated with @Path or @Provider. It registers all those classes that it finds.

When you use the classes, you don't need to use @Provider as you're explicitly telling Jersey what classes to register.

Paul Samsotha
  • 205,037
  • 37
  • 486
  • 720