use of com.opensymphony.xwork2.inject.Factory in project struts by apache.
the class DummyFileManager method testCreateDefaultFileManager.
public void testCreateDefaultFileManager() throws Exception {
// given
fileManager = null;
DefaultFileManagerFactory factory = new DefaultFileManagerFactory();
factory.setFileManager(new DefaultFileManager());
factory.setContainer(new DummyContainer());
// when
FileManager fm = factory.getFileManager();
// then
assertTrue(fm instanceof DefaultFileManager);
}
use of com.opensymphony.xwork2.inject.Factory in project struts by apache.
the class Dispatcher method cleanup.
/**
* Releases all instances bound to this dispatcher instance.
*/
public void cleanup() {
// clean up ObjectFactory
ObjectFactory objectFactory = getContainer().getInstance(ObjectFactory.class);
if (objectFactory == null) {
LOG.warn("Object Factory is null, something is seriously wrong, no clean up will be performed");
}
if (objectFactory instanceof ObjectFactoryDestroyable) {
try {
((ObjectFactoryDestroyable) objectFactory).destroy();
} catch (Exception e) {
// catch any exception that may occurred during destroy() and log it
LOG.error("Exception occurred while destroying ObjectFactory [{}]", objectFactory.toString(), e);
}
}
// clean up Dispatcher itself for this thread
instance.set(null);
servletContext.setAttribute(StrutsStatics.SERVLET_DISPATCHER, null);
// clean up DispatcherListeners
if (!dispatcherListeners.isEmpty()) {
for (DispatcherListener l : dispatcherListeners) {
l.dispatcherDestroyed(this);
}
}
// clean up all interceptors by calling their destroy() method
Set<Interceptor> interceptors = new HashSet<>();
Collection<PackageConfig> packageConfigs = configurationManager.getConfiguration().getPackageConfigs().values();
for (PackageConfig packageConfig : packageConfigs) {
for (Object config : packageConfig.getAllInterceptorConfigs().values()) {
if (config instanceof InterceptorStackConfig) {
for (InterceptorMapping interceptorMapping : ((InterceptorStackConfig) config).getInterceptors()) {
interceptors.add(interceptorMapping.getInterceptor());
}
}
}
}
for (Interceptor interceptor : interceptors) {
interceptor.destroy();
}
// Clear container holder when application is unloaded / server shutdown
ContainerHolder.clear();
// cleanup action context
ActionContext.clear();
// clean up configuration
configurationManager.destroyConfiguration();
configurationManager = null;
}
use of com.opensymphony.xwork2.inject.Factory in project struts by apache.
the class Jsr168Dispatcher method init.
/**
* Initialize the portlet with the init parameters from <tt>portlet.xml</tt>
*
* @param cfg portlet configuration
* @throws PortletException in case of errors
*/
public void init(PortletConfig cfg) throws PortletException {
super.init(cfg);
LOG.debug("Initializing portlet {}", getPortletName());
Map<String, String> params = new HashMap<String, String>();
for (Enumeration e = cfg.getInitParameterNames(); e.hasMoreElements(); ) {
String name = (String) e.nextElement();
String value = cfg.getInitParameter(name);
params.put(name, value);
}
servletContext = new PortletServletContext(cfg.getPortletContext());
dispatcherUtils = new Dispatcher(servletContext, params);
dispatcherUtils.init();
// For testability
if (factory == null) {
factory = dispatcherUtils.getContainer().getInstance(ActionProxyFactory.class);
}
portletNamespace = cfg.getInitParameter("portletNamespace");
LOG.debug("PortletNamespace: {}", portletNamespace);
parseModeConfig(actionMap, cfg, PortletMode.VIEW, "viewNamespace", "defaultViewAction");
parseModeConfig(actionMap, cfg, PortletMode.EDIT, "editNamespace", "defaultEditAction");
parseModeConfig(actionMap, cfg, PortletMode.HELP, "helpNamespace", "defaultHelpAction");
parseModeConfig(actionMap, cfg, new PortletMode("config"), "configNamespace", "defaultConfigAction");
parseModeConfig(actionMap, cfg, new PortletMode("about"), "aboutNamespace", "defaultAboutAction");
parseModeConfig(actionMap, cfg, new PortletMode("print"), "printNamespace", "defaultPrintAction");
parseModeConfig(actionMap, cfg, new PortletMode("preview"), "previewNamespace", "defaultPreviewAction");
parseModeConfig(actionMap, cfg, new PortletMode("edit_defaults"), "editDefaultsNamespace", "defaultEditDefaultsAction");
if (StringUtils.isEmpty(portletNamespace)) {
portletNamespace = "";
}
container = dispatcherUtils.getContainer();
actionMapper = container.getInstance(ActionMapper.class);
}
use of com.opensymphony.xwork2.inject.Factory in project struts by apache.
the class ServletActionRedirectResultTest method testBuildResultWithParameter.
public void testBuildResultWithParameter() throws Exception {
ResultConfig resultConfig = new ResultConfig.Builder("", ServletActionRedirectResult.class.getName()).addParam("actionName", "someActionName").addParam("namespace", "someNamespace").addParam("encode", "true").addParam("parse", "true").addParam("location", "someLocation").addParam("prependServletContext", "true").addParam("method", "someMethod").addParam("param1", "value 1").addParam("param2", "value 2").addParam("param3", "value 3").addParam("anchor", "fragment").build();
ObjectFactory factory = container.getInstance(ObjectFactory.class);
ServletActionRedirectResult result = (ServletActionRedirectResult) factory.buildResult(resultConfig, ActionContext.getContext().getContextMap());
assertNotNull(result);
}
use of com.opensymphony.xwork2.inject.Factory in project struts by apache.
the class PrefixBasedActionProxyFactoryTest method setUp.
@Override
public void setUp() throws Exception {
ConfigurationProvider[] providers = new ConfigurationProvider[] { new StrutsXmlConfigurationProvider("xwork-sample.xml"), new StubConfigurationProvider() {
@Override
public void register(ContainerBuilder builder, LocatableProperties props) throws ConfigurationException {
builder.factory(ActionProxyFactory.class, "prefix1", new Factory() {
public Object create(Context context) throws Exception {
return new Prefix1Factory();
}
public Class type() {
return Prefix1Factory.class;
}
}, Scope.SINGLETON);
}
}, new StubConfigurationProvider() {
@Override
public void register(ContainerBuilder builder, LocatableProperties props) throws ConfigurationException {
builder.factory(ActionProxyFactory.class, "prefix2", new Factory() {
public Object create(Context context) throws Exception {
return new Prefix2Factory();
}
public Class type() {
return Prefix2Factory.class;
}
}, Scope.SINGLETON);
}
} };
loadConfigurationProviders(providers);
factory = new PrefixBasedActionProxyFactory();
factory.setContainer(container);
}
Aggregations