use of com.opensymphony.xwork2.inject.Context in project onebusaway-application-modules by camsys.
the class ApiKeyInterceptor method isAllowed.
// package private for unit tests
int isAllowed(ActionInvocation invocation) {
ActionContext context = invocation.getInvocationContext();
Map<String, Object> parameters = context.getParameters();
String[] keys = (String[]) parameters.get("key");
if (keys == null || keys.length == 0) {
// 401: we couldn't find the api key
return HttpServletResponse.SC_UNAUTHORIZED;
}
Status status = _keyService.getPermission(keys[0], "api");
if (status == Status.AUTHORIZED) {
return HttpServletResponse.SC_OK;
}
if (status == Status.RATE_EXCEEDED) {
return RESPONSE_TOO_MANY_REQUESTS;
}
// fall through is 403 Forbidden (we understood the key, but auth failed)
return HttpServletResponse.SC_FORBIDDEN;
}
use of com.opensymphony.xwork2.inject.Context in project onebusaway-application-modules by camsys.
the class IndexAction 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")) && (namespace.equals("") || namespace.equals("/"))) {
return SUCCESS;
}
return "NotFound";
}
use of com.opensymphony.xwork2.inject.Context in project onebusaway-application-modules by camsys.
the class ExceptionInterceptor method getActionAsUrl.
private String getActionAsUrl(ActionInvocation invocation) {
ActionProxy proxy = invocation.getProxy();
ActionContext context = invocation.getInvocationContext();
StringBuilder b = new StringBuilder();
b.append(proxy.getNamespace());
b.append("/");
b.append(proxy.getActionName());
b.append("!");
b.append(proxy.getMethod());
Map<String, Object> params = context.getParameters();
if (!params.isEmpty()) {
b.append("?");
boolean seenFirst = false;
for (Map.Entry<String, Object> entry : params.entrySet()) {
// Prune out any identifying information
if ("app_uid".equals(entry.getKey()))
continue;
Object value = entry.getValue();
String[] values = (value instanceof String[]) ? (String[]) value : new String[] { value.toString() };
for (String v : values) {
if (seenFirst)
b.append("&");
else
seenFirst = true;
b.append(entry.getKey());
b.append("=");
b.append(v);
}
}
}
return b.toString();
}
use of com.opensymphony.xwork2.inject.Context in project onebusaway-application-modules by camsys.
the class IndexTemplate method buildTemplate.
@SuppressWarnings("unchecked")
@Override
public void buildTemplate(ActionContext context) {
ValueStack stack = context.getValueStack();
List<BookmarkWithStopsBean> bookmarks = (List<BookmarkWithStopsBean>) stack.findValue("bookmarks");
if (bookmarks.isEmpty()) {
addMessage(Messages.BOOKMARKS_EMPTY);
} else {
int index = 1;
for (BookmarkWithStopsBean bookmark : bookmarks) {
String toPress = Integer.toString(index);
addMessage(Messages.FOR);
AgiActionName stopAction = addAction(toPress, "/stop/arrivalsAndDeparturesForStopId");
List<String> stopIds = MappingLibrary.map(bookmark.getStops(), "id");
Set<String> routeIds = new HashSet<String>(MappingLibrary.map(bookmark.getRoutes(), "id", String.class));
stopAction.putParam("stopIds", stopIds);
stopAction.putParam("routeIds", routeIds);
addBookmarkDescription(bookmark);
addMessage(Messages.PLEASE_PRESS);
addText(toPress);
index++;
}
}
addAction("(#|0|.+\\*)", "/repeat");
addMessage(Messages.HOW_TO_GO_BACK);
addAction("\\*", "/back");
addMessage(Messages.TO_REPEAT);
}
use of com.opensymphony.xwork2.inject.Context in project onebusaway-application-modules by camsys.
the class MultipleRoutesFoundTemplate method buildTemplate.
@SuppressWarnings("unchecked")
@Override
public void buildTemplate(ActionContext context) {
ValueStack vs = context.getValueStack();
List<RouteBean> routes = (List<RouteBean>) vs.findValue("routes");
int index = 1;
addMessage(Messages.MULTIPLE_ROUTES_WERE_FOUND);
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);
AgiActionName action = addAction(key, "/search/tree");
action.putParam("route", route);
}
addMessage(Messages.HOW_TO_GO_BACK);
addAction("\\*", "/back");
addMessage(Messages.TO_REPEAT);
}
Aggregations