Search in sources :

Example 26 with Context

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;
}
Also used : Status(org.onebusaway.users.services.ApiKeyPermissionService.Status) ServletActionContext(org.apache.struts2.ServletActionContext) ActionContext(com.opensymphony.xwork2.ActionContext)

Example 27 with Context

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";
}
Also used : ActionProxy(com.opensymphony.xwork2.ActionProxy) ActionInvocation(com.opensymphony.xwork2.ActionInvocation) ActionContext(com.opensymphony.xwork2.ActionContext)

Example 28 with Context

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();
}
Also used : ActionProxy(com.opensymphony.xwork2.ActionProxy) ActionContext(com.opensymphony.xwork2.ActionContext) Map(java.util.Map)

Example 29 with Context

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);
}
Also used : ValueStack(com.opensymphony.xwork2.util.ValueStack) BookmarkWithStopsBean(org.onebusaway.presentation.model.BookmarkWithStopsBean) List(java.util.List) AgiActionName(org.onebusaway.probablecalls.AgiActionName) HashSet(java.util.HashSet)

Example 30 with Context

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);
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) ValueStack(com.opensymphony.xwork2.util.ValueStack) List(java.util.List) AgiActionName(org.onebusaway.probablecalls.AgiActionName)

Aggregations

ActionContext (com.opensymphony.xwork2.ActionContext)21 ValueStack (com.opensymphony.xwork2.util.ValueStack)14 AgiActionName (org.onebusaway.probablecalls.AgiActionName)7 List (java.util.List)5 ActionProxy (com.opensymphony.xwork2.ActionProxy)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 ActionInvocation (com.opensymphony.xwork2.ActionInvocation)3 StopBean (org.onebusaway.transit_data.model.StopBean)3 XWorkException (com.opensymphony.xwork2.XWorkException)2 Inject (com.opensymphony.xwork2.inject.Inject)2 Constructor (java.lang.reflect.Constructor)2 DateFormat (java.text.DateFormat)2 ParseException (java.text.ParseException)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2 Map (java.util.Map)2 ServletActionContext (org.apache.struts2.ServletActionContext)2 SessionAware (org.apache.struts2.interceptor.SessionAware)2 XWorkRequestAttributes (org.onebusaway.presentation.impl.users.XWorkRequestAttributes)2 BookmarkWithStopsBean (org.onebusaway.presentation.model.BookmarkWithStopsBean)2