Hello,
On 6/4/12 12:01 PM, daniel.cklam_at_gmail.com wrote:
> Thank you for prompt reply!
>
> When I searched around before I did come across suggestions of using
> "LoggingFilter" from here:
> http://stackoverflow.com/questions/2332515/how-to-get-jersey-logs-at-se
> rver
>
> What I did was I copied and pasted the following to my web.xml:
>
> <init-param>
>
> <param-name>com.sun.jersey.spi.container.ContainerRequestFilters</param
> -name>
>
> <param-value>com.sun.jersey.api.container.filter.LoggingFilter</param-v
> alue>
> </init-param>
> <init-param>
>
> <param-name>com.sun.jersey.spi.container.ContainerResponseFilters</para
> m-name>
>
> <param-value>com.sun.jersey.api.container.filter.LoggingFilter</param-v
> alue>
> </init-param>
>
> ...which gave me errors:
>
> [#|2012-06-04T14:26:48.448+1000|SEVERE|glassfish3.1.2|javax.enterprise.
> system.tools.admin.org.glassfish.deployment.admin|_ThreadID=21;_ThreadN
> ame=Thread-2;|Exception while deploying the app
> [lamophone-resource-1.0] : org.xml.sax.SAXParseException:
> cvc-complex-type.2.4.a: Invalid content was found starting with element
> 'init-param'. One of '{"http://java.sun.com/xml/ns/javaee":description,
> "http://java.sun.com/xml/ns/javaee":display-name, "...
>
> I didn't know how to proceed further.
>
> Now that you mentioned the use of LoggingFilter again, I looked at
> JavaDoc again
> (http://jersey.java.net/nonav/apidocs/1.12/jersey/com/sun/jersey/api/co
> ntainer/filter/LoggingFilter.html) and studied some samples you
> suggested (this one to be exact:
> http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22jersey-samples%22).
>
> What I found is that the JavaDoc for LoggingFilter did say "When an
> application is deployed as ***a Servlet or Filter*** this Jersey filter
> can be registered using the following initialization parameters...". I
> also saw samples where the "init-param" is used in web.xml like:
>
> <servlet>
> <servlet-name>Jersey Web Application</servlet-name>
>
> <servlet-class>com.sun.jersey.server.impl.container.servlet.ServletAdap
> tor</servlet-class>
>
> <init-param>
> ....
> </init-param>
> ....
> </servlet>
>
> So, now I realized that the init-param is supposed to be used within
> <servlet> tags or<filter> tags.
>
> However my simple web service provider class is just a simple stateless
> EJB. Its pom.xml doesn't have<servlet> or<filter> tags. How's it
> supposed to use the LoggingFilter?
<servlet> or <filter> needs to be in web.xml. If you don't have one and
you are using ResourceConfig for configuring Jersey, you can add these
params as its properties and it should work. Or you can add web.xml to
your project, (it should be in ./src/main/webapp/WEB-INF/web.xml, see
helloworld-webapp [1] sample for more details).
> Btw, I have already figured out my original error was caused by caller
> not "escaping" some return characters in a service parameter.
great, good for you :) you might consider using Jersey Client at least
for testing, it should solve these kinds of problems for you without any
effort.
Regards,
Pavel
[1]
http://search.maven.org/remotecontent?filepath=com/sun/jersey/samples/helloworld-webapp/1.12/helloworld-webapp-1.12-project.zip