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

(-)src/components/org/apache/jmeter/assertions/SMIMEAssertion.java (-1 / +1 lines)
Lines 302-308 Link Here
302
302
303
        final SampleResult sampleResult = subResults[messageNumber];
303
        final SampleResult sampleResult = subResults[messageNumber];
304
        if (log.isDebugEnabled()) {
304
        if (log.isDebugEnabled()) {
305
            log.debug("Bytes: "+sampleResult.getBytes()+" CT: "+sampleResult.getContentType());
305
            log.debug("Bytes: "+sampleResult.getBytesAsLong()+" CT: "+sampleResult.getContentType());
306
        }
306
        }
307
        byte[] data = sampleResult.getResponseData();
307
        byte[] data = sampleResult.getResponseData();
308
        Session session = Session.getDefaultInstance(new Properties());
308
        Session session = Session.getDefaultInstance(new Properties());
(-)src/components/org/apache/jmeter/assertions/SizeAssertion.java (-3 / +3 lines)
Lines 79-85 Link Here
79
            String variableName = getVariableName();
79
            String variableName = getVariableName();
80
            String value = getThreadContext().getVariables().get(variableName);
80
            String value = getThreadContext().getVariables().get(variableName);
81
            try {
81
            try {
82
                resultSize = Integer.parseInt(value);
82
                resultSize = Long.parseLong(value);
83
            } catch (NumberFormatException e) {
83
            } catch (NumberFormatException e) {
84
                result.setFailure(true);
84
                result.setFailure(true);
85
                result.setFailureMessage("Error parsing variable name: "+variableName+" value: "+value);
85
                result.setFailureMessage("Error parsing variable name: "+variableName+" value: "+value);
Lines 88-100 Link Here
88
        } else if (isTestFieldResponseHeaders()) {
88
        } else if (isTestFieldResponseHeaders()) {
89
            resultSize = response.getHeadersSize();
89
            resultSize = response.getHeadersSize();
90
        }  else if (isTestFieldResponseBody()) {
90
        }  else if (isTestFieldResponseBody()) {
91
            resultSize = response.getBodySize();
91
            resultSize = response.getBodySizeAsLong();
92
        } else if (isTestFieldResponseCode()) {
92
        } else if (isTestFieldResponseCode()) {
93
            resultSize = response.getResponseCode().length();
93
            resultSize = response.getResponseCode().length();
94
        } else if (isTestFieldResponseMessage()) {
94
        } else if (isTestFieldResponseMessage()) {
95
            resultSize = response.getResponseMessage().length();
95
            resultSize = response.getResponseMessage().length();
96
        } else {
96
        } else {
97
            resultSize = response.getBytes();
97
            resultSize = response.getBytesAsLong();
98
        }
98
        }
99
        // is the Sample the correct size?
99
        // is the Sample the correct size?
100
        final String msg = compareSize(resultSize);
100
        final String msg = compareSize(resultSize);
(-)src/components/org/apache/jmeter/visualizers/SamplerResultTab.java (-4 / +4 lines)
Lines 238-246 Link Here
238
                statsBuff.append(JMeterUtils.getResString("view_results_load_time")).append(sampleResult.getTime()).append(NL); //$NON-NLS-1$
238
                statsBuff.append(JMeterUtils.getResString("view_results_load_time")).append(sampleResult.getTime()).append(NL); //$NON-NLS-1$
239
                statsBuff.append(JMeterUtils.getResString("view_results_connect_time")).append(sampleResult.getConnectTime()).append(NL); //$NON-NLS-1$
239
                statsBuff.append(JMeterUtils.getResString("view_results_connect_time")).append(sampleResult.getConnectTime()).append(NL); //$NON-NLS-1$
240
                statsBuff.append(JMeterUtils.getResString("view_results_latency")).append(sampleResult.getLatency()).append(NL); //$NON-NLS-1$
240
                statsBuff.append(JMeterUtils.getResString("view_results_latency")).append(sampleResult.getLatency()).append(NL); //$NON-NLS-1$
241
                statsBuff.append(JMeterUtils.getResString("view_results_size_in_bytes")).append(sampleResult.getBytes()).append(NL); //$NON-NLS-1$
241
                statsBuff.append(JMeterUtils.getResString("view_results_size_in_bytes")).append(sampleResult.getBytesAsLong()).append(NL); //$NON-NLS-1$
242
                statsBuff.append(JMeterUtils.getResString("view_results_size_headers_in_bytes")).append(sampleResult.getHeadersSize()).append(NL); //$NON-NLS-1$
242
                statsBuff.append(JMeterUtils.getResString("view_results_size_headers_in_bytes")).append(sampleResult.getHeadersSize()).append(NL); //$NON-NLS-1$
243
                statsBuff.append(JMeterUtils.getResString("view_results_size_body_in_bytes")).append(sampleResult.getBodySize()).append(NL); //$NON-NLS-1$
243
                statsBuff.append(JMeterUtils.getResString("view_results_size_body_in_bytes")).append(sampleResult.getBodySizeAsLong()).append(NL); //$NON-NLS-1$
244
                statsBuff.append(JMeterUtils.getResString("view_results_sample_count")).append(sampleResult.getSampleCount()).append(NL); //$NON-NLS-1$
