use of javax.servlet.http.HttpSession in project javaee7-samples by javaee-samples.
the class PublicServletPublicEJBLogout method doGet.
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String webName = null;
if (request.getUserPrincipal() != null) {
webName = request.getUserPrincipal().getName();
}
String ejbName = "";
try {
ejbName = publicEJB.getUserName();
} catch (Exception e) {
logger.log(SEVERE, "", e);
}
request.logout();
HttpSession session = request.getSession(false);
if (session != null) {
session.invalidate();
}
String webNameAfterLogout = null;
if (request.getUserPrincipal() != null) {
webNameAfterLogout = request.getUserPrincipal().getName();
}
String ejbNameAfterLogout = "";
try {
ejbNameAfterLogout = publicEJB.getUserName();
} catch (Exception e) {
logger.log(SEVERE, "", e);
}
response.getWriter().write("web username: " + webName + "\n" + "EJB username: " + ejbName + "\n");
response.getWriter().write("web username after logout: " + webNameAfterLogout + "\n" + "EJB username after logout: " + ejbNameAfterLogout + "\n");
}
use of javax.servlet.http.HttpSession in project jfinal by jfinal.
the class JFinalSession method intercept.
@SuppressWarnings({ "rawtypes", "unchecked" })
public void intercept(Invocation inv) {
inv.invoke();
Controller c = inv.getController();
if (c.getRender() instanceof com.jfinal.render.JsonRender) {
return;
}
HttpSession hs = c.getSession(createSession);
if (hs != null) {
Map session = new JFinalSession(hs);
for (Enumeration<String> names = hs.getAttributeNames(); names.hasMoreElements(); ) {
String name = names.nextElement();
session.put(name, hs.getAttribute(name));
}
c.setAttr("session", session);
}
}
use of javax.servlet.http.HttpSession in project head by mifos.
the class RepayLoanActionForm method getUserLocale.
protected Locale getUserLocale(HttpServletRequest request) {
Locale locale = null;
HttpSession session = request.getSession();
if (session != null) {
UserContext userContext = (UserContext) session.getAttribute(LoginConstants.USERCONTEXT);
if (null != userContext) {
locale = userContext.getCurrentLocale();
}
}
return locale;
}
use of javax.servlet.http.HttpSession in project head by mifos.
the class ApplyAdjustmentActionForm method getUserLocale.
protected Locale getUserLocale(HttpServletRequest request) {
Locale locale = null;
HttpSession session = request.getSession();
if (session != null) {
UserContext userContext = (UserContext) session.getAttribute(LoginConstants.USERCONTEXT);
if (null != userContext) {
locale = userContext.getCurrentLocale();
}
}
return locale;
}
use of javax.servlet.http.HttpSession in project head by mifos.
the class MifosRequestProcessor method processActionPerform.
/**
* This method is overridden because in case of exception we need to
* populate the request with the old values so that when the user goes back
* to the previous page it has all the values in the request.For this we
* create an object which will store the values of previous request in case
* the request is successful and if there is an exception it reads values
* from that object and context and dups all in the request.
*/
@Override
protected ActionForward processActionPerform(HttpServletRequest request, HttpServletResponse response, Action action, ActionForm form, ActionMapping mapping) throws IOException, ServletException {
ActivityContext activityContext = null;
ActionForward forward = null;
HttpSession session = request.getSession();
// gets the object where we will store values from request.
PreviousRequestValues previousRequestValues = (PreviousRequestValues) session.getAttribute(Constants.PREVIOUS_REQUEST);
if (null == previousRequestValues) {
previousRequestValues = new PreviousRequestValues();
session.setAttribute(Constants.PREVIOUS_REQUEST, previousRequestValues);
}
// getting the activity context from the session
activityContext = (ActivityContext) session.getAttribute("ActivityContext");
try {
String currentFlowKey = request.getParameter(Constants.CURRENTFLOWKEY);
if (currentFlowKey != null) {
previousRequestValues.getPreviousRequestValueMap().put(Constants.CURRENTFLOWKEY, currentFlowKey);
}
forward = (action.execute(mapping, form, request, response));
String method = request.getParameter("method");
if (method.equals(ClientConstants.METHOD_RETRIEVE_PICTURE)) {
forward = mapping.findForward("get_success");
}
// set the last forward in the activity context
if (activityContext != null) {
activityContext.setLastForward(forward);
}
// read the request and add the values to the PreviousRequestValues
// object. this will set every thing in the request apart from
// context and value object.
Enumeration requestAttributes = request.getAttributeNames();
while (requestAttributes.hasMoreElements()) {
String nextName = (String) requestAttributes.nextElement();
if (nextName.startsWith(Constants.STORE_ATTRIBUTE) || nextName.equalsIgnoreCase(Constants.CURRENTFLOWKEY)) {
logger.debug(nextName + "=" + request.getAttribute(nextName));
previousRequestValues.getPreviousRequestValueMap().put(nextName, request.getAttribute(nextName));
}
}
} catch (Exception e) {
// processException logs an error (see MifosExceptionHandler)
forward = (processException(request, response, e, form, mapping));
// set the last forward in the activity context
if (activityContext != null) {
activityContext.setLastForward(forward);
}
populateTheRequestFromPreviousValues(request, previousRequestValues);
} finally {
try {
session.removeAttribute(SecurityConstants.SECURITY_PARAM);
} catch (Exception e) {
// FIXME: yikes, what is being swallowed here?
}
}
if (null != forward) {
logger.info("forward.path=" + forward.getPath());
}
return forward;
}
Aggregations