Jersey 2.0 and Moxy Internal Server Error But No Server Log

jax-rs, jersey, json, moxy, pojo

Solution

I had the same problem and found this post:

- http://jersey.576304.n2.nabble.com/Missing-MOXy-Log-Messages-In-Tomcat-td7580992.html

The author implemented ApplicationEventListener to log the exceptions thrown by Moxy. This is my implementation (needs to be registered in your application):

public class ExceptionListener implements ApplicationEventListener {

    @Override
    public void onEvent(ApplicationEvent event) {

    }

    @Override
    public RequestEventListener onRequest(RequestEvent requestEvent) {
        return new ExceptionRequestEventListener();
    }

    public static class ExceptionRequestEventListener implements RequestEventListener{
        private final Logger logger;

        public ExceptionRequestEventListener(){
            logger = Logger.getLogger(getClass());
        }

        @Override
        public void onEvent(RequestEvent event) {
            switch (event.getType()){
                case ON_EXCEPTION:
                    Throwable t = event.getException();
                    logger.error("Found exception for requestType: "+event.getType(), t);
            }
        }
    }
}

Problem

I followed the Jersey 2.0 document (https://jersey.java.net/documentation/latest/user-guide.html#json.moxy), modified pom.xml, included jersey-media-moxy artifact, compiled and installed. I could get basic POJO to JSON mapping work for both Produces and Consumes cases. However, when I tried with some POJO with complex data type as resource return type, I got a lot Status 500 Internal Server Error but without any server log. It is very annoying. Does anybody know if it is a bug or I missed something in configuration? By the way, in order to use Moxy mapping for a POJO object, the POJO needs to have a empty parameter constructor. Are there any other requirements?

Original source