Search in sources :

Example 6 with ActionInvocation

use of com.opensymphony.xwork2.ActionInvocation in project bamboobsc by billchen198318.

the class BaseSimpleActionInfo method handlerActionAnnotations.

public void handlerActionAnnotations() {
    if (this.actionAnnotations != null) {
        return;
    }
    ActionInvocation actionInvocation = ActionContext.getContext().getActionInvocation();
    this.actionAnnotations = actionInvocation.getAction().getClass().getAnnotations();
    Method[] methods = actionInvocation.getAction().getClass().getMethods();
    for (Method method : methods) {
        if (this.actionMethodName.equals(method.getName())) {
            this.actionMethodAnnotations = method.getAnnotations();
        }
    }
}
Also used : ActionInvocation(com.opensymphony.xwork2.ActionInvocation) Method(java.lang.reflect.Method)

Example 7 with ActionInvocation

use of com.opensymphony.xwork2.ActionInvocation in project dhis2-core by dhis2.

the class I18nInterceptor method intercept.

@Override
public String intercept(ActionInvocation invocation) throws Exception {
    Action action = (Action) invocation.getAction();
    I18n i18n = i18nManager.getI18n(action.getClass());
    I18nFormat i18nFormat = i18nManager.getI18nFormat();
    Locale locale = localeManager.getCurrentLocale();
    // ---------------------------------------------------------------------
    // Make the objects available for web templates
    // ---------------------------------------------------------------------
    Map<String, Object> i18nMap = new HashMap<>(3);
    i18nMap.put(KEY_I18N, i18n);
    i18nMap.put(KEY_I18N_FORMAT, i18nFormat);
    i18nMap.put(KEY_LOCALE, locale);
    invocation.getStack().push(i18nMap);
    // ---------------------------------------------------------------------
    // Set the objects in the action class if the properties exist
    // ---------------------------------------------------------------------
    Map<?, ?> contextMap = invocation.getInvocationContext().getContextMap();
    try {
        Ognl.setValue(KEY_I18N, contextMap, action, i18n);
    } catch (NoSuchPropertyException ignored) {
    }
    try {
        Ognl.setValue(KEY_I18N_FORMAT, contextMap, action, i18nFormat);
    } catch (NoSuchPropertyException ignored) {
    }
    try {
        Ognl.setValue(KEY_LOCALE, contextMap, action, locale);
    } catch (NoSuchPropertyException ignored) {
    }
    return invocation.invoke();
}
Also used : Locale(java.util.Locale) Action(com.opensymphony.xwork2.Action) HashMap(java.util.HashMap) NoSuchPropertyException(ognl.NoSuchPropertyException) I18nFormat(org.hisp.dhis.i18n.I18nFormat) I18n(org.hisp.dhis.i18n.I18n)

Example 8 with ActionInvocation

use of com.opensymphony.xwork2.ActionInvocation in project KeyBox by skavanagh.

the class ClickjackingInterceptor method intercept.

@Override
public String intercept(ActionInvocation invocation) throws Exception {
    ActionContext context = invocation.getInvocationContext();
    HttpServletResponse response = (HttpServletResponse) context.get(StrutsStatics.HTTP_RESPONSE);
    String headerValue = VALUE;
    response.addHeader(HEADER, headerValue);
    return invocation.invoke();
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) ActionContext(com.opensymphony.xwork2.ActionContext)

Example 9 with ActionInvocation

use of com.opensymphony.xwork2.ActionInvocation in project qi4j-sdk by Qi4j.

the class ConstraintViolationInterceptor method intercept.

@Override
public String intercept(ActionInvocation invocation) throws Exception {
    ActionContext invocationContext = invocation.getInvocationContext();
    ValueStack stack = invocationContext.getValueStack();
    Object action = invocation.getAction();
    if (action instanceof ValidationAware) {
        ValidationAware va = (ValidationAware) action;
        HashMap<Object, Object> propertyOverrides = new HashMap<Object, Object>();
        for (Map.Entry<String, FieldConstraintViolations> fieldViolations : fieldConstraintViolations(invocationContext).entrySet()) {
            addConstraintViolationFieldErrors(stack, va, fieldViolations.getKey(), fieldViolations.getValue());
            propertyOverrides.put(fieldViolations.getKey(), getOverrideExpr(invocation, fieldViolations.getValue()));
        }
        // if there were some errors, put the original (fake) values in place right before the result
        if (!propertyOverrides.isEmpty()) {
            overrideActionValues(invocation, stack, propertyOverrides);
        }
    }
    return invocation.invoke();
}
Also used : ValueStack(com.opensymphony.xwork2.util.ValueStack) HashMap(java.util.HashMap) ValidationAware(com.opensymphony.xwork2.ValidationAware) ActionContext(com.opensymphony.xwork2.ActionContext) Collections.emptyMap(java.util.Collections.emptyMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 10 with ActionInvocation

use of com.opensymphony.xwork2.ActionInvocation in project bamboobsc by billchen198318.

the class BaseSimpleActionInfo method execute.

public void execute() {
    ActionInvocation actionInvocation = ActionContext.getContext().getActionInvocation();
    HttpServletRequest request = ServletActionContext.getRequest();
    String action = SimpleUtils.getStr(actionInvocation.getProxy().getActionName(), "");
    String namespace = SimpleUtils.getStr(actionInvocation.getProxy().getNamespace(), "");
    String remoteAddr = SimpleUtils.getStr(request.getRemoteAddr(), "");
    String referer = SimpleUtils.getStr(request.getHeader("referer"), "");
    this.actionMethodName = actionInvocation.getProxy().getMethod();
    ActionContext.getContext().getSession().put(Constants.SESS_PAGE_INFO_ACTION_ByAction, action);
    ActionContext.getContext().getSession().put(Constants.SESS_PAGE_INFO_NAMESPACE_ByAction, namespace);
    ActionContext.getContext().getSession().put(Constants.SESS_PAGE_INFO_RemoteAddr_ByAction, remoteAddr);
    ActionContext.getContext().getSession().put(Constants.SESS_PAGE_INFO_Referer_ByAction, referer);
    this.pageInfoActionName = action;
    this.pageInfoNamespace = namespace;
    this.pageInfoRemoteAddr = remoteAddr;
    this.pageInfoReferer = referer;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ActionInvocation(com.opensymphony.xwork2.ActionInvocation)

Aggregations

ActionContext (com.opensymphony.xwork2.ActionContext)7 HttpServletResponse (javax.servlet.http.HttpServletResponse)6 HashMap (java.util.HashMap)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 ValueStack (com.opensymphony.xwork2.util.ValueStack)3 Map (java.util.Map)3 Action (com.opensymphony.xwork2.Action)2 ActionInvocation (com.opensymphony.xwork2.ActionInvocation)2 ActionConfig (com.opensymphony.xwork2.config.entities.ActionConfig)2 PrintWriter (java.io.PrintWriter)2 ServletActionContext (org.apache.struts2.ServletActionContext)2 GreenStepBaseUsernamePasswordToken (com.netsteadfast.greenstep.sys.GreenStepBaseUsernamePasswordToken)1 AccountVO (com.netsteadfast.greenstep.vo.AccountVO)1 ValidationAware (com.opensymphony.xwork2.ValidationAware)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 Method (java.lang.reflect.Method)1 Connection (java.sql.Connection)1