Search in sources :

Example 1 with Context

use of com.opensymphony.xwork2.inject.Context in project KeyBox by skavanagh.

the class HTTPStrictTransportSecurityInterceptor method intercept.

@Override
public String intercept(ActionInvocation invocation) throws Exception {
    ActionContext context = invocation.getInvocationContext();
    HttpServletResponse response = (HttpServletResponse) context.get(StrutsStatics.HTTP_RESPONSE);
    String headerValue = MAX_AGE + ONE_YEAR;
    response.addHeader(HEADER, headerValue);
    return invocation.invoke();
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) ActionContext(com.opensymphony.xwork2.ActionContext)

Example 2 with Context

use of com.opensymphony.xwork2.inject.Context in project bamboobsc by billchen198318.

the class NoCacheHeaderInterceptor method intercept.

@Override
public String intercept(ActionInvocation actionInvocation) throws Exception {
    ActionContext context = actionInvocation.getInvocationContext();
    HttpServletResponse response = (HttpServletResponse) context.get(StrutsStatics.HTTP_RESPONSE);
    if (response != null) {
        response.setHeader("Cache-control", "no-cache, no-store");
        response.setHeader("Pragma", "no-cache");
        response.setHeader("Expires", "0");
    }
    return actionInvocation.invoke();
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) ActionContext(com.opensymphony.xwork2.ActionContext)

Example 3 with Context

use of com.opensymphony.xwork2.inject.Context in project onebusaway-application-modules by camsys.

the class TextmarksSessionInterceptor method intercept.

@Override
public String intercept(ActionInvocation invocation) throws Exception {
    processGoogleAnalytics();
    ActionContext context = invocation.getInvocationContext();
    Map<String, Object> parameters = context.getParameters();
    Object phoneNumber = parameters.get(_phoneNumberParameterName);
    if (phoneNumber == null)
        return invocation.invoke();
    if (phoneNumber instanceof String[]) {
        String[] values = (String[]) phoneNumber;
        if (values.length == 0)
            return invocation.invoke();
        phoneNumber = values[0];
    }
    String sessionId = phoneNumber.toString();
    Map<String, Object> persistentSession = _sessionManager.getContext(sessionId);
    Map<String, Object> originalSession = context.getSession();
    context.setSession(persistentSession);
    XWorkRequestAttributes attributes = new XWorkRequestAttributes(context, sessionId);
    RequestAttributes originalAttributes = RequestContextHolder.getRequestAttributes();
    RequestContextHolder.setRequestAttributes(attributes);
    Object action = invocation.getAction();
    if (action instanceof SessionAware)
        ((SessionAware) action).setSession(persistentSession);
    try {
        return invocation.invoke();
    } finally {
        RequestContextHolder.setRequestAttributes(originalAttributes);
        context.setSession(originalSession);
    }
}
Also used : SessionAware(org.apache.struts2.interceptor.SessionAware) XWorkRequestAttributes(org.onebusaway.presentation.impl.users.XWorkRequestAttributes) XWorkRequestAttributes(org.onebusaway.presentation.impl.users.XWorkRequestAttributes) RequestAttributes(org.springframework.web.context.request.RequestAttributes) ActionContext(com.opensymphony.xwork2.ActionContext)

Example 4 with Context

use of com.opensymphony.xwork2.inject.Context in project onebusaway-application-modules by camsys.

the class TwilioInterceptor method intercept.

@Override
public String intercept(ActionInvocation invocation) throws Exception {
    ActionContext context = invocation.getInvocationContext();
    Map<String, Object> parameters = context.getParameters();
    /* Stringify parameters for debugging output */
    String paramString = "";
    for (Entry<String, Object> entry : parameters.entrySet()) {
        paramString += entry.getKey() + "=";
        Object val = entry.getValue();
        if (val instanceof String[]) {
            paramString += Arrays.toString((String[]) val);
        } else {
            paramString += val.toString();
        }
        paramString += ", ";
    }
    int idx = paramString.lastIndexOf(',');
    if (idx >= 0) {
        paramString = paramString.substring(0, idx);
    }
    _log.debug("in with params={" + paramString + "} and session=" + context.getSession());
    Object phoneNumber = parameters.get(_phoneNumberParameterName);
    if (phoneNumber == null) {
        return invocation.invoke();
    }
    if (phoneNumber instanceof String[]) {
        String[] values = (String[]) phoneNumber;
        if (values.length == 0)
            return invocation.invoke();
        phoneNumber = values[0];
    }
    String sessionId = phoneNumber.toString();
    // Strip off leading '+', if any
    sessionId = sessionId.replaceFirst("\\+", "");
    Map<String, Object> persistentSession = _sessionManager.getContext(sessionId);
    _log.debug("remapping sesssionId " + sessionId + " to " + persistentSession);
    Map<String, Object> originalSession = context.getSession();
    context.setSession(persistentSession);
    XWorkRequestAttributes attributes = new XWorkRequestAttributes(context, sessionId);
    RequestAttributes originalAttributes = RequestContextHolder.getRequestAttributes();
    RequestContextHolder.setRequestAttributes(attributes);
    Object action = invocation.getAction();
    if (action instanceof SessionAware)
        ((SessionAware) action).setSession(persistentSession);
    try {
        return invocation.invoke();
    } finally {
        RequestContextHolder.setRequestAttributes(originalAttributes);
        context.setSession(originalSession);
    }
}
Also used : SessionAware(org.apache.struts2.interceptor.SessionAware) XWorkRequestAttributes(org.onebusaway.presentation.impl.users.XWorkRequestAttributes) XWorkRequestAttributes(org.onebusaway.presentation.impl.users.XWorkRequestAttributes) RequestAttributes(org.springframework.web.context.request.RequestAttributes) ActionContext(com.opensymphony.xwork2.ActionContext)

