I still not understand why you want to do this, but this way it should work
@RequestMapping(value="/controller", method=GET)
public ResponseEntity<String> foo() {
String content =
"<header>"
+ "<h1><span>Url is not reachable from</span>" + l.getReachableDate() + "</h1>"
+ "</header>";
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.setContentType(MediaType.TEXT_HTML);
return new ResponseEntity<String>(content, responseHeaders, HttpStatus.NOT_FOUND);
}
after some comments....
Instead of redirecting the user to an resource not found page, it would been better to have an ResourceNotFoundRuntimeException
(extends RuntimeException) and register an MVC exception handler (that is what prem kumar suggested, but wihtout the customized exception html text):
public class ResourceNotFoundRuntimeException extends RuntimeException{
...
}
The handler:
@ControllerAdvice
public class ExceptionHandlerController {
@ExceptionHandler(ResourceNotFoundRuntimeException .class)
public ResponseEntity<String> resourceNotFoundRuntimeExceptionHandling(){
String content =
"<header>"
+ "<h1><span>Url is not reachable from</span>" + l.getReachableDate() + "</h1>"
+ "</header>";
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.setContentType(MediaType.TEXT_HTML);
return new ResponseEntity<String>(content, responseHeaders, HttpStatus.NOT_FOUND);
}
}