Search in sources :

Example 1 with ActionProxy

use of com.opensymphony.xwork2.ActionProxy 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 2 with ActionProxy

use of com.opensymphony.xwork2.ActionProxy 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 3 with ActionProxy

use of com.opensymphony.xwork2.ActionProxy 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);
}
Also used : ActionProxy(com.opensymphony.xwork2.ActionProxy) Method(java.lang.reflect.Method) DateParseException(org.apache.commons.httpclient.util.DateParseException)

Example 4 with ActionProxy

use of com.opensymphony.xwork2.ActionProxy in project onebusaway-application-modules by camsys.

the class VehicleStatusMapAction method execute.

@Override
public String execute() {
    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 5 with ActionProxy

use of com.opensymphony.xwork2.ActionProxy 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)

Aggregations

ActionProxy (com.opensymphony.xwork2.ActionProxy)8 ActionContext (com.opensymphony.xwork2.ActionContext)6 ActionInvocation (com.opensymphony.xwork2.ActionInvocation)5 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 Method (java.lang.reflect.Method)1 Map (java.util.Map)1 DateParseException (org.apache.commons.httpclient.util.DateParseException)1 DefaultHttpHeaders (org.apache.struts2.rest.DefaultHttpHeaders)1 ResponseBean (org.onebusaway.api.model.ResponseBean)1