Example 5 with Context

use of com.opensymphony.xwork2.inject.Context in project onebusaway-application-modules by camsys.

the class MultipleRoutesFoundAction method execute.

@Override
public String execute() throws Exception {
    Integer navState = (Integer) sessionMap.get("navState");
    if (navState == null) {
        navState = DISPLAY_DATA;
    }
    _log.debug("MultipleRoutesFound, navState: " + navState);
    if (navState == DISPLAY_DATA) {
        ActionContext context = ActionContext.getContext();
        ValueStack vs = context.getValueStack();
        List<RouteBean> routes = (List<RouteBean>) vs.findValue("routes");
        int index = 1;
        addMessage(Messages.MULTIPLE_ROUTES_WERE_FOUND);
        // Keep a map of key options and their corresponding route beans
        Map<Integer, RouteBean> keyMapping = new HashMap<Integer, RouteBean>();
        for (RouteBean route : routes) {
            addMessage(Messages.FOR);
            addMessage(Messages.ROUTE);
            String routeNumber = route.getShortName();
            addText(_routeNumberPronunciation.modify(routeNumber));
            addMessage(Messages.OPERATED_BY);
            addText(route.getAgency().getName());
            addMessage(Messages.PLEASE_PRESS);
            String key = Integer.toString(index++);
            addText(key);
            keyMapping.put(new Integer(index - 1), route);
        }
        addMessage(Messages.HOW_TO_GO_BACK);
        // addAction("\\*", "/back");
        addMessage(Messages.TO_REPEAT);
        sessionMap.put("keyMapping", keyMapping);
        navState = DO_ROUTING;
        sessionMap.put("navState", navState);
        setNextAction("search/multiple-routes-found");
    } else {
        // Do the routing, matching the key pressed with the correct route bean.
        _log.debug("Handling selection of choice of routes.");
        // Handle "back" request ('*' key pressed)
        if (PREVIOUS_MENU_ITEM.equals(getInput())) {
            return "back";
        }
        int key = Integer.parseInt(getInput());
        Map<Integer, RouteBean> keyMapping = (Map<Integer, RouteBean>) sessionMap.get("keyMapping");
        _route = (RouteBean) keyMapping.get(key);
        navState = DISPLAY_DATA;
        sessionMap.put("navState", navState);
        _log.debug("Key " + key + " entered for route: " + _route.getId());
        return "route-selected";
    }
    return SUCCESS;
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) ValueStack(com.opensymphony.xwork2.util.ValueStack) HashMap(java.util.HashMap) List(java.util.List) ActionContext(com.opensymphony.xwork2.ActionContext) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ActionContext (com.opensymphony.xwork2.ActionContext)21 ValueStack (com.opensymphony.xwork2.util.ValueStack)14 AgiActionName (org.onebusaway.probablecalls.AgiActionName)7 List (java.util.List)5 ActionProxy (com.opensymphony.xwork2.ActionProxy)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 ActionInvocation (com.opensymphony.xwork2.ActionInvocation)3 StopBean (org.onebusaway.transit_data.model.StopBean)3 XWorkException (com.opensymphony.xwork2.XWorkException)2 Inject (com.opensymphony.xwork2.inject.Inject)2 Constructor (java.lang.reflect.Constructor)2 DateFormat (java.text.DateFormat)2 ParseException (java.text.ParseException)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2 Map (java.util.Map)2 ServletActionContext (org.apache.struts2.ServletActionContext)2 SessionAware (org.apache.struts2.interceptor.SessionAware)2 XWorkRequestAttributes (org.onebusaway.presentation.impl.users.XWorkRequestAttributes)2 BookmarkWithStopsBean (org.onebusaway.presentation.model.BookmarkWithStopsBean)2