1

I'm working with an API that is not well documented and I am trying to save the requests made to the server so I can better understand the inner workings.

Some preliminary research yielded two possible solutions:

A) Filters

B) Request Dumper Valve


Here are some of the areas where I found helpful advice that I didn't understand how to use:

Logging Payload of POSTs to Tomcat

https://coderanch.com/t/484631/application-servers/configure-Tomcat-log-POST-data


My problem is not with the solutions that were provided in the above links, it's that I don't understand how to utilize them in Tomcat.

For example, in the first link the OP posts:

public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse,
                     FilterChain chain) throws IOException, ServletException {
    HttpServletRequest request = (HttpServletRequest) servletRequest;
    LOG.debug("payload: " + requestWrapper.getRequestBody());

and web.xml:

<filter>
    <filter-name>PayloadLoggingFilter</filter-name>
    <filter-class>com.host.PayloadLoggingFilter</filter-class>
</filter>

<filter-mapping>
    <filter-name>PayloadLoggingFilter</filter-name>
    <url-pattern>/resources/*</url-pattern>
</filter-mapping>

Which is great! Except that if I add the code above into my web.xml my localhost TomCat will only return 404, and I have no idea where I should put the Java code as it can't compile on its' own and definitely requires some dependencies.

Any help is appreciated.

Eugène Adell
  • 3,089
  • 2
  • 18
  • 34
CatAtGat
  • 11
  • 1
  • 1
    The `doFilter` method belongs in a class that you have to write. The class has to implement the `Filter` interface. There are tutorials which describe this, step-by-step. For example, [here](http://www.avajava.com/tutorials/lessons/what-is-a-filter-and-how-do-i-use-it.html). The fully qualified name of your class then goes into the `` tag. Regarding the ``, your example is filtering everything arriving at `/resources/*`. Your web app almost certainly does not have such a URL pattern. The tutorials should cover this. That should get you started. – andrewJames Mar 06 '20 at 19:51
  • Thank you, this tutorial was exactly the kind of content I was searching for! – CatAtGat Mar 06 '20 at 19:56

0 Answers0