WW-4875 Add rest constant configuration

This commit is contained in:
Aleksandr Mashchenko
2017-11-25 02:06:44 +02:00
parent 9f082b264c
commit a049d1709b
7 changed files with 254 additions and 22 deletions
@@ -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;
}
@@ -64,12 +64,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;
}
@@ -80,7 +80,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);
}
@@ -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;
}
}