Hello,
we have a problem disabling logging. The situation is as follows:
We have a JUnit test that makes a big amount of requests to our REST
API. Cause we may throw an exception on the server (due to wrong /
parameters) we have an ErrorModel and and exception mapper for that.
Now it can happen that we have accidently have no error model while
there should be one (negative tests) or that there is none while there
should be one (positive tests). Thus we can not avoid trying to get an
ErrorModel with
response.getEntity( ErrorModelWithoutStatus.class ); /* response is an
instance of ClientResponse */
but that leads to ClientResponse.getEntity(Class<T> c, Type type) with
the unavoidable logging of an error message due to
...
String message = "A message body reader for Java class " + c.getName() +
", and Java type " + type +
", and MIME media type " + mediaType + " was not
found";
LOGGER.severe(message);
Map<MediaType, List<MessageBodyReader>> m =
workers.getReaders(mediaType);
LOGGER.severe("The registered message body readers
compatible with the MIME media type are:\n" +
workers.readersToString(m));
throw new ClientHandlerException(message);
(in Jersey 1.6, class ClientResponse, method .getEntity(Class<T> c, Type
type), behaviour seems to be the same in Jersey 1.7)
So there are cases where we expect the thrown ClientHandlerException and
catch them accordingly but we can not prevent the misleading logging. So
how can we avoid the logging?
Trying init-param in web.xml failed, trying configuring log4j.xml
failed, even trying
private final static Logger COM_SUN_JERSEY_LOGGER = Logger.getLogger(
"com.sun.jersey" );
private final static java.util.logging.Logger COM_SUN_JERSEY_LOGGER2 =
LogManager.getLogManager( ).getLogger( "com.sun.jersey" );
static
{
COM_SUN_JERSEY_LOGGER.setLevel( Level.OFF );
COM_SUN_JERSEY_LOGGER2.setLevel(java.util.logging.Level.OFF);
}
failed.
With kind regards
Sebastian / Pengfei
--
Pengfei Di
Technology
match2blue software development GmbH
Leutragraben 1
07743 Jena
Tel: +49 3641 816 8092
Mobil: +49 1520 166 8691
Fax: +49 3641 573 3479
Email: pengfei.di_at_match2blue.com
Web : www.match2blue.com
Blog : http://blog.match2blue.com
Registergericht: Amtsgericht Jena
Registernummer: HRB 503726
Geschäftsführerin: Stephanie Renda