1

wanting to use RestControllerAdvice and in like the default response from Spring have the path. Seems like via the ExceptionHandler I can use the WebRequest. I can see the headers but unsure how to show the path. looked at the parameters but nothing in there showed the path. How can I obtain the path of the request:

@RestControllerAdvice
public class RestControllerExceptionHandler {
 
 @Autowired
 private ErrorAttributesConfig errAttrib;


 @ExceptionHandler(value = {IOException.class})
 @ResponseStatus(HttpStatus.BANDWIDTH_LIMIT_EXCEEDED)
 public AppErrorAttributes internalServerError(Exception e, WebRequest h) {
  
  System.out.println(h.getContextPath());
//  for (Iterator<String> i = h.getParameterNames(); i.hasNext(); ) {
//   System.out.println(i.next());
//  }
  String[] s = h.getAttributeNames(0);
  for (Iterator<String> i = h.getHeaderNames(); i.hasNext();) {
   System.out.println(i.next());
  }
  AppErrorAttributes aea = errAttrib.appErrorAttributes();
  aea.setStatus(HttpStatus.BAD_REQUEST.value());
  aea.setError(HttpStatus.BAD_REQUEST.getReasonPhrase());
  aea.setMessage(e.getMessage());
  return aea;
 }

1 Answer 1

1

used

 @ExceptionHandler(value = {IOException.class})
 @ResponseStatus(HttpStatus.BANDWIDTH_LIMIT_EXCEEDED)
// public AppErrorAttributes internalServerError(Exception e, WebRequest h) {
 public AppErrorAttributes internalServerError(Exception e, HttpServletRequest h) {

  System.out.println(h.getServletPath());
  System.out.println(h.getRequestURI());
  
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.