📄 dispatcher.java
字号:
public void init(Configuration configuration1)
throws ConfigurationException
{
}
public void loadPackages()
throws ConfigurationException
{
}
public boolean needsReload()
{
return false;
}
public void register(ContainerBuilder builder, LocatableProperties props)
throws ConfigurationException
{
props.putAll(initParams);
}
{
this$0 = Dispatcher.this;
super();
}
});
}
private void init_AliasStandardObjects()
{
configurationManager.addConfigurationProvider(new BeanSelectionProvider());
}
private Container init_PreloadConfiguration()
{
Configuration config = configurationManager.getConfiguration();
Container container = config.getContainer();
boolean reloadi18n = Boolean.valueOf((String)container.getInstance(java/lang/String, "struts.i18n.reload")).booleanValue();
LocalizedTextUtil.setReloadBundles(reloadi18n);
ObjectTypeDeterminer objectTypeDeterminer = (ObjectTypeDeterminer)container.getInstance(com/opensymphony/xwork2/util/ObjectTypeDeterminer);
ObjectTypeDeterminerFactory.setInstance(objectTypeDeterminer);
return container;
}
private void init_CheckConfigurationReloading(Container container)
{
FileManager.setReloadingConfigs("true".equals(container.getInstance(java/lang/String, "struts.configuration.xml.reload")));
}
private void init_CheckWebLogicWorkaround(Container container)
{
if (servletContext != null && servletContext.getServerInfo() != null && servletContext.getServerInfo().indexOf("WebLogic") >= 0)
{
LOG.info("WebLogic server detected. Enabling Struts parameter access work-around.");
paramsWorkaroundEnabled = true;
} else
{
paramsWorkaroundEnabled = "true".equals(container.getInstance(java/lang/String, "struts.dispatcher.parametersWorkaround"));
}
synchronized (org/apache/struts2/dispatcher/Dispatcher)
{
if (dispatcherListeners.size() > 0)
{
DispatcherListener l;
for (Iterator i$ = dispatcherListeners.iterator(); i$.hasNext(); l.dispatcherInitialized(this))
l = (DispatcherListener)i$.next();
}
}
}
public void init()
{
if (configurationManager == null)
configurationManager = new ConfigurationManager("struts");
init_DefaultProperties();
init_TraditionalXmlConfigurations();
init_LegacyStrutsProperties();
init_ZeroConfiguration();
init_CustomConfigurationProviders();
init_MethodConfigurationProvider();
init_FilterInitParameters();
init_AliasStandardObjects();
Container container = init_PreloadConfiguration();
init_CheckConfigurationReloading(container);
init_CheckWebLogicWorkaround(container);
}
public void serviceAction(HttpServletRequest request, HttpServletResponse response, ServletContext context, ActionMapping mapping)
throws ServletException
{
Map extraContext;
ValueStack stack;
String timerKey;
extraContext = createContextMap(request, response, mapping, context);
stack = (ValueStack)request.getAttribute("struts.valueStack");
if (stack != null)
extraContext.put("com.opensymphony.xwork2.util.ValueStack.ValueStack", ValueStackFactory.getFactory().createValueStack(stack));
timerKey = "Handling request from Dispatcher";
UtilTimerStack.push(timerKey);
String namespace = mapping.getNamespace();
String name = mapping.getName();
String method = mapping.getMethod();
Configuration config = configurationManager.getConfiguration();
ActionProxy proxy = ((ActionProxyFactory)config.getContainer().getInstance(com/opensymphony/xwork2/ActionProxyFactory)).createActionProxy(namespace, name, extraContext, true, false);
proxy.setMethod(method);
request.setAttribute("struts.valueStack", proxy.getInvocation().getStack());
if (mapping.getResult() != null)
{
Result result = mapping.getResult();
result.execute(proxy.getInvocation());
} else
{
proxy.execute();
}
if (stack != null)
request.setAttribute("struts.valueStack", stack);
UtilTimerStack.pop(timerKey);
break MISSING_BLOCK_LABEL_267;
ConfigurationException e;
e;
LOG.error("Could not find action or result", e);
sendError(request, response, context, 404, e);
UtilTimerStack.pop(timerKey);
break MISSING_BLOCK_LABEL_267;
e;
throw new ServletException(e);
Exception exception;
exception;
UtilTimerStack.pop(timerKey);
throw exception;
}
public Map createContextMap(HttpServletRequest request, HttpServletResponse response, ActionMapping mapping, ServletContext context)
{
Map requestMap = new RequestMap(request);
Map params = null;
if (mapping != null)
params = mapping.getParams();
Map requestParams = new HashMap(request.getParameterMap());
if (params != null)
params.putAll(requestParams);
else
params = requestParams;
Map session = new SessionMap(request);
Map application = new ApplicationMap(context);
Map extraContext = createContextMap(requestMap, params, session, application, request, response, context);
extraContext.put("struts.actionMapping", mapping);
return extraContext;
}
public HashMap createContextMap(Map requestMap, Map parameterMap, Map sessionMap, Map applicationMap, HttpServletRequest request, HttpServletResponse response, ServletContext servletContext)
{
HashMap extraContext = new HashMap();
extraContext.put("com.opensymphony.xwork2.ActionContext.parameters", new HashMap(parameterMap));
extraContext.put("com.opensymphony.xwork2.ActionContext.session", sessionMap);
extraContext.put("com.opensymphony.xwork2.ActionContext.application", applicationMap);
java.util.Locale locale;
if (defaultLocale != null)
locale = LocalizedTextUtil.localeFromString(defaultLocale, request.getLocale());
else
locale = request.getLocale();
extraContext.put("com.opensymphony.xwork2.ActionContext.locale", locale);
extraContext.put("com.opensymphony.xwork2.dispatcher.HttpServletRequest", request);
extraContext.put("com.opensymphony.xwork2.dispatcher.HttpServletResponse", response);
extraContext.put("com.opensymphony.xwork2.dispatcher.ServletContext", servletContext);
extraContext.put("request", requestMap);
extraContext.put("session", sessionMap);
extraContext.put("application", applicationMap);
extraContext.put("parameters", parameterMap);
AttributeMap attrMap = new AttributeMap(extraContext);
extraContext.put("attr", attrMap);
return extraContext;
}
private String getSaveDir(ServletContext servletContext)
{
String saveDir = multipartSaveDir.trim();
if (saveDir.equals(""))
{
File tempdir = (File)servletContext.getAttribute("javax.servlet.context.tempdir");
LOG.info("Unable to find 'struts.multipart.saveDir' property setting. Defaulting to javax.servlet.context.tempdir");
if (tempdir != null)
saveDir = tempdir.toString();
} else
{
File multipartSaveDir = new File(saveDir);
if (!multipartSaveDir.exists())
multipartSaveDir.mkdir();
}
if (LOG.isDebugEnabled())
LOG.debug((new StringBuilder()).append("saveDir=").append(saveDir).toString());
return saveDir;
}
public void prepare(HttpServletRequest request, HttpServletResponse response)
{
String encoding = null;
if (defaultEncoding != null)
encoding = defaultEncoding;
java.util.Locale locale = null;
if (defaultLocale != null)
locale = LocalizedTextUtil.localeFromString(defaultLocale, request.getLocale());
if (encoding != null)
try
{
request.setCharacterEncoding(encoding);
}
catch (Exception e)
{
LOG.error((new StringBuilder()).append("Error setting character encoding to '").append(encoding).append("' - ignoring.").toString(), e);
}
if (locale != null)
response.setLocale(locale);
if (paramsWorkaroundEnabled)
request.getParameter("foo");
}
public HttpServletRequest wrapRequest(HttpServletRequest request, ServletContext servletContext)
throws IOException
{
if (request instanceof StrutsRequestWrapper)
return request;
String content_type = request.getContentType();
if (content_type != null && content_type.indexOf("multipart/form-data") != -1)
{
MultiPartRequest multi = (MultiPartRequest)getContainer().getInstance(org/apache/struts2/dispatcher/multipart/MultiPartRequest);
request = new MultiPartRequestWrapper(multi, request, getSaveDir(servletContext));
} else
{
request = new StrutsRequestWrapper(request);
}
return request;
}
public void sendError(HttpServletRequest request, HttpServletResponse response, ServletContext ctx, int code, Exception e)
{
if (devMode)
{
response.setContentType("text/html");
try
{
FreemarkerManager mgr = (FreemarkerManager)getContainer().getInstance(org/apache/struts2/views/freemarker/FreemarkerManager);
freemarker.template.Configuration config = mgr.getConfiguration(ctx);
Template template = config.getTemplate("/org/apache/struts2/dispatcher/error.ftl");
List chain = new ArrayList();
Throwable cur = e;
chain.add(cur);
while ((cur = cur.getCause()) != null)
chain.add(cur);
HashMap data = new HashMap();
data.put("exception", e);
data.put("unknown", Location.UNKNOWN);
data.put("chain", chain);
data.put("locator", new Locator());
template.process(data, response.getWriter());
response.getWriter().close();
}
catch (Exception exp)
{
try
{
response.sendError(code, (new StringBuilder()).append("Unable to show problem report: ").append(exp).toString());
}
catch (IOException ex) { }
}
} else
{
try
{
if (code == 500)
{
request.setAttribute("javax.servlet.error.exception", e);
request.setAttribute("javax.servlet.jsp.jspException", e);
}
response.sendError(code, e.getMessage());
}
catch (IOException e1) { }
}
}
public boolean isPortletSupportActive()
{
return portletSupportActive;
}
public static void setPortletSupportActive(boolean portletSupportActive)
{
portletSupportActive = portletSupportActive;
}
public ConfigurationManager getConfigurationManager()
{
return configurationManager;
}
public void setConfigurationManager(ConfigurationManager mgr)
{
configurationManager = mgr;
}
public Container getContainer()
{
ConfigurationManager mgr = getConfigurationManager();
if (mgr == null)
throw new IllegalStateException("The configuration manager shouldn't be null");
Configuration config = mgr.getConfiguration();
if (config == null)
throw new IllegalStateException("Unable to load configuration");
else
return config.getContainer();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -