use of com.opensymphony.xwork2.FileManagerFactory in project struts by apache.
the class NotURLClassLoader method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
result = new EmbeddedJSPResult();
request = EasyMock.createNiceMock(HttpServletRequest.class);
response = new MockHttpServletResponse();
context = new MockServletContext();
config = new MockServletConfig(context);
final Map params = new HashMap();
HttpSession session = EasyMock.createNiceMock(HttpSession.class);
EasyMock.replay(session);
EasyMock.expect(request.getSession()).andReturn(session).anyTimes();
EasyMock.expect(request.getParameterMap()).andReturn(params).anyTimes();
EasyMock.expect(request.getParameter("username")).andAnswer(() -> ActionContext.getContext().getParameters().get("username").getValue());
EasyMock.expect(request.getAttribute("something")).andReturn("somethingelse").anyTimes();
EasyMock.replay(request);
// mock value stack
ValueStack valueStack = EasyMock.createNiceMock(ValueStack.class);
EasyMock.expect(valueStack.getActionContext()).andReturn(ActionContext.getContext()).anyTimes();
EasyMock.replay(valueStack);
// mock converter
XWorkConverter converter = new DummyConverter();
DefaultFileManager fileManager = new DefaultFileManager();
fileManager.setReloadingConfigs(false);
// mock container
Container container = EasyMock.createNiceMock(Container.class);
EasyMock.expect(container.getInstance(XWorkConverter.class)).andReturn(converter).anyTimes();
TextParser parser = new OgnlTextParser();
EasyMock.expect(container.getInstance(TextParser.class)).andReturn(parser).anyTimes();
EasyMock.expect(container.getInstanceNames(FileManager.class)).andReturn(new HashSet<>()).anyTimes();
EasyMock.expect(container.getInstance(FileManager.class)).andReturn(fileManager).anyTimes();
UrlHelper urlHelper = new DefaultUrlHelper();
EasyMock.expect(container.getInstance(UrlHelper.class)).andReturn(urlHelper).anyTimes();
FileManagerFactory fileManagerFactory = new DummyFileManagerFactory();
EasyMock.expect(container.getInstance(FileManagerFactory.class)).andReturn(fileManagerFactory).anyTimes();
EasyMock.replay(container);
ActionContext.of(new HashMap<>()).withParameters(HttpParameters.create(params).build()).withServletRequest(request).withServletResponse(response).withServletContext(context).withContainer(container).withValueStack(valueStack).bind();
}
use of com.opensymphony.xwork2.FileManagerFactory in project struts by apache.
the class OsgiConfigurationProvider method loadConfigFromBundle.
/**
* Loads XML config as well as Convention config from a bundle
* Limitation: Constants and Beans are ignored on XML config
*
* @param bundle the bundle
*/
protected void loadConfigFromBundle(Bundle bundle) {
if (bundle == null) {
// Better than a NPE.
throw new IllegalArgumentException("Cannot load configuration from a null bundle");
}
if (configuration == null) {
// Better than a NPE.
throw new IllegalStateException("Struts OSGi configuration is null. Cannot load bundle configuration");
}
if (bundleAccessor == null) {
LOG.warn("BundleAccessor is null (may not have been injected). May cause NPE to be thrown");
}
if (fileManagerFactory == null) {
LOG.warn("FileManagerFactory is null, FileManagerFactory may not have been set. May cause NPE to be thrown");
}
String bundleName = bundle.getSymbolicName();
LOG.debug("Loading packages from bundle [{}]", bundleName);
// init action context
ActionContext ctx = ActionContext.getContext();
if (ctx == null) {
ctx = createActionContext();
}
try {
// the Convention plugin will use BundleClassLoaderInterface from the ActionContext to find resources
// and load classes
ctx.put(ClassLoaderInterface.CLASS_LOADER_INTERFACE, new BundleClassLoaderInterface());
ctx.put(BundleAccessor.CURRENT_BUNDLE_NAME, bundleName);
LOG.trace("Loading XML config from bundle [{}]", bundleName);
// XML config
PackageLoader loader = new BundlePackageLoader();
loader.loadPackages(bundle, bundleContext, objectFactory, fileManagerFactory, configuration.getPackageConfigs()).stream().map(pkg -> {
configuration.addPackageConfig(pkg.getName(), pkg);
return pkg;
}).forEachOrdered(pkg -> {
bundleAccessor.addPackageFromBundle(bundle, pkg.getName());
});
// Convention
// get the existing packages before reloading the provider (se we can figure out what are the new packages)
Set<String> packagesBeforeLoading = new HashSet<>(configuration.getPackageConfigNames());
PackageProvider conventionPackageProvider = configuration.getContainer().getInstance(PackageProvider.class, "convention.packageProvider");
if (conventionPackageProvider != null) {
LOG.trace("Loading Convention config from bundle [{}]", bundleName);
conventionPackageProvider.loadPackages();
}
Set<String> packagesAfterLoading = new HashSet<>(configuration.getPackageConfigNames());
packagesAfterLoading.removeAll(packagesBeforeLoading);
if (!packagesAfterLoading.isEmpty()) {
// add the new packages to the map of bundle -> package
packagesAfterLoading.forEach(packageName -> {
bundleAccessor.addPackageFromBundle(bundle, packageName);
});
}
if (this.configuration.getRuntimeConfiguration() != null) {
// if there is a runtime config, it meas that this method was called froma bundle start event
// instead of the initial load, in that case, reload the config
this.configuration.rebuildRuntimeConfiguration();
}
} finally {
ctx.put(BundleAccessor.CURRENT_BUNDLE_NAME, null);
ctx.put(ClassLoaderInterface.CLASS_LOADER_INTERFACE, null);
}
}
Aggregations