Using the default method for unsurpassed REST methods in Jersey

I know that this is not entirely “reassuring,” but I want to learn how and how I can handle all requests that do not match any of the methods of my REST resource (I want to proxy these requests to another server). For example, it could be a method like:

@GET @Path("*") public Response defaultMethod(@Context HttpServletRequest request, @Context HttpServletResponse response) { // do proxying here } 

how can i achieve this

BR,

Serkanc

+4
source share
2 answers
 @Path("/{default: .*}") 

This works for:

  • http://example.com/someUnexpectedPath
  • http://example.com/someUnexpectedPath/withAdditionalSubPaths
  • http://example.com/someUnexpectedPath/withAdditionalSubPaths?andParams=whatever
+8
source

One option is to define a 404 user mapping. Since 404s handles all unsurpassed requests, it must catch all undefined URLs.

I added the following to my web.xml

  <error-page> <error-code>404</error-code> <location>/error/404</location> </error-page> 

Where location is the path you want to send the request to. Then just determine that the call is normal.

+2
source

All Articles