package hirondelle.fish.all.logoff;
import hirondelle.web4j.model.AppException;
import hirondelle.web4j.action.ActionImpl;
import hirondelle.web4j.request.RequestParser;
import hirondelle.web4j.action.ResponsePage;
import javax.servlet.http.Cookie;
public final class LogoffAction extends ActionImpl {
public LogoffAction(RequestParser aRequestParser){
super(REDIRECT, aRequestParser);
}
public ResponsePage execute() throws AppException {
Cookie[] cookies = getRequestParser().getRequest().getCookies();
for(Cookie cookie : cookies){
if( cookie.getName().equalsIgnoreCase(SESSION_COOKIE_NAME)) {
cookie.setMaxAge(DELETE_IMMEDIATELY);
cookie.setValue(TEMP_COOKIE_VALUE);
cookie.setPath(getContext());
getRequestParser().getResponse().addCookie(cookie);
}
}
endSession();
return getResponsePage();
}
private static final ResponsePage REDIRECT = new ResponsePage("../../Logoff.jsp");
private static final String SESSION_COOKIE_NAME = "JSESSIONID";
private static final String TEMP_COOKIE_VALUE = "EXPIRED";
private static final int DELETE_IMMEDIATELY = 0;
private String getContext(){
return getRequestParser().getRequest().getContextPath();
}
}