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 badge1 Answer
Reset to default 0Jetty 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条)