RESTeasy and X-HTTP override method

Is there a way that supports the request header of an X-HTTP override method (automatically / transparently) in RESTeasy?

This will simplify support for clients who cannot send PUT / DELETE requests.

Yes, overriding POST is less than ideal, but I think the Google convention using X-HTTP-Method-Override is reasonable / convenient work.

If RESTeasy can send POST requests with the X-HTTP-Method-Override header automatically, that would be a big time saver. I think Jersey just added something, for example, using a filtering approach, but I would rather stick with RESTeasy.

+4
source share
2 answers

RESTeasy processing headers support interceptors, which are described in the Reference Guide .

What you want is perhaps a PreProcessInterceptor that intercepts the call, looks for the header and, if necessary, changes the line / method redirection.

+3
source

I recently had the same problem, and the best solution I found was:

@Provider @PreMatching public class OverrideHttpMethodFilter implements ContainerRequestFilter { @Override public void filter(ContainerRequestContext requestContext) throws IOException { String receivedMethod = requestContext.getMethod(); String methodFromHeader = requestContext.getHeaderString("X-HTTP-Method-Override"); if (receivedMethod != null && !receivedMethod.equals(methodFromHeader)) { requestContext.setMethod(methodFromHeader); } } } 
+5
source

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


All Articles