Closed ludoo0d0a closed 8 years ago
or add an exclusion filter based on "originUri" at the beginning of doFilterInternal, to bypass some specifics urls...
Here is my working solution :
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
try {
runIfTrue(charon.getTracing().isEnabled(), () -> traceInterceptor.initTraceId());
String originUri = extractor.extractUri(request);
log.debug("Incoming: {} {}", request.getMethod(), originUri);
ResponseEntity<byte[]> responseEntity = null;
//Add an exclusion filter
if (!exclusionFilter.isIgnored(originUri)){
byte[] body = extractor.extractBody(request);
HttpHeaders headers = extractor.extractHttpHeaders(request);
HttpMethod method = extractor.extractHttpMethod(request);
runIfTrue(charon.getTracing().isEnabled(), () -> traceInterceptor.onRequestReceived(method, originUri, body, headers));
addForwardHeaders(request, headers);
if (isMappingAsynchronous(originUri)) {
taskExecutor.execute(() -> retryOperations.execute(
context -> requestForwarder.forwardHttpRequest(body, headers, method, originUri, context)
));
responseEntity = new ResponseEntity<>(ACCEPTED);
} else {
responseEntity = retryOperations.execute(context -> requestForwarder.forwardHttpRequest(body, headers, method, originUri, context));
}
}
Thanks for reporting the bug. I'll check that out soon.
This exclusion filter is required, when in your application, you use some extra resources like an API or just web pages. Access to these "internal" resources will trigger noisely the tracing system. So it doesn't conflict with dynamic mappings because it is about internal resources.
As sample, add a /static/index.html and will see 2 requests trigger index.html + favicon.ico ... Thats why we need to exclude these requests.
@mkopylec When the 1.8.0 will be released? Please :)
@matheusmessora The fix is already done, I will release it tomorrow.
@mkopylec Thanks. I will be waiting :) Nice starter btw, it is helping us a lot in a new feature.
It is already released. You have to wait a few minutes for maven central update :)
I failed to POST data on a controller in the same app hosting charon proxy. The requestbody is eternally empty (but it works if I remove charon).
I think that body is read forn inputstream once in doFilterInternal
byte[] body = extractor.extractBody(request);
but since inputstream has already been read once, it can be reused later in another servlet filter or in the controller, especially if there is no mapping (responseEntity==null).One solution would be to read body only if mapping exist. Isn't it ?