mirror of
https://github.com/apache/struts.git
synced 2026-08-31 19:35:40 +00:00
Merge branch 'master' into action-context-boost
This commit is contained in:
-10
@@ -73,16 +73,6 @@ public class AnnotationValidationConfigurationBuilder {
|
||||
if (a instanceof Validations) {
|
||||
processValidationAnnotation(a, fieldName, methodName, result);
|
||||
}
|
||||
|
||||
// Process single custom validator
|
||||
if (a instanceof Validation) {
|
||||
Validation v = (Validation) a;
|
||||
if (v.validations() != null) {
|
||||
for (Validations val : v.validations()) {
|
||||
processValidationAnnotation(val, fieldName, methodName, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Process single custom validator
|
||||
else if (a instanceof ExpressionValidator) {
|
||||
ExpressionValidator v = (ExpressionValidator) a;
|
||||
|
||||
@@ -1,141 +0,0 @@
|
||||
/*
|
||||
* 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 com.opensymphony.xwork2.validator.annotations;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* <!-- START SNIPPET: description -->
|
||||
* This annotation has been deprecated since 2.1 as its previous purpose, to define classes that support annotation validations,
|
||||
* is no longer necessary.
|
||||
* <!-- END SNIPPET: description -->
|
||||
*
|
||||
* <p><u>Annotation usage:</u></p>
|
||||
*
|
||||
* <!-- START SNIPPET: usage -->
|
||||
* <p>The Validation annotation must be applied at Type level.</p>
|
||||
* <!-- END SNIPPET: usage -->
|
||||
*
|
||||
* <p><u>Annotation parameters:</u></p>
|
||||
*
|
||||
* <!-- START SNIPPET: parameters -->
|
||||
* <table class='confluenceTable' summary=''>
|
||||
* <tr>
|
||||
* <th class='confluenceTh'> Parameter </th>
|
||||
* <th class='confluenceTh'> Required </th>
|
||||
* <th class='confluenceTh'> Default </th>
|
||||
* <th class='confluenceTh'> Notes </th>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td class='confluenceTd'>validations</td>
|
||||
* <td class='confluenceTd'>yes</td>
|
||||
* <td class='confluenceTd'> </td>
|
||||
* <td class='confluenceTd'></td>
|
||||
* </tr>
|
||||
* </table>
|
||||
* <!-- END SNIPPET: parameters -->
|
||||
*
|
||||
* <p><u>Example code:</u></p>
|
||||
*
|
||||
* <u>An Annotated Interface</u>
|
||||
* <pre>
|
||||
* <!-- START SNIPPET: example -->
|
||||
* @Validation()
|
||||
* public interface AnnotationDataAware {
|
||||
*
|
||||
* void setBarObj(Bar b);
|
||||
*
|
||||
* Bar getBarObj();
|
||||
*
|
||||
* @RequiredFieldValidator(message = "You must enter a value for data.")
|
||||
* @RequiredStringValidator(message = "You must enter a value for data.")
|
||||
* void setData(String data);
|
||||
*
|
||||
* String getData();
|
||||
* }
|
||||
* <!-- END SNIPPET: example -->
|
||||
* </pre>
|
||||
*
|
||||
* <p><u>Example code:</u></p>
|
||||
*
|
||||
* <u>An Annotated Class</u>
|
||||
* <pre>
|
||||
* <!-- START SNIPPET: example2 -->
|
||||
* @Validation()
|
||||
* public class SimpleAnnotationAction extends ActionSupport {
|
||||
*
|
||||
* @RequiredFieldValidator(type = ValidatorType.FIELD, message = "You must enter a value for bar.")
|
||||
* @IntRangeFieldValidator(type = ValidatorType.FIELD, min = "6", max = "10", message = "bar must be between ${min} and ${max}, current value is ${bar}.")
|
||||
* public void setBar(int bar) {
|
||||
* this.bar = bar;
|
||||
* }
|
||||
*
|
||||
* public int getBar() {
|
||||
* return bar;
|
||||
* }
|
||||
*
|
||||
* @Validations(
|
||||
* requiredFields =
|
||||
* {@RequiredFieldValidator(type = ValidatorType.SIMPLE, fieldName = "customfield", message = "You must enter a value for field.")},
|
||||
* requiredStrings =
|
||||
* {@RequiredStringValidator(type = ValidatorType.SIMPLE, fieldName = "stringisrequired", message = "You must enter a value for string.")},
|
||||
* emails =
|
||||
* { @EmailValidator(type = ValidatorType.SIMPLE, fieldName = "emailaddress", message = "You must enter a value for email.")},
|
||||
* urls =
|
||||
* { @UrlValidator(type = ValidatorType.SIMPLE, fieldName = "hreflocation", message = "You must enter a value for email.")},
|
||||
* stringLengthFields =
|
||||
* {@StringLengthFieldValidator(type = ValidatorType.SIMPLE, trim = true, minLength="10" , maxLength = "12", fieldName = "needstringlength", message = "You must enter a stringlength.")},
|
||||
* intRangeFields =
|
||||
* { @IntRangeFieldValidator(type = ValidatorType.SIMPLE, fieldName = "intfield", min = "6", max = "10", message = "bar must be between ${min} and ${max}, current value is ${bar}.")},
|
||||
* dateRangeFields =
|
||||
* {@DateRangeFieldValidator(type = ValidatorType.SIMPLE, fieldName = "datefield", min = "-1", max = "99", message = "bar must be between ${min} and ${max}, current value is ${bar}.")},
|
||||
* expressions = {
|
||||
* @ExpressionValidator(expression = "foo > 1", message = "Foo must be greater than Bar 1. Foo = ${foo}, Bar = ${bar}."),
|
||||
* @ExpressionValidator(expression = "foo > 2", message = "Foo must be greater than Bar 2. Foo = ${foo}, Bar = ${bar}."),
|
||||
* @ExpressionValidator(expression = "foo > 3", message = "Foo must be greater than Bar 3. Foo = ${foo}, Bar = ${bar}."),
|
||||
* @ExpressionValidator(expression = "foo > 4", message = "Foo must be greater than Bar 4. Foo = ${foo}, Bar = ${bar}."),
|
||||
* @ExpressionValidator(expression = "foo > 5", message = "Foo must be greater than Bar 5. Foo = ${foo}, Bar = ${bar}.")
|
||||
* }
|
||||
* )
|
||||
* public String execute() throws Exception {
|
||||
* return SUCCESS;
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* <!-- END SNIPPET: example2 -->
|
||||
* </pre>
|
||||
*
|
||||
* @author Rainer Hermanns
|
||||
* @deprecated Since Struts 2.1 because it isn't necessary anymore
|
||||
*/
|
||||
@Deprecated
|
||||
@Target({ElementType.TYPE})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Validation {
|
||||
|
||||
/**
|
||||
* Used for class or interface validation rules.
|
||||
*
|
||||
* @return array of validations
|
||||
*/
|
||||
Validations[] validations() default {};
|
||||
}
|
||||
@@ -26,12 +26,8 @@ import java.util.Properties;
|
||||
|
||||
|
||||
/**
|
||||
* Simple Test Action for annotaton processing.
|
||||
*
|
||||
* @author Rainer Hermanns
|
||||
* @version $Revision$
|
||||
* Simple Test Action for annotation processing.
|
||||
*/
|
||||
@Validation()
|
||||
public class SimpleAnnotationAction extends ActionSupport {
|
||||
//~ Static fields/initializers /////////////////////////////////////////////
|
||||
|
||||
|
||||
@@ -24,7 +24,6 @@ import com.opensymphony.xwork2.conversion.impl.FooBarConverter;
|
||||
import com.opensymphony.xwork2.util.Bar;
|
||||
import com.opensymphony.xwork2.validator.annotations.RequiredFieldValidator;
|
||||
import com.opensymphony.xwork2.validator.annotations.RequiredStringValidator;
|
||||
import com.opensymphony.xwork2.validator.annotations.Validation;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -21,7 +21,11 @@ package com.opensymphony.xwork2.test;
|
||||
import com.opensymphony.xwork2.conversion.annotations.ConversionRule;
|
||||
import com.opensymphony.xwork2.conversion.annotations.TypeConversion;
|
||||
import com.opensymphony.xwork2.util.KeyProperty;
|
||||
import com.opensymphony.xwork2.validator.annotations.*;
|
||||
import com.opensymphony.xwork2.validator.annotations.EmailValidator;
|
||||
import com.opensymphony.xwork2.validator.annotations.ExpressionValidator;
|
||||
import com.opensymphony.xwork2.validator.annotations.FieldExpressionValidator;
|
||||
import com.opensymphony.xwork2.validator.annotations.RequiredFieldValidator;
|
||||
import com.opensymphony.xwork2.validator.annotations.Validations;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@@ -30,17 +34,12 @@ import java.util.Map;
|
||||
|
||||
/**
|
||||
* Test bean.
|
||||
*
|
||||
* @author Mark Woon
|
||||
* @author Rainer Hermanns
|
||||
*/
|
||||
@Validation(
|
||||
validations = @Validations(
|
||||
expressions = {
|
||||
@ExpressionValidator(expression = "email.startsWith('mark')", message = "Email does not start with mark"),
|
||||
@ExpressionValidator(expression = "email2.startsWith('mark')", message = "Email2 does not start with mark")
|
||||
}
|
||||
)
|
||||
@Validations(
|
||||
expressions = {
|
||||
@ExpressionValidator(expression = "email.startsWith('mark')", message = "Email does not start with mark"),
|
||||
@ExpressionValidator(expression = "email2.startsWith('mark')", message = "Email2 does not start with mark")
|
||||
}
|
||||
)
|
||||
public class AnnotationUser implements AnnotationUserMarker {
|
||||
|
||||
@@ -84,7 +83,7 @@ public class AnnotationUser implements AnnotationUserMarker {
|
||||
list = l;
|
||||
}
|
||||
|
||||
@KeyProperty( value = "name")
|
||||
@KeyProperty(value = "name")
|
||||
@TypeConversion(converterClass = String.class, rule = ConversionRule.COLLECTION)
|
||||
public List getList() {
|
||||
return list;
|
||||
|
||||
@@ -20,25 +20,19 @@ package com.opensymphony.xwork2.test;
|
||||
|
||||
import com.opensymphony.xwork2.validator.annotations.ExpressionValidator;
|
||||
import com.opensymphony.xwork2.validator.annotations.RequiredFieldValidator;
|
||||
import com.opensymphony.xwork2.validator.annotations.Validation;
|
||||
import com.opensymphony.xwork2.validator.annotations.Validations;
|
||||
|
||||
/**
|
||||
* Marker interface to help test hierarchy traversal.
|
||||
*
|
||||
* @author Mark Woon
|
||||
* @author Rainer Hermanns
|
||||
*/
|
||||
@Validation(
|
||||
validations = @Validations(
|
||||
requiredFields = {
|
||||
@RequiredFieldValidator(fieldName = "email", shortCircuit = true, message = "You must enter a value for email."),
|
||||
@RequiredFieldValidator(fieldName = "email2", shortCircuit = true, message = "You must enter a value for email2.")
|
||||
},
|
||||
expressions = {
|
||||
@ExpressionValidator(shortCircuit = true, expression = "email.equals(email2)", message = "Email not the same as email2" )
|
||||
}
|
||||
)
|
||||
@Validations(
|
||||
requiredFields = {
|
||||
@RequiredFieldValidator(fieldName = "email", shortCircuit = true, message = "You must enter a value for email."),
|
||||
@RequiredFieldValidator(fieldName = "email2", shortCircuit = true, message = "You must enter a value for email2.")
|
||||
},
|
||||
expressions = {
|
||||
@ExpressionValidator(shortCircuit = true, expression = "email.equals(email2)", message = "Email not the same as email2")
|
||||
}
|
||||
)
|
||||
public interface AnnotationUserMarker {
|
||||
}
|
||||
|
||||
+1
-6
@@ -20,15 +20,10 @@ package com.opensymphony.xwork2.test.annotations;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
import com.opensymphony.xwork2.validator.annotations.ExpressionValidator;
|
||||
import com.opensymphony.xwork2.validator.annotations.Validation;
|
||||
|
||||
/**
|
||||
* <code>ValidateAnnotatedMethodOnlyAction</code>
|
||||
*
|
||||
* @author <a href="mailto:hermanns@aixcept.de">Rainer Hermanns</a>
|
||||
* @version $Id$
|
||||
*/
|
||||
@Validation
|
||||
public class ValidateAnnotatedMethodOnlyAction extends ActionSupport {
|
||||
|
||||
String param1;
|
||||
@@ -52,7 +47,7 @@ public class ValidateAnnotatedMethodOnlyAction extends ActionSupport {
|
||||
}
|
||||
|
||||
@ExpressionValidator(expression = "(param1 != null) || (param2 != null)",
|
||||
message = "Need param1 or param2.")
|
||||
message = "Need param1 or param2.")
|
||||
public String annotatedMethod() {
|
||||
try {
|
||||
// do search
|
||||
|
||||
@@ -1,94 +0,0 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
/**
|
||||
* Utility methods for test classes
|
||||
*
|
||||
*/
|
||||
public class TestUtils {
|
||||
/**
|
||||
* normalizes a string so that strings generated on different platforms can be compared. any group of one or more
|
||||
* space, tab, \r, and \n characters are converted to a single space character
|
||||
*
|
||||
* @param obj the object to be normalized. normalize will perform its operation on obj.toString().trim() ;
|
||||
* @param appendSpace
|
||||
* @return the normalized string
|
||||
*/
|
||||
public static String normalize(Object obj, boolean appendSpace) {
|
||||
StringTokenizer st =
|
||||
new StringTokenizer(obj.toString().trim(), " \t\r\n");
|
||||
StringBuilder buffer = new StringBuilder(128);
|
||||
|
||||
while(st.hasMoreTokens()) {
|
||||
buffer.append(st.nextToken());
|
||||
}
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
|
||||
public static String normalize(URL url) throws Exception {
|
||||
return normalize(readContent(url), true);
|
||||
}
|
||||
/**
|
||||
* Attempt to verify the contents of text against the contents of the URL specified. Performs a
|
||||
* trim on both ends
|
||||
*
|
||||
* @param url the HTML snippet that we want to validate against
|
||||
* @throws Exception if the validation failed
|
||||
*/
|
||||
public static boolean compare(URL url, String text)
|
||||
throws Exception {
|
||||
/**
|
||||
* compare the trimmed values of each buffer and make sure they're equivalent. however, let's make sure to
|
||||
* normalize the strings first to account for line termination differences between platforms.
|
||||
*/
|
||||
String writerString = TestUtils.normalize(text, true);
|
||||
String bufferString = TestUtils.normalize(readContent(url), true);
|
||||
|
||||
return bufferString.equals(writerString);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static String readContent(URL url)
|
||||
throws Exception {
|
||||
if(url == null) {
|
||||
throw new Exception("unable to verify a null URL");
|
||||
}
|
||||
|
||||
StringBuilder buffer = new StringBuilder(128);
|
||||
try (InputStream in = url.openStream()) {
|
||||
byte[] buf = new byte[4096];
|
||||
int nbytes;
|
||||
|
||||
while ((nbytes = in.read(buf)) > 0) {
|
||||
buffer.append(new String(buf, 0, nbytes));
|
||||
}
|
||||
}
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,4 @@
|
||||
<!-- Make the CDI object factory the automatic default -->
|
||||
<constant name="struts.objectFactory" value="cdi" />
|
||||
|
||||
<constant name="struts.class.reloading.reloadConfig" value="false" />
|
||||
|
||||
</struts>
|
||||
|
||||
@@ -20,6 +20,7 @@ package org.apache.struts2.json;
|
||||
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
import com.opensymphony.xwork2.ActionInvocation;
|
||||
import com.opensymphony.xwork2.ModelDriven;
|
||||
import com.opensymphony.xwork2.Result;
|
||||
import com.opensymphony.xwork2.inject.Inject;
|
||||
import com.opensymphony.xwork2.util.ValueStack;
|
||||
@@ -65,7 +66,7 @@ import java.util.regex.Pattern;
|
||||
*/
|
||||
public class JSONResult implements Result {
|
||||
|
||||
private static final long serialVersionUID = 8624350183189931165L;
|
||||
private static final long serialVersionUID = 233903199020467341L;
|
||||
|
||||
private static final Logger LOG = LogManager.getLogger(JSONResult.class);
|
||||
|
||||
@@ -209,12 +210,21 @@ public class JSONResult implements Result {
|
||||
}
|
||||
|
||||
protected Object findRootObject(ActionInvocation invocation) {
|
||||
ValueStack stack = invocation.getStack();
|
||||
Object rootObject;
|
||||
if (this.root != null) {
|
||||
ValueStack stack = invocation.getStack();
|
||||
LOG.debug("Root was defined as [{}], searching stack for it", this.root);
|
||||
rootObject = stack.findValue(root);
|
||||
} else {
|
||||
rootObject = invocation.getStack().peek(); // model overrides action
|
||||
LOG.debug("Root was not defined, searching for #action");
|
||||
rootObject = stack.findValue("#action");
|
||||
if (rootObject instanceof ModelDriven) {
|
||||
LOG.debug("Action is an instance of ModelDriven, assuming model is on the top of the stack and using it");
|
||||
rootObject = stack.peek();
|
||||
} else if (rootObject == null) {
|
||||
LOG.debug("Neither #action nor ModelDriven, peeking up object from the top of the stack");
|
||||
rootObject = stack.peek();
|
||||
}
|
||||
}
|
||||
return rootObject;
|
||||
}
|
||||
@@ -236,7 +246,6 @@ public class JSONResult implements Result {
|
||||
wrapSuffix));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected org.apache.struts2.json.smd.SMD buildSMDObject(ActionInvocation invocation) {
|
||||
return new SMDGenerator(findRootObject(invocation), excludeProperties, ignoreInterfaces).generate(invocation);
|
||||
}
|
||||
@@ -283,7 +292,9 @@ public class JSONResult implements Result {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the root object to be serialized, defaults to the Action
|
||||
* Sets the root object to be serialized, defaults to the Action.
|
||||
* If the Action implements {@link ModelDriven}, the Model will be used instead,
|
||||
* with the logic assuming the Model was pushed onto the top of the stack.
|
||||
*
|
||||
* @param root OGNL expression of root object to be serialized
|
||||
*/
|
||||
|
||||
@@ -21,6 +21,7 @@ package org.apache.struts2.json;
|
||||
import org.apache.struts2.StrutsTestCase;
|
||||
import org.apache.struts2.json.annotations.JSONFieldBridge;
|
||||
import org.apache.struts2.json.bridge.StringBridge;
|
||||
import org.apache.struts2.util.TestUtils;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
@@ -23,6 +23,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.struts2.StrutsTestCase;
|
||||
import org.apache.struts2.util.TestUtils;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
import org.springframework.mock.web.MockServletContext;
|
||||
|
||||
@@ -27,6 +27,7 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.apache.struts2.util.TestUtils;
|
||||
|
||||
public class JSONPopulatorTest extends TestCase {
|
||||
|
||||
|
||||
@@ -35,10 +35,9 @@ import java.util.regex.Pattern;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.aopalliance.intercept.MethodInterceptor;
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
import org.apache.struts2.StrutsStatics;
|
||||
import org.apache.struts2.StrutsTestCase;
|
||||
import org.apache.struts2.util.TestUtils;
|
||||
import org.springframework.aop.framework.ProxyFactory;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
|
||||
@@ -32,6 +32,7 @@ import org.apache.struts2.StrutsStatics;
|
||||
import org.apache.struts2.StrutsTestCase;
|
||||
import org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor;
|
||||
import org.apache.struts2.interceptor.validation.SkipValidation;
|
||||
import org.apache.struts2.util.TestUtils;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
+33
-27
@@ -16,13 +16,15 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.struts2.json;
|
||||
package org.apache.struts2.util;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.junit.Assert;
|
||||
|
||||
import java.net.URL;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -30,6 +32,7 @@ import java.util.regex.Pattern;
|
||||
* Utility methods for test classes
|
||||
*/
|
||||
public class TestUtils {
|
||||
|
||||
/**
|
||||
* A regex pattern for recognizing blocks of whitespace characters.
|
||||
*/
|
||||
@@ -39,21 +42,16 @@ public class TestUtils {
|
||||
* normalizes a string so that strings generated on different platforms can
|
||||
* be compared. any group of one or more space, tab, \r, and \n characters
|
||||
* are converted to a single space character
|
||||
*
|
||||
* @param obj
|
||||
* the object to be normalized. normalize will perform its
|
||||
* operation on obj.toString().trim() ;
|
||||
* @param appendSpace
|
||||
*
|
||||
* @param json the JSON to be normalized. normalize will trim before starting
|
||||
* @param removeSpaces removes white spaces from the JSON or not
|
||||
* @return the normalized string
|
||||
*/
|
||||
public static String normalize(Object obj, boolean appendSpace) {
|
||||
Matcher matcher = WHITESPACE_BLOCK.matcher(StringUtils.trim(obj.toString()));
|
||||
/*
|
||||
FIXME: appendSpace has been always ignored, uncommenting the following line will cause dozen of test fails
|
||||
if (appendSpace) {
|
||||
return matcher.replaceAll(" ");
|
||||
public static String normalize(String json, boolean removeSpaces) {
|
||||
Matcher matcher = WHITESPACE_BLOCK.matcher(StringUtils.trim(json));
|
||||
if (removeSpaces) {
|
||||
return matcher.replaceAll("").replaceAll(" ", "");
|
||||
}
|
||||
*/
|
||||
return matcher.replaceAll("");
|
||||
}
|
||||
|
||||
@@ -64,17 +62,15 @@ public class TestUtils {
|
||||
/**
|
||||
* Attempt to verify the contents of text against the contents of the URL
|
||||
* specified. Performs a trim on both ends
|
||||
*
|
||||
* @param url
|
||||
* the HTML snippet that we want to validate against
|
||||
* @throws Exception
|
||||
* if the validation failed
|
||||
*
|
||||
* @param url the HTML snippet that we want to validate against
|
||||
* @throws Exception if the validation failed
|
||||
*/
|
||||
public static boolean compare(URL url, String text) throws Exception {
|
||||
/**
|
||||
* compare the trimmed values of each buffer and make sure they're
|
||||
* equivalent. however, let's make sure to normalize the strings first
|
||||
* to account for line termination differences between platforms.
|
||||
/*
|
||||
compare the trimmed values of each buffer and make sure they're
|
||||
equivalent. however, let's make sure to normalize the strings first
|
||||
to account for line termination differences between platforms.
|
||||
*/
|
||||
String writerString = TestUtils.normalize(text, true);
|
||||
String bufferString = TestUtils.normalize(readContent(url), true);
|
||||
@@ -85,13 +81,23 @@ public class TestUtils {
|
||||
public static void assertEquals(URL source, String text) throws Exception {
|
||||
String writerString = TestUtils.normalize(text, true);
|
||||
String bufferString = TestUtils.normalize(readContent(source), true);
|
||||
Assert.assertEquals(bufferString,writerString);
|
||||
Assert.assertEquals(bufferString, writerString);
|
||||
}
|
||||
|
||||
public static String readContent(URL url) throws Exception {
|
||||
if (url == null)
|
||||
throw new Exception("unable to verify a null URL");
|
||||
|
||||
return IOUtils.toString(url.openStream());
|
||||
return readContent(url, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
public static String readContent(URL url, Charset encoding) throws Exception {
|
||||
if (url == null) {
|
||||
throw new IllegalArgumentException("Unable to verify a null URL");
|
||||
}
|
||||
|
||||
if (encoding == null) {
|
||||
throw new IllegalArgumentException("Unable to verify the URL using a null Charset");
|
||||
}
|
||||
|
||||
return IOUtils.toString(url.openStream(), encoding);
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -52,7 +52,7 @@ import java.util.regex.Pattern;
|
||||
* </p>
|
||||
* <ul>
|
||||
* <li>Set "struts.devMode" to "true" </li>
|
||||
* <li>Set "struts.class.reloading.watchList" to a comma separated list of directories, or jar files (absolute paths)</li>
|
||||
* <li>Set "struts.objectFactory.spring.class.reloading.watchList" to a comma separated list of directories, or jar files (absolute paths)</li>
|
||||
* <li>Add this to web.xml:
|
||||
* <pre>
|
||||
* <context-param>
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
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";
|
||||
public static final String STRUTS_OBJECTFACTORY_SPRING_CLASS_RELOADING_WATCH_LIST = "struts.objectFactory.spring.class.reloading.watchList";
|
||||
public static final String STRUTS_OBJECTFACTORY_SPRING_CLASS_RELOADING_ACCEPT_CLASSES = "struts.objectFactory.spring.class.reloading.acceptClasses";
|
||||
public static final String STRUTS_OBJECTFACTORY_SPRING_CLASS_RELOADING_RELOAD_CONFIG = "struts.objectFactory.spring.class.reloading.reloadConfig";
|
||||
}
|
||||
|
||||
+3
-3
@@ -94,9 +94,9 @@ public class StrutsSpringObjectFactory extends SpringObjectFactory {
|
||||
return;
|
||||
}
|
||||
|
||||
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);
|
||||
String watchList = container.getInstance(String.class, SpringConstants.STRUTS_OBJECTFACTORY_SPRING_CLASS_RELOADING_WATCH_LIST);
|
||||
String acceptClasses = container.getInstance(String.class, SpringConstants.STRUTS_OBJECTFACTORY_SPRING_CLASS_RELOADING_ACCEPT_CLASSES);
|
||||
String reloadConfig = container.getInstance(String.class, SpringConstants.STRUTS_OBJECTFACTORY_SPRING_CLASS_RELOADING_RELOAD_CONFIG);
|
||||
|
||||
if ("true".equals(devMode)
|
||||
&& StringUtils.isNotBlank(watchList)
|
||||
|
||||
+3
-3
@@ -37,9 +37,9 @@ public class SpringConstantConfig extends ConstantConfig {
|
||||
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));
|
||||
map.put(SpringConstants.STRUTS_OBJECTFACTORY_SPRING_CLASS_RELOADING_WATCH_LIST, StringUtils.join(classReloadingWatchList, ','));
|
||||
map.put(SpringConstants.STRUTS_OBJECTFACTORY_SPRING_CLASS_RELOADING_ACCEPT_CLASSES, StringUtils.join(classReloadingAcceptClasses, ','));
|
||||
map.put(SpringConstants.STRUTS_OBJECTFACTORY_SPRING_CLASS_RELOADING_RELOAD_CONFIG, Objects.toString(classReloadingReloadConfig, null));
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
@@ -29,9 +29,9 @@
|
||||
<!-- Make the Spring object factory the automatic default -->
|
||||
<constant name="struts.objectFactory" value="spring" />
|
||||
|
||||
<constant name="struts.class.reloading.watchList" value="" />
|
||||
<constant name="struts.class.reloading.acceptClasses" value="" />
|
||||
<constant name="struts.class.reloading.reloadConfig" value="false" />
|
||||
<constant name="struts.objectFactory.spring.class.reloading.watchList" value="" />
|
||||
<constant name="struts.objectFactory.spring.class.reloading.acceptClasses" value="" />
|
||||
<constant name="struts.objectFactory.spring.class.reloading.reloadConfig" value="false" />
|
||||
|
||||
<constant name="struts.disallowProxyMemberAccess" value="true" />
|
||||
<constant name="struts.json.result.excludeProxyProperties" value="true" />
|
||||
|
||||
Reference in New Issue
Block a user