Logging of api-rest requests and responses

Hi,

Currently we have a poc and are integrating our portal with camunda.
It would be helpful if we where able to log the rest requests we received from our portal.
This will help to analyze in case of errors.

Regards Dirk

Hi Dirk,

have you tried to configure jul already? You can read more details here:

https://docs.camunda.org/manual/7.6/user-guide/logging/

Cheers,
Askar

1 Like

Sounds to me like something an application server should do for you or that should be implemented in a servlet filter.

1 Like

My solution:

  1. Add javax.servlet dependency
<dependency>  
  <groupId>javax.servlet</groupId>
  <artifactId>servlet-api</artifactId>
  <version>3.0-alpha-1</version>
  <scope>provided</scope>
</dependency>
  1. Create a javax.servlet.Filter

     package org.camunda.bpm.example.loanapproval.rest;
     import javax.servlet.Filter;
     public class RequestLoggingFilter implements Filter {
     	private static final Logger logger = LoggerFactory.getLogger(RequestLoggingFilter.class);
    
     	public void init(FilterConfig fConfig) throws ServletException {
     	}
    
     	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
     		logger.info("Peticion REST");
     		chain.doFilter(request, response);
     	}
     }
    
  2. Add new filter to web.xml. The filter should be the first applied.

         <filter>
     		<filter-name>RequestLoggingFilter</filter-name>
     		<filter-class>org.camunda.bpm.example.loanapproval.rest.RequestLoggingFilter</filter-class>
     	</filter>
     	
     	<filter-mapping>
     		<filter-name>RequestLoggingFilter</filter-name>
     		<url-pattern>/*</url-pattern>
     	</filter-mapping>
1 Like