Search code examples
javajettyhttp-proxy

Need to intercept the PUT calls from client with the header of manipulation


I have a written a jetty http proxy server, in that i need to intercept the PUT calls from client with the header of manipulation.

when I refer jetty there is some fixes in jetty to handle issue (100-continue) header, so I thought it is useful for my request to interrupt and manipulate the request. can anyone please suggest how to implement this logic's in my java code.


Solution

  • This is possible via Filter Interface, you need to implement the interface and do your logic inside the doFilter method as per below code sample.

    public class HttpFilter implements Filter
    {
      public void doFilter(ServletRequest request, ServletResponse response,
           FilterChain filterChain) throws IOException, ServletException
       {
           HttpServletRequest httpRequest = (HttpServletRequest) request;        
           if(httpRequest.getMethod().equalsIgnoreCase("PUT")){
    
           }
           filterChain.doFilter(request, response);
       }
        // other methods etc
    }
    

    Then you need to make sure you declare your filter and filter-mapping entries inside web.xml