本文整理汇总了Java中com.opensymphony.xwork2.ActionInvocation.getInvocationContext方法的典型用法代码示例。如果您正苦于以下问题:Java ActionInvocation.getInvocationContext方法的具体用法?Java ActionInvocation.getInvocationContext怎么用?Java ActionInvocation.getInvocationContext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.opensymphony.xwork2.ActionInvocation
的用法示例。
在下文中一共展示了ActionInvocation.getInvocationContext方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: intercept
import com.opensymphony.xwork2.ActionInvocation; //导入方法依赖的package包/类
@Override
public String intercept(ActionInvocation ai) throws Exception {
HttpServletRequest request = ServletActionContext.getRequest();
String sessionId = request.getSession().getId();
if (ai.getAction() instanceof SessionIdAware) {
SessionIdAware action = (SessionIdAware) ai.getAction();
action.setSessionId(sessionId);
}
ActionContext actionContext = ai.getInvocationContext();
Admin admin = adminService.getCurrentAdmin(sessionId);
actionContext.put("admin", admin);
actionContext.put("domain", webConfiguration.getDomain());
actionContext.put("image_action_url", webConfiguration.getImageActionUrl());
actionContext.put("google_signin_client_id", webConfiguration.getGoogleSigninClientId());
return ai.invoke();
}
示例2: doExecute
import com.opensymphony.xwork2.ActionInvocation; //导入方法依赖的package包/类
@Override
protected void doExecute(String finalLocation, ActionInvocation invocation) throws Exception {
ActionContext ctx = invocation.getInvocationContext();
HttpServletRequest request = (HttpServletRequest) ctx.get(ServletActionContext.HTTP_REQUEST);
HttpServletResponse response = (HttpServletResponse) ctx.get(ServletActionContext.HTTP_RESPONSE);
// Cache?
if (!cache) {
response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1
response.setHeader("Pragma", "no-cache"); // HTTP 1.0
response.setDateHeader("Expires", 0); // Proxies
}
//set contenttype @see ww-4564
response.setContentType("text/html");
// Render
PrintWriter pw = new PrintWriter(response.getOutputStream());
pw.write("<!DOCTYPE html><html><body><form action=\"" + finalLocation + "\" method=\"POST\">");
writeFormElements(request, pw);
writePrologueScript(pw);
pw.write("</html>");
pw.flush();
}
示例3: intercept
import com.opensymphony.xwork2.ActionInvocation; //导入方法依赖的package包/类
/**
* 鍩轰簬褰撳墠鐧诲綍鐢ㄦ埛缁熻pv uv鐨勬嫤鎴櫒锛岄渶瑕侀厤缃湪sso鐨勬嫤鎴櫒鍚庨潰,浠ヤ究褰撳墠context鏈夊綋鍓嶇櫥褰曠敤鎴蜂俊鎭�
* @param invocation
* @return
* @throws Exception
*/
public String intercept(ActionInvocation invocation) throws Exception {
try{
if(mstatsService==null){
mstatsService=ResourceServlet.context.getBean(ActionMethodService.class);
}
if(pinService==null){
pinService=ResourceServlet.context.getBean(IPinService.class);
}
ActionContext actionContext = invocation.getInvocationContext();
HttpServletRequest request = (HttpServletRequest) actionContext.get(StrutsStatics.HTTP_REQUEST);
String erpId=pinService.getPin(request);
String currentPath=request.getServletPath();
mstatsService.putVisitData(erpId,currentPath);
}catch (Exception e)
{
log.error(e.getMessage(),e);
}
return invocation.invoke(); //To change body of implemented methods use File | Settings | File Templates.
}
示例4: doIntercept
import com.opensymphony.xwork2.ActionInvocation; //导入方法依赖的package包/类
@Override
protected String doIntercept(ActionInvocation invocation) throws Exception {
ActionContext actionContext = invocation.getInvocationContext();
Map<String, Object> session = actionContext.getSession();
Admin admin = (Admin) session.get("admin");
if (admin != null) {
return invocation.invoke();
}
actionContext.put("notice", "您还未登录,无法获得管理员权限");
return Action.LOGIN;
}
示例5: intercept
import com.opensymphony.xwork2.ActionInvocation; //导入方法依赖的package包/类
@Override
public String intercept(ActionInvocation invocation) throws Exception {
// ��ȡActionContext
ActionContext context = invocation.getInvocationContext();
// ��ȡMap���͵�session
Map<String, Object> session = context.getSession();
// �ж��û��Ƿ��¼
if(session.get("admin") != null){
// ����ִ�з���
return invocation.invoke();
}
// ���ص�¼
return BaseAction.USER_LOGIN;
}
示例6: intercept
import com.opensymphony.xwork2.ActionInvocation; //导入方法依赖的package包/类
@Override
public String intercept(ActionInvocation invocation) throws Exception {
ActionContext context = invocation.getInvocationContext();// ��ȡActionContext
Map<String, Object> session = context.getSession();// ��ȡMap���͵�session
if(session.get("customer") != null){// �ж��û��Ƿ��¼
return invocation.invoke();// ����ִ�з���
}
return BaseAction.CUSTOMER_LOGIN;// ���ص�¼
}
示例7: handleInvalidToken
import com.opensymphony.xwork2.ActionInvocation; //导入方法依赖的package包/类
@Override
protected String handleInvalidToken(ActionInvocation invocation) throws Exception {
ActionContext ac = invocation.getInvocationContext();
HttpServletRequest request = (HttpServletRequest) ac.get(ServletActionContext.HTTP_REQUEST);
HttpServletResponse response = (HttpServletResponse) ac.get(ServletActionContext.HTTP_RESPONSE);
String tokenName = TokenHelper.getTokenName();
String token = TokenHelper.getToken(tokenName);
if ((tokenName != null) && (token != null)) {
Map params = ac.getParameters();
params.remove(tokenName);
params.remove(TokenHelper.TOKEN_NAME_FIELD);
String sessionTokenName = TokenHelper.buildTokenSessionAttributeName(tokenName);
ActionInvocation savedInvocation = InvocationSessionStore.loadInvocation(sessionTokenName, token);
if (savedInvocation != null) {
// set the valuestack to the request scope
ValueStack stack = savedInvocation.getStack();
request.setAttribute(ServletActionContext.STRUTS_VALUESTACK_KEY, stack);
ActionContext savedContext = savedInvocation.getInvocationContext();
savedContext.getContextMap().put(ServletActionContext.HTTP_REQUEST, request);
savedContext.getContextMap().put(ServletActionContext.HTTP_RESPONSE, response);
Result result = savedInvocation.getResult();
if ((result != null) && (savedInvocation.getProxy().getExecuteResult())) {
result.execute(savedInvocation);
}
// turn off execution of this invocations result
invocation.getProxy().setExecuteResult(false);
return savedInvocation.getResultCode();
}
}
return INVALID_TOKEN_CODE;
}
示例8: storeLocale
import com.opensymphony.xwork2.ActionInvocation; //导入方法依赖的package包/类
@Override
protected Locale storeLocale(ActionInvocation invocation, Locale locale, String storage) {
if (COOKIE_STORAGE.equals(storage)) {
ActionContext ac = invocation.getInvocationContext();
HttpServletResponse response = (HttpServletResponse) ac.get(StrutsStatics.HTTP_RESPONSE);
Cookie cookie = new Cookie(DEFAULT_COOKIE_ATTRIBUTE, locale.toString());
cookie.setMaxAge(1209600); // two weeks
response.addCookie(cookie);
storage = Storage.SESSION.toString();
}
return super.storeLocale(invocation, locale, storage);
}
示例9: intercept
import com.opensymphony.xwork2.ActionInvocation; //导入方法依赖的package包/类
public String intercept(ActionInvocation invocation) throws Exception {
LOG.debug("Clearing HttpSession");
ActionContext ac = invocation.getInvocationContext();
Map session = ac.getSession();
if (null != session) {
session.clear();
}
return invocation.invoke();
}
示例10: beforeResult
import com.opensymphony.xwork2.ActionInvocation; //导入方法依赖的package包/类
public void beforeResult(ActionInvocation invocation, String resultCode) {
try {
LOG.trace("beforeResult start");
ActionContext ac = invocation.getInvocationContext();
if (invocation.getAction() instanceof CookieProvider) {
HttpServletResponse response = (HttpServletResponse) ac.get(StrutsStatics.HTTP_RESPONSE);
addCookiesToResponse((CookieProvider) invocation.getAction(), response);
}
LOG.trace("beforeResult end");
} catch (Exception ex) {
LOG.error("Unable to setup cookies", ex);
}
}
示例11: makePostbackUri
import com.opensymphony.xwork2.ActionInvocation; //导入方法依赖的package包/类
protected String makePostbackUri(ActionInvocation invocation) {
ActionContext ctx = invocation.getInvocationContext();
HttpServletRequest request = (HttpServletRequest) ctx.get(ServletActionContext.HTTP_REQUEST);
String postbackUri;
if (actionName != null) {
actionName = conditionalParse(actionName, invocation);
if (namespace == null) {
namespace = invocation.getProxy().getNamespace();
} else {
namespace = conditionalParse(namespace, invocation);
}
if (method == null) {
method = "";
} else {
method = conditionalParse(method, invocation);
}
postbackUri = request.getContextPath() + actionMapper.getUriFromActionMapping(new ActionMapping(actionName, namespace, method, null));
} else {
String location = getLocation();
// Do not prepend if the URL is a FQN
if (!location.matches("^([a-zA-z]+:)?//.*")) {
// If the URL is relative to the servlet context, prepend the servlet context path
if (prependServletContext && (request.getContextPath() != null) && (request.getContextPath().length() > 0)) {
location = request.getContextPath() + location;
}
}
postbackUri = location;
}
return postbackUri;
}
示例12: intercept
import com.opensymphony.xwork2.ActionInvocation; //导入方法依赖的package包/类
/**
* Decide if the parameter should be removed from the parameter map based on
* <code>paramNames</code> and <code>paramValues</code>.
*
* @see com.opensymphony.xwork2.interceptor.AbstractInterceptor
*/
@Override
public String intercept(ActionInvocation invocation) throws Exception {
if (!(invocation.getAction() instanceof NoParameters)
&& (null != this.paramNames)) {
ActionContext ac = invocation.getInvocationContext();
final Map<String, Object> parameters = ac.getParameters();
if (parameters != null) {
for (String removeName : paramNames) {
// see if the field is in the parameter map
if (parameters.containsKey(removeName)) {
try {
String[] values = (String[]) parameters.get(removeName);
String value = values[0];
if (null != value && this.paramValues.contains(value)) {
parameters.remove(removeName);
}
} catch (Exception e) {
LOG.error("Failed to convert parameter to string", e);
}
}
}
}
}
return invocation.invoke();
}
示例13: doIntercept
import com.opensymphony.xwork2.ActionInvocation; //导入方法依赖的package包/类
@Override
public String doIntercept(ActionInvocation invocation) throws Exception {
Object action = invocation.getAction();
if (!(action instanceof NoParameters)) {
ActionContext ac = invocation.getInvocationContext();
final Map<String, Object> parameters = retrieveParameters(ac);
if (LOG.isDebugEnabled()) {
LOG.debug("Setting params {}", getParameterLogMap(parameters));
}
if (parameters != null) {
Map<String, Object> contextMap = ac.getContextMap();
try {
ReflectionContextState.setCreatingNullObjects(contextMap, true);
ReflectionContextState.setDenyMethodExecution(contextMap, true);
ReflectionContextState.setReportingConversionErrors(contextMap, true);
ValueStack stack = ac.getValueStack();
setParameters(action, stack, parameters);
} finally {
ReflectionContextState.setCreatingNullObjects(contextMap, false);
ReflectionContextState.setDenyMethodExecution(contextMap, false);
ReflectionContextState.setReportingConversionErrors(contextMap, false);
}
}
}
return invocation.invoke();
}
示例14: doIntercept
import com.opensymphony.xwork2.ActionInvocation; //导入方法依赖的package包/类
protected String doIntercept(ActionInvocation actionInvocation) throws Exception {
ActionProxy proxy = actionInvocation.getProxy();
String name = getBackgroundProcessName(proxy);
ActionContext context = actionInvocation.getInvocationContext();
Map session = context.getSession();
HttpSession httpSession = ServletActionContext.getRequest().getSession(true);
Boolean secondTime = true;
if (executeAfterValidationPass) {
secondTime = (Boolean) context.get(KEY);
if (secondTime == null) {
context.put(KEY, true);
secondTime = false;
} else {
secondTime = true;
context.put(KEY, null);
}
}
//sync on the real HttpSession as the session from the context is a wrap that is created
//on every request
synchronized (httpSession) {
BackgroundProcess bp = (BackgroundProcess) session.get(KEY + name);
if ((!executeAfterValidationPass || secondTime) && bp == null) {
bp = getNewBackgroundProcess(name, actionInvocation, threadPriority);
session.put(KEY + name, bp);
performInitialDelay(bp); // first time let some time pass before showing wait page
secondTime = false;
}
if ((!executeAfterValidationPass || !secondTime) && bp != null && !bp.isDone()) {
actionInvocation.getStack().push(bp.getAction());
final String token = TokenHelper.getToken();
if (token != null) {
TokenHelper.setSessionToken(TokenHelper.getTokenName(), token);
}
Map results = proxy.getConfig().getResults();
if (!results.containsKey(WAIT)) {
LOG.warn("ExecuteAndWait interceptor has detected that no result named 'wait' is available. " +
"Defaulting to a plain built-in wait page. It is highly recommend you " +
"provide an action-specific or global result named '{}'.", WAIT);
// no wait result? hmm -- let's try to do dynamically put it in for you!
//we used to add a fake "wait" result here, since the configuration is unmodifiable, that is no longer
//an option, see WW-3068
FreemarkerResult waitResult = new FreemarkerResult();
container.inject(waitResult);
waitResult.setLocation("/org/apache/struts2/interceptor/wait.ftl");
waitResult.execute(actionInvocation);
return Action.NONE;
}
return WAIT;
} else if ((!executeAfterValidationPass || !secondTime) && bp != null && bp.isDone()) {
session.remove(KEY + name);
actionInvocation.getStack().push(bp.getAction());
// if an exception occured during action execution, throw it here
if (bp.getException() != null) {
throw bp.getException();
}
return bp.getResult();
} else {
// this is the first instance of the interceptor and there is no existing action
// already run in the background, so let's just let this pass through. We assume
// the action invocation will be run in the background on the subsequent pass through
// this interceptor
return actionInvocation.invoke();
}
}
}
示例15: doExecute
import com.opensymphony.xwork2.ActionInvocation; //导入方法依赖的package包/类
/**
* Redirects to the location specified by calling
* {@link HttpServletResponse#sendRedirect(String)}.
*
* @param finalLocation the location to redirect to.
* @param invocation an encapsulation of the action execution state.
* @throws Exception if an error occurs when redirecting.
*/
protected void doExecute(String finalLocation, ActionInvocation invocation) throws Exception {
ActionContext ctx = invocation.getInvocationContext();
HttpServletRequest request = (HttpServletRequest) ctx.get(ServletActionContext.HTTP_REQUEST);
HttpServletResponse response = (HttpServletResponse) ctx.get(ServletActionContext.HTTP_RESPONSE);
if (isPathUrl(finalLocation)) {
if (!finalLocation.startsWith("/")) {
ActionMapping mapping = actionMapper.getMapping(request, Dispatcher.getInstance().getConfigurationManager());
String namespace = null;
if (mapping != null) {
namespace = mapping.getNamespace();
}
if ((namespace != null) && (namespace.length() > 0) && (!"/".equals(namespace))) {
finalLocation = namespace + "/" + finalLocation;
} else {
finalLocation = "/" + finalLocation;
}
}
// if the URL's are relative to the servlet context, append the servlet context path
if (prependServletContext && (request.getContextPath() != null) && (request.getContextPath().length() > 0)) {
finalLocation = request.getContextPath() + finalLocation;
}
}
ResultConfig resultConfig = invocation.getProxy().getConfig().getResults().get(invocation.getResultCode());
if (resultConfig != null) {
Map<String, String> resultConfigParams = resultConfig.getParams();
List<String> prohibitedResultParams = getProhibitedResultParams();
for (Map.Entry<String, String> e : resultConfigParams.entrySet()) {
if (!prohibitedResultParams.contains(e.getKey())) {
Collection<String> values = conditionalParseCollection(e.getValue(), invocation, suppressEmptyParameters);
if (!suppressEmptyParameters || !values.isEmpty()) {
requestParameters.put(e.getKey(), values);
}
}
}
}
StringBuilder tmpLocation = new StringBuilder(finalLocation);
urlHelper.buildParametersString(requestParameters, tmpLocation, "&");
// add the anchor
if (anchor != null) {
tmpLocation.append('#').append(anchor);
}
finalLocation = response.encodeRedirectURL(tmpLocation.toString());
LOG.debug("Redirecting to finalLocation: {}", finalLocation);
sendRedirect(response, finalLocation);
}