Search in sources :

Example 26 with ActionContext

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

the class ActionInfoSupportInterceptor method intercept.

@Override
public String intercept(ActionInvocation actionInvocation) throws Exception {
    /*
		ActionInvocation ai=(ActionInvocation)ActionContext.getContext().get(ActionContext.ACTION_INVOCATION); 
		String action=ai.getProxy().getActionName(); 
		String namespace=ai.getProxy().getNamespace();
		*/
    HttpServletRequest request = ServletActionContext.getRequest();
    ActionContext context = actionInvocation.getInvocationContext();
    String action = actionInvocation.getProxy().getActionName();
    String namespace = actionInvocation.getProxy().getNamespace();
    String remoteAddr = request.getRemoteAddr();
    String referer = request.getHeader("referer");
    context.getSession().put(Constants.SESS_PAGE_INFO_ACTION_ByInterceptor, action);
    context.getSession().put(Constants.SESS_PAGE_INFO_NAMESPACE_ByInterceptor, namespace);
    context.getSession().put(Constants.SESS_PAGE_INFO_RemoteAddr_ByInterceptor, remoteAddr);
    context.getSession().put(Constants.SESS_PAGE_INFO_Referer_ByInterceptor, referer);
    return actionInvocation.invoke();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ActionContext(com.opensymphony.xwork2.ActionContext) ServletActionContext(org.apache.struts2.ServletActionContext)

Example 27 with ActionContext

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

the class JsonOutermostBracketsInterceptor method intercept.

@Override
public String intercept(ActionInvocation actionInvocation) throws Exception {
    ActionContext context = actionInvocation.getInvocationContext();
    HttpServletResponse response = (HttpServletResponse) context.get(StrutsStatics.HTTP_RESPONSE);
    response.setCharacterEncoding("utf8");
    response.setContentType("text/html");
    PrintWriter writer = response.getWriter();
    writer.print("[");
    writer.flush();
    String forward = actionInvocation.invoke();
    writer.print("]");
    writer.flush();
    return forward;
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) ActionContext(com.opensymphony.xwork2.ActionContext) PrintWriter(java.io.PrintWriter)

Example 28 with ActionContext

use of com.opensymphony.xwork2.ActionContext in project entando-core by entando.

the class GuiFragmentResult method doExecute.

/**
 * Execute this result, using the specified fragment.
 * @param code The code of the fragment
 * @param invocation The invocation
 */
@Override
public void doExecute(String code, ActionInvocation invocation) throws Exception {
    if (null == code) {
        code = conditionalParse(this._code, invocation);
    }
    if (null == code) {
        this.executeDispatcherResult(invocation);
        return;
    }
    ActionContext ctx = invocation.getInvocationContext();
    HttpServletRequest req = (HttpServletRequest) ctx.get(ServletActionContext.HTTP_REQUEST);
    IGuiFragmentManager guiFragmentManager = (IGuiFragmentManager) ApsWebApplicationUtils.getBean(SystemConstants.GUI_FRAGMENT_MANAGER, req);
    try {
        GuiFragment guiFragment = guiFragmentManager.getGuiFragment(code);
        String output = (null != guiFragment) ? guiFragment.getCurrentGui() : null;
        if (StringUtils.isBlank(output)) {
            _logger.info("The fragment '{}' is not available - Action '{}' - Namespace '{}'", code, invocation.getProxy().getActionName(), invocation.getProxy().getNamespace());
            boolean execution = this.executeDispatcherResult(invocation);
            if (!execution) {
                output = "The fragment '" + code + "' is not available";
            } else {
                return;
            }
        }
        RequestContext reqCtx = (RequestContext) req.getAttribute(RequestContext.REQCTX);
        ExecutorBeanContainer ebc = (ExecutorBeanContainer) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_EXECUTOR_BEAN_CONTAINER);
        Writer writer = this.getWriter();
        Template template = new Template(code, new StringReader(output), ebc.getConfiguration());
        template.process(ebc.getTemplateModel(), writer);
    } catch (Throwable t) {
        _logger.error("Error processing GuiFragment result!", t);
        throw new RuntimeException("Error processing GuiFragment result!", t);
    }
}
Also used : IGuiFragmentManager(org.entando.entando.aps.system.services.guifragment.IGuiFragmentManager) GuiFragment(org.entando.entando.aps.system.services.guifragment.GuiFragment) ServletActionContext(org.apache.struts2.ServletActionContext) ActionContext(com.opensymphony.xwork2.ActionContext) Template(freemarker.template.Template) HttpServletRequest(javax.servlet.http.HttpServletRequest) StringReader(java.io.StringReader) RequestContext(com.agiletec.aps.system.RequestContext) ExecutorBeanContainer(org.entando.entando.aps.system.services.controller.executor.ExecutorBeanContainer) Writer(java.io.Writer)

Example 29 with ActionContext

use of com.opensymphony.xwork2.ActionContext in project beetl2.0 by javamonkey.

the class Struts2BeetlActionResult method doExecute.

protected void doExecute(String locationArg, ActionInvocation invocation) throws Exception {
    ActionContext ctx = invocation.getInvocationContext();
    HttpServletRequest req = (HttpServletRequest) ctx.get(ServletActionContext.HTTP_REQUEST);
    HttpServletResponse rsp = (HttpServletResponse) ctx.get(ServletActionContext.HTTP_RESPONSE);
    if (!locationArg.startsWith("/")) {
        String base = ResourceUtil.getResourceBase(req);
        locationArg = base + "/" + locationArg;
    }
    Object action = invocation.getAction();
    Map<String, Object> values = reflectionProvider.getBeanMap(action);
    rsp.setContentType(this.pContentType);
    WebRender render = new WebRender(groupTemplate) {

        protected void modifyTemplate(Template template, String key, HttpServletRequest request, HttpServletResponse response, Object... args) {
            Map model = (Map) args[0];
            for (Object o : model.entrySet()) {
                Entry entry = (Entry) o;
                String name = (String) entry.getKey();
                Object value = entry.getValue();
                template.binding(name, value);
            }
        }
    };
    render.render(locationArg, req, rsp, values);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) WebRender(org.beetl.ext.web.WebRender) Entry(java.util.Map.Entry) HttpServletResponse(javax.servlet.http.HttpServletResponse) ServletActionContext(org.apache.struts2.ServletActionContext) ActionContext(com.opensymphony.xwork2.ActionContext) Map(java.util.Map) Template(org.beetl.core.Template) GroupTemplate(org.beetl.core.GroupTemplate)

Example 30 with ActionContext

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

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