use of org.apache.struts2.interceptor.SessionAware 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);
}
}
use of org.apache.struts2.interceptor.SessionAware 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);
}
}
Aggregations