use of com.opensymphony.xwork2.Action 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);
}
}
use of com.opensymphony.xwork2.Action in project onebusaway-application-modules by camsys.
the class StopsForRouteNavigationAction method buildStopsList.
// protected void buildPredictedArrivals(List<ArrivalAndDepartureBean> arrivals) {
protected void buildStopsList() {
ActionContext context = ActionContext.getContext();
ValueStack vs = context.getValueStack();
// NavigationBean navigation = (NavigationBean) vs.findValue("navigation");
NavigationBean navigation = (NavigationBean) sessionMap.get("navigation");
List<NameBean> names = navigation.getNames();
index = navigation.getCurrentIndex();
_log.debug("StopsForRoute.buildStopsList: index: " + index);
if (index < 0)
index = 0;
/**
* We always listen for the key-press for the previous name in case it takes
* the user a second to press
*/
_log.debug("in StopsForRouteNavigationAction, index = " + index + ", names.size = " + names.size());
if (index > 0)
addNavigationSelectionActionForIndex(navigation, index - 1);
/**
* If we're at the first entry and there is a second, we allow the user to
* jump ahead
*/
if (index == 0 && names.size() > 1) {
addNavigationSelectionActionForIndex(navigation, index + 1);
}
if (index >= names.size()) {
// AgiActionName action = setNextAction("/search/navigate-to");
// action.putParam("navigation", navigation);
// action.putParam("index", 0);
// action.setExcludeFromHistory(true);
// Add an extra pause so the user has a chance to make a selection from
// the previous entry
addMessage("<Pause length=\"1\"/>");
// addPause(1000);
addMessage(Messages.TO_REPEAT);
} else {
String key = addNavigationSelectionActionForIndex(navigation, index);
NameBean name = names.get(index);
handleName(name, key);
addNavigateToAction(navigation, "4", first(index - 1));
addNavigateToAction(navigation, "6", index + 1);
addNavigateToAction(navigation, "7", first(index - 10));
addNavigateToAction(navigation, "9", index + 10);
// AgiActionName action = setNextAction("/search/navigate-to");
// action.putParam("navigation", navigation);
// action.putParam("index", index + 1);
// action.setExcludeFromHistory(true);
// setNextAction("navigate-to");
}
sessionMap.put("navigation", navigation);
// addAction("\\*", "/back");
}
use of com.opensymphony.xwork2.Action in project onebusaway-application-modules by camsys.
the class IndexActionTest method test404.
@Test
public void test404() throws Exception {
ActionProxy proxy = Mockito.mock(ActionProxy.class);
Mockito.when(proxy.getActionName()).thenReturn("something-else");
Mockito.when(proxy.getNamespace()).thenReturn("/");
ActionInvocation invocation = Mockito.mock(ActionInvocation.class);
Mockito.when(invocation.getProxy()).thenReturn(proxy);
Map<String, Object> c = new HashMap<String, Object>();
ActionContext ac = new ActionContext(c);
ac.setActionInvocation(invocation);
ActionContext.setContext(ac);
IndexAction action = new IndexAction();
String response = action.execute();
assertEquals("404 response", "NotFound", response);
}
use of com.opensymphony.xwork2.Action in project onebusaway-application-modules by camsys.
the class CacheControlInterceptor method getCacheControlAnnotation.
private CacheControl getCacheControlAnnotation(ActionInvocation invocation) {
Object action = invocation.getAction();
Class<? extends Object> actionClass = action.getClass();
ActionProxy proxy = invocation.getProxy();
String methodName = proxy.getMethod();
if (methodName != null) {
try {
Method m = actionClass.getMethod(methodName);
if (m != null) {
CacheControl methodCacheControl = m.getAnnotation(CacheControl.class);
if (methodCacheControl != null)
return methodCacheControl;
}
} catch (Exception ex) {
_log.warn("error searching for action method=\"" + methodName + "\" on action class=\"" + actionClass.getName() + "\"", ex);
}
}
return actionClass.getAnnotation(CacheControl.class);
}
use of com.opensymphony.xwork2.Action in project onebusaway-application-modules by camsys.
the class StackInterceptor method intercept.
@Override
public String intercept(ActionInvocation invocation) throws Exception {
Object action = invocation.getAction();
Class<?> actionType = action.getClass();
AddToStack addToStackAnnotation = actionType.getAnnotation(AddToStack.class);
if (addToStackAnnotation != null) {
ValueStack stack = invocation.getStack();
List<Object> toPush = new ArrayList<Object>();
for (String name : addToStackAnnotation.value()) {
Object value = stack.findValue(name);
if (value != null)
toPush.add(value);
}
/**
* We push the values onto the stack after finding ALL the values first
*/
for (Object value : toPush) stack.push(value);
}
return invocation.invoke();
}
Aggregations