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

(-)src/components/org/apache/jmeter/assertions/XMLAssertion.java (-17 / +26 lines)
Lines 22-34 Link Here
22
import java.io.Serializable;
22
import java.io.Serializable;
23
import java.io.StringReader;
23
import java.io.StringReader;
24
24
25
import javax.xml.parsers.ParserConfigurationException;
26
import javax.xml.parsers.SAXParser;
27
import javax.xml.parsers.SAXParserFactory;
28
25
import org.apache.jmeter.samplers.SampleResult;
29
import org.apache.jmeter.samplers.SampleResult;
26
import org.apache.jmeter.testelement.AbstractTestElement;
30
import org.apache.jmeter.testelement.AbstractTestElement;
27
import org.apache.jmeter.testelement.ThreadListener;
31
import org.apache.jmeter.testelement.ThreadListener;
28
import org.apache.jorphan.logging.LoggingManager;
32
import org.apache.jorphan.logging.LoggingManager;
29
import org.apache.log.Logger;
33
import org.apache.log.Logger;
30
import org.jdom.JDOMException;
34
import org.xml.sax.InputSource;
31
import org.jdom.input.SAXBuilder;
35
import org.xml.sax.SAXException;
36
import org.xml.sax.helpers.DefaultHandler;
32
37
33
/**
38
/**
34
 * Checks if the result is a well-formed XML content using jdom
39
 * Checks if the result is a well-formed XML content using jdom
Lines 37-49 Link Here
37
public class XMLAssertion extends AbstractTestElement implements Serializable, Assertion, ThreadListener {
42
public class XMLAssertion extends AbstractTestElement implements Serializable, Assertion, ThreadListener {
38
    private static final Logger log = LoggingManager.getLoggerForClass();
43
    private static final Logger log = LoggingManager.getLoggerForClass();
39
44
40
    private static final long serialVersionUID = 240L;
45
    private static final long serialVersionUID = 241L;
41
46
42
    // one builder for all requests in a thread
47
    // one builder for all requests in a thread
43
    private static final ThreadLocal<SAXBuilder> myBuilder = new ThreadLocal<SAXBuilder>() {
48
    private static final ThreadLocal<SAXParser> myBuilder = new ThreadLocal<SAXParser>() {
44
        @Override
49
        @Override
45
        protected SAXBuilder initialValue() {
50
        protected SAXParser initialValue() {
46
            return new SAXBuilder();
51
            try {
52
                return SAXParserFactory.newInstance().newSAXParser();
53
            } catch (ParserConfigurationException | SAXException e) {
54
                return null;
55
            }
47
        }
56
        }
48
    };
57
    };
49
58
Lines 62-79 Link Here
62
            return result.setResultForNull();
71
            return result.setResultForNull();
63
        }
72
        }
64
        result.setFailure(false);
73
        result.setFailure(false);
65
        SAXBuilder builder = myBuilder.get();
74
        SAXParser builder = myBuilder.get();
66
75
        if(myBuilder!=null) {
67
        try {
76
            try {
68
            builder.build(new StringReader(resultData));
77
                builder.parse(new InputSource(new StringReader(resultData)), new DefaultHandler());
69
        } catch (JDOMException e) {
78
            } catch (SAXException | IOException e) {
70
            log.debug("Cannot parse result content", e); // may well happen
79
                log.error("Cannot read result content", e); // should never happen
71
            result.setFailure(true);
80
                result.setError(true);
72
            result.setFailureMessage(e.getMessage());
81
                result.setFailureMessage(e.getMessage());
73
        } catch (IOException e) {
82
            }
74
            log.error("Cannot read result content", e); // should never happen
83
        } else {
75
            result.setError(true);
84
            result.setError(true);
76
            result.setFailureMessage(e.getMessage());
85
            result.setFailureMessage("Cannot initialize SAXParser, check jmeter.log file");
77
        }
86
        }
78
87
79
        return result;
88
        return result;

Return to bug 59156