Search in sources :

Example 1 with XWorkRequestAttributes

use of org.onebusaway.presentation.impl.users.XWorkRequestAttributes 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 2 with XWorkRequestAttributes

use of org.onebusaway.presentation.impl.users.XWorkRequestAttributes 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 3 with XWorkRequestAttributes

use of org.onebusaway.presentation.impl.users.XWorkRequestAttributes in project onebusaway-application-modules by camsys.

the class CustomAgiEntryPoint method onActionTearDown.

@Override
protected void onActionTearDown() {
    super.onActionTearDown();
    RequestAttributes attributes = RequestContextHolder.getRequestAttributes();
    RequestContextHolder.resetRequestAttributes();
    if (attributes instanceof XWorkRequestAttributes)
        ((XWorkRequestAttributes) attributes).requestCompleted();
}
Also used : XWorkRequestAttributes(org.onebusaway.presentation.impl.users.XWorkRequestAttributes) XWorkRequestAttributes(org.onebusaway.presentation.impl.users.XWorkRequestAttributes) RequestAttributes(org.springframework.web.context.request.RequestAttributes)

Example 4 with XWorkRequestAttributes

use of org.onebusaway.presentation.impl.users.XWorkRequestAttributes in project onebusaway-application-modules by camsys.

the class CustomAgiEntryPoint method onActionSetup.

@Override
protected void onActionSetup(Map<String, Object> contextMap) {
    super.onActionSetup(contextMap);
    String sessionId = UUID.randomUUID().toString();
    XWorkRequestAttributes attributes = new XWorkRequestAttributes(new ActionContext(contextMap), sessionId);
    RequestContextHolder.setRequestAttributes(attributes);
}
Also used : XWorkRequestAttributes(org.onebusaway.presentation.impl.users.XWorkRequestAttributes) ActionContext(com.opensymphony.xwork2.ActionContext)

Aggregations

XWorkRequestAttributes (org.onebusaway.presentation.impl.users.XWorkRequestAttributes)4 ActionContext (com.opensymphony.xwork2.ActionContext)3 RequestAttributes (org.springframework.web.context.request.RequestAttributes)3 SessionAware (org.apache.struts2.interceptor.SessionAware)2