Search in sources :

Example 36 with Action

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

the class TwilioInterceptor method intercept.

@Override
public String intercept(ActionInvocation invocation) throws Exception {
    ActionContext context = invocation.getInvocationContext();
    Map<String, Object> parameters = context.getParameters();
    /* Stringify parameters for debugging output */
    String paramString = "";
    for (Entry<String, Object> entry : parameters.entrySet()) {
        paramString += entry.getKey() + "=";
        Object val = entry.getValue();
        if (val instanceof String[]) {
            paramString += Arrays.toString((String[]) val);
        } else {
            paramString += val.toString();
        }
        paramString += ", ";
    }
    int idx = paramString.lastIndexOf(',');
    if (idx >= 0) {
        paramString = paramString.substring(0, idx);
    }
    _log.debug("in with params={" + paramString + "} and session=" + context.getSession());
    Object phoneNumber = parameters.get(_phoneNumberParameterName);
    if (phoneNumber == null) {
        return invocation.invoke();
    }
    if (phoneNumber instanceof String[]) {
        String[] values = (String[]) phoneNumber;
        if (values.length == 0)
            return invocation.invoke();
        phoneNumber = values[0];
    }
    String sessionId = phoneNumber.toString();
    // Strip off leading '+', if any
    sessionId = sessionId.replaceFirst("\\+", "");
    Map<String, Object> persistentSession = _sessionManager.getContext(sessionId);
    _log.debug("remapping sesssionId " + sessionId + " to " + persistentSession);
    Map<String, Object> originalSession = context.getSession();
    context.setSession(persistentSession);
    XWorkRequestAttributes attributes = new XWorkRequestAttributes(context, sessionId);
    RequestAttributes originalAttributes = RequestContextHolder.getRequestAttributes();
    RequestContextHolder.setRequestAttributes(attributes);
    Object action = invocation.getAction();
    if (action instanceof SessionAware)
        ((SessionAware) action).setSession(persistentSession);
    try {
        return invocation.invoke();
    } finally {
        RequestContextHolder.setRequestAttributes(originalAttributes);
        context.setSession(originalSession);
    }
}
Also used : SessionAware(org.apache.struts2.interceptor.SessionAware) XWorkRequestAttributes(org.onebusaway.presentation.impl.users.XWorkRequestAttributes) XWorkRequestAttributes(org.onebusaway.presentation.impl.users.XWorkRequestAttributes) RequestAttributes(org.springframework.web.context.request.RequestAttributes) ActionContext(com.opensymphony.xwork2.ActionContext)

Example 37 with Action

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

the class StopsForRouteNavigationAction method buildStopsList.

// protected void buildPredictedArrivals(List<ArrivalAndDepartureBean> arrivals) {
protected void buildStopsList() {
    ActionContext context = ActionContext.getContext();
    ValueStack vs = context.getValueStack();
    // NavigationBean navigation = (NavigationBean) vs.findValue("navigation");
    NavigationBean navigation = (NavigationBean) sessionMap.get("navigation");
    List<NameBean> names = navigation.getNames();
    index = navigation.getCurrentIndex();
    _log.debug("StopsForRoute.buildStopsList: index: " + index);
    if (index < 0)
        index = 0;
    /**
     * We always listen for the key-press for the previous name in case it takes
     * the user a second to press
     */
    _log.debug("in StopsForRouteNavigationAction, index = " + index + ", names.size = " + names.size());
    if (index > 0)
        addNavigationSelectionActionForIndex(navigation, index - 1);
    /**
     * If we're at the first entry and there is a second, we allow the user to
     * jump ahead
     */
    if (index == 0 && names.size() > 1) {
        addNavigationSelectionActionForIndex(navigation, index + 1);
    }
    if (index >= names.size()) {
        // AgiActionName action = setNextAction("/search/navigate-to");
        // action.putParam("navigation", navigation);
        // action.putParam("index", 0);
        // action.setExcludeFromHistory(true);
        // Add an extra pause so the user has a chance to make a selection from
        // the previous entry
        addMessage("<Pause length=\"1\"/>");
        // addPause(1000);
        addMessage(Messages.TO_REPEAT);
    } else {
        String key = addNavigationSelectionActionForIndex(navigation, index);
        NameBean name = names.get(index);
        handleName(name, key);
        addNavigateToAction(navigation, "4", first(index - 1));
        addNavigateToAction(navigation, "6", index + 1);
        addNavigateToAction(navigation, "7", first(index - 10));
        addNavigateToAction(navigation, "9", index + 10);
    // AgiActionName action = setNextAction("/search/navigate-to");
    // action.putParam("navigation", navigation);
    // action.putParam("index", index + 1);
    // action.setExcludeFromHistory(true);
    // setNextAction("navigate-to");
    }
    sessionMap.put("navigation", navigation);
// addAction("\\*", "/back");
}
Also used : ValueStack(com.opensymphony.xwork2.util.ValueStack) ActionContext(com.opensymphony.xwork2.ActionContext) NameBean(org.onebusaway.transit_data.model.NameBean)

Example 38 with Action

use of com.opensymphony.xwork2.Action 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 39 with Action

use of com.opensymphony.xwork2.Action 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 40 with Action

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

the class StackInterceptor method intercept.

@Override
public String intercept(ActionInvocation invocation) throws Exception {
    Object action = invocation.getAction();
    Class<?> actionType = action.getClass();
    AddToStack addToStackAnnotation = actionType.getAnnotation(AddToStack.class);
    if (addToStackAnnotation != null) {
        ValueStack stack = invocation.getStack();
        List<Object> toPush = new ArrayList<Object>();
        for (String name : addToStackAnnotation.value()) {
            Object value = stack.findValue(name);
            if (value != null)
                toPush.add(value);
        }
        /**
         * We push the values onto the stack after finding ALL the values first
         */
        for (Object value : toPush) stack.push(value);
    }
    return invocation.invoke();
}
Also used : ValueStack(com.opensymphony.xwork2.util.ValueStack) ArrayList(java.util.ArrayList)

Aggregations

ActionSupport (com.opensymphony.xwork2.ActionSupport)61 List (java.util.List)40 Action (io.atlasmap.v2.Action)35 ArrayList (java.util.ArrayList)23 Test (org.junit.jupiter.api.Test)16 Content (com.agiletec.plugins.jacms.aps.system.services.content.model.Content)14 SimpleField (io.atlasmap.v2.SimpleField)13 Field (io.atlasmap.v2.Field)12 Mapping (io.atlasmap.v2.Mapping)11 ActionContext (com.opensymphony.xwork2.ActionContext)9 AtlasMapping (io.atlasmap.v2.AtlasMapping)9 Collections (java.util.Collections)9 HashMap (java.util.HashMap)9 SettableApiFuture (com.google.api.core.SettableApiFuture)8 ServiceOptions (com.google.cloud.ServiceOptions)8 DlpServiceClient (com.google.cloud.dlp.v2.DlpServiceClient)8 Subscriber (com.google.cloud.pubsub.v1.Subscriber)8 Action (com.google.privacy.dlp.v2.Action)8 BigQueryTable (com.google.privacy.dlp.v2.BigQueryTable)8 CreateDlpJobRequest (com.google.privacy.dlp.v2.CreateDlpJobRequest)8