Jersey Order Request

I am trying to implement RequestDispatcher using the dropwizard, which should look at the Entity in the body for messages and compute certain statistics.

so I implemented ResourceMethodDispatchAdapterand ResourceMethodDispatchProvider, and I can successfully insert and call my RequestDispatcher,

 private static class InspectRequestDispatcher implements RequestDispatcher {

    private final RequestDispatcher dispatcher;

    private InspectRequestDispatcher(RequestDispatcher dispatcher) {
        this.dispatcher = dispatcher;
    }

    @Override
    public void dispatch(final Object resource, final HttpContext context) {
        final Saying day = context.getRequest().getEntity(Saying.class);
        dispatcher.dispatch(resource, context); // this throws ConstraintViolationException
    }
}

The above code throws an exception, since I already read the body (which is understandable), I could reset the stream, but then I will pay a fine for reading the body twice.

Is it possible to intercept a method call AFTER parameters have been entered? for some reason to plan this interceptor last?

using dropwizard version 7

+4
source share
1 answer

ContainerRequestFilter RequestDispatcher, CachedEntityContainerRequest, .

HTTP- , , .

, , .

:

@Provider
public class StatsFilter implements ContainerRequestFilter {
    @Override
    public ContainerRequest filter(ContainerRequest request) {
        final CachedEntityContainerRequest cachedRequest
                = new CachedEntityContainerRequest(request);

        final Saying saying = cachedRequest.getEntity(Saying.class);

        return cachedRequest;
    }
}

.

+2

Source: https://habr.com/ru/post/1658360/


All Articles