java - Camel-Jetty Rest DSL custom filter not working on GET requests - Stack Overflow

I am using camel-jetty (camel version 3.20.0 and jetty version 9.44) rest-configuration for rest servic

I am using camel-jetty (camel version 3.20.0 and jetty version 9.44) rest-configuration for rest services.

<restConfiguration component="jetty" port="9091" bindingMode="off" enableCORS="true">
    <componentProperty key="sendServerVersion" value="false"/>
    <endpointProperty key="filters" value="#logFilter"/>
</restConfiguration>

The logFilter implements javax.servlet.Filter and logs the event data at the end of the request.

@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) {

   try {
      if (servletRequest instanceof HttpServletRequest request && servletResponse instanceof HttpServletResponse response) {
         // Setup Logging
      } else {
         // Pass non-HTTP requests through without logging
         filterChain.doFilter(servletRequest, servletResponse);
      }
   } catch (Exception e) {
      sendErrorResponse((HttpServletResponse) servletResponse, e);
   } finally {
      MDC.clear();
   }

}

For the POST requests, the request is going through this filter, but for GET requests its not working. I am guessing it only goes through this filter if the request contains any request body. How can I make this work with GET requests? Please help.

I tried with setting custom Handlers also, but even that is not working. I want this filter to work with GET requests too.

I am using camel-jetty (camel version 3.20.0 and jetty version 9.44) rest-configuration for rest services.

<restConfiguration component="jetty" port="9091" bindingMode="off" enableCORS="true">
    <componentProperty key="sendServerVersion" value="false"/>
    <endpointProperty key="filters" value="#logFilter"/>
</restConfiguration>

The logFilter implements javax.servlet.Filter and logs the event data at the end of the request.

@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) {

   try {
      if (servletRequest instanceof HttpServletRequest request && servletResponse instanceof HttpServletResponse response) {
         // Setup Logging
      } else {
         // Pass non-HTTP requests through without logging
         filterChain.doFilter(servletRequest, servletResponse);
      }
   } catch (Exception e) {
      sendErrorResponse((HttpServletResponse) servletResponse, e);
   } finally {
      MDC.clear();
   }

}

For the POST requests, the request is going through this filter, but for GET requests its not working. I am guessing it only goes through this filter if the request contains any request body. How can I make this work with GET requests? Please help.

I tried with setting custom Handlers also, but even that is not working. I want this filter to work with GET requests too.

Share Improve this question asked Mar 10 at 15:29 Arthur LeywinArthur Leywin 11 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

Jetty 9 is EOL.

  • See Jetty 9 EOL Announcement

You should be using a supported version of Jetty at this point in time. At the time of me writing this, that would be a Jetty 12.0.x version.

If you require support for the older javax.servlet namespace, then you can use the ee8 environment on Jetty 12 to maintain support for the legacy servlet namespace.

The behavior you are asking about is well supported on supported versions of Jetty.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744838004a4596382.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信