Hi All,
Hope doing well.
I am using Jersey 1.8 (JAX-RS) for REST web services development. While
doing it, i want to log all incoming requests and responses into a file and
so i tried to use LoggingFilter.java. But by default, it logs on System.out
rather than file.
So i wrote one more Filter extending default LoggingFilter class and make
appropriate entry of new filter in web.xml. But i am getting an exception -
SEVERE: Missing dependency for constructor public
com.abc.common.ApplianceLoggingFilter(java.util.logging.Logger) at parameter
index 0
Attaching the exception trace and code i have written for more reference -
*Sample Code*
1. web.xml
<init-param>
<param-name>com.sun.jersey.spi.container.ContainerRequestFilters</param-name
>
<param-value>com.abc.common.ApplianceLoggingFilter</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.spi.container.ContainerResponseFilters</
param-name>
<param-value>com.abc.common.ApplianceLoggingFilter</param-value>
</init-param>
2. ApplianceLoggingFilter.java
*
package* com.abc.common;
*
import* java.util.logging.Logger;
*
import* com.sun.jersey.api.container.filter.LoggingFilter;
*
import* com.sun.jersey.spi.container.ContainerRequest;
*
import* com.sun.jersey.spi.container.ContainerResponse;
*
public* *class* ApplianceLoggingFilter *extends* LoggingFilter {
*private* *static* *final* Logger *alogger* = ApplianceWSLoggerFactory.*
getLogger*();
*public* ApplianceLoggingFilter(Logger logger) {
*super*(*alogger*);
}
@Override
*public* ContainerResponse filter(ContainerRequest request,
ContainerResponse response) {
*return* *super*.filter(request, response);
}
@Override
*public* ContainerRequest filter(ContainerRequest arg0) {
*return* *super*.filter(arg0);
}
}
3. ApplianceWSLoggerFactory.java
Its a singleton class to give reference of java.util.looging.Logger object.
*
public* *class* ApplianceWSLoggerFactory {
*private* *static* *volatile* Logger *logger* = Logger.*getLogger*(
"ApplianceWSLogger");
*private* ApplianceWSLoggerFactory() {}
/**
* Get the java.util.looging.Logger to log the REST web services requests and
responses.
*
* *_at_return
*
*/
*public* *static* Logger getLogger() {
*return* *logger*;
}
/**
* Set the file appender root logger to log every requests and responses.
*
* *_at_param* alogger
*/
*public* *static* *void* setLogger(Logger alogger) {
*logger* = alogger;
}
*Entire exception trace*:
21 Oct, 2011 4:39:01 PM
com.sun.jersey.server.impl.application.WebApplicationImpl _initiate
INFO: Initiating Jersey application, version 'Jersey: 1.8 06/24/2011 12:17
PM'
21 Oct, 2011 4:39:04 PM com.sun.jersey.spi.inject.Errors
processErrorMessages
SEVERE: The following errors and warnings have been detected with resource
and/or provider classes:
SEVERE: Missing dependency for constructor public
com.abc.common.ApplianceLoggingFilter(java.util.logging.Logger) at parameter
index 0
21 Oct, 2011 4:39:04 PM org.apache.catalina.core.ApplicationContext log
SEVERE: StandardWrapper.Throwable
*
com.sun.jersey.spi.inject.Errors$ErrorMessagesException
*
at com.sun.jersey.spi.inject.Errors.processErrorMessages(*Errors.java:170*)
at com.sun.jersey.spi.inject.Errors.postProcess(*Errors.java:136*)
at com.sun.jersey.spi.inject.Errors.processWithErrors(*Errors.java:199*)
at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(*
WebApplicationImpl.java:771*)
at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(*
WebApplicationImpl.java:766*)
at com.sun.jersey.spi.container.servlet.ServletContainer.initiate(*
ServletContainer.java:488*)
at
com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(
*ServletContainer.java:318*)
at com.sun.jersey.spi.container.servlet.WebComponent.load(*
WebComponent.java:609*)
at com.sun.jersey.spi.container.servlet.WebComponent.init(*
WebComponent.java:210*)
at com.sun.jersey.spi.container.servlet.ServletContainer.init(*
ServletContainer.java:373*)
at com.sun.jersey.spi.container.servlet.ServletContainer.init(*
ServletContainer.java:556*)
at javax.servlet.GenericServlet.init(*GenericServlet.java:212*)
at org.apache.catalina.core.StandardWrapper.loadServlet(*
StandardWrapper.java:1173*)
at org.apache.catalina.core.StandardWrapper.load(*StandardWrapper.java:993*)
at org.apache.catalina.core.StandardContext.loadOnStartup(*
StandardContext.java:4350*)
at org.apache.catalina.core.StandardContext.start(*StandardContext.java:4659
*)
at org.apache.catalina.core.ContainerBase.start(*ContainerBase.java:1045*)
at org.apache.catalina.core.StandardHost.start(*StandardHost.java:785*)
at org.apache.catalina.core.ContainerBase.start(*ContainerBase.java:1045*)
at org.apache.catalina.core.StandardEngine.start(*StandardEngine.java:445*)
at org.apache.catalina.core.StandardService.start(*StandardService.java:519*
)
at org.apache.catalina.core.StandardServer.start(*StandardServer.java:710*)
at org.apache.catalina.startup.Catalina.start(*Catalina.java:581*)
at sun.reflect.NativeMethodAccessorImpl.invoke0(*Native Method*)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(*Bootstrap.java:289*)
at org.apache.catalina.startup.Bootstrap.main(*Bootstrap.java:414*)
21 Oct, 2011 4:39:04 PM org.apache.catalina.core.StandardContext
loadOnStartup
SEVERE: Servlet /APPLIANCE_WS threw load() exception
*
com.sun.jersey.spi.inject.Errors$ErrorMessagesException
*
at com.sun.jersey.spi.inject.Errors.processErrorMessages(*Errors.java:170*)
at com.sun.jersey.spi.inject.Errors.postProcess(*Errors.java:136*)
at com.sun.jersey.spi.inject.Errors.processWithErrors(*Errors.java:199*)
at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(*
WebApplicationImpl.java:771*)
at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(*
WebApplicationImpl.java:766*)
at com.sun.jersey.spi.container.servlet.ServletContainer.initiate(*
ServletContainer.java:488*)
at
com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(
*ServletContainer.java:318*)
at com.sun.jersey.spi.container.servlet.WebComponent.load(*
WebComponent.java:609*)
at com.sun.jersey.spi.container.servlet.WebComponent.init(*
WebComponent.java:210*)
at com.sun.jersey.spi.container.servlet.ServletContainer.init(*
ServletContainer.java:373*)
at com.sun.jersey.spi.container.servlet.ServletContainer.init(*
ServletContainer.java:556*)
at javax.servlet.GenericServlet.init(*GenericServlet.java:212*)
at org.apache.catalina.core.StandardWrapper.loadServlet(*
StandardWrapper.java:1173*)
at org.apache.catalina.core.StandardWrapper.load(*StandardWrapper.java:993*)
at org.apache.catalina.core.StandardContext.loadOnStartup(*
StandardContext.java:4350*)
at org.apache.catalina.core.StandardContext.start(*StandardContext.java:4659
*)
at org.apache.catalina.core.ContainerBase.start(*ContainerBase.java:1045*)
at org.apache.catalina.core.StandardHost.start(*StandardHost.java:785*)
at org.apache.catalina.core.ContainerBase.start(*ContainerBase.java:1045*)
at org.apache.catalina.core.StandardEngine.start(*StandardEngine.java:445*)
at org.apache.catalina.core.StandardService.start(*StandardService.java:519*
)
at org.apache.catalina.core.StandardServer.start(*StandardServer.java:710*)
at org.apache.catalina.startup.Catalina.start(*Catalina.java:581*)
at sun.reflect.NativeMethodAccessorImpl.invoke0(*Native Method*)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(*Bootstrap.java:289*)
at org.apache.catalina.startup.Bootstrap.main(*Bootstrap.java:414*)
Please ignore typo errors.
It will be a great help if someone provide me guidence on this issue. Sample
working code will be more than expected.
Thanks,
Amar