244
                statsBuff.append(JMeterUtils.getResString("view_results_sample_count")).append(sampleResult.getSampleCount()).append(NL); //$NON-NLS-1$
245
                statsBuff.append(JMeterUtils.getResString("view_results_error_count")).append(sampleResult.getErrorCount()).append(NL); //$NON-NLS-1$
245
                statsBuff.append(JMeterUtils.getResString("view_results_error_count")).append(sampleResult.getErrorCount()).append(NL); //$NON-NLS-1$
246
                statsBuff.append(JMeterUtils.getResString("view_results_datatype")).append(sampleResult.getDataType()).append(NL); //$NON-NLS-1$
246
                statsBuff.append(JMeterUtils.getResString("view_results_datatype")).append(sampleResult.getDataType()).append(NL); //$NON-NLS-1$
Lines 296-304 Link Here
296
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_sample_start"), startTime)); //$NON-NLS-1$
296
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_sample_start"), startTime)); //$NON-NLS-1$
297
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_load_time"), sampleResult.getTime())); //$NON-NLS-1$
297
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_load_time"), sampleResult.getTime())); //$NON-NLS-1$
298
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_latency"), sampleResult.getLatency())); //$NON-NLS-1$
298
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_latency"), sampleResult.getLatency())); //$NON-NLS-1$
299
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_size_in_bytes"), sampleResult.getBytes())); //$NON-NLS-1$
299
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_size_in_bytes"), sampleResult.getBytesAsLong())); //$NON-NLS-1$
300
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_size_headers_in_bytes"), sampleResult.getHeadersSize())); //$NON-NLS-1$
300
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_size_headers_in_bytes"), sampleResult.getHeadersSize())); //$NON-NLS-1$
301
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_size_body_in_bytes"), sampleResult.getBodySize())); //$NON-NLS-1$
301
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_size_body_in_bytes"), sampleResult.getBodySizeAsLong())); //$NON-NLS-1$
302
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_sample_count"), sampleResult.getSampleCount())); //$NON-NLS-1$
302
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_sample_count"), sampleResult.getSampleCount())); //$NON-NLS-1$
303
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_error_count"), sampleResult.getErrorCount())); //$NON-NLS-1$
303
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_error_count"), sampleResult.getErrorCount())); //$NON-NLS-1$
304
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_response_code"), responseCode)); //$NON-NLS-1$
304
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_response_code"), responseCode)); //$NON-NLS-1$
(-)src/components/org/apache/jmeter/visualizers/TableVisualizer.java (-1 / +1 lines)
Lines 192-198 Link Here
192
                            res.getSampleLabel(),
192
                            res.getSampleLabel(),
193
                            res.getTime(),
193
                            res.getTime(),
194
                            res.isSuccessful(),
194
                            res.isSuccessful(),
195
                            res.getBytes(),
195
                            res.getBytesAsLong(),
196
                            res.getLatency(),
196
                            res.getLatency(),
197
                            res.getConnectTime()
197
                            res.getConnectTime()
198
                            );
198
                            );
