Basically, we redirect from a jsp page, that is, from the user interface level, we process such an operation (redirection). Therefore, I hope that you will use some soothing services in your application. And for most other services we ask for an asynchronous request. If it is a combination of asynchronous and quiet services; and I'm sure that you will use this in your application. If your session is invalid and you are trying to access any operation on a "session", then it will drop you into an "IllegalStateException". For this type of scenario, please follow the centralized JAX-RS Exception Handling engine below : javax.ws.rs.ext.ExceptionMapper . Follow these steps: step-1: Create a custom exception thrown as MyApplicationException:
public class MyApplicationException extends RuntimeException { public MyApplicationException() {super();}
step-2: Create a custom type ExceptionMapper
public class MyApplicationExceptionHandler implements ExceptionMapper<MyApplicationException> { @Override public Response toResponse(MyApplicationException exception) { return Response.status(Status.FORBIDDEN).entity(exception.getMessage()).build();
step-3: In all your ajax request in the UI code check this Status Code and redirect to the login page.
So that you can do it with a more subtle implementation. Guaranteed ...
source share