Skip to content

Commit 4f5bf9f

Browse files
committed
fix: exclude XML document header when saving events via StaX driver
1 parent cfdccba commit 4f5bf9f

File tree

6 files changed

+144
-11
lines changed

6 files changed

+144
-11
lines changed

bin/testfiles/BUG_62847.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<testResults version="1.2">
3-
<sample s="true" lb="SuccessLoop" rc="200" rm="OK" tn="TG 1-1"/>
4-
<sample s="true" lb="DS_after_loop" rc="200" rm="OK" tn="TG 1-1"/>
5-
<sample s="true" lb="SuccessWhile" rc="200" rm="OK" tn="TG 2-1"/>
6-
<sample s="true" lb="DS_after_while" rc="200" rm="OK" tn="TG 2-1"/>
7-
<sample s="true" lb="Success_FEC" rc="200" rm="OK" tn="TG 3-1"/>
8-
<sample s="true" lb="DS_after_fec" rc="200" rm="OK" tn="TG 3-1"/>
3+
<sample s="true" lb="SuccessLoop" rc="200" rm="OK" tn="TG 1-1"></sample>
4+
<sample s="true" lb="DS_after_loop" rc="200" rm="OK" tn="TG 1-1"></sample>
5+
<sample s="true" lb="SuccessWhile" rc="200" rm="OK" tn="TG 2-1"></sample>
6+
<sample s="true" lb="DS_after_while" rc="200" rm="OK" tn="TG 2-1"></sample>
7+
<sample s="true" lb="Success_FEC" rc="200" rm="OK" tn="TG 3-1"></sample>
8+
<sample s="true" lb="DS_after_fec" rc="200" rm="OK" tn="TG 3-1"></sample>
99

1010
</testResults>