(-)src/core/org/apache/jmeter/control/TransactionController.java (-1 / +1 lines)
Lines 321-327 Link Here
321
            if(res != null && !se.isTransactionSampleEvent()) {
321
            if(res != null && !se.isTransactionSampleEvent()) {
322
                SampleResult sampleResult = se.getResult();
322
                SampleResult sampleResult = se.getResult();
323
                res.setThreadName(sampleResult.getThreadName());
323
                res.setThreadName(sampleResult.getThreadName());
324
                res.setBytes(res.getBytes() + sampleResult.getBytes());
324
                res.setBytes(res.getBytesAsLong() + sampleResult.getBytesAsLong());
325
                if (!isIncludeTimers()) {// Accumulate waiting time for later
325
                if (!isIncludeTimers()) {// Accumulate waiting time for later
326
                    pauseTime += sampleResult.getEndTime() - sampleResult.getTime() - prevEndTime;
326
                    pauseTime += sampleResult.getEndTime() - sampleResult.getTime() - prevEndTime;
327
                    prevEndTime = sampleResult.getEndTime();
327
                    prevEndTime = sampleResult.getEndTime();
(-)src/core/org/apache/jmeter/samplers/DataStrippingSampleSender.java (-1 / +1 lines)
Lines 117-123 Link Here
117
     * @param result {@link SampleResult}
117
     * @param result {@link SampleResult}
118
     */
118
     */
119
    private void stripResponse(SampleResult result) {
119
    private void stripResponse(SampleResult result) {
120
        result.setBytes(result.getBytes());
120
        result.setBytes(result.getBytesAsLong());
121
        result.setResponseData(SampleResult.EMPTY_BA);
121
        result.setResponseData(SampleResult.EMPTY_BA);
122
    }
122
    }
123
123
(-)src/core/org/apache/jmeter/samplers/SampleResult.java (-9 / +42 lines)
Lines 210-220 Link Here
210
210
211
    private int sampleCount = 1;
211
    private int sampleCount = 1;
212
212
213
    private int bytes = 0; // Allows override of sample size in case sampler does not want to store all the data
213
    private long bytes = 0; // Allows override of sample size in case sampler does not want to store all the data
214
    
214
    
215
    private int headersSize = 0;
215
    private int headersSize = 0;
216
    
216
    
217
    private int bodySize = 0;
217
    private long bodySize = 0;
218
218
219
    /** Currently active threads in this thread group */
219
    /** Currently active threads in this thread group */
220
    private volatile int groupThreads = 0;
220
    private volatile int groupThreads = 0;
Lines 610-618 Link Here
610
        // Extend the time to the end of the added sample
610
        // Extend the time to the end of the added sample
611
        setEndTime(Math.max(getEndTime(), subResult.getEndTime() + nanoTimeOffset - subResult.nanoTimeOffset)); // Bug 51855
611
        setEndTime(Math.max(getEndTime(), subResult.getEndTime() + nanoTimeOffset - subResult.nanoTimeOffset)); // Bug 51855
612
        // Include the byte count for the added sample
612
        // Include the byte count for the added sample
613
        setBytes(getBytes() + subResult.getBytes());
613
        setBytes(getBytesAsLong() + subResult.getBytesAsLong());
614
        setHeadersSize(getHeadersSize() + subResult.getHeadersSize());
614
        setHeadersSize(getHeadersSize() + subResult.getHeadersSize());
615
        setBodySize(getBodySize() + subResult.getBodySize());
615
        setBodySize(getBodySizeAsLong() + subResult.getBodySizeAsLong());
616
        addRawSubResult(subResult);
616
        addRawSubResult(subResult);
617
    }
617
    }
618
    
618
    
Lines 1190-1212 Link Here
1190
     * @param length
1190
     * @param length
1191
     *            the number of bytes of the response data for this sample
1191
     *            the number of bytes of the response data for this sample
1192
     */
1192
     */
1193
    public void setBytes(int length) {
1193
    public void setBytes(long length) {
1194
        bytes = length;
1194
        bytes = length;
1195
    }
1195
    }
1196
1196
    
1197
    /**
1198
     * In the event the sampler does want to pass back the actual contents, we
1199
     * still want to calculate the throughput. The bytes are the bytes of the
1200
     * response data.
1201
     *
1202
     * @param length
1203
     *            the number of bytes of the response data for this sample
1204
     * @deprecated use setBytes(long)
1205
     */
1206
    @Deprecated
1207
    public void setBytes(int length) {
1208
        setBytes((long) length);
1209
    }
1210
    
1197
    /**
1211
    /**
1198
     * return the bytes returned by the response.
1212
     * return the bytes returned by the response.
1199
     *
1213
     *
1200
     * @return byte count
1214
     * @return byte count
1215
     * @deprecated use getBytesAsLong 
1201
     */
1216
     */
1217
    @Deprecated
1202
    public int getBytes() {
1218
    public int getBytes() {
1219
        return (int) getBytesAsLong();
1220
    }
1221
1222
    /**
1223
     * return the bytes returned by the response.
1224
     *
1225
     * @return byte count
1226
     */
1227
    public long getBytesAsLong() {
1203
        if (GETBYTES_NETWORK_SIZE) {
1228
        if (GETBYTES_NETWORK_SIZE) {
1204
            int tmpSum = this.getHeadersSize() + this.getBodySize();
1229
            long tmpSum = this.getHeadersSize() + this.getBodySizeAsLong();
1205
            return tmpSum == 0 ? bytes : tmpSum;
1230
            return tmpSum == 0 ? bytes : tmpSum;
1206
        } else if (GETBYTES_HEADERS_SIZE) {
1231
        } else if (GETBYTES_HEADERS_SIZE) {
1207
            return this.getHeadersSize();
1232
            return this.getHeadersSize();
1208
        } else if (GETBYTES_BODY_REALSIZE) {
1233
        } else if (GETBYTES_BODY_REALSIZE) {
1209
            return this.getBodySize();
1234
            return this.getBodySizeAsLong();
1210
        }
1235
        }
1211
        return bytes == 0 ? responseData.length : bytes;
1236
        return bytes == 0 ? responseData.length : bytes;
1212
    }
1237
    }
Lines 1364-1377 Link Here
1364
    /**
1389
    /**
1365
     * @return the body size in bytes
1390
     * @return the body size in bytes
1366
     */
1391
     */
1392
    @Deprecated
1367
    public int getBodySize() {
1393
    public int getBodySize() {
1394
        return (int) getBodySizeAsLong();
1395
    }
1396
    
1397
    /**
1398
     * @return the body size in bytes
1399
     */
1400
    public long getBodySizeAsLong() {
1368
        return bodySize == 0 ? responseData.length : bodySize;
1401
        return bodySize == 0 ? responseData.length : bodySize;
1369
    }
1402
    }
1370
1403
1371
    /**
1404
    /**
1372
     * @param bodySize the body size to set
1405
     * @param bodySize the body size to set
1373
     */
1406
     */
1374
    public void setBodySize(int bodySize) {
1407
    public void setBodySize(long bodySize) {
1375
        this.bodySize = bodySize;
1408
        this.bodySize = bodySize;
1376
    }
1409
    }
1377
1410
(-)src/core/org/apache/jmeter/samplers/StatisticalSampleResult.java (-1 / +1 lines)
Lines 72-78 Link Here
72
        // Add Sample Counter
72
        // Add Sample Counter
73
        setSampleCount(getSampleCount() + res.getSampleCount());
73
        setSampleCount(getSampleCount() + res.getSampleCount());
74
74
75
        setBytes(getBytes() + res.getBytes());
75
        setBytes(getBytesAsLong() + res.getBytesAsLong());
76
76
77
        // Add Error Counter
77
        // Add Error Counter
78
        if (!res.isSuccessful()) {
78
        if (!res.isSuccessful()) {
(-)src/core/org/apache/jmeter/save/CSVSaveService.java (-2 / +2 lines)
Lines 298-304 Link Here
298
            if (saveConfig.saveBytes()) {
298
            if (saveConfig.saveBytes()) {
299
                field = CSV_BYTES;
299
                field = CSV_BYTES;
300
                text = parts[i++];
300
                text = parts[i++];
301
                result.setBytes(Integer.parseInt(text));
301
                result.setBytes(Long.parseLong(text));
302
            }
302
            }
303
303
304
            if (saveConfig.saveThreadCounts()) {
304
            if (saveConfig.saveThreadCounts()) {
Lines 923-929 Link Here
923
        }
923
        }
924
924
925
        if (saveConfig.saveBytes()) {
925
        if (saveConfig.saveBytes()) {
926
            text.append(sample.getBytes());
926
            text.append(sample.getBytesAsLong());
927
        }
927
        }
928
928
929
        if (saveConfig.saveThreadCounts()) {
929
        if (saveConfig.saveThreadCounts()) {
(-)src/core/org/apache/jmeter/save/converters/SampleResultConverter.java (-4 / +3 lines)
Lines 319-325 Link Here
319
            writer.addAttribute(ATT_DATA_ENCODING, ConversionHelp.encode(res.getDataEncodingNoDefault()));
319
            writer.addAttribute(ATT_DATA_ENCODING, ConversionHelp.encode(res.getDataEncodingNoDefault()));
320
        }
320
        }
321
        if (save.saveBytes()) {
321
        if (save.saveBytes()) {
322
            writer.addAttribute(ATT_BYTES, String.valueOf(res.getBytes()));
322
            writer.addAttribute(ATT_BYTES, String.valueOf(res.getBytesAsLong()));
323
        }
323
        }
324
        if (save.saveSampleCount()){
324
        if (save.saveSampleCount()){
325
            writer.addAttribute(ATT_SAMPLE_COUNT, String.valueOf(res.getSampleCount()));
325
            writer.addAttribute(ATT_SAMPLE_COUNT, String.valueOf(res.getSampleCount()));
Lines 445-451 Link Here
445
        res.setIdleTime(Converter.getLong(reader.getAttribute(ATT_IDLETIME)));
445
        res.setIdleTime(Converter.getLong(reader.getAttribute(ATT_IDLETIME)));
446
        res.setLatency(Converter.getLong(reader.getAttribute(ATT_LATENCY)));
446
        res.setLatency(Converter.getLong(reader.getAttribute(ATT_LATENCY)));
447
        res.setConnectTime(Converter.getLong(reader.getAttribute(ATT_CONNECT_TIME)));
447
        res.setConnectTime(Converter.getLong(reader.getAttribute(ATT_CONNECT_TIME)));
448
        res.setBytes(Converter.getInt(reader.getAttribute(ATT_BYTES)));
448
        res.setBytes(Converter.getLong(reader.getAttribute(ATT_BYTES)));
449
        res.setSampleCount(Converter.getInt(reader.getAttribute(ATT_SAMPLE_COUNT),1)); // default is 1
449
        res.setSampleCount(Converter.getInt(reader.getAttribute(ATT_SAMPLE_COUNT),1)); // default is 1
450
        res.setErrorCount(Converter.getInt(reader.getAttribute(ATT_ERROR_COUNT),0)); // default is 0
450
        res.setErrorCount(Converter.getInt(reader.getAttribute(ATT_ERROR_COUNT),0)); // default is 0
451
        res.setGroupThreads(Converter.getInt(reader.getAttribute(ATT_GRP_THRDS)));
451
        res.setGroupThreads(Converter.getInt(reader.getAttribute(ATT_GRP_THRDS)));
Lines 456-462 Link Here
456
        File in = new File(resultFileName);
456
        File in = new File(resultFileName);
457
        try (FileInputStream fis = new FileInputStream(in);
457
        try (FileInputStream fis = new FileInputStream(in);
458
                BufferedInputStream bis = new BufferedInputStream(fis)){
458
                BufferedInputStream bis = new BufferedInputStream(fis)){
459
            ByteArrayOutputStream outstream = new ByteArrayOutputStream(res.getBytes());
459
            ByteArrayOutputStream outstream = new ByteArrayOutputStream(4096);
460
            byte[] buffer = new byte[4096];
460
            byte[] buffer = new byte[4096];
461
            int len;
461
            int len;
462
            while ((len = bis.read(buffer)) > 0) {
462
            while ((len = bis.read(buffer)) > 0) {
Lines 469-475 Link Here
469
        } 
469
        } 
470
    }
470
    }
471
471
472
473
    /**
472
    /**
474
     * @param arg0 the mapper
473
     * @param arg0 the mapper
475
     */
474
     */
(-)src/core/org/apache/jmeter/util/Calculator.java (-1 / +1 lines)
Lines 110-116 Link Here
110
     * @param res the sample result; might represent multiple values
110
     * @param res the sample result; might represent multiple values
111
     */
111
     */
112
    public void addSample(SampleResult res) {
112
    public void addSample(SampleResult res) {
113
        addBytes(res.getBytes());
113
        addBytes(res.getBytesAsLong());
114
        addValue(res.getTime(),res.getSampleCount());
114
        addValue(res.getTime(),res.getSampleCount());
115
        errors+=res.getErrorCount(); // account for multiple samples
115
        errors+=res.getErrorCount(); // account for multiple samples
116
        if (startTime == 0){ // not yet intialised
116
        if (startTime == 0){ // not yet intialised
(-)src/core/org/apache/jmeter/visualizers/SamplingStatCalculator.java (-1 / +1 lines)
Lines 157-163 Link Here
157
        boolean rbool;
157
        boolean rbool;
158
        synchronized (calculator) {
158
        synchronized (calculator) {
159
            calculator.addValue(res.getTime(), res.getSampleCount());
159
            calculator.addValue(res.getTime(), res.getSampleCount());
160
            calculator.addBytes(res.getBytes());
160
            calculator.addBytes(res.getBytesAsLong());
161
            setStartTime(res);
161
            setStartTime(res);
162
            eCount = getCurrentSample().getErrorCount();
162
            eCount = getCurrentSample().getErrorCount();
163
            eCount += res.getErrorCount();
163
            eCount += res.getErrorCount();
(-)src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPAbstractImpl.java (+26 lines)
Lines 409-414 Link Here
409
     */
409
     */
410
    protected byte[] readResponse(SampleResult res, InputStream instream,
410
    protected byte[] readResponse(SampleResult res, InputStream instream,
411
            int responseContentLength) throws IOException {
411
            int responseContentLength) throws IOException {
412
        return readResponse(res, instream, (long)responseContentLength);
413
    }
414
    /**
415
     * Read response from the input stream, converting to MD5 digest if the
416
     * useMD5 property is set.
417
     * <p>
418
     * For the MD5 case, the result byte count is set to the size of the
419
     * original response.
420
     * <p>
421
     * Closes the inputStream
422
     * <p>
423
     * Invokes
424
     * {@link HTTPSamplerBase#readResponse(SampleResult, InputStream, int)}
425
     * 
426
     * @param res
427
     *            sample to store information about the response into
428
     * @param instream
429
     *            input stream from which to read the response
430
     * @param responseContentLength
431
     *            expected input length or zero
432
     * @return the response or the MD5 of the response
433
     * @throws IOException
434
     *             if reading the result fails
435
     */
436
    protected byte[] readResponse(SampleResult res, InputStream instream,
437
            long responseContentLength) throws IOException {
412
        return testElement.readResponse(res, instream, responseContentLength);
438
        return testElement.readResponse(res, instream, responseContentLength);
413
    }
439
    }
414
440
(-)src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPFileImpl.java (-2 / +16 lines)
Lines 26-36 Link Here
26
26
27
import org.apache.commons.io.IOUtils;
27
import org.apache.commons.io.IOUtils;
28
import org.apache.jmeter.protocol.http.util.HTTPConstants;
28
import org.apache.jmeter.protocol.http.util.HTTPConstants;
29
import org.apache.jmeter.util.JMeterUtils;
29
30
30
/**
31
/**
31
 * HTTP Sampler which can read from file: URLs
32
 * HTTP Sampler which can read from file: URLs
32
 */
33
 */
33
public class HTTPFileImpl extends HTTPAbstractImpl {
34
public class HTTPFileImpl extends HTTPAbstractImpl {
35
    private static final int MAX_BYTES_TO_STORE_PER_REQUEST =
36
            JMeterUtils.getPropDefault("httpsampler.max_bytes_to_store_per_request", 10 * 1024 *1024); // $NON-NLS-1$ // default value: false
34
37
35
    protected HTTPFileImpl(HTTPSamplerBase base) {
38
    protected HTTPFileImpl(HTTPSamplerBase base) {
36
        super(base);
39
        super(base);
Lines 51-63 Link Here
51
        res.setSampleLabel(url.toString());
54
        res.setSampleLabel(url.toString());
52
        InputStream is = null;
55
        InputStream is = null;
53
        res.sampleStart();
56
        res.sampleStart();
54
        try {
57
        int bufferSize = 4096;
58
        try ( org.apache.commons.io.output.ByteArrayOutputStream bos = new org.apache.commons.io.output.ByteArrayOutputStream(bufferSize) ) {
55
            byte[] responseData;
59
            byte[] responseData;
56
            URLConnection conn = url.openConnection();
60
            URLConnection conn = url.openConnection();
57
            is = conn.getInputStream();
61
            is = conn.getInputStream();
58
            responseData = IOUtils.toByteArray(is);
62
            byte[] readBuffer = new byte[bufferSize];
63
            int bytesReadInBuffer = 0;
64
            long totalBytes = 0;
65
            while ((bytesReadInBuffer = is.read(readBuffer)) > -1) {
66
                if(totalBytes+bytesReadInBuffer<=MAX_BYTES_TO_STORE_PER_REQUEST) {
67
                    bos.write(readBuffer, 0, bytesReadInBuffer);
68
                }
69
                totalBytes += bytesReadInBuffer;
70
            }
71
            responseData = bos.toByteArray();
59
            res.sampleEnd();
72
            res.sampleEnd();
60
            res.setResponseData(responseData);
73
            res.setResponseData(responseData);
74
            res.setBodySize(totalBytes);
61
            res.setResponseCodeOK();
75
            res.setResponseCodeOK();
62
            res.setResponseMessageOK();
76
            res.setResponseMessageOK();
63
            res.setSuccessful(true);
77
            res.setSuccessful(true);
(-)src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC3Impl.java (-5 / +5 lines)
Lines 285-293 Link Here
285
                    Header responseHeader = httpMethod.getResponseHeader(HTTPConstants.HEADER_CONTENT_ENCODING);
285
                    Header responseHeader = httpMethod.getResponseHeader(HTTPConstants.HEADER_CONTENT_ENCODING);
286
                    if (responseHeader!= null && HTTPConstants.ENCODING_GZIP.equals(responseHeader.getValue())) {
286
                    if (responseHeader!= null && HTTPConstants.ENCODING_GZIP.equals(responseHeader.getValue())) {
287
                        InputStream tmpInput = new GZIPInputStream(instream); // tmp inputstream needs to have a good counting
287
                        InputStream tmpInput = new GZIPInputStream(instream); // tmp inputstream needs to have a good counting
288
                        res.setResponseData(readResponse(res, tmpInput, (int) httpMethod.getResponseContentLength()));                        
288
                        res.setResponseData(readResponse(res, tmpInput, httpMethod.getResponseContentLength()));                        
289
                    } else {
289
                    } else {
290
                        res.setResponseData(readResponse(res, instream, (int) httpMethod.getResponseContentLength()));
290
                        res.setResponseData(readResponse(res, instream, httpMethod.getResponseContentLength()));
291
                    }
291
                    }
292
                } finally {
292
                } finally {
293
                    JOrphanUtils.closeQuietly(instream);
293
                    JOrphanUtils.closeQuietly(instream);
Lines 328-339 Link Here
328
328
329
            // record some sizes to allow HTTPSampleResult.getBytes() with different options
329
            // record some sizes to allow HTTPSampleResult.getBytes() with different options
330
            if (instream != null) {
330
            if (instream != null) {
331
                res.setBodySize(((CountingInputStream) instream).getCount());
331
                res.setBodySize(((CountingInputStream) instream).getByteCount());
332
            }
332
            }
333
            res.setHeadersSize(calculateHeadersSize(httpMethod));
333
            res.setHeadersSize(calculateHeadersSize(httpMethod));
334
            if (log.isDebugEnabled()) {
334
            if (log.isDebugEnabled()) {
335
                log.debug("Response headersSize=" + res.getHeadersSize() + " bodySize=" + res.getBodySize()
335
                log.debug("Response headersSize=" + res.getHeadersSize() + " bodySize=" + res.getBodySizeAsLong()
336
                        + " Total=" + (res.getHeadersSize() + res.getBodySize()));
336
                        + " Total=" + (res.getHeadersSize() + res.getBodySizeAsLong()));
337
            }
337
            }
338
            
338
            
339
            // If we redirected automatically, the URL may have changed
339
            // If we redirected automatically, the URL may have changed
(-)src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java (-5 / +5 lines)
Lines 406-412 Link Here
406
            }
406
            }
407
            HttpEntity entity = httpResponse.getEntity();
407
            HttpEntity entity = httpResponse.getEntity();
408
            if (entity != null) {
408
            if (entity != null) {
409
                res.setResponseData(readResponse(res, entity.getContent(), (int) entity.getContentLength()));
409
                res.setResponseData(readResponse(res, entity.getContent(), entity.getContentLength()));
410
            }
410
            }
411
            
411
            
412
            res.sampleEnd(); // Done with the sampling proper.
412
            res.sampleEnd(); // Done with the sampling proper.
Lines 437-447 Link Here
437
              + 1 // Add \r for initial header
437
              + 1 // Add \r for initial header
438
              + 2; // final \r\n before data
438
              + 2; // final \r\n before data
439
            long totalBytes = metrics.getReceivedBytesCount();
439
            long totalBytes = metrics.getReceivedBytesCount();
440
            res.setHeadersSize((int) headerBytes);
440
            res.setHeadersSize((int)headerBytes);
441
            res.setBodySize((int)(totalBytes - headerBytes));
441
            res.setBodySize(totalBytes - headerBytes);
442
            if (log.isDebugEnabled()) {
442
            if (log.isDebugEnabled()) {
443
                log.debug("ResponseHeadersSize=" + res.getHeadersSize() + " Content-Length=" + res.getBodySize()
443
                log.debug("ResponseHeadersSize=" + res.getHeadersSize() + " Content-Length=" + res.getBodySizeAsLong()
444
                        + " Total=" + (res.getHeadersSize() + res.getBodySize()));
444
                        + " Total=" + (res.getHeadersSize() + res.getBodySizeAsLong()));
445
            }
445
            }
446
446
447
            // If we redirected automatically, the URL may have changed
447
            // If we redirected automatically, the URL may have changed
(-)src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPJavaImpl.java (-3 / +3 lines)
Lines 284-290 Link Here
284
        // N.B. this closes 'in'
284
        // N.B. this closes 'in'
285
        byte[] responseData = readResponse(res, in, contentLength);
285
        byte[] responseData = readResponse(res, in, contentLength);
286
        if (instream != null) {
286
        if (instream != null) {
287
            res.setBodySize(((CountingInputStream) instream).getCount());
287
            res.setBodySize(((CountingInputStream) instream).getByteCount());
288
            instream.close();
288
            instream.close();
289
        }
289
        }
290
        return responseData;
290
        return responseData;
Lines 566-573 Link Here
566
            res.setHeadersSize(responseHeaders.replaceAll("\n", "\r\n") // $NON-NLS-1$ $NON-NLS-2$
566
            res.setHeadersSize(responseHeaders.replaceAll("\n", "\r\n") // $NON-NLS-1$ $NON-NLS-2$
567
                    .length() + 2); // add 2 for a '\r\n' at end of headers (before data) 
567
                    .length() + 2); // add 2 for a '\r\n' at end of headers (before data) 
568
            if (log.isDebugEnabled()) {
568
            if (log.isDebugEnabled()) {
569
                log.debug("Response headersSize=" + res.getHeadersSize() + " bodySize=" + res.getBodySize()
569
                log.debug("Response headersSize=" + res.getHeadersSize() + " bodySize=" + res.getBodySizeAsLong()
570
                        + " Total=" + (res.getHeadersSize() + res.getBodySize()));
570
                        + " Total=" + (res.getHeadersSize() + res.getBodySizeAsLong()));
571
            }
571
            }
572
            
572
            
573
            // If we redirected automatically, the URL may have changed
573
            // If we redirected automatically, the URL may have changed
(-)src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java (-14 / +24 lines)
Lines 189-194 Link Here
189
189
190
    public static final boolean BROWSER_COMPATIBLE_MULTIPART_MODE_DEFAULT = false; // The default setting to be used (i.e. historic)
190
    public static final boolean BROWSER_COMPATIBLE_MULTIPART_MODE_DEFAULT = false; // The default setting to be used (i.e. historic)
191
191
192
    private static final int MAX_BYTES_TO_STORE_PER_REQUEST =
193
            JMeterUtils.getPropDefault("httpsampler.max_bytes_to_store_per_request", 10 * 1024 *1024); // $NON-NLS-1$ // default value: false
194
195
    private static final int MAX_BUFFER_SIZE = 
196
            JMeterUtils.getPropDefault("httpsampler.max_buffer_size", 65 * 1024); // $NON-NLS-1$
197
192
    private static final boolean IGNORE_FAILED_EMBEDDED_RESOURCES =
198
    private static final boolean IGNORE_FAILED_EMBEDDED_RESOURCES =
193
            JMeterUtils.getPropDefault("httpsampler.ignore_failed_embedded_resources", false); // $NON-NLS-1$ // default value: false
199
            JMeterUtils.getPropDefault("httpsampler.ignore_failed_embedded_resources", false); // $NON-NLS-1$ // default value: false
194
200
Lines 926-931 Link Here
926
    private static final boolean SEPARATE_CONTAINER =
932
    private static final boolean SEPARATE_CONTAINER =
927
            JMeterUtils.getPropDefault("httpsampler.separate.container", true); // $NON-NLS-1$
933
            JMeterUtils.getPropDefault("httpsampler.separate.container", true); // $NON-NLS-1$
928
934
935
929
    /**
936
    /**
930
     * Get the URL, built from its component parts.
937
     * Get the URL, built from its component parts.
931
     *
938
     *
Lines 1757-1763 Link Here
1757
     * @return the response or the MD5 of the response
1764
     * @return the response or the MD5 of the response
1758
     * @throws IOException if reading the result fails
1765
     * @throws IOException if reading the result fails
1759
     */
1766
     */
1760
    public byte[] readResponse(SampleResult sampleResult, InputStream in, int length) throws IOException {
1767
    public byte[] readResponse(SampleResult sampleResult, InputStream in, long length) throws IOException {
1761
        
1768
        
1762
        OutputStream w = null;
1769
        OutputStream w = null;
1763
        try {
1770
        try {
Lines 1776-1809 Link Here
1776
                if (!knownResponseLength) {
1783
                if (!knownResponseLength) {
1777
                    bufferSize = 4 * 1024;
1784
                    bufferSize = 4 * 1024;
1778
                } else {
1785
                } else {
1779
                    bufferSize = length;
1786
                    bufferSize = (int) Math.min(MAX_BUFFER_SIZE, length);
1780
                }
1787
                }
1781
            }
1788
            }
1782
            
1789
            
1783
            
1790
            
1784
            int bytesRead = 0;
1791
            int bytesReadInBuffer = 0;
1785
            int totalBytes = 0;
1792
            long totalBytes = 0;
1786
            boolean first = true;
1793
            boolean first = true;
1787
            while ((bytesRead = in.read(readBuffer)) > -1) {
1794
            while ((bytesReadInBuffer = in.read(readBuffer)) > -1) {
1788
                if (first) {
1795
                if (first) {
1789
                    sampleResult.latencyEnd();
1796
                    sampleResult.latencyEnd();
1790
                    first = false;
1797
                    first = false;
1791
                    if(md == null) {
1798
                    if(md == null) {
1792
                        if(knownResponseLength) {
1799
                        if(!knownResponseLength) {
1793
                            w = new DirectAccessByteArrayOutputStream(bufferSize);
1800
                            w = new org.apache.commons.io.output.ByteArrayOutputStream(bufferSize);
1794
                        }
1801
                        }
1795
                        else {
1802
                        else {
1796
                            w = new org.apache.commons.io.output.ByteArrayOutputStream(bufferSize);
1803
                            w = new DirectAccessByteArrayOutputStream(bufferSize);
1797
                        }
1804
                        }
1798
                    }
1805
                    }
1799
                }
1806
                }
1800
                
1807
                
1801
                if (md == null) {
1808
                if (md == null) {
1802
                    w.write(readBuffer, 0, bytesRead);
1809
                    if(totalBytes+bytesReadInBuffer<=MAX_BYTES_TO_STORE_PER_REQUEST) {
1810
                        w.write(readBuffer, 0, bytesReadInBuffer);
1811
                    } 
1803
                } else {
1812
                } else {
1804
                    md.update(readBuffer, 0, bytesRead);
1813
                    md.update(readBuffer, 0, bytesReadInBuffer);
1805
                    totalBytes += bytesRead;
1806
                }
1814
                }
1815
                totalBytes += bytesReadInBuffer;
1807
            }
1816
            }
1808
            
1817
            
1809
            if (first) { // Bug 46838 - if there was no data, still need to set latency
1818
            if (first) { // Bug 46838 - if there was no data, still need to set latency
Lines 1811-1823 Link Here
1811
                return new byte[0];
1820
                return new byte[0];
1812
            }
1821
            }
1813
            
1822
            
1814
            if (md != null) {
1823
            if (md == null) {
1824
                return toByteArray(w);
1825
            } else {
1815
                byte[] md5Result = md.digest();
1826
                byte[] md5Result = md.digest();
1816
                sampleResult.setBytes(totalBytes);
1827
                sampleResult.setBytes(totalBytes);
1817
                return JOrphanUtils.baToHexBytes(md5Result);
1828
                return JOrphanUtils.baToHexBytes(md5Result);                
1818
            }
1829
            }
1819
            
1830
            
1820
            return toByteArray(w);
1821
        } finally {
1831
        } finally {
1822
            IOUtils.closeQuietly(in);
1832
            IOUtils.closeQuietly(in);
1823
            IOUtils.closeQuietly(w);
1833
            IOUtils.closeQuietly(w);
(-)test/src/org/apache/jmeter/samplers/TestSampleResult.java (-4 / +4 lines)
Lines 146-152 Link Here
146
            res.setBytes(100);
146
            res.setBytes(100);
147
            res.setSampleLabel("sample of size 100 bytes");
147
            res.setSampleLabel("sample of size 100 bytes");
148
            res.sampleEnd();
148
            res.sampleEnd();
149
            assertEquals(100, res.getBytes());
149
            assertEquals(100, res.getBytesAsLong());
150
            assertEquals("sample of size 100 bytes", res.getSampleLabel());
150
            assertEquals("sample of size 100 bytes", res.getSampleLabel());
151
        }
151
        }
152
152
Lines 234-240 Link Here
234
            long child1Elapsed = child1.getTime();
234
            long child1Elapsed = child1.getTime();
235
235
236
            assertTrue(child1.isSuccessful());
236
            assertTrue(child1.isSuccessful());
237
            assertEquals(100, child1.getBytes());
237
            assertEquals(100, child1.getBytesAsLong());
238
            assertEquals("Child1 Sample", child1.getSampleLabel());
238
            assertEquals("Child1 Sample", child1.getSampleLabel());
239
            assertEquals(1, child1.getSampleCount());
239
            assertEquals(1, child1.getSampleCount());
240
            assertEquals(0, child1.getSubResults().length);
240
            assertEquals(0, child1.getSubResults().length);
Lines 257-263 Link Here
257
            long child2Elapsed = child2.getTime();
257
            long child2Elapsed = child2.getTime();
258
258
259
            assertTrue(child2.isSuccessful());
259
            assertTrue(child2.isSuccessful());
260
            assertEquals(200, child2.getBytes());
260
            assertEquals(200, child2.getBytesAsLong());
261
            assertEquals("Child2 Sample", child2.getSampleLabel());
261
            assertEquals("Child2 Sample", child2.getSampleLabel());
262
            assertEquals(1, child2.getSampleCount());
262
            assertEquals(1, child2.getSampleCount());
263
            assertEquals(0, child2.getSubResults().length);
263
            assertEquals(0, child2.getSubResults().length);
Lines 266-272 Link Here
266
            parent.addSubResult(child1);
266
            parent.addSubResult(child1);
267
            parent.addSubResult(child2);
267
            parent.addSubResult(child2);
268
            assertTrue(parent.isSuccessful());
268
            assertTrue(parent.isSuccessful());
269
            assertEquals(600, parent.getBytes());
269
            assertEquals(600, parent.getBytesAsLong());
270
            assertEquals("Parent Sample", parent.getSampleLabel());
270
            assertEquals("Parent Sample", parent.getSampleLabel());
271
            assertEquals(1, parent.getSampleCount());
271
            assertEquals(1, parent.getSampleCount());
272
            assertEquals(2, parent.getSubResults().length);
272
            assertEquals(2, parent.getSubResults().length);

Return to bug 53039