View | Details | Raw Unified | Return to bug 43382
Collapse All | Expand All

(-)jakarta-jmeter-2.3/src/components/org/apache/jmeter/assertions/XPathAssertion.java (+5 lines)
Lines 30-35 Link Here
30
import org.apache.jmeter.testelement.property.BooleanProperty;
30
import org.apache.jmeter.testelement.property.BooleanProperty;
31
import org.apache.jmeter.testelement.property.StringProperty;
31
import org.apache.jmeter.testelement.property.StringProperty;
32
import org.apache.jmeter.util.XPathUtil;
32
import org.apache.jmeter.util.XPathUtil;
33
import org.apache.jmeter.util.TidyException;
33
import org.apache.jorphan.logging.LoggingManager;
34
import org.apache.jorphan.logging.LoggingManager;
34
import org.apache.log.Logger;
35
import org.apache.log.Logger;
35
import org.apache.xpath.XPathAPI;
36
import org.apache.xpath.XPathAPI;
Lines 105-110 Link Here
105
			result.setFailureMessage(new StringBuffer("ParserConfigurationException: ").append(e.getMessage())
106
			result.setFailureMessage(new StringBuffer("ParserConfigurationException: ").append(e.getMessage())
106
					.toString());
107
					.toString());
107
			return result;
108
			return result;
109
		} catch (TidyException e) {						
110
			result.setError(true);
111
			result.setFailureMessage(e.getMessage());
112
			return result;
108
		}
113
		}
109
114
110
		if (doc == null || doc.getDocumentElement() == null) {
115
		if (doc == null || doc.getDocumentElement() == null) {
(-)jakarta-jmeter-2.3/src/components/org/apache/jmeter/extractor/XPathExtractor.java (-1 / +11 lines)
Lines 32-37 Link Here
32
import org.apache.jmeter.threads.JMeterContext;
32
import org.apache.jmeter.threads.JMeterContext;
33
import org.apache.jmeter.threads.JMeterVariables;
33
import org.apache.jmeter.threads.JMeterVariables;
34
import org.apache.jmeter.util.XPathUtil;
34
import org.apache.jmeter.util.XPathUtil;
35
import org.apache.jmeter.util.TidyException;
36
import org.apache.jmeter.assertions.AssertionResult;
35
import org.apache.jorphan.logging.LoggingManager;
37
import org.apache.jorphan.logging.LoggingManager;
36
import org.apache.jorphan.util.JMeterError;
38
import org.apache.jorphan.util.JMeterError;
37
import org.apache.log.Logger;
39
import org.apache.log.Logger;
Lines 106-111 Link Here
106
			log.warn("error on "+XPATH_QUERY+"("+getXPathQuery()+")"+e.getLocalizedMessage());
108
			log.warn("error on "+XPATH_QUERY+"("+getXPathQuery()+")"+e.getLocalizedMessage());
107
		} catch (TransformerException e) {// Can happen for incorrect XPath expression
109
		} catch (TransformerException e) {// Can happen for incorrect XPath expression
108
			log.warn("error on "+XPATH_QUERY+"("+getXPathQuery()+")"+e.getLocalizedMessage());
110
			log.warn("error on "+XPATH_QUERY+"("+getXPathQuery()+")"+e.getLocalizedMessage());
111
		} catch (TidyException e) {			
112
			SampleResult prev = getThreadContext().getPreviousResult();
113
			AssertionResult ass = new AssertionResult();
114
			ass.setFailure(true);
115
			ass.setFailureMessage(e.getMessage());
116
			ass.setName("TidyException");
117
			prev.addAssertionResult(ass);
118
			prev.setSuccessful(false);
109
		}
119
		}
110
    }    
120
    }    
111
            
121
            
Lines 159-165 Link Here
159
     * 
169
     * 
160
     */
170
     */
161
    private Document parseResponse(SampleResult result)
171
    private Document parseResponse(SampleResult result)
162
      throws UnsupportedEncodingException, IOException, ParserConfigurationException,SAXException
172
      throws UnsupportedEncodingException, IOException, ParserConfigurationException,SAXException,TidyException
