use of com.opensymphony.xwork2.config.entities.PackageConfig.Builder in project tis by qlangtech.
the class TisPackageBasedActionConfigBuilder method getPackageConfig.
@Override
protected Builder getPackageConfig(Map<String, Builder> packageConfigs, String actionNamespace, String actionPackage, Class<?> actionClass, Action action) {
Matcher matcher = NAMESPACE_PATTERN.matcher(actionClass.getName());
// 解析struts2的命名空间
String name = null;
if (// || (matcher = NAMESPACE_TIS_PATTERN.matcher(actionClass.getName())).matches()
matcher.matches()) {
name = '/' + matcher.group(1) + StringUtils.replace(matcher.group(3), ".", "/") + "#" + matcher.group(2);
} else {
throw new IllegalStateException("actionPackage:" + actionPackage + " is not a valid actionPackage");
}
PackageConfig.Builder pkgConfig = packageConfigs.get(name);
if (pkgConfig == null) {
pkgConfig = new PackageConfig.Builder(name).namespace(name).addParent(this.parentPkgConfig);
// add by baisui: 2020/7/13
pkgConfig.strictMethodInvocation(false);
packageConfigs.put(name, pkgConfig);
// check for @DefaultInterceptorRef in the package
DefaultInterceptorRef defaultInterceptorRef = AnnotationUtils.findAnnotation(actionClass, DefaultInterceptorRef.class);
if (defaultInterceptorRef != null) {
pkgConfig.defaultInterceptorRef(defaultInterceptorRef.value());
if (LOG.isTraceEnabled())
LOG.debug("Setting [#0] as the default interceptor ref for [#1]", defaultInterceptorRef.value(), pkgConfig.getName());
}
}
if (LOG.isTraceEnabled()) {
LOG.trace("Created package config named [#0] with a namespace [#1]", name, actionNamespace);
}
return pkgConfig;
}
use of com.opensymphony.xwork2.config.entities.PackageConfig.Builder in project struts by apache.
the class DefaultResultMapBuilderTest method testFromServletContextWithBadNames.
public void testFromServletContextWithBadNames() throws Exception {
ServletContext context = EasyMock.createStrictMock(ServletContext.class);
// Setup some mock jsps
Set<String> resources = new HashSet<>();
resources.add("/WEB-INF/location/namespace/.something");
resources.add("/WEB-INF/location/namespace/.somethingelse/");
EasyMock.expect(context.getResourcePaths("/WEB-INF/location/namespace/")).andReturn(resources);
EasyMock.replay(context);
PackageConfig packageConfig = createPackageConfigBuilder("/namespace");
this.conventionsService = new ConventionsServiceImpl("/WEB-INF/location");
DefaultResultMapBuilder builder = new DefaultResultMapBuilder(context, container, "dispatcher,velocity,freemarker");
Map<String, ResultConfig> results = builder.build(NoAnnotationAction.class, null, "no-annotation", packageConfig);
assertEquals(0, results.size());
EasyMock.verify(context);
}
use of com.opensymphony.xwork2.config.entities.PackageConfig.Builder in project struts by apache.
the class DefaultResultMapBuilderTest method testActionLevelMultipleResultNamesAnnotation.
public void testActionLevelMultipleResultNamesAnnotation() throws Exception {
ServletContext context = EasyMock.createStrictMock(ServletContext.class);
// Setup some mock jsps
Set<String> resources = new HashSet<>();
EasyMock.expect(context.getResourcePaths("/WEB-INF/location/namespace/")).andReturn(resources);
EasyMock.replay(context);
PackageConfig packageConfig = createPackageConfigBuilder("/namespace");
this.conventionsService = new ConventionsServiceImpl("/WEB-INF/location");
DefaultResultMapBuilder builder = new DefaultResultMapBuilder(context, container, "dispatcher,velocity,freemarker");
Map<String, ResultConfig> results = builder.build(ActionLevelResultsNamesAction.class, getAnnotation(ActionLevelResultsNamesAction.class, "execute", Action.class), "action-level-results", packageConfig);
assertEquals(4, results.size());
assertEquals("error", results.get("error").getName());
assertEquals("input", results.get("input").getName());
assertEquals("success", results.get("success").getName());
assertEquals("failure", results.get("failure").getName());
assertEquals(3, results.get("error").getParams().size());
assertEquals("/WEB-INF/location/namespace/error.jsp", results.get("error").getParams().get("location"));
assertEquals("org.apache.struts2.result.ServletDispatcherResult", results.get("error").getClassName());
assertEquals("value", results.get("success").getParams().get("key"));
assertEquals("value1", results.get("success").getParams().get("key1"));
assertEquals(3, results.get("input").getParams().size());
assertEquals("/WEB-INF/location/namespace/error.jsp", results.get("input").getParams().get("location"));
assertEquals("org.apache.struts2.result.ServletDispatcherResult", results.get("input").getClassName());
assertEquals(3, results.get("failure").getParams().size());
assertEquals("/WEB-INF/location/namespace/action-failure.jsp", results.get("failure").getParams().get("location"));
assertEquals("org.apache.struts2.result.ServletDispatcherResult", results.get("failure").getClassName());
assertEquals(3, results.get("success").getParams().size());
assertEquals("/WEB-INF/location/namespace/action-success.jsp", results.get("success").getParams().get("location"));
assertEquals("org.apache.struts2.result.ServletDispatcherResult", results.get("success").getClassName());
EasyMock.verify(context);
}
use of com.opensymphony.xwork2.config.entities.PackageConfig.Builder in project struts by apache.
the class DefaultResultMapBuilderTest method testNull.
public void testNull() throws Exception {
ServletContext context = EasyMock.createStrictMock(ServletContext.class);
EasyMock.expect(context.getResourcePaths("/WEB-INF/location/namespace/")).andReturn(null);
EasyMock.replay(context);
// Test with a slash
PackageConfig packageConfig = createPackageConfigBuilder("/namespace");
this.conventionsService = new ConventionsServiceImpl("/WEB-INF/location");
DefaultResultMapBuilder builder = new DefaultResultMapBuilder(context, container, "dispatcher,velocity,freemarker");
Map<String, ResultConfig> results = builder.build(NoAnnotationAction.class, null, "action", packageConfig);
assertEquals(0, results.size());
EasyMock.verify(context);
}
use of com.opensymphony.xwork2.config.entities.PackageConfig.Builder in project struts by apache.
the class DefaultResultMapBuilderTest method testClassLevelMultipleResultAnnotation.
public void testClassLevelMultipleResultAnnotation() throws Exception {
ServletContext context = EasyMock.createStrictMock(ServletContext.class);
// Setup some mock jsps
Set<String> resources = new HashSet<>();
EasyMock.expect(context.getResourcePaths("/WEB-INF/location/namespace/")).andReturn(resources);
EasyMock.replay(context);
PackageConfig packageConfig = createPackageConfigBuilder("/namespace");
this.conventionsService = new ConventionsServiceImpl("/WEB-INF/location");
DefaultResultMapBuilder builder = new DefaultResultMapBuilder(context, container, "dispatcher,velocity,freemarker");
Map<String, ResultConfig> results = builder.build(ClassLevelResultsAction.class, null, "class-level-results", packageConfig);
assertEquals(4, results.size());
assertEquals("error", results.get("error").getName());
assertEquals("input", results.get("input").getName());
assertEquals("success", results.get("success").getName());
assertEquals("failure", results.get("failure").getName());
assertEquals(3, results.get("error").getParams().size());
assertEquals("org.apache.struts2.result.ServletDispatcherResult", results.get("error").getClassName());
assertEquals("/WEB-INF/location/namespace/error.jsp", results.get("error").getParams().get("location"));
assertEquals("ann-value", results.get("error").getParams().get("key"));
assertEquals("ann-value1", results.get("error").getParams().get("key1"));
assertEquals(1, results.get("input").getParams().size());
assertEquals("foo.action", results.get("input").getParams().get("actionName"));
assertEquals("org.apache.struts2.result.ServletActionRedirectResult", results.get("input").getClassName());
assertEquals(3, results.get("failure").getParams().size());
assertEquals("/WEB-INF/location/namespace/action-failure.jsp", results.get("failure").getParams().get("location"));
assertEquals("org.apache.struts2.result.ServletDispatcherResult", results.get("failure").getClassName());
assertEquals("value", results.get("failure").getParams().get("key"));
assertEquals("value1", results.get("failure").getParams().get("key1"));
assertEquals(3, results.get("success").getParams().size());
assertEquals("/WEB-INF/location/namespace/action-success.jsp", results.get("success").getParams().get("location"));
assertEquals("org.apache.struts2.result.ServletDispatcherResult", results.get("success").getClassName());
assertEquals("value", results.get("success").getParams().get("key"));
assertEquals("value1", results.get("success").getParams().get("key1"));
EasyMock.verify(context);
}
Aggregations