In the context of Jersey 2.25.1, a very simple REST API is built with a simple JAXB POJO bean:
@XmlRootElement
public class Profile {
@XmlAttribute
private String name;
//setter and getter
}
and a resource
public class ProfileResource {
@Path("/profile")
@Produce(MediaType.APPLICATION_XML)
public Profile getProfile() {
Profile p = new Profile();
p.setName("test");
return p;
}
}
and it is running on a Tomcat server.
A bug is in the POJO - Profile - deliterately so that when sending http request to localhost:8080/contextroot/profile
, I would get an internal error response with STATUS 500. However, the ERROR detail is not written into the default log file in the backend Tomcat server. By comparison, with Spring framework all errors will be logged.
According to the Jersey Documentation, tracing support can be enabled by set jersey.config.server.tracing.type
to ALL
. So I extends
the jax.ws.rs.core.Application
as the following:
@ApplicationPath("contextroot")
public class ApplicationConfig extends Application {
@Override
public Map<String, Object> getProperties() {
Map<String,Object> properties = new HashMap<>();
properties.put(ServerProperties.TRACING, TracingConfig.ALL.toString());
System.out.println("Appliction is getting properties::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::");
return properties;
}
}
with the jaxrs-ri
dependency according to How to set up JAX-RS Application using annotations only (no web.xml). So this class is indeed instantiated when starting the application on the Tomcat server. However, when debugging on the the first line in org.glassfish.jersey.server.ServerRuntime.process(final ContainerRequest request)
class, i.e. TracingUtils.initTracingSupport(tracingConfig, tracingThreshold, request);
, the value of property jersey.config.server.tracing.type
was detected to be still OFF
when sending a request, meaning the ApplicationConfig
is not used at all.
Question: How to enable the tracing support of a Jersey application on the Tomcat server
NOTE! There is a rough answer in Why does jersey have no error log when the status is 500? However, this answer will turn all the errors into internal error with status 500, which is unexpected obviously