Search in sources :

Example 11 with ActionContext

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

Example 12 with ActionContext

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);
}
Also used : ActionProxy(com.opensymphony.xwork2.ActionProxy) HashMap(java.util.HashMap) ActionInvocation(com.opensymphony.xwork2.ActionInvocation) ActionContext(com.opensymphony.xwork2.ActionContext) Test(org.junit.Test)

Example 13 with ActionContext

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, "");
}
Also used : Locale(java.util.Locale) IOException(java.io.IOException) ActionContext(com.opensymphony.xwork2.ActionContext)

Example 14 with ActionContext

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();
}
Also used : UserIndexKey(org.onebusaway.users.model.UserIndexKey) IndexedUserDetails(org.onebusaway.users.model.IndexedUserDetails) DefaultUserAuthenticationToken(org.onebusaway.users.impl.authentication.DefaultUserAuthenticationToken) ActionContext(com.opensymphony.xwork2.ActionContext)

Example 15 with ActionContext

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

Aggregations

ActionContext (com.opensymphony.xwork2.ActionContext)32 ValueStack (com.opensymphony.xwork2.util.ValueStack)15 AgiActionName (org.onebusaway.probablecalls.AgiActionName)7 ActionProxy (com.opensymphony.xwork2.ActionProxy)6 ServletActionContext (org.apache.struts2.ServletActionContext)6 ActionInvocation (com.opensymphony.xwork2.ActionInvocation)5 List (java.util.List)5 HttpServletResponse (javax.servlet.http.HttpServletResponse)5 HashMap (java.util.HashMap)4 Locale (java.util.Locale)4 Map (java.util.Map)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 XWorkRequestAttributes (org.onebusaway.presentation.impl.users.XWorkRequestAttributes)3 StopBean (org.onebusaway.transit_data.model.StopBean)3 IOException (java.io.IOException)2 SessionAware (org.apache.struts2.interceptor.SessionAware)2 Test (org.junit.Test)2 BookmarkWithStopsBean (org.onebusaway.presentation.model.BookmarkWithStopsBean)2 NameBean (org.onebusaway.transit_data.model.NameBean)2 RouteBean (org.onebusaway.transit_data.model.RouteBean)2