0

I want to handle exceptions from XSSRequestWrapper.

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
                chain.doFilter(new XSSRequestWrapper((HttpServletRequest) request), response);}

And class XSSEncoderRequestWrapper extends HttpServletRequestWrapper. In XSSRequestWrapper class, I want to validate the email and name fields. If they are not valid then want to throw some customer exception. Like email is not valid.

user2144684
  • 103
  • 2
  • 12
  • Where are these email and name fields? Are they query parameters or a part of a POST body or somewhere else? Seems like you just need to get those values and then validate them. – Steven Diamante Mar 01 '22 at 16:13
  • Yes, they are part of a POST body and want to be validated. Actually, we want to validate all these fields at the application level. So that the fields are valid for all the forms available through the application. – user2144684 Mar 02 '22 at 05:05
  • Here's what you're looking for: https://stackoverflow.com/questions/8100634/get-the-post-request-body-from-httpservletrequest – Steven Diamante Mar 02 '22 at 12:26
  • Thanks for sharing it. But how do I throw some custom exception from it? So that users can be banned for not giving the wrong name or email in the request form. Want to share one thing that I am working on a legacy application that has UI in JSP and submitting the JSP form. – user2144684 Mar 03 '22 at 07:29
  • Just make a new class that extends Runtime Exception. Then throw new MyCustomException("error message"; – Steven Diamante Mar 04 '22 at 13:01

0 Answers0