morgand 02/05/03 12:08:02 Modified: latka/src/java/org/apache/commons/latka/validators RegexpValidator.java Log: Validator would throw NullPointerException when it encountered a null HTTP body response. Revision Changes Path 1.9 +20 -3 jakarta-commons/latka/src/java/org/apache/commons/latka/validators/RegexpValidator.java Index: RegexpValidator.java =================================================================== RCS file: /home/cvs/jakarta-commons/latka/src/java/org/apache/commons/latka/validators/RegexpValidator.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- RegexpValidator.java 2 May 2002 22:25:44 -0000 1.8 +++ RegexpValidator.java 3 May 2002 19:08:02 -0000 1.9 @@ -70,11 +70,16 @@ import org.apache.regexp.RESyntaxException; /** - * FIXME: Docs - * + * Perform regular expression matches on the body of + * the HTTP response. Setting the "condition" attribute + * of the test indicates whether or not a match + * is expected. If the server returns a <i>null</i> + * (e.g. in the case of an empty HEAD response), the + * match will always return false. + * * @author Morgan Delagrange * @author dIon Gillard - * @version $Id: RegexpValidator.java,v 1.8 2002/05/02 22:25:44 morgand Exp $ + * @version $Id: RegexpValidator.java,v 1.9 2002/05/03 19:08:02 morgand Exp $ */ public class RegexpValidator extends BaseConditionalValidator implements Validator { @@ -82,6 +87,7 @@ protected String _pattern = null; protected boolean _ignoreCase = false; + protected boolean _wasResponseBodyNull = false; protected static final String BARE_EXCEPTION_MESSAGE = " TO MATCH PATTERN: "; @@ -114,6 +120,12 @@ public boolean assertTrue(Response response) throws ValidationException { + String responseBody = response.getResource(); + if (responseBody == null) { + _wasResponseBodyNull = true; + return false; + } + RE r = null; try { r = new RE(_pattern); // Compile expression @@ -133,6 +145,11 @@ } public String generateBareExceptionMessage() { + if (_wasResponseBodyNull == true) { + return BARE_EXCEPTION_MESSAGE + _pattern + + " (HTTP response body was null.)"; + } + return BARE_EXCEPTION_MESSAGE + _pattern; }
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>