mirror of
https://github.com/apache/struts.git
synced 2026-08-06 15:17:00 +00:00
Merge pull request #177 from aleksandr-m/feature/WW-4875
WW-4875 Add ability to use Java based configuration
This commit is contained in:
@@ -19,6 +19,8 @@
|
||||
package com.opensymphony.xwork2.util.location;
|
||||
|
||||
import com.opensymphony.xwork2.util.ClassLoaderUtil;
|
||||
|
||||
import org.apache.struts2.config.StrutsJavaConfiguration;
|
||||
import org.w3c.dom.Element;
|
||||
import org.xml.sax.Locator;
|
||||
import org.xml.sax.SAXParseException;
|
||||
@@ -305,6 +307,10 @@ public class LocationUtils {
|
||||
}
|
||||
}
|
||||
|
||||
if (obj instanceof StrutsJavaConfiguration) {
|
||||
return new LocationImpl(description, obj.toString());
|
||||
}
|
||||
|
||||
return Location.UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.struts2.config;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.struts2.config.entities.BeanConfig;
|
||||
import org.apache.struts2.config.entities.ConstantConfig;
|
||||
|
||||
public interface StrutsJavaConfiguration {
|
||||
List<BeanConfig> beans();
|
||||
|
||||
List<ConstantConfig> constants();
|
||||
|
||||
List<String> unknownHandlerStack();
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.struts2.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.struts2.config.entities.BeanConfig;
|
||||
import org.apache.struts2.config.entities.ConstantConfig;
|
||||
|
||||
import com.opensymphony.xwork2.config.Configuration;
|
||||
import com.opensymphony.xwork2.config.ConfigurationException;
|
||||
import com.opensymphony.xwork2.config.ConfigurationProvider;
|
||||
import com.opensymphony.xwork2.config.entities.UnknownHandlerConfig;
|
||||
import com.opensymphony.xwork2.config.impl.LocatableFactory;
|
||||
import com.opensymphony.xwork2.config.providers.ValueSubstitutor;
|
||||
import com.opensymphony.xwork2.inject.ContainerBuilder;
|
||||
import com.opensymphony.xwork2.inject.Inject;
|
||||
import com.opensymphony.xwork2.util.location.LocatableProperties;
|
||||
import com.opensymphony.xwork2.util.location.Location;
|
||||
import com.opensymphony.xwork2.util.location.LocationUtils;
|
||||
|
||||
public class StrutsJavaConfigurationProvider implements ConfigurationProvider {
|
||||
private static final Logger LOG = LogManager.getLogger(StrutsJavaConfigurationProvider.class);
|
||||
|
||||
private final StrutsJavaConfiguration javaConfig;
|
||||
private Configuration configuration;
|
||||
private boolean throwExceptionOnDuplicateBeans = true;
|
||||
private ValueSubstitutor valueSubstitutor;
|
||||
|
||||
public StrutsJavaConfigurationProvider(StrutsJavaConfiguration javaConfig) {
|
||||
this.javaConfig = javaConfig;
|
||||
}
|
||||
|
||||
public void setThrowExceptionOnDuplicateBeans(boolean val) {
|
||||
this.throwExceptionOnDuplicateBeans = val;
|
||||
}
|
||||
|
||||
@Inject(required = false)
|
||||
public void setValueSubstitutor(ValueSubstitutor valueSubstitutor) {
|
||||
this.valueSubstitutor = valueSubstitutor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(ContainerBuilder builder, LocatableProperties props) throws ConfigurationException {
|
||||
Map<String, Object> loadedBeans = new HashMap<>();
|
||||
|
||||
// bean
|
||||
List<BeanConfig> beanConfigs = javaConfig.beans();
|
||||
if (beanConfigs != null) {
|
||||
for (BeanConfig bc : beanConfigs) {
|
||||
if (bc != null) {
|
||||
registerBean(loadedBeans, builder, bc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// constant
|
||||
List<ConstantConfig> constantConfigList = javaConfig.constants();
|
||||
if (constantConfigList != null) {
|
||||
for (ConstantConfig constantConf : constantConfigList) {
|
||||
if (constantConf != null) {
|
||||
Map<String, String> constantMap = constantConf.getAllAsStringsMap();
|
||||
for (Entry<String, String> entr : constantMap.entrySet()) {
|
||||
if (entr.getKey() != null && entr.getValue() != null) {
|
||||
registerConstant(props, entr.getKey(), entr.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// unknown-handler-stack
|
||||
List<String> unknownHandlers = javaConfig.unknownHandlerStack();
|
||||
if (unknownHandlers != null) {
|
||||
List<UnknownHandlerConfig> unknownHandlerStack = new ArrayList<>();
|
||||
for (String unknownHandler : unknownHandlers) {
|
||||
Location location = LocationUtils.getLocation(unknownHandler);
|
||||
unknownHandlerStack.add(new UnknownHandlerConfig(unknownHandler, location));
|
||||
}
|
||||
|
||||
if (!unknownHandlerStack.isEmpty()) {
|
||||
configuration.setUnknownHandlerStack(unknownHandlerStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void registerConstant(LocatableProperties props, String key, String value) {
|
||||
if (valueSubstitutor != null) {
|
||||
LOG.debug("Substituting value [{}] using [{}]", value, valueSubstitutor.getClass().getName());
|
||||
value = valueSubstitutor.substitute(value);
|
||||
}
|
||||
|
||||
props.setProperty(key, value, javaConfig);
|
||||
}
|
||||
|
||||
private void registerBean(Map<String, Object> loadedBeans, ContainerBuilder containerBuilder, BeanConfig beanConf) {
|
||||
try {
|
||||
if (beanConf.isOnlyStatic()) {
|
||||
// Force loading of class to detect no class def found
|
||||
// exceptions
|
||||
beanConf.getClazz().getDeclaredClasses();
|
||||
containerBuilder.injectStatics(beanConf.getClazz());
|
||||
} else {
|
||||
if (containerBuilder.contains(beanConf.getType(), beanConf.getName())) {
|
||||
Location loc = LocationUtils
|
||||
.getLocation(loadedBeans.get(beanConf.getType().getName() + beanConf.getName()));
|
||||
if (throwExceptionOnDuplicateBeans) {
|
||||
throw new ConfigurationException("Bean type " + beanConf.getType() + " with the name "
|
||||
+ beanConf.getName() + " has already been loaded by " + loc, javaConfig);
|
||||
}
|
||||
}
|
||||
|
||||
// Force loading of class to detect no class def found
|
||||
// exceptions
|
||||
beanConf.getClazz().getDeclaredConstructors();
|
||||
|
||||
LOG.debug("Loaded type: {} name: {} clazz: {}", beanConf.getType(), beanConf.getName(),
|
||||
beanConf.getClazz());
|
||||
containerBuilder.factory(
|
||||
beanConf.getType(), beanConf.getName(), new LocatableFactory(beanConf.getName(),
|
||||
beanConf.getType(), beanConf.getClazz(), beanConf.getScope(), javaConfig),
|
||||
beanConf.getScope());
|
||||
}
|
||||
loadedBeans.put(beanConf.getType().getName() + beanConf.getName(), javaConfig);
|
||||
} catch (Throwable ex) {
|
||||
if (!beanConf.isOptional()) {
|
||||
throw new ConfigurationException(
|
||||
"Unable to load bean: type:" + beanConf.getType() + " class:" + beanConf.getClazz(), ex);
|
||||
} else {
|
||||
LOG.debug("Unable to load optional class: {}", beanConf.getClazz());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(Configuration configuration) throws ConfigurationException {
|
||||
this.configuration = configuration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean needsReload() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadPackages() throws ConfigurationException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.struts2.config.entities;
|
||||
|
||||
import com.opensymphony.xwork2.inject.Container;
|
||||
import com.opensymphony.xwork2.inject.Scope;
|
||||
|
||||
public class BeanConfig {
|
||||
private final Class<?> clazz;
|
||||
private final String name;
|
||||
private final Class<?> type;
|
||||
private final Scope scope;
|
||||
private final boolean onlyStatic;
|
||||
private final boolean optional;
|
||||
|
||||
public BeanConfig(Class<?> clazz) {
|
||||
this(clazz, Container.DEFAULT_NAME);
|
||||
}
|
||||
|
||||
public BeanConfig(Class<?> clazz, String name) {
|
||||
this(clazz, name, clazz);
|
||||
}
|
||||
|
||||
public BeanConfig(Class<?> clazz, String name, Class<?> type) {
|
||||
this(clazz, name, type, Scope.SINGLETON, false, false);
|
||||
}
|
||||
|
||||
public BeanConfig(Class<?> clazz, String name, Class<?> type, Scope scope, boolean onlyStatic, boolean optional) {
|
||||
this.clazz = clazz;
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
this.scope = scope;
|
||||
this.onlyStatic = onlyStatic;
|
||||
this.optional = optional;
|
||||
}
|
||||
|
||||
public Class<?> getClazz() {
|
||||
return clazz;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Class<?> getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public Scope getScope() {
|
||||
return scope;
|
||||
}
|
||||
|
||||
public boolean isOnlyStatic() {
|
||||
return onlyStatic;
|
||||
}
|
||||
|
||||
public boolean isOptional() {
|
||||
return optional;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -48,6 +48,8 @@ import org.apache.struts2.StrutsStatics;
|
||||
import org.apache.struts2.config.DefaultBeanSelectionProvider;
|
||||
import org.apache.struts2.config.DefaultPropertiesProvider;
|
||||
import org.apache.struts2.config.PropertiesConfigurationProvider;
|
||||
import org.apache.struts2.config.StrutsJavaConfiguration;
|
||||
import org.apache.struts2.config.StrutsJavaConfigurationProvider;
|
||||
import org.apache.struts2.config.StrutsXmlConfigurationProvider;
|
||||
import org.apache.struts2.dispatcher.mapper.ActionMapping;
|
||||
import org.apache.struts2.dispatcher.multipart.MultiPartRequest;
|
||||
@@ -411,6 +413,30 @@ public class Dispatcher {
|
||||
return new StrutsXmlConfigurationProvider(filename, errorIfMissing, ctx);
|
||||
}
|
||||
|
||||
private void init_JavaConfigurations() {
|
||||
String configClasses = initParams.get("javaConfigClasses");
|
||||
if (configClasses != null) {
|
||||
String[] classes = configClasses.split("\\s*[,]\\s*");
|
||||
for (String cname : classes) {
|
||||
try {
|
||||
Class cls = ClassLoaderUtil.loadClass(cname, this.getClass());
|
||||
StrutsJavaConfiguration config = (StrutsJavaConfiguration) cls.newInstance();
|
||||
configurationManager.addContainerProvider(createJavaConfigurationProvider(config));
|
||||
} catch (InstantiationException e) {
|
||||
throw new ConfigurationException("Unable to instantiate java configuration: " + cname, e);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new ConfigurationException("Unable to access java configuration: " + cname, e);
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new ConfigurationException("Unable to locate java configuration class: " + cname, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected StrutsJavaConfigurationProvider createJavaConfigurationProvider(StrutsJavaConfiguration config) {
|
||||
return new StrutsJavaConfigurationProvider(config);
|
||||
}
|
||||
|
||||
private void init_CustomConfigurationProviders() {
|
||||
String configProvs = initParams.get("configProviders");
|
||||
if (configProvs != null) {
|
||||
@@ -488,6 +514,7 @@ public class Dispatcher {
|
||||
init_FileManager();
|
||||
init_DefaultProperties(); // [1]
|
||||
init_TraditionalXmlConfigurations(); // [2]
|
||||
init_JavaConfigurations();
|
||||
init_LegacyStrutsProperties(); // [3]
|
||||
init_CustomConfigurationProviders(); // [5]
|
||||
init_FilterInitParameters() ; // [6]
|
||||
|
||||
@@ -18,6 +18,12 @@
|
||||
*/
|
||||
package com.opensymphony.xwork2.util.location;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.struts2.config.StrutsJavaConfiguration;
|
||||
import org.apache.struts2.config.entities.BeanConfig;
|
||||
import org.apache.struts2.config.entities.ConstantConfig;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class LocationUtilsTest extends TestCase {
|
||||
@@ -53,4 +59,25 @@ public class LocationUtilsTest extends TestCase {
|
||||
"com/opensymphony/xwork2/util/location/LocationUtilsTest.java"
|
||||
.equals(loc.getURI()));
|
||||
}
|
||||
|
||||
public void testGetLocationStrutsJavaConfiguration() throws Exception {
|
||||
StrutsJavaConfiguration conf = new StrutsJavaConfiguration() {
|
||||
@Override
|
||||
public List<String> unknownHandlerStack() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public List<ConstantConfig> constants() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public List<BeanConfig> beans() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
Location loc = LocationUtils.getLocation(conf, null);
|
||||
|
||||
assertNotNull(loc);
|
||||
assertEquals(conf.toString(), loc.getURI());
|
||||
}
|
||||
}
|
||||
|
||||
+330
@@ -0,0 +1,330 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.struts2.convention.config.entities;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.struts2.config.entities.BeanConfig;
|
||||
import org.apache.struts2.config.entities.ConstantConfig;
|
||||
import org.apache.struts2.convention.ConventionConstants;
|
||||
|
||||
public class ConventionConstantConfig extends ConstantConfig {
|
||||
private BeanConfig conventionActionConfigBuilder;
|
||||
private BeanConfig conventionActionNameBuilder;
|
||||
private BeanConfig conventionResultMapBuilder;
|
||||
private BeanConfig conventionInterceptorMapBuilder;
|
||||
private BeanConfig conventionConventionsService;
|
||||
private Boolean conventionActionNameLowercase;
|
||||
private String conventionActionNameSeparator;
|
||||
private Set<String> conventionActionSuffix;
|
||||
private Boolean conventionClassesReload;
|
||||
private String conventionResultPath;
|
||||
private String conventionDefaultParentPackage;
|
||||
private Boolean conventionRedirectToSlash;
|
||||
private Set<String> conventionRelativeResultTypes;
|
||||
private Boolean conventionExcludeParentClassLoader;
|
||||
private Boolean conventionActionAlwaysMapExecute;
|
||||
private Set<String> conventionActionFileProtocols;
|
||||
private Boolean conventionActionDisableScanning;
|
||||
private List<String> conventionActionIncludeJars;
|
||||
private Boolean conventionPackageLocatorsDisable;
|
||||
private List<String> conventionActionPackages;
|
||||
private Boolean conventionActionCheckImplementsAction;
|
||||
private List<String> conventionExcludePackages;
|
||||
private List<String> conventionPackageLocators;
|
||||
private String conventionPackageLocatorsBasePackage;
|
||||
private Boolean conventionActionMapAllMatches;
|
||||
private Boolean conventionActionEagerLoading;
|
||||
private Boolean conventionResultFlatLayout;
|
||||
|
||||
@Override
|
||||
public Map<String, String> getAllAsStringsMap() {
|
||||
Map<String, String> map = super.getAllAsStringsMap();
|
||||
|
||||
map.put(ConventionConstants.CONVENTION_ACTION_CONFIG_BUILDER, beanConfToString(conventionActionConfigBuilder));
|
||||
map.put(ConventionConstants.CONVENTION_ACTION_NAME_BUILDER, beanConfToString(conventionActionNameBuilder));
|
||||
map.put(ConventionConstants.CONVENTION_RESULT_MAP_BUILDER, beanConfToString(conventionResultMapBuilder));
|
||||
map.put(ConventionConstants.CONVENTION_INTERCEPTOR_MAP_BUILDER, beanConfToString(conventionInterceptorMapBuilder));
|
||||
map.put(ConventionConstants.CONVENTION_CONVENTIONS_SERVICE, beanConfToString(conventionConventionsService));
|
||||
map.put(ConventionConstants.CONVENTION_ACTION_NAME_LOWERCASE, Objects.toString(conventionActionNameLowercase, null));
|
||||
map.put(ConventionConstants.CONVENTION_ACTION_NAME_SEPARATOR, conventionActionNameSeparator);
|
||||
map.put(ConventionConstants.CONVENTION_ACTION_SUFFIX, StringUtils.join(conventionActionSuffix, ','));
|
||||
map.put(ConventionConstants.CONVENTION_CLASSES_RELOAD, Objects.toString(conventionClassesReload, null));
|
||||
map.put(ConventionConstants.CONVENTION_RESULT_PATH, conventionResultPath);
|
||||
map.put(ConventionConstants.CONVENTION_DEFAULT_PARENT_PACKAGE, conventionDefaultParentPackage);
|
||||
map.put(ConventionConstants.CONVENTION_REDIRECT_TO_SLASH, Objects.toString(conventionRedirectToSlash, null));
|
||||
map.put(ConventionConstants.CONVENTION_RELATIVE_RESULT_TYPES, StringUtils.join(conventionRelativeResultTypes, ','));
|
||||
map.put(ConventionConstants.CONVENTION_EXCLUDE_PARENT_CLASS_LOADER, Objects.toString(conventionExcludeParentClassLoader, null));
|
||||
map.put(ConventionConstants.CONVENTION_ACTION_ALWAYS_MAP_EXECUTE, Objects.toString(conventionActionAlwaysMapExecute, null));
|
||||
map.put(ConventionConstants.CONVENTION_ACTION_FILE_PROTOCOLS, StringUtils.join(conventionActionFileProtocols, ','));
|
||||
map.put(ConventionConstants.CONVENTION_ACTION_DISABLE_SCANNING, Objects.toString(conventionActionDisableScanning, null));
|
||||
map.put(ConventionConstants.CONVENTION_ACTION_INCLUDE_JARS, StringUtils.join(conventionActionIncludeJars, ','));
|
||||
map.put(ConventionConstants.CONVENTION_PACKAGE_LOCATORS_DISABLE, Objects.toString(conventionPackageLocatorsDisable, null));
|
||||
map.put(ConventionConstants.CONVENTION_ACTION_PACKAGES, StringUtils.join(conventionActionPackages, ','));
|
||||
map.put(ConventionConstants.CONVENTION_ACTION_CHECK_IMPLEMENTS_ACTION, Objects.toString(conventionActionCheckImplementsAction, null));
|
||||
map.put(ConventionConstants.CONVENTION_EXCLUDE_PACKAGES, StringUtils.join(conventionExcludePackages, ','));
|
||||
map.put(ConventionConstants.CONVENTION_PACKAGE_LOCATORS, StringUtils.join(conventionPackageLocators, ','));
|
||||
map.put(ConventionConstants.CONVENTION_PACKAGE_LOCATORS_BASE_PACKAGE, conventionPackageLocatorsBasePackage);
|
||||
map.put(ConventionConstants.CONVENTION_ACTION_MAP_ALL_MATCHES, Objects.toString(conventionActionMapAllMatches, null));
|
||||
map.put(ConventionConstants.CONVENTION_ACTION_EAGER_LOADING, Objects.toString(conventionActionEagerLoading, null));
|
||||
map.put(ConventionConstants.CONVENTION_RESULT_FLAT_LAYOUT, Objects.toString(conventionResultFlatLayout, null));
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
public BeanConfig getConventionActionConfigBuilder() {
|
||||
return conventionActionConfigBuilder;
|
||||
}
|
||||
|
||||
public void setConventionActionConfigBuilder(BeanConfig conventionActionConfigBuilder) {
|
||||
this.conventionActionConfigBuilder = conventionActionConfigBuilder;
|
||||
}
|
||||
|
||||
public void setConventionActionConfigBuilder(Class<?> clazz) {
|
||||
this.conventionActionConfigBuilder = new BeanConfig(clazz, clazz.getName());
|
||||
}
|
||||
|
||||
public BeanConfig getConventionActionNameBuilder() {
|
||||
return conventionActionNameBuilder;
|
||||
}
|
||||
|
||||
public void setConventionActionNameBuilder(BeanConfig conventionActionNameBuilder) {
|
||||
this.conventionActionNameBuilder = conventionActionNameBuilder;
|
||||
}
|
||||
|
||||
public void setConventionActionNameBuilder(Class<?> clazz) {
|
||||
this.conventionActionNameBuilder = new BeanConfig(clazz, clazz.getName());
|
||||
}
|
||||
|
||||
public BeanConfig getConventionResultMapBuilder() {
|
||||
return conventionResultMapBuilder;
|
||||
}
|
||||
|
||||
public void setConventionResultMapBuilder(BeanConfig conventionResultMapBuilder) {
|
||||
this.conventionResultMapBuilder = conventionResultMapBuilder;
|
||||
}
|
||||
|
||||
public void setConventionResultMapBuilder(Class<?> clazz) {
|
||||
this.conventionResultMapBuilder = new BeanConfig(clazz, clazz.getName());
|
||||
}
|
||||
|
||||
public BeanConfig getConventionInterceptorMapBuilder() {
|
||||
return conventionInterceptorMapBuilder;
|
||||
}
|
||||
|
||||
public void setConventionInterceptorMapBuilder(BeanConfig conventionInterceptorMapBuilder) {
|
||||
this.conventionInterceptorMapBuilder = conventionInterceptorMapBuilder;
|
||||
}
|
||||
|
||||
public void setConventionInterceptorMapBuilder(Class<?> clazz) {
|
||||
this.conventionInterceptorMapBuilder = new BeanConfig(clazz, clazz.getName());
|
||||
}
|
||||
|
||||
public BeanConfig getConventionConventionsService() {
|
||||
return conventionConventionsService;
|
||||
}
|
||||
|
||||
public void setConventionConventionsService(BeanConfig conventionConventionsService) {
|
||||
this.conventionConventionsService = conventionConventionsService;
|
||||
}
|
||||
|
||||
public void setConventionConventionsService(Class<?> clazz) {
|
||||
this.conventionConventionsService = new BeanConfig(clazz, clazz.getName());
|
||||
}
|
||||
|
||||
public Boolean getConventionActionNameLowercase() {
|
||||
return conventionActionNameLowercase;
|
||||
}
|
||||
|
||||
public void setConventionActionNameLowercase(Boolean conventionActionNameLowercase) {
|
||||
this.conventionActionNameLowercase = conventionActionNameLowercase;
|
||||
}
|
||||
|
||||
public String getConventionActionNameSeparator() {
|
||||
return conventionActionNameSeparator;
|
||||
}
|
||||
|
||||
public void setConventionActionNameSeparator(String conventionActionNameSeparator) {
|
||||
this.conventionActionNameSeparator = conventionActionNameSeparator;
|
||||
}
|
||||
|
||||
public Set<String> getConventionActionSuffix() {
|
||||
return conventionActionSuffix;
|
||||
}
|
||||
|
||||
public void setConventionActionSuffix(Set<String> conventionActionSuffix) {
|
||||
this.conventionActionSuffix = conventionActionSuffix;
|
||||
}
|
||||
|
||||
public Boolean getConventionClassesReload() {
|
||||
return conventionClassesReload;
|
||||
}
|
||||
|
||||
public void setConventionClassesReload(Boolean conventionClassesReload) {
|
||||
this.conventionClassesReload = conventionClassesReload;
|
||||
}
|
||||
|
||||
public String getConventionResultPath() {
|
||||
return conventionResultPath;
|
||||
}
|
||||
|
||||
public void setConventionResultPath(String conventionResultPath) {
|
||||
this.conventionResultPath = conventionResultPath;
|
||||
}
|
||||
|
||||
public String getConventionDefaultParentPackage() {
|
||||
return conventionDefaultParentPackage;
|
||||
}
|
||||
|
||||
public void setConventionDefaultParentPackage(String conventionDefaultParentPackage) {
|
||||
this.conventionDefaultParentPackage = conventionDefaultParentPackage;
|
||||
}
|
||||
|
||||
public Boolean getConventionRedirectToSlash() {
|
||||
return conventionRedirectToSlash;
|
||||
}
|
||||
|
||||
public void setConventionRedirectToSlash(Boolean conventionRedirectToSlash) {
|
||||
this.conventionRedirectToSlash = conventionRedirectToSlash;
|
||||
}
|
||||
|
||||
public Set<String> getConventionRelativeResultTypes() {
|
||||
return conventionRelativeResultTypes;
|
||||
}
|
||||
|
||||
public void setConventionRelativeResultTypes(Set<String> conventionRelativeResultTypes) {
|
||||
this.conventionRelativeResultTypes = conventionRelativeResultTypes;
|
||||
}
|
||||
|
||||
public Boolean getConventionExcludeParentClassLoader() {
|
||||
return conventionExcludeParentClassLoader;
|
||||
}
|
||||
|
||||
public void setConventionExcludeParentClassLoader(Boolean conventionExcludeParentClassLoader) {
|
||||
this.conventionExcludeParentClassLoader = conventionExcludeParentClassLoader;
|
||||
}
|
||||
|
||||
public Boolean getConventionActionAlwaysMapExecute() {
|
||||
return conventionActionAlwaysMapExecute;
|
||||
}
|
||||
|
||||
public void setConventionActionAlwaysMapExecute(Boolean conventionActionAlwaysMapExecute) {
|
||||
this.conventionActionAlwaysMapExecute = conventionActionAlwaysMapExecute;
|
||||
}
|
||||
|
||||
public Set<String> getConventionActionFileProtocols() {
|
||||
return conventionActionFileProtocols;
|
||||
}
|
||||
|
||||
public void setConventionActionFileProtocols(Set<String> conventionActionFileProtocols) {
|
||||
this.conventionActionFileProtocols = conventionActionFileProtocols;
|
||||
}
|
||||
|
||||
public Boolean getConventionActionDisableScanning() {
|
||||
return conventionActionDisableScanning;
|
||||
}
|
||||
|
||||
public void setConventionActionDisableScanning(Boolean conventionActionDisableScanning) {
|
||||
this.conventionActionDisableScanning = conventionActionDisableScanning;
|
||||
}
|
||||
|
||||
public List<String> getConventionActionIncludeJars() {
|
||||
return conventionActionIncludeJars;
|
||||
}
|
||||
|
||||
public void setConventionActionIncludeJars(List<String> conventionActionIncludeJars) {
|
||||
this.conventionActionIncludeJars = conventionActionIncludeJars;
|
||||
}
|
||||
|
||||
public Boolean getConventionPackageLocatorsDisable() {
|
||||
return conventionPackageLocatorsDisable;
|
||||
}
|
||||
|
||||
public void setConventionPackageLocatorsDisable(Boolean conventionPackageLocatorsDisable) {
|
||||
this.conventionPackageLocatorsDisable = conventionPackageLocatorsDisable;
|
||||
}
|
||||
|
||||
public List<String> getConventionActionPackages() {
|
||||
return conventionActionPackages;
|
||||
}
|
||||
|
||||
public void setConventionActionPackages(List<String> conventionActionPackages) {
|
||||
this.conventionActionPackages = conventionActionPackages;
|
||||
}
|
||||
|
||||
public Boolean getConventionActionCheckImplementsAction() {
|
||||
return conventionActionCheckImplementsAction;
|
||||
}
|
||||
|
||||
public void setConventionActionCheckImplementsAction(Boolean conventionActionCheckImplementsAction) {
|
||||
this.conventionActionCheckImplementsAction = conventionActionCheckImplementsAction;
|
||||
}
|
||||
|
||||
public List<String> getConventionExcludePackages() {
|
||||
return conventionExcludePackages;
|
||||
}
|
||||
|
||||
public void setConventionExcludePackages(List<String> conventionExcludePackages) {
|
||||
this.conventionExcludePackages = conventionExcludePackages;
|
||||
}
|
||||
|
||||
public List<String> getConventionPackageLocators() {
|
||||
return conventionPackageLocators;
|
||||
}
|
||||
|
||||
public void setConventionPackageLocators(List<String> conventionPackageLocators) {
|
||||
this.conventionPackageLocators = conventionPackageLocators;
|
||||
}
|
||||
|
||||
public String getConventionPackageLocatorsBasePackage() {
|
||||
return conventionPackageLocatorsBasePackage;
|
||||
}
|
||||
|
||||
public void setConventionPackageLocatorsBasePackage(String conventionPackageLocatorsBasePackage) {
|
||||
this.conventionPackageLocatorsBasePackage = conventionPackageLocatorsBasePackage;
|
||||
}
|
||||
|
||||
public Boolean getConventionActionMapAllMatches() {
|
||||
return conventionActionMapAllMatches;
|
||||
}
|
||||
|
||||
public void setConventionActionMapAllMatches(Boolean conventionActionMapAllMatches) {
|
||||
this.conventionActionMapAllMatches = conventionActionMapAllMatches;
|
||||
}
|
||||
|
||||
public Boolean getConventionActionEagerLoading() {
|
||||
return conventionActionEagerLoading;
|
||||
}
|
||||
|
||||
public void setConventionActionEagerLoading(Boolean conventionActionEagerLoading) {
|
||||
this.conventionActionEagerLoading = conventionActionEagerLoading;
|
||||
}
|
||||
|
||||
public Boolean getConventionResultFlatLayout() {
|
||||
return conventionResultFlatLayout;
|
||||
}
|
||||
|
||||
public void setConventionResultFlatLayout(Boolean conventionResultFlatLayout) {
|
||||
this.conventionResultFlatLayout = conventionResultFlatLayout;
|
||||
}
|
||||
}
|
||||
@@ -30,4 +30,5 @@ public class JSONConstants {
|
||||
|
||||
public static final String JSON_WRITER = "struts.json.writer";
|
||||
public static final String RESULT_EXCLUDE_PROXY_PROPERTIES = "struts.json.result.excludeProxyProperties";
|
||||
public static final String DATE_FORMAT = "struts.json.dateformat";
|
||||
}
|
||||
|
||||
@@ -456,7 +456,7 @@ public class JSONResult implements Result {
|
||||
return defaultDateFormat;
|
||||
}
|
||||
|
||||
@Inject(required=false,value="struts.json.dateformat")
|
||||
@Inject(required = false, value = JSONConstants.DATE_FORMAT)
|
||||
public void setDefaultDateFormat(String defaultDateFormat) {
|
||||
this.defaultDateFormat = defaultDateFormat;
|
||||
}
|
||||
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.struts2.json.config.entities;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.apache.struts2.config.entities.BeanConfig;
|
||||
import org.apache.struts2.config.entities.ConstantConfig;
|
||||
import org.apache.struts2.json.JSONConstants;
|
||||
|
||||
public class JSONConstantConfig extends ConstantConfig {
|
||||
private BeanConfig jsonWriter;
|
||||
private Boolean jsonResultExcludeProxyProperties;
|
||||
private String jsonDateFormat;
|
||||
|
||||
@Override
|
||||
public Map<String, String> getAllAsStringsMap() {
|
||||
Map<String, String> map = super.getAllAsStringsMap();
|
||||
|
||||
map.put(JSONConstants.JSON_WRITER, beanConfToString(jsonWriter));
|
||||
map.put(JSONConstants.RESULT_EXCLUDE_PROXY_PROPERTIES, Objects.toString(jsonResultExcludeProxyProperties, null));
|
||||
map.put(JSONConstants.DATE_FORMAT, jsonDateFormat);
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
public BeanConfig getJsonWriter() {
|
||||
return jsonWriter;
|
||||
}
|
||||
|
||||
public void setJsonWriter(BeanConfig jsonWriter) {
|
||||
this.jsonWriter = jsonWriter;
|
||||
}
|
||||
|
||||
public void setJsonWriter(Class<?> clazz) {
|
||||
this.jsonWriter = new BeanConfig(clazz, clazz.getName());
|
||||
}
|
||||
|
||||
public Boolean getJsonResultExcludeProxyProperties() {
|
||||
return jsonResultExcludeProxyProperties;
|
||||
}
|
||||
|
||||
public void setJsonResultExcludeProxyProperties(Boolean jsonResultExcludeProxyProperties) {
|
||||
this.jsonResultExcludeProxyProperties = jsonResultExcludeProxyProperties;
|
||||
}
|
||||
|
||||
public String getJsonDateFormat() {
|
||||
return jsonDateFormat;
|
||||
}
|
||||
|
||||
public void setJsonDateFormat(String jsonDateFormat) {
|
||||
this.jsonDateFormat = jsonDateFormat;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -50,7 +50,7 @@ public class DefaultContentTypeHandlerManager implements ContentTypeHandlerManag
|
||||
|
||||
private String defaultExtension;
|
||||
|
||||
@Inject("struts.rest.defaultExtension")
|
||||
@Inject(RestConstants.REST_DEFAULT_EXTENSION)
|
||||
public void setDefaultExtension(String name) {
|
||||
this.defaultExtension = name;
|
||||
}
|
||||
|
||||
@@ -62,12 +62,12 @@ public class RestActionInvocation extends DefaultActionInvocation {
|
||||
super(extraContext, pushAction);
|
||||
}
|
||||
|
||||
@Inject("struts.rest.logger")
|
||||
@Inject(RestConstants.REST_LOGGER)
|
||||
public void setLogger(String logger) {
|
||||
this.logger = BooleanUtils.toBoolean(logger);
|
||||
}
|
||||
|
||||
@Inject("struts.rest.defaultErrorResultName")
|
||||
@Inject(RestConstants.REST_DEFAULT_ERROR_RESULT_NAME)
|
||||
public void setDefaultErrorResultName(String defaultErrorResultName) {
|
||||
this.defaultErrorResultName = defaultErrorResultName;
|
||||
}
|
||||
@@ -78,7 +78,7 @@ public class RestActionInvocation extends DefaultActionInvocation {
|
||||
*
|
||||
* @param restrictToGet true or false
|
||||
*/
|
||||
@Inject(value = "struts.rest.content.restrictToGET", required = false)
|
||||
@Inject(value = RestConstants.REST_CONTENT_RESTRICT_TO_GET, required = false)
|
||||
public void setRestrictToGet(String restrictToGet) {
|
||||
this.restrictToGet = BooleanUtils.toBoolean(restrictToGet);
|
||||
}
|
||||
|
||||
@@ -130,52 +130,52 @@ public class RestActionMapper extends DefaultActionMapper {
|
||||
this.idParameterName = idParameterName;
|
||||
}
|
||||
|
||||
@Inject(required=false,value="struts.mapper.indexMethodName")
|
||||
@Inject(required = false, value = RestConstants.REST_MAPPER_INDEX_METHOD_NAME)
|
||||
public void setIndexMethodName(String indexMethodName) {
|
||||
this.indexMethodName = indexMethodName;
|
||||
}
|
||||
|
||||
@Inject(required=false,value="struts.mapper.getMethodName")
|
||||
@Inject(required = false, value = RestConstants.REST_MAPPER_GET_METHOD_NAME)
|
||||
public void setGetMethodName(String getMethodName) {
|
||||
this.getMethodName = getMethodName;
|
||||
}
|
||||
|
||||
@Inject(required=false,value="struts.mapper.postMethodName")
|
||||
@Inject(required = false, value = RestConstants.REST_MAPPER_POST_METHOD_NAME)
|
||||
public void setPostMethodName(String postMethodName) {
|
||||
this.postMethodName = postMethodName;
|
||||
}
|
||||
|
||||
@Inject(required=false,value="struts.mapper.editMethodName")
|
||||
@Inject(required = false, value = RestConstants.REST_MAPPER_EDIT_METHOD_NAME)
|
||||
public void setEditMethodName(String editMethodName) {
|
||||
this.editMethodName = editMethodName;
|
||||
}
|
||||
|
||||
@Inject(required=false,value="struts.mapper.newMethodName")
|
||||
@Inject(required = false, value = RestConstants.REST_MAPPER_NEW_METHOD_NAME)
|
||||
public void setNewMethodName(String newMethodName) {
|
||||
this.newMethodName = newMethodName;
|
||||
}
|
||||
|
||||
@Inject(required=false,value="struts.mapper.deleteMethodName")
|
||||
@Inject(required = false, value = RestConstants.REST_MAPPER_DELETE_METHOD_NAME)
|
||||
public void setDeleteMethodName(String deleteMethodName) {
|
||||
this.deleteMethodName = deleteMethodName;
|
||||
}
|
||||
|
||||
@Inject(required=false,value="struts.mapper.putMethodName")
|
||||
@Inject(required = false, value = RestConstants.REST_MAPPER_PUT_METHOD_NAME)
|
||||
public void setPutMethodName(String putMethodName) {
|
||||
this.putMethodName = putMethodName;
|
||||
}
|
||||
|
||||
@Inject(required=false,value="struts.mapper.optionsMethodName")
|
||||
@Inject(required = false, value = RestConstants.REST_MAPPER_OPTIONS_METHOD_NAME)
|
||||
public void setOptionsMethodName(String optionsMethodName) {
|
||||
this.optionsMethodName = optionsMethodName;
|
||||
}
|
||||
|
||||
@Inject(required=false,value="struts.mapper.postContinueMethodName")
|
||||
@Inject(required = false, value = RestConstants.REST_MAPPER_POST_CONTINUE_METHOD_NAME)
|
||||
public void setPostContinueMethodName(String postContinueMethodName) {
|
||||
this.postContinueMethodName = postContinueMethodName;
|
||||
}
|
||||
|
||||
@Inject(required=false,value="struts.mapper.putContinueMethodName")
|
||||
@Inject(required = false, value = RestConstants.REST_MAPPER_PUT_CONTINUE_METHOD_NAME)
|
||||
public void setPutContinueMethodName(String putContinueMethodName) {
|
||||
this.putContinueMethodName = putContinueMethodName;
|
||||
}
|
||||
|
||||
@@ -31,11 +31,9 @@ import java.util.Map;
|
||||
*/
|
||||
public class RestActionProxyFactory extends DefaultActionProxyFactory {
|
||||
|
||||
public static final String STRUTS_REST_NAMESPACE = "struts.rest.namespace";
|
||||
|
||||
protected String namespace;
|
||||
|
||||
@Inject(value = STRUTS_REST_NAMESPACE, required = false)
|
||||
@Inject(value = RestConstants.STRUTS_REST_NAMESPACE, required = false)
|
||||
public void setNamespace(String namespace) {
|
||||
this.namespace = namespace;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.struts2.rest;
|
||||
|
||||
public class RestConstants {
|
||||
public static final String REST_DEFAULT_EXTENSION = "struts.rest.defaultExtension";
|
||||
public static final String REST_LOGGER = "struts.rest.logger";
|
||||
public static final String REST_DEFAULT_ERROR_RESULT_NAME = "struts.rest.defaultErrorResultName";
|
||||
public static final String REST_CONTENT_RESTRICT_TO_GET = "struts.rest.content.restrictToGET";
|
||||
public static final String REST_MAPPER_INDEX_METHOD_NAME = "struts.mapper.indexMethodName";
|
||||
public static final String REST_MAPPER_GET_METHOD_NAME = "struts.mapper.getMethodName";
|
||||
public static final String REST_MAPPER_POST_METHOD_NAME = "struts.mapper.postMethodName";
|
||||
public static final String REST_MAPPER_EDIT_METHOD_NAME = "struts.mapper.editMethodName";
|
||||
public static final String REST_MAPPER_NEW_METHOD_NAME = "struts.mapper.newMethodName";
|
||||
public static final String REST_MAPPER_DELETE_METHOD_NAME = "struts.mapper.deleteMethodName";
|
||||
public static final String REST_MAPPER_PUT_METHOD_NAME = "struts.mapper.putMethodName";
|
||||
public static final String REST_MAPPER_OPTIONS_METHOD_NAME = "struts.mapper.optionsMethodName";
|
||||
public static final String REST_MAPPER_POST_CONTINUE_METHOD_NAME = "struts.mapper.postContinueMethodName";
|
||||
public static final String REST_MAPPER_PUT_CONTINUE_METHOD_NAME = "struts.mapper.putContinueMethodName";
|
||||
public static final String STRUTS_REST_NAMESPACE = "struts.rest.namespace";
|
||||
public static final String REST_VALIDATION_FAILURE_STATUS_CODE = "struts.rest.validationFailureStatusCode";
|
||||
}
|
||||
@@ -146,27 +146,27 @@ public class RestWorkflowInterceptor extends MethodFilterInterceptor {
|
||||
|
||||
private int validationFailureStatusCode = SC_BAD_REQUEST;
|
||||
|
||||
@Inject(required=false,value="struts.mapper.postMethodName")
|
||||
@Inject(required = false, value = RestConstants.REST_MAPPER_POST_METHOD_NAME)
|
||||
public void setPostMethodName(String postMethodName) {
|
||||
this.postMethodName = postMethodName;
|
||||
}
|
||||
|
||||
@Inject(required=false,value="struts.mapper.editMethodName")
|
||||
@Inject(required = false, value = RestConstants.REST_MAPPER_EDIT_METHOD_NAME)
|
||||
public void setEditMethodName(String editMethodName) {
|
||||
this.editMethodName = editMethodName;
|
||||
}
|
||||
|
||||
@Inject(required=false,value="struts.mapper.newMethodName")
|
||||
@Inject(required = false, value = RestConstants.REST_MAPPER_NEW_METHOD_NAME)
|
||||
public void setNewMethodName(String newMethodName) {
|
||||
this.newMethodName = newMethodName;
|
||||
}
|
||||
|
||||
@Inject(required=false,value="struts.mapper.putMethodName")
|
||||
@Inject(required = false, value = RestConstants.REST_MAPPER_PUT_METHOD_NAME)
|
||||
public void setPutMethodName(String putMethodName) {
|
||||
this.putMethodName = putMethodName;
|
||||
}
|
||||
|
||||
@Inject(required=false,value="struts.rest.validationFailureStatusCode")
|
||||
@Inject(required = false, value = RestConstants.REST_VALIDATION_FAILURE_STATUS_CODE)
|
||||
public void setValidationFailureStatusCode(String code) {
|
||||
this.validationFailureStatusCode = Integer.parseInt(code);
|
||||
}
|
||||
|
||||
+196
@@ -0,0 +1,196 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.struts2.rest.config.entities;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.apache.struts2.config.entities.ConstantConfig;
|
||||
import org.apache.struts2.rest.RestConstants;
|
||||
|
||||
public class RestConstantConfig extends ConstantConfig {
|
||||
private String restDefaultExtension;
|
||||
private Boolean restLogger;
|
||||
private String restDefaultErrorResultName;
|
||||
private Boolean restContentRestrictToGet;
|
||||
private String mapperIndexMethodName;
|
||||
private String mapperGetMethodName;
|
||||
private String mapperPostMethodName;
|
||||
private String mapperEditMethodName;
|
||||
private String mapperNewMethodName;
|
||||
private String mapperDeleteMethodName;
|
||||
private String mapperPutMethodName;
|
||||
private String mapperOptionsMethodName;
|
||||
private String mapperPostContinueMethodName;
|
||||
private String mapperPutContinueMethodName;
|
||||
private String restNamespace;
|
||||
private String restValidationFailureStatusCode;
|
||||
|
||||
@Override
|
||||
public Map<String, String> getAllAsStringsMap() {
|
||||
Map<String, String> map = super.getAllAsStringsMap();
|
||||
|
||||
map.put(RestConstants.REST_DEFAULT_EXTENSION, restDefaultExtension);
|
||||
map.put(RestConstants.REST_LOGGER, Objects.toString(restLogger, null));
|
||||
map.put(RestConstants.REST_DEFAULT_ERROR_RESULT_NAME, restDefaultErrorResultName);
|
||||
map.put(RestConstants.REST_CONTENT_RESTRICT_TO_GET, Objects.toString(restContentRestrictToGet, null));
|
||||
map.put(RestConstants.REST_MAPPER_INDEX_METHOD_NAME, mapperIndexMethodName);
|
||||
map.put(RestConstants.REST_MAPPER_GET_METHOD_NAME, mapperGetMethodName);
|
||||
map.put(RestConstants.REST_MAPPER_POST_METHOD_NAME, mapperPostMethodName);
|
||||
map.put(RestConstants.REST_MAPPER_EDIT_METHOD_NAME, mapperEditMethodName);
|
||||
map.put(RestConstants.REST_MAPPER_NEW_METHOD_NAME, mapperNewMethodName);
|
||||
map.put(RestConstants.REST_MAPPER_DELETE_METHOD_NAME, mapperDeleteMethodName);
|
||||
map.put(RestConstants.REST_MAPPER_PUT_METHOD_NAME, mapperPutMethodName);
|
||||
map.put(RestConstants.REST_MAPPER_OPTIONS_METHOD_NAME, mapperOptionsMethodName);
|
||||
map.put(RestConstants.REST_MAPPER_POST_CONTINUE_METHOD_NAME, mapperPostContinueMethodName);
|
||||
map.put(RestConstants.REST_MAPPER_PUT_CONTINUE_METHOD_NAME, mapperPutContinueMethodName);
|
||||
map.put(RestConstants.STRUTS_REST_NAMESPACE, restNamespace);
|
||||
map.put(RestConstants.REST_VALIDATION_FAILURE_STATUS_CODE, restValidationFailureStatusCode);
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
public String getRestDefaultExtension() {
|
||||
return restDefaultExtension;
|
||||
}
|
||||
|
||||
public void setRestDefaultExtension(String restDefaultExtension) {
|
||||
this.restDefaultExtension = restDefaultExtension;
|
||||
}
|
||||
|
||||
public Boolean getRestLogger() {
|
||||
return restLogger;
|
||||
}
|
||||
|
||||
public void setRestLogger(Boolean restLogger) {
|
||||
this.restLogger = restLogger;
|
||||
}
|
||||
|
||||
public String getRestDefaultErrorResultName() {
|
||||
return restDefaultErrorResultName;
|
||||
}
|
||||
|
||||
public void setRestDefaultErrorResultName(String restDefaultErrorResultName) {
|
||||
this.restDefaultErrorResultName = restDefaultErrorResultName;
|
||||
}
|
||||
|
||||
public Boolean getRestContentRestrictToGet() {
|
||||
return restContentRestrictToGet;
|
||||
}
|
||||
|
||||
public void setRestContentRestrictToGet(Boolean restContentRestrictToGet) {
|
||||
this.restContentRestrictToGet = restContentRestrictToGet;
|
||||
}
|
||||
|
||||
public String getMapperIndexMethodName() {
|
||||
return mapperIndexMethodName;
|
||||
}
|
||||
|
||||
public void setMapperIndexMethodName(String mapperIndexMethodName) {
|
||||
this.mapperIndexMethodName = mapperIndexMethodName;
|
||||
}
|
||||
|
||||
public String getMapperGetMethodName() {
|
||||
return mapperGetMethodName;
|
||||
}
|
||||
|
||||
public void setMapperGetMethodName(String mapperGetMethodName) {
|
||||
this.mapperGetMethodName = mapperGetMethodName;
|
||||
}
|
||||
|
||||
public String getMapperPostMethodName() {
|
||||
return mapperPostMethodName;
|
||||
}
|
||||
|
||||
public void setMapperPostMethodName(String mapperPostMethodName) {
|
||||
this.mapperPostMethodName = mapperPostMethodName;
|
||||
}
|
||||
|
||||
public String getMapperEditMethodName() {
|
||||
return mapperEditMethodName;
|
||||
}
|
||||
|
||||
public void setMapperEditMethodName(String mapperEditMethodName) {
|
||||
this.mapperEditMethodName = mapperEditMethodName;
|
||||
}
|
||||
|
||||
public String getMapperNewMethodName() {
|
||||
return mapperNewMethodName;
|
||||
}
|
||||
|
||||
public void setMapperNewMethodName(String mapperNewMethodName) {
|
||||
this.mapperNewMethodName = mapperNewMethodName;
|
||||
}
|
||||
|
||||
public String getMapperDeleteMethodName() {
|
||||
return mapperDeleteMethodName;
|
||||
}
|
||||
|
||||
public void setMapperDeleteMethodName(String mapperDeleteMethodName) {
|
||||
this.mapperDeleteMethodName = mapperDeleteMethodName;
|
||||
}
|
||||
|
||||
public String getMapperPutMethodName() {
|
||||
return mapperPutMethodName;
|
||||
}
|
||||
|
||||
public void setMapperPutMethodName(String mapperPutMethodName) {
|
||||
this.mapperPutMethodName = mapperPutMethodName;
|
||||
}
|
||||
|
||||
public String getMapperOptionsMethodName() {
|
||||
return mapperOptionsMethodName;
|
||||
}
|
||||
|
||||
public void setMapperOptionsMethodName(String mapperOptionsMethodName) {
|
||||
this.mapperOptionsMethodName = mapperOptionsMethodName;
|
||||
}
|
||||
|
||||
public String getMapperPostContinueMethodName() {
|
||||
return mapperPostContinueMethodName;
|
||||
}
|
||||
|
||||
public void setMapperPostContinueMethodName(String mapperPostContinueMethodName) {
|
||||
this.mapperPostContinueMethodName = mapperPostContinueMethodName;
|
||||
}
|
||||
|
||||
public String getMapperPutContinueMethodName() {
|
||||
return mapperPutContinueMethodName;
|
||||
}
|
||||
|
||||
public void setMapperPutContinueMethodName(String mapperPutContinueMethodName) {
|
||||
this.mapperPutContinueMethodName = mapperPutContinueMethodName;
|
||||
}
|
||||
|
||||
public String getRestNamespace() {
|
||||
return restNamespace;
|
||||
}
|
||||
|
||||
public void setRestNamespace(String restNamespace) {
|
||||
this.restNamespace = restNamespace;
|
||||
}
|
||||
|
||||
public String getRestValidationFailureStatusCode() {
|
||||
return restValidationFailureStatusCode;
|
||||
}
|
||||
|
||||
public void setRestValidationFailureStatusCode(String restValidationFailureStatusCode) {
|
||||
this.restValidationFailureStatusCode = restValidationFailureStatusCode;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.struts2.spring;
|
||||
|
||||
public class SpringConstants {
|
||||
public static final String SPRING_CLASS_RELOADING_WATCH_LIST = "struts.class.reloading.watchList";
|
||||
public static final String SPRING_CLASS_RELOADING_ACCEPT_CLASSES = "struts.class.reloading.acceptClasses";
|
||||
public static final String SPRING_CLASS_RELOADING_RELOAD_CONFIG = "struts.class.reloading.reloadConfig";
|
||||
}
|
||||
+3
-3
@@ -94,9 +94,9 @@ public class StrutsSpringObjectFactory extends SpringObjectFactory {
|
||||
return;
|
||||
}
|
||||
|
||||
String watchList = container.getInstance(String.class, "struts.class.reloading.watchList");
|
||||
String acceptClasses = container.getInstance(String.class, "struts.class.reloading.acceptClasses");
|
||||
String reloadConfig = container.getInstance(String.class, "struts.class.reloading.reloadConfig");
|
||||
String watchList = container.getInstance(String.class, SpringConstants.SPRING_CLASS_RELOADING_WATCH_LIST);
|
||||
String acceptClasses = container.getInstance(String.class, SpringConstants.SPRING_CLASS_RELOADING_ACCEPT_CLASSES);
|
||||
String reloadConfig = container.getInstance(String.class, SpringConstants.SPRING_CLASS_RELOADING_RELOAD_CONFIG);
|
||||
|
||||
if ("true".equals(devMode)
|
||||
&& StringUtils.isNotBlank(watchList)
|
||||
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.struts2.spring.config.entities;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.struts2.config.entities.ConstantConfig;
|
||||
import org.apache.struts2.spring.SpringConstants;
|
||||
|
||||
public class SpringConstantConfig extends ConstantConfig {
|
||||
private List<String> classReloadingWatchList;
|
||||
private Set<Pattern> classReloadingAcceptClasses;
|
||||
private Boolean classReloadingReloadConfig;
|
||||
|
||||
@Override
|
||||
public Map<String, String> getAllAsStringsMap() {
|
||||
Map<String, String> map = super.getAllAsStringsMap();
|
||||
|
||||
map.put(SpringConstants.SPRING_CLASS_RELOADING_WATCH_LIST, StringUtils.join(classReloadingWatchList, ','));
|
||||
map.put(SpringConstants.SPRING_CLASS_RELOADING_ACCEPT_CLASSES, StringUtils.join(classReloadingAcceptClasses, ','));
|
||||
map.put(SpringConstants.SPRING_CLASS_RELOADING_RELOAD_CONFIG, Objects.toString(classReloadingReloadConfig, null));
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
public List<String> getClassReloadingWatchList() {
|
||||
return classReloadingWatchList;
|
||||
}
|
||||
|
||||
public void setClassReloadingWatchList(List<String> classReloadingWatchList) {
|
||||
this.classReloadingWatchList = classReloadingWatchList;
|
||||
}
|
||||
|
||||
public Set<Pattern> getClassReloadingAcceptClasses() {
|
||||
return classReloadingAcceptClasses;
|
||||
}
|
||||
|
||||
public void setClassReloadingAcceptClasses(Set<Pattern> classReloadingAcceptClasses) {
|
||||
this.classReloadingAcceptClasses = classReloadingAcceptClasses;
|
||||
}
|
||||
|
||||
public Boolean getClassReloadingReloadConfig() {
|
||||
return classReloadingReloadConfig;
|
||||
}
|
||||
|
||||
public void setClassReloadingReloadConfig(Boolean classReloadingReloadConfig) {
|
||||
this.classReloadingReloadConfig = classReloadingReloadConfig;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user