use of com.opensymphony.xwork2.ActionContext in project onebusaway-application-modules by camsys.
the class Debug method execute.
@Override
public String execute() throws Exception {
ActionContext context = ActionContext.getContext();
ActionInvocation invocation = context.getActionInvocation();
ActionProxy proxy = invocation.getProxy();
String name = proxy.getActionName().toLowerCase();
String namespace = proxy.getNamespace().toLowerCase();
// return the 404 message if so. There has to be a better way than this?
if ((name.equals("") || name.equals("index") || name.equals("debug")) && (namespace.equals("") || namespace.equals("/"))) {
return SUCCESS;
}
return "NotFound";
}
use of com.opensymphony.xwork2.ActionContext 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.ActionContext in project onebusaway-application-modules by camsys.
the class ResourcesUrlComponent method end.
@Override
public boolean end(Writer writer, String body) {
Locale locale = Locale.getDefault();
ActionContext ctx = ActionContext.getContext();
if (ctx != null)
locale = ctx.getLocale();
String url = _resourceService.getExternalUrlForResources(_id, _resourcePaths, locale);
if (url != null) {
if (getVar() != null) {
/**
* We either write the url out to a variable
*/
putInContext(url);
} else {
/**
* Or otherwise print out the url directly
*/
try {
writer.write(url);
} catch (IOException e) {
LOG.error("Could not write out resource-url tag", e);
}
}
}
return super.end(writer, "");
}
use of com.opensymphony.xwork2.ActionContext in project onebusaway-application-modules by camsys.
the class PhoneNumberLoginInterceptor method intercept.
@Override
public String intercept(ActionInvocation invocation) throws Exception {
ActionContext context = invocation.getInvocationContext();
Map<String, Object> params = context.getParameters();
String phoneNumber = getPhoneNumber(params);
phoneNumber = PhoneNumberLibrary.normalizePhoneNumber(phoneNumber);
if (phoneNumber != null && phoneNumber.length() > 0) {
UserIndexKey key = new UserIndexKey(UserIndexTypes.PHONE_NUMBER, phoneNumber);
if (params.containsKey(RESET_USER))
_indexedUserDetailsService.resetUserForIndexKey(key);
// Ensure that we have authentication, even if it's anonymous
if (!isCurrentUserLoggedInWithKey(key)) {
IndexedUserDetails userDetails = _indexedUserDetailsService.getOrCreateUserForIndexKey(key, "", false);
DefaultUserAuthenticationToken token = new DefaultUserAuthenticationToken(userDetails);
SecurityContextHolder.getContext().setAuthentication(token);
}
}
return invocation.invoke();
}
use of com.opensymphony.xwork2.ActionContext in project onebusaway-application-modules by camsys.
the class RequestContextInterceptor method intercept.
@Override
public String intercept(ActionInvocation invocation) throws Exception {
ActionContext context = invocation.getInvocationContext();
String id = getSessionId(context);
XWorkRequestAttributes attributes = new XWorkRequestAttributes(context, id);
RequestContextHolder.setRequestAttributes(attributes);
String result = invocation.invoke();
RequestContextHolder.resetRequestAttributes();
attributes.requestCompleted();
return result;
}
Aggregations