src/core/src/main/java/org/apache/jmeter/save/SaveService.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
import com.thoughtworks.xstream.converters.reflection.ReflectionProvider;
5959
import com.thoughtworks.xstream.io.HierarchicalStreamDriver;
6060
import com.thoughtworks.xstream.io.xml.StaxDriver;
61-
import com.thoughtworks.xstream.io.xml.XppDriver;
6261
import com.thoughtworks.xstream.mapper.CannotResolveClassException;
6362
import com.thoughtworks.xstream.mapper.Mapper;
6463
import com.thoughtworks.xstream.mapper.MapperWrapper;
@@ -114,6 +113,7 @@ public String serializedClass(@SuppressWarnings("rawtypes") // superclass does n
114113

115114
private static final XStream JMXSAVER = new XStreamWrapper(new PureJavaReflectionProvider(), new StaxDriver());
116115
private static final XStream JTLSAVER = new XStreamWrapper(new PureJavaReflectionProvider(), new StaxDriver());
116+
private static final StaxDriverSkipHeader STAXDRIVER_SKIP_HEADER = new StaxDriverSkipHeader();
117117
static {
118118
JTLSAVER.setMode(XStream.NO_REFERENCES); // This is needed to stop XStream keeping copies of each class
119119
JMeterUtils.setupXStreamSecurityPolicy(JMXSAVER);
@@ -346,7 +346,7 @@ public static synchronized void saveSampleResult(SampleEvent evt, Writer writer)
346346
// This is effectively the same as saver.toXML(Object, Writer) except we get to provide the DataHolder
347347
// Don't know why there is no method for this in the XStream class
348348
try {
349-
JTLSAVER.marshal(evt.getResult(), new XppDriver().createWriter(writer), dh);
349+
JTLSAVER.marshal(evt.getResult(), STAXDRIVER_SKIP_HEADER.createWriter(writer), dh);
350350
} catch(RuntimeException e) {
351351
throw new IllegalArgumentException("Failed marshalling:"+(evt.getResult() != null ? showDebuggingInfo(evt.getResult()) : "null"), e);
352352
}
@@ -413,7 +413,7 @@ public static void loadTestResults(InputStream reader, ResultCollectorHelper res
413413
dh.put(RESULTCOLLECTOR_HELPER_OBJECT, resultCollectorHelper); // Allow TestResultWrapper to feed back the samples
414414
// This is effectively the same as saver.fromXML(InputStream) except we get to provide the DataHolder
415415
// Don't know why there is no method for this in the XStream class
416-
JTLSAVER.unmarshal(new XppDriver().createReader(reader), null, dh);
416+
JTLSAVER.unmarshal(STAXDRIVER_SKIP_HEADER.createReader(reader), null, dh);
417417
inputStreamReader.close();
418418
}
419419

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to you under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. 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+
package org.apache.jmeter.save
19+
20+
import com.thoughtworks.xstream.io.xml.StaxDriver
21+
import javax.xml.stream.XMLOutputFactory
22+
23+
public class StaxDriverSkipHeader : StaxDriver() {
24+
override fun createOutputFactory(): XMLOutputFactory {
25+
return XMLOutputFactoryDelegate(super.createOutputFactory())
26+
}
27+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to you under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. 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+
package org.apache.jmeter.save
19+
20+
import java.io.OutputStream
21+
import java.io.Writer
22+
import javax.xml.stream.XMLEventWriter
23+
import javax.xml.stream.XMLOutputFactory
24+
import javax.xml.stream.XMLStreamWriter
25+
import javax.xml.transform.Result
26+
27+
public class XMLOutputFactoryDelegate(private val delegate: XMLOutputFactory) : XMLOutputFactory() {
28+
override fun createXMLStreamWriter(stream: Writer): XMLStreamWriter {
29+
return XMLStreamWriterSkipHeader(delegate.createXMLStreamWriter(stream))
30+
}
31+
32+
override fun createXMLStreamWriter(stream: OutputStream): XMLStreamWriter {
33+
return XMLStreamWriterSkipHeader(delegate.createXMLStreamWriter(stream))
34+
}
35+
36+
override fun createXMLStreamWriter(
37+
stream: OutputStream,
38+
encoding: String?
39+
): XMLStreamWriter {
40+
return XMLStreamWriterSkipHeader(delegate.createXMLStreamWriter(stream, encoding))
41+
}
42+
43+
override fun createXMLStreamWriter(result: Result): XMLStreamWriter {
44+
return XMLStreamWriterSkipHeader(delegate.createXMLStreamWriter(result))
45+
}
46+
47+
override fun createXMLEventWriter(result: Result): XMLEventWriter {
48+
return delegate.createXMLEventWriter(result)
49+
}
50+
51+
override fun createXMLEventWriter(stream: OutputStream): XMLEventWriter {
52+
return delegate.createXMLEventWriter(stream)
53+
}
54+
55+
override fun createXMLEventWriter(
56+
stream: OutputStream,
57+
encoding: String?
58+
): XMLEventWriter {
59+
return delegate.createXMLEventWriter(stream, encoding)
60+
}
61+
62+
override fun createXMLEventWriter(stream: Writer): XMLEventWriter {
63+
return delegate.createXMLEventWriter(stream)
64+
}
65+
66+
override fun setProperty(name: String, value: Any?) {
67+
return delegate.setProperty(name, value)
68+
}
69+
70+
override fun getProperty(name: String): Any {
71+
return delegate.getProperty(name)
72+
}
73+
74+
override fun isPropertySupported(name: String): Boolean {
75+
return delegate.isPropertySupported(name)
76+
}
77+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to you under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. 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+
package org.apache.jmeter.save
19+
20+
import javax.xml.stream.XMLStreamWriter
21+
22+
public class XMLStreamWriterSkipHeader(private val delegate: XMLStreamWriter) : XMLStreamWriter by delegate {
23+
override fun writeStartDocument() {
24+
}
25+
26+
override fun writeStartDocument(version: String?) {
27+
}
28+
29+
override fun writeStartDocument(encoding: String?, version: String?) {
30+
}
31+
}

src/dist/src/dist/expected_release_jars.csv

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@
109109
519087,mail-1.5.0-b01.jar
110110
120438,miglayout-core-11.4.2.jar
111111
23287,miglayout-swing-11.4.2.jar
112-
29680,mxparser-1.2.2.jar
113112
99796,neo4j-bolt-connection-10.1.0.jar
114113
320489,neo4j-bolt-connection-netty-10.1.0.jar
115114
27442,neo4j-bolt-connection-pooled-10.1.0.jar
@@ -157,7 +156,6 @@
157156
220536,xml-apis-1.4.01.jar
158157
85686,xml-apis-ext-1.3.04.jar
159158
686441,xmlgraphics-commons-2.11.jar
160-
7188,xmlpull-1.1.3.1.jar
161159
1033122,xmlresolver-5.3.3-data.jar
162160
167889,xmlresolver-5.3.3.jar
163161
646504,xstream-1.4.21.jar

0 commit comments

Comments
 (0)