163
    {
173
    {
164
      //TODO: validate contentType for reasonable types?
174
      //TODO: validate contentType for reasonable types?
165
175
(-)jakarta-jmeter-2.3/src/core/org/apache/jmeter/util/TidyException.java (+29 lines)
Line 0 Link Here
1
// $Header$
2
/*
3
 * Copyright 2001-2004 The Apache Software Foundation.
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at
8
 *
9
 *   http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 * 
17
 */
18
19
package org.apache.jmeter.util;
20
21
public class TidyException extends Exception {
22
	
23
	public TidyException() {
24
	}
25
26
	public TidyException(String name) {
27
		super(name);
28
	}
29
}
(-)jakarta-jmeter-2.3/src/core/org/apache/jmeter/util/XPathUtil.java (-6 / +16 lines)
Lines 27-32 Link Here
27
27
28
import org.apache.jorphan.logging.LoggingManager;
28
import org.apache.jorphan.logging.LoggingManager;
29
import org.apache.log.Logger;
29
import org.apache.log.Logger;
30
import org.apache.jmeter.util.TidyException;
31
30
import org.w3c.dom.Document;
32
import org.w3c.dom.Document;
31
import org.w3c.tidy.Tidy;
33
import org.w3c.tidy.Tidy;
32
import org.xml.sax.ErrorHandler;
34
import org.xml.sax.ErrorHandler;
Lines 104-110 Link Here
104
	 * @throws SAXException
106
	 * @throws SAXException
105
	 */
107
	 */
106
	public static Document makeDocument(InputStream stream, boolean validate, boolean whitespace, boolean namespace,
108
	public static Document makeDocument(InputStream stream, boolean validate, boolean whitespace, boolean namespace,
107
			boolean tolerant) throws ParserConfigurationException, SAXException, IOException {
109
			boolean tolerant) throws ParserConfigurationException, SAXException, IOException, TidyException {
108
		Document doc;
110
		Document doc;
109
		if (tolerant) {
111
		if (tolerant) {
110
			doc = tidyDoc(stream);
112
			doc = tidyDoc(stream);
Lines 124-132 Link Here
124
	// return builder;
126
	// return builder;
125
	// }
127
	// }
126
128
127
	private static Document tidyDoc(InputStream stream) {
129
	private static Document tidyDoc(InputStream stream) throws TidyException {
128
		Document doc = null;
130
		Document doc = null;
129
		doc = makeTidyParser().parseDOM(stream, null);
131
		Tidy tidy = makeTidyParser();		
132
		java.io.StringWriter sw = new java.io.StringWriter();
133
		tidy.setErrout(new java.io.PrintWriter(sw));
134
		doc = tidy.parseDOM(stream, null);		
130
		doc.normalize();
135
		doc.normalize();
131
		// remove the document declaration cause I think it causes
136
		// remove the document declaration cause I think it causes
132
		// issues this is only needed for JDOM, since I am not
137
		// issues this is only needed for JDOM, since I am not
Lines 134-147 Link Here
134
		// Node name = doc.getDoctype();
139
		// Node name = doc.getDoctype();
135
		// doc.removeChild(name);
140
		// doc.removeChild(name);
136
141
142
		boolean tolerate_errors = JMeterUtils.getPropDefault("tidy.tolerate_errors", true);
143
		if (!tolerate_errors && tidy.getParseErrors() > 0) {
144
			log.error("Caught TidyException: " + sw.toString());			
145
			throw new TidyException("tidy: " + tidy.getParseErrors() + " errors, " + tidy.getParseWarnings() + " warnings\n");
146
		}
137
		return doc;
147
		return doc;
138
	}
148
	}
139
149
140
	private static Tidy makeTidyParser() {
150
	private static Tidy makeTidyParser() {
141
		Tidy tidy = new Tidy();
151
		Tidy tidy = new Tidy();		
142
		tidy.setCharEncoding(org.w3c.tidy.Configuration.UTF8);
152
		tidy.setCharEncoding(org.w3c.tidy.Configuration.UTF8);
143
		tidy.setQuiet(true);
153
		tidy.setQuiet(JMeterUtils.getPropDefault("tidy.quiet", true));		
144
		tidy.setShowWarnings(false);
154
		tidy.setShowWarnings(JMeterUtils.getPropDefault("tidy.showwarnings", false));
145
		tidy.setMakeClean(true);
155
		tidy.setMakeClean(true);
146
		tidy.setXmlTags(false); // Input is not valid XML
156
		tidy.setXmlTags(false); // Input is not valid XML
147
		// tidy.setShowErrors(1);
157
		// tidy.setShowErrors(1);

Return to bug 43382