1

I have one controller that is configured with session authentication for /session_auth_uri as below:

@Controller
@RequestMapping("/session_auth_uri")
public class BaseController {

  @RequestMapping(value = "/do", method = RequestMethod.POST, consumes =    "application/json", produces = "application/json")
  @ResponseBody
  public Result do(@RequestBody Query query) throws SomeException {
    return new Result();
  }

  @RequestMapping(value = "/exec", method = RequestMethod.POST, consumes =    "application/json", produces = "application/json")
  @ResponseBody
  public Result exec(@RequestBody Query query) throws SomeException {
    return new Result();
  }
}

I want to extend BaseController to reuse 1 handler method => do(...) (basic authentication is used for /basic_auth_uri):

@Controller
@RequestMapping("/basic_auth_uri")
public class SubclassController extends BaseController {
}

The problem is that I want to be returned HttpStatus.NOT_IMPLEMENTED for exec(...) handler method when accessing /basic_auth_uri/exec.

Thanks for any suggestions.

1 Answer 1

1

Can't think of any other way than overriding it in SubclassController:

@Controller
@RequestMapping("/basic_auth_uri")
public class SubclassController extends BaseController {
  @RequestMapping(value = "/exec", method = RequestMethod.POST, consumes =    "application/json", produces = "application/json")
  @ResponseStatus(HttpStatus.NOT_IMPLEMENTED)
  public Result exec(@RequestBody Query query) throws SomeException {
    return null;
  }

}
Sign up to request clarification or add additional context in comments.

2 Comments

Indeed this works in case I provide a valid JSON serialized Query in the request. If I provide nothing in the request I get 500 - Internal server error because of MappingJacksonHttpMessageConverter; if I provide an invalid input in the request I get a JSONParseException; suppose we have an @ExceptionHandler method for RuntimeException and that returns 200 OK and the exception message in the response. I was thinking of something like: no matter what the request input is => always return the 501 - NOT IMPLEMENTED response status. Is there a way to have that?
I get the 501 - Not Implemented HTTP status code only if I remove the @RequestBody annotation.

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.