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

(-)src/core/org/apache/jmeter/resources/messages.properties (+5 lines)
Lines 65-80 Link Here
65
appearance=Look and Feel
65
appearance=Look and Feel
66
argument_must_not_be_negative=The Argument must not be negative\!
66
argument_must_not_be_negative=The Argument must not be negative\!
67
assertion_assume_success=Ignore Status
67
assertion_assume_success=Ignore Status
68
assertion_body_resp=Response Body
68
assertion_code_resp=Response Code
69
assertion_code_resp=Response Code
69
assertion_contains=Contains
70
assertion_contains=Contains
70
assertion_equals=Equals
71
assertion_equals=Equals
71
assertion_headers=Response Headers
72
assertion_headers=Response Headers
72
assertion_matches=Matches
73
assertion_matches=Matches
73
assertion_message_resp=Response Message
74
assertion_message_resp=Response Message
75
assertion_network_size=Full Response
74
assertion_not=Not
76
assertion_not=Not
75
assertion_pattern_match_rules=Pattern Matching Rules
77
assertion_pattern_match_rules=Pattern Matching Rules
76
assertion_patterns_to_test=Patterns to Test
78
assertion_patterns_to_test=Patterns to Test
77
assertion_resp_field=Response Field to Test
79
assertion_resp_field=Response Field to Test
80
assertion_resp_size_field=Response Size Field to Test
78
assertion_substring=Substring
81
assertion_substring=Substring
79
assertion_text_resp=Text Response
82
assertion_text_resp=Text Response
80
assertion_textarea_label=Assertions\:
83
assertion_textarea_label=Assertions\:
Lines 988-993 Link Here
988
view_results_sample_start=Sample Start: 
991
view_results_sample_start=Sample Start: 
989
view_results_search_pane=Search pane
992
view_results_search_pane=Search pane
990
view_results_size_in_bytes=Size in bytes: 
993
view_results_size_in_bytes=Size in bytes: 
994
view_results_size_body_in_bytes=Body size in bytes: 
995
view_results_size_headers_in_bytes=Headers size in bytes: 
991
view_results_tab_assertion=Assertion result
996
view_results_tab_assertion=Assertion result
992
view_results_tab_request=Request
997
view_results_tab_request=Request
993
view_results_tab_response=Response data
998
view_results_tab_response=Response data
(-)src/components/org/apache/jmeter/assertions/SizeAssertion.java (-1 / +70 lines)
Lines 34-40 Link Here
34
 */
34
 */
35
public class SizeAssertion extends AbstractScopedAssertion implements Serializable, Assertion {
35
public class SizeAssertion extends AbstractScopedAssertion implements Serializable, Assertion {
36
36
37
    private static final long serialVersionUID = 233L;
37
    private static final long serialVersionUID = 241L;
38
38
39
    // * Static int to signify the type of logical comparitor to assert
39
    // * Static int to signify the type of logical comparitor to assert
40
    public final static int EQUAL = 1;
40
    public final static int EQUAL = 1;
Lines 53-58 Link Here
53
    private static final String SIZE_KEY = "SizeAssertion.size"; // $NON-NLS-1$
53
    private static final String SIZE_KEY = "SizeAssertion.size"; // $NON-NLS-1$
54
54
55
    private static final String OPERATOR_KEY = "SizeAssertion.operator"; // $NON-NLS-1$
55
    private static final String OPERATOR_KEY = "SizeAssertion.operator"; // $NON-NLS-1$
56
    
57
    private final static String TEST_FIELD = "Assertion.test_field";  // $NON-NLS-1$
58
59
    private final static String RESPONSE_NETWORK_SIZE = "SizeAssertion.response_network_size"; // $NON-NLS-1$
60
61
    private final static String RESPONSE_HEADERS = "SizeAssertion.response_headers"; // $NON-NLS-1$
62
63
    private final static String RESPONSE_BODY = "SizeAssertion.response_data"; // $NON-NLS-1$
64
65
    private final static String RESPONSE_CODE = "SizeAssertion.response_code"; // $NON-NLS-1$
66
67
    private final static String RESPONSE_MESSAGE = "SizeAssertion.response_message"; // $NON-NLS-1$
56
68
57
    /**
69
    /**
58
     * Returns the result of the Assertion. 
70
     * Returns the result of the Assertion. 
Lines 72-77 Link Here
72
                result.setFailureMessage("Error parsing variable name: "+variableName+" value: "+value);
84
                result.setFailureMessage("Error parsing variable name: "+variableName+" value: "+value);
73
                return result;
85
                return result;
74
            }
86
            }
87
        } else if (isTestFieldResponseHeaders()) {
88
            resultSize = response.getHeadersSize();
89
        }  else if (isTestFieldResponseBody()) {
90
            resultSize = response.getBodySize();
91
        } else if (isTestFieldResponseCode()) {
92
            resultSize = response.getResponseCode().length();
93
        } else if (isTestFieldResponseMessage()) {
94
            resultSize = response.getResponseMessage().length();
75
        } else {
95
        } else {
76
            resultSize = response.getBytes();
96
            resultSize = response.getBytes();
77
        }
97
        }
Lines 168-171 Link Here
168
        }
188
        }
169
        return result ? "" : comparatorErrorMessage;
189
        return result ? "" : comparatorErrorMessage;
170
    }
190
    }
191
    
192
    private void setTestField(String testField) {
193
        setProperty(TEST_FIELD, testField);
194
    }
195
196
    public void setTestFieldNetworkSize(){
197
        setTestField(RESPONSE_NETWORK_SIZE);
198
    }
199
    
200
    public void setTestFieldResponseHeaders(){
201
        setTestField(RESPONSE_HEADERS);
202
    }
203
    
204
    public void setTestFieldResponseBody(){
205
        setTestField(RESPONSE_BODY);
206
    }
207
    
208
    public void setTestFieldResponseCode(){
209
        setTestField(RESPONSE_CODE);
210
    }
211
    
212
    public void setTestFieldResponseMessage(){
213
        setTestField(RESPONSE_MESSAGE);
214
    }
215
216
    public String getTestField() {
217
        return getPropertyAsString(TEST_FIELD);
218
    }
219
220
    public boolean isTestFieldNetworkSize(){
221
        return RESPONSE_NETWORK_SIZE.equals(getTestField());
222
    }
223
224
    public boolean isTestFieldResponseHeaders(){
225
        return RESPONSE_HEADERS.equals(getTestField());
226
    }
227
    
228
    public boolean isTestFieldResponseBody(){
229
        return RESPONSE_BODY.equals(getTestField());
230
    }
231
232
    public boolean isTestFieldResponseCode(){
233
        return RESPONSE_CODE.equals(getTestField());
234
    }
235
236
    public boolean isTestFieldResponseMessage(){
237
        return RESPONSE_MESSAGE.equals(getTestField());
238
    }
239
171
}
240
}
(-)src/components/org/apache/jmeter/visualizers/SamplerResultTab.java (+4 lines)
Lines 227-232 Link Here
227
                statsBuff.append(JMeterUtils.getResString("view_results_load_time")).append(sampleResult.getTime()).append(NL); //$NON-NLS-1$
227
                statsBuff.append(JMeterUtils.getResString("view_results_load_time")).append(sampleResult.getTime()).append(NL); //$NON-NLS-1$
228
                statsBuff.append(JMeterUtils.getResString("view_results_latency")).append(sampleResult.getLatency()).append(NL); //$NON-NLS-1$
228
                statsBuff.append(JMeterUtils.getResString("view_results_latency")).append(sampleResult.getLatency()).append(NL); //$NON-NLS-1$
229
                statsBuff.append(JMeterUtils.getResString("view_results_size_in_bytes")).append(sampleResult.getBytes()).append(NL); //$NON-NLS-1$
229
                statsBuff.append(JMeterUtils.getResString("view_results_size_in_bytes")).append(sampleResult.getBytes()).append(NL); //$NON-NLS-1$
230
                statsBuff.append(JMeterUtils.getResString("view_results_size_headers_in_bytes")).append(sampleResult.getHeadersSize()).append(NL); //$NON-NLS-1$
231
                statsBuff.append(JMeterUtils.getResString("view_results_size_body_in_bytes")).append(sampleResult.getBodySize()).append(NL); //$NON-NLS-1$
230
                statsBuff.append(JMeterUtils.getResString("view_results_sample_count")).append(sampleResult.getSampleCount()).append(NL); //$NON-NLS-1$
232
                statsBuff.append(JMeterUtils.getResString("view_results_sample_count")).append(sampleResult.getSampleCount()).append(NL); //$NON-NLS-1$
231
                statsBuff.append(JMeterUtils.getResString("view_results_error_count")).append(sampleResult.getErrorCount()).append(NL); //$NON-NLS-1$
233
                statsBuff.append(JMeterUtils.getResString("view_results_error_count")).append(sampleResult.getErrorCount()).append(NL); //$NON-NLS-1$
232
                statsDoc.insertString(statsDoc.getLength(), statsBuff.toString(), null);
234
                statsDoc.insertString(statsDoc.getLength(), statsBuff.toString(), null);
Lines 280-285 Link Here
280
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_load_time"), sampleResult.getTime())); //$NON-NLS-1$
282
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_load_time"), sampleResult.getTime())); //$NON-NLS-1$
281
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_latency"), sampleResult.getLatency())); //$NON-NLS-1$
283
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_latency"), sampleResult.getLatency())); //$NON-NLS-1$
282
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_size_in_bytes"), sampleResult.getBytes())); //$NON-NLS-1$
284
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_size_in_bytes"), sampleResult.getBytes())); //$NON-NLS-1$
285
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_size_headers_in_bytes"), sampleResult.getHeadersSize())); //$NON-NLS-1$
286
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_size_body_in_bytes"), sampleResult.getBodySize())); //$NON-NLS-1$
283
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_sample_count"), sampleResult.getSampleCount())); //$NON-NLS-1$
287
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_sample_count"), sampleResult.getSampleCount())); //$NON-NLS-1$
284
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_error_count"), sampleResult.getErrorCount())); //$NON-NLS-1$
288
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_error_count"), sampleResult.getErrorCount())); //$NON-NLS-1$
285
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_response_code"), responseCode)); //$NON-NLS-1$
289
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_response_code"), responseCode)); //$NON-NLS-1$
(-)src/core/org/apache/jmeter/samplers/SampleResult.java (+54 lines)
Lines 93-98 Link Here
93
    private static final SampleResult[] EMPTY_SR = new SampleResult[0];
93
    private static final SampleResult[] EMPTY_SR = new SampleResult[0];
94
94
95
    private static final AssertionResult[] EMPTY_AR = new AssertionResult[0];
95
    private static final AssertionResult[] EMPTY_AR = new AssertionResult[0];
96
    
97
    private static final boolean GETBYTES_BODY_REALSIZE = 
98
        JMeterUtils.getPropDefault("sampleresult.getbytes.body_real_size", true); // $NON-NLS-1$
99
100
    private static final boolean GETBYTES_HEADERS_SIZE = 
101
        JMeterUtils.getPropDefault("sampleresult.getbytes.headers_size", true); // $NON-NLS-1$
102
    
103
    private static final boolean GETBYTES_NETWORK_SIZE = 
104
        GETBYTES_HEADERS_SIZE && GETBYTES_BODY_REALSIZE ? true : false;
96
105
97
    private SampleSaveConfiguration saveConfig;
106
    private SampleSaveConfiguration saveConfig;
98
107
Lines 181-186 Link Here
181
    private int sampleCount = 1;
190
    private int sampleCount = 1;
182
191
183
    private int bytes = 0; // Allows override of sample size in case sampler does not want to store all the data
192
    private int bytes = 0; // Allows override of sample size in case sampler does not want to store all the data
193
    
194
    private int headersSize = 0;
195
    
196
    private int bodySize = 0;
184
197
185
    /** Currently active threads in this thread group */
198
    /** Currently active threads in this thread group */
186
    private volatile int groupThreads = 0;
199
    private volatile int groupThreads = 0;
Lines 1082-1087 Link Here
1082
     * @return byte count
1095
     * @return byte count
1083
     */
1096
     */
1084
    public int getBytes() {
1097
    public int getBytes() {
1098
        if (GETBYTES_NETWORK_SIZE) {
1099
            int tmpSum = this.getHeadersSize() + this.getBodySize();
1100
            return tmpSum == 0 ? bytes : tmpSum;
1101
        } else if (GETBYTES_HEADERS_SIZE) {
1102
            return this.getHeadersSize();
1103
        } else if (GETBYTES_BODY_REALSIZE) {
1104
            return this.getBodySize();
1105
        }
1085
        return bytes == 0 ? responseData.length : bytes;
1106
        return bytes == 0 ? responseData.length : bytes;
1086
    }
1107
    }
1087
1108
Lines 1192-1195 Link Here
1192
    public void removeSubResults() {
1213
    public void removeSubResults() {
1193
        this.subResults = null;
1214
        this.subResults = null;
1194
    }
1215
    }
1216
    
1217
    /**
1218
     * Set the headers size in bytes
1219
     * 
1220
     * @param size
1221
     */
1222
    public void setHeadersSize(int size) {
1223
        this.headersSize = size;
1224
    }
1225
    
1226
    /**
1227
     * Get the headers size in bytes
1228
     * 
1229
     * @return the headers size
1230
     */
1231
    public int getHeadersSize() {
1232
        return headersSize;
1233
    }
1234
1235
    /**
1236
     * @return the body size in bytes
1237
     */
1238
    public int getBodySize() {
1239
        return bodySize == 0 ? responseData.length : bodySize;
1240
    }
1241
1242
    /**
1243
     * @param bodySize the body size to set
1244
     */
1245
    public void setBodySize(int bodySize) {
1246
        this.bodySize = bodySize;
1247
    }
1248
1195
}
1249
}
(-)bin/jmeter.properties (-11 / +8 lines)
Lines 243-259 Link Here
243
#log_config=logkit.xml
243
#log_config=logkit.xml
244
244
245
#---------------------------------------------------------------------------
245
#---------------------------------------------------------------------------
246
# HTTP common configuration
247
#---------------------------------------------------------------------------
248
249
# Response size calculate method
250
# Include headers: add the headers size in total of response size
251
# Use Content-Length: if web server uses a deflate/gzip module,
252
# gets the value of Content-Length to get response size rather uncompressed length
253
#http.getbytes.include.headers=false
254
#http.getbytes.use.contentlength=false
255
256
#---------------------------------------------------------------------------
257
# HTTP Java configuration
246
# HTTP Java configuration
258
#---------------------------------------------------------------------------
247
#---------------------------------------------------------------------------
259
248
Lines 699-704 Link Here
699
# The encoding to be used if none is provided (default ISO-8859-1)
688
# The encoding to be used if none is provided (default ISO-8859-1)
700
#sampleresult.default.encoding=ISO-8859-1
689
#sampleresult.default.encoding=ISO-8859-1
701
690
691
# Network response size calculation method
692
# Use real size: number of bytes for response body return by webserver
693
# (i.e. the network bytes received for response)
694
# if set to false, the (uncompressed) response data size will used (default before 2.4.1)
695
# Include headers: add the headers size in real size
696
#sampleresult.getbytes.body_real_size=true
697
#sampleresult.getbytes.headers_size=true
698
702
# CookieManager behaviour - should cookies with null/empty values be deleted?
699
# CookieManager behaviour - should cookies with null/empty values be deleted?
703
# Default is true. Use false to revert to original behaviour
700
# Default is true. Use false to revert to original behaviour
704
#CookieManager.delete_null_cookies=true
701
#CookieManager.delete_null_cookies=true
(-)src/components/org/apache/jmeter/assertions/gui/SizeAssertionGui.java (-1 / +82 lines)
Lines 20-25 Link Here
20
20
21
import java.awt.event.ActionEvent;
21
import java.awt.event.ActionEvent;
22
import java.awt.event.ActionListener;
22
import java.awt.event.ActionListener;
23
23
import javax.swing.BorderFactory;
24
import javax.swing.BorderFactory;
24
import javax.swing.Box;
25
import javax.swing.Box;
25
import javax.swing.ButtonGroup;
26
import javax.swing.ButtonGroup;
Lines 38-44 Link Here
38
 */
39
 */
39
public class SizeAssertionGui extends AbstractAssertionGui implements ActionListener {
40
public class SizeAssertionGui extends AbstractAssertionGui implements ActionListener {
40
41
41
    private static final long serialVersionUID = 240L;
42
    private static final long serialVersionUID = 241L;
43
    
44
    /** Radio button indicating that the body response should be tested. */
45
    private JRadioButton responseBodyButton;
46
47
    /** Radio button indicating that the network response size should be tested. */
48
    private JRadioButton responseNetworkButton;
49
50
    /** Radio button indicating that the responseMessage should be tested. */
51
    private JRadioButton responseMessageButton;
52
53
    /** Radio button indicating that the responseCode should be tested. */
54
    private JRadioButton responseCodeButton;
55
56
    /** Radio button indicating that the headers should be tested. */
57
    private JRadioButton responseHeadersButton;
42
58
43
    private JTextField size;
59
    private JTextField size;
44
60
Lines 69-74 Link Here
69
    public void modifyTestElement(TestElement el) {
85
    public void modifyTestElement(TestElement el) {
70
        configureTestElement(el);
86
        configureTestElement(el);
71
        SizeAssertion assertion = (SizeAssertion) el;
87
        SizeAssertion assertion = (SizeAssertion) el;
88
        
89
        if (responseHeadersButton.isSelected()) {
90
            assertion.setTestFieldResponseHeaders();
91
        } else if (responseBodyButton.isSelected()) {
92
            assertion.setTestFieldResponseBody();
93
        } else if (responseCodeButton.isSelected()) {
94
            assertion.setTestFieldResponseCode();
95
        } else if (responseMessageButton.isSelected()) {
96
            assertion.setTestFieldResponseMessage();
97
        } else {
98
            assertion.setTestFieldNetworkSize();
99
        }
72
        assertion.setAllowedSize(size.getText());
100
        assertion.setAllowedSize(size.getText());
73
        assertion.setCompOper(getState());
101
        assertion.setCompOper(getState());
74
        saveScopeSettings(assertion);
102
        saveScopeSettings(assertion);
Lines 81-86 Link Here
81
    public void clearGui() {
109
    public void clearGui() {
82
        super.clearGui();
110
        super.clearGui();
83
111
112
        responseNetworkButton.setSelected(true); // default
113
        responseHeadersButton.setSelected(false);
114
        responseBodyButton.setSelected(false);
115
        responseCodeButton.setSelected(false);
116
        responseMessageButton.setSelected(false);
117
        
84
        size.setText(""); //$NON-NLS-1$
118
        size.setText(""); //$NON-NLS-1$
85
        equalButton.setSelected(true);
119
        equalButton.setSelected(true);
86
        notequalButton.setSelected(false);
120
        notequalButton.setSelected(false);
Lines 98-103 Link Here
98
        size.setText(assertion.getAllowedSize());
132
        size.setText(assertion.getAllowedSize());
99
        setState(assertion.getCompOper());
133
        setState(assertion.getCompOper());
100
        showScopeSettings(assertion);
134
        showScopeSettings(assertion);
135
        
136
        if (assertion.isTestFieldResponseHeaders()) {
137
        responseHeadersButton.setSelected(true);
138
        } else if (assertion.isTestFieldResponseBody()) {
139
            responseBodyButton.setSelected(true);
140
        } else if (assertion.isTestFieldResponseCode()) {
141
            responseCodeButton.setSelected(true);
142
        } else if (assertion.isTestFieldResponseMessage()) {
143
            responseMessageButton.setSelected(true);
144
        } else {
145
            responseNetworkButton.setSelected(true);
146
        }
101
    }
147
    }
102
148
103
    /**
149
    /**
Lines 139-144 Link Here
139
        add(makeTitlePanel());
185
        add(makeTitlePanel());
140
186
141
        add(createScopePanel(true));
187
        add(createScopePanel(true));
188
        add(createFieldPanel());
142
189
143
        // USER_INPUT
190
        // USER_INPUT
144
        JPanel sizePanel = new JPanel();
191
        JPanel sizePanel = new JPanel();
Lines 153-158 Link Here
153
200
154
        add(sizePanel);
201
        add(sizePanel);
155
    }
202
    }
203
    
204
    /**
205
     * Create a panel allowing the user to choose which response field should be
206
     * tested.
207
     *
208
     * @return a new panel for selecting the response field
209
     */
210
    private JPanel createFieldPanel() {
211
        JPanel panel = new JPanel();
212
        panel.setBorder(BorderFactory.createTitledBorder(JMeterUtils.getResString("assertion_resp_size_field"))); //$NON-NLS-1$
213
214
        responseNetworkButton = new JRadioButton(JMeterUtils.getResString("assertion_network_size")); //$NON-NLS-1$
215
        responseHeadersButton = new JRadioButton(JMeterUtils.getResString("assertion_headers")); //$NON-NLS-1$
216
        responseBodyButton = new JRadioButton(JMeterUtils.getResString("assertion_body_resp")); //$NON-NLS-1$
217
        responseCodeButton = new JRadioButton(JMeterUtils.getResString("assertion_code_resp")); //$NON-NLS-1$
218
        responseMessageButton = new JRadioButton(JMeterUtils.getResString("assertion_message_resp")); //$NON-NLS-1$
219
220
        ButtonGroup group = new ButtonGroup();
221
        group.add(responseNetworkButton);
222
        group.add(responseHeadersButton);
223
        group.add(responseBodyButton);
224
        group.add(responseCodeButton);
225
        group.add(responseMessageButton);
226
227
        panel.add(responseNetworkButton);
228
        panel.add(responseHeadersButton);
229
        panel.add(responseBodyButton);
230
        panel.add(responseCodeButton);
231
        panel.add(responseMessageButton);
232
233
        responseNetworkButton.setSelected(true);
234
235
        return panel;
236
    }
156
237
157
    private Box createComparatorButtonPanel() {
238
    private Box createComparatorButtonPanel() {
158
        ButtonGroup group = new ButtonGroup();
239
        ButtonGroup group = new ButtonGroup();
(-)src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampleResult.java (-63 lines)
Lines 23-29 Link Here
23
23
24
import org.apache.jmeter.protocol.http.util.HTTPConstants;
24
import org.apache.jmeter.protocol.http.util.HTTPConstants;
25
import org.apache.jmeter.samplers.SampleResult;
25
import org.apache.jmeter.samplers.SampleResult;
26
import org.apache.jmeter.util.JMeterUtils;
27
26
28
/**
27
/**
29
 * This is a specialisation of the SampleResult class for the HTTP protocol.
28
 * This is a specialisation of the SampleResult class for the HTTP protocol.
Lines 32-54 Link Here
32
public class HTTPSampleResult extends SampleResult {
31
public class HTTPSampleResult extends SampleResult {
33
32
34
    private static final long serialVersionUID = 240L;
33
    private static final long serialVersionUID = 240L;
35
    
36
    private static final boolean GETBYTES_INCLUDE_HEADERS = 
37
        JMeterUtils.getPropDefault("http.getbytes.include.headers", false); // $NON-NLS-1$
38
    
39
    private static final boolean GETBYTES_USE_CONTENTLENGTH = 
40
        JMeterUtils.getPropDefault("http.getbytes.use.contentlength", false); // $NON-NLS-1$
41
42
    private static final boolean GETBYTES_HEADERS_CONTENTLENGTH = 
43
        GETBYTES_INCLUDE_HEADERS && GETBYTES_USE_CONTENTLENGTH ? true : false;
44
34
45
    private String cookies = ""; // never null
35
    private String cookies = ""; // never null
46
36
47
    private String method;
37
    private String method;
48
    
49
    private int headersSize = 0;
50
    
51
    private int contentLength = 0;
52
38
53
    /**
39
    /**
54
     * The raw value of the Location: header; may be null.
40
     * The raw value of the Location: header; may be null.
Lines 230-282 Link Here
230
        setResponseMessage(HTTP_NO_CONTENT_MSG);
216
        setResponseMessage(HTTP_NO_CONTENT_MSG);
231
    }
217
    }
232
    
218
    
233
    /**
234
     * Set the headers size in bytes
235
     * 
236
     * @param size
237
     */
238
    public void setHeadersSize(int size) {
239
        this.headersSize = size;
240
    }
241
    
242
    /**
243
     * Get the headers size in bytes
244
     * 
245
     * @return the headers size
246
     */
247
    public int getHeadersSize() {
248
        return headersSize;
249
    }
250
251
    /**
252
     * @return the contentLength
253
     */
254
    public int getContentLength() {
255
        return contentLength == 0 ? super.getBytes() : contentLength;
256
    }
257
258
    /**
259
     * @param contentLength the contentLength to set
260
     */
261
    public void setContentLength(int contentLength) {
262
        this.contentLength = contentLength;
263
    }
264
265
    /*
266
     * (non-Javadoc)
267
     * 
268
     * @see org.apache.jmeter.samplers.SampleResult#getBytes()
269
     */
270
    @Override
271
    public int getBytes() {
272
        if (GETBYTES_HEADERS_CONTENTLENGTH) {
273
            return headersSize + contentLength;
274
        } else if (GETBYTES_INCLUDE_HEADERS) {
275
            return headersSize + super.getBytes();
276
        } else if (GETBYTES_USE_CONTENTLENGTH) {
277
            return contentLength;
278
        }
279
        return super.getBytes(); // Default
280
    }
281
    
282
}
219
}
(-)src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPJavaImpl.java (-9 / +11 lines)
Lines 34-39 Link Here
34
import java.util.Set;
34
import java.util.Set;
35
import java.util.zip.GZIPInputStream;
35
import java.util.zip.GZIPInputStream;
36
36
37
import org.apache.commons.io.input.CountingInputStream;
37
import org.apache.jmeter.protocol.http.control.AuthManager;
38
import org.apache.jmeter.protocol.http.control.AuthManager;
38
import org.apache.jmeter.protocol.http.control.Authorization;
39
import org.apache.jmeter.protocol.http.control.Authorization;
39
import org.apache.jmeter.protocol.http.control.CacheManager;
40
import org.apache.jmeter.protocol.http.control.CacheManager;
Lines 241-252 Link Here
241
242
242
        // works OK even if ContentEncoding is null
243
        // works OK even if ContentEncoding is null
243
        boolean gzipped = ENCODING_GZIP.equals(conn.getContentEncoding());
244
        boolean gzipped = ENCODING_GZIP.equals(conn.getContentEncoding());
244
245
        InputStream instream = null;
245
        try {
246
        try {
247
            instream = new CountingInputStream(conn.getInputStream());
246
            if (gzipped) {
248
            if (gzipped) {
247
                in = new BufferedInputStream(new GZIPInputStream(conn.getInputStream()));
249
                in = new BufferedInputStream(new GZIPInputStream(instream));
248
            } else {
250
            } else {
249
                in = new BufferedInputStream(conn.getInputStream());
251
                in = new BufferedInputStream(instream);
250
            }
252
            }
251
        } catch (IOException e) {
253
        } catch (IOException e) {
252
            if (! (e.getCause() instanceof FileNotFoundException))
254
            if (! (e.getCause() instanceof FileNotFoundException))
Lines 281-287 Link Here
281
            }
283
            }
282
            in = new BufferedInputStream(conn.getErrorStream());
284
            in = new BufferedInputStream(conn.getErrorStream());
283
        }
285
        }
284
        return readResponse(res, in, contentLength);
286
        byte[] responseData = readResponse(res, in, contentLength);
287
        res.setBodySize(((CountingInputStream) instream).getCount());
288
        return responseData;
285
    }
289
    }
286
290
287
    /**
291
    /**
Lines 562-575 Link Here
562
                res.setRedirectLocation(conn.getHeaderField(HEADER_LOCATION));
566
                res.setRedirectLocation(conn.getHeaderField(HEADER_LOCATION));
563
            }
567
            }
564
            
568
            
565
            // record some sizes to allow HTTPSampleResult.getBytes() with different options
569
            // record headers size to allow HTTPSampleResult.getBytes() with different options
566
            String contentLength = conn.getHeaderField(HEADER_CONTENT_LENGTH);
567
            res.setContentLength(contentLength != null ? Integer.parseInt(contentLength) : 0); // 0 to getBytes with responseData length
568
            res.setHeadersSize(responseHeaders.replaceAll("\n", "\r\n") // $NON-NLS-1$ $NON-NLS-2$
570
            res.setHeadersSize(responseHeaders.replaceAll("\n", "\r\n") // $NON-NLS-1$ $NON-NLS-2$
569
                    .length() + 2); // add 2 for a '\r\n' at end of headers (before data) 
571
                    .length() + 2); // add 2 for a '\r\n' at end of headers (before data) 
570
            if (log.isDebugEnabled()) {
572
            if (log.isDebugEnabled()) {
571
                log.debug("ResponseHeadersSize=" + res.getHeadersSize() + " Content-Length=" + res.getContentLength()
573
                log.debug("Response headersSize=" + res.getHeadersSize() + " bodySize=" + res.getBodySize()
572
                        + " Total=" + (res.getHeadersSize() + res.getContentLength()));
574
                        + " Total=" + (res.getHeadersSize() + res.getBodySize()));
573
            }
575
            }
574
            
576
            
575
            // If we redirected automatically, the URL may have changed
577
            // If we redirected automatically, the URL may have changed
(-)test/src/org/apache/jmeter/assertions/SizeAssertionTest.java (+1 lines)
Lines 39-44 Link Here
39
          jmctx = JMeterContextService.getContext();
39
          jmctx = JMeterContextService.getContext();
40
          assertion = new SizeAssertion();
40
          assertion = new SizeAssertion();
41
          assertion.setThreadContext(jmctx);
41
          assertion.setThreadContext(jmctx);
42
          assertion.setTestFieldResponseBody();
42
          vars = new JMeterVariables();
43
          vars = new JMeterVariables();
43
          jmctx.setVariables(vars);
44
          jmctx.setVariables(vars);
44
          sample0 = new SampleResult();
45
          sample0 = new SampleResult();
(-)src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC3Impl.java (-6 / +9 lines)
Lines 60-65 Link Here
60
import org.apache.commons.httpclient.params.HttpClientParams;
60
import org.apache.commons.httpclient.params.HttpClientParams;
61
import org.apache.commons.httpclient.params.HttpMethodParams;
61
import org.apache.commons.httpclient.params.HttpMethodParams;
62
import org.apache.commons.httpclient.protocol.Protocol;
62
import org.apache.commons.httpclient.protocol.Protocol;
63
import org.apache.commons.io.input.CountingInputStream;
63
import org.apache.jmeter.protocol.http.control.AuthManager;
64
import org.apache.jmeter.protocol.http.control.AuthManager;
64
import org.apache.jmeter.protocol.http.control.Authorization;
65
import org.apache.jmeter.protocol.http.control.Authorization;
65
import org.apache.jmeter.protocol.http.control.CacheManager;
66
import org.apache.jmeter.protocol.http.control.CacheManager;
Lines 244-258 Link Here
244
            res.setRequestHeaders(getConnectionHeaders(httpMethod));
245
            res.setRequestHeaders(getConnectionHeaders(httpMethod));
245
246
246
            // Request sent. Now get the response:
247
            // Request sent. Now get the response:
247
            InputStream instream = httpMethod.getResponseBodyAsStream();
248
            InputStream instream = new CountingInputStream(httpMethod.getResponseBodyAsStream());
248
249
249
            if (instream != null) {// will be null for HEAD
250
            if (instream != null) {// will be null for HEAD
250
                try {
251
                try {
251
                    Header responseHeader = httpMethod.getResponseHeader(HEADER_CONTENT_ENCODING);
252
                    Header responseHeader = httpMethod.getResponseHeader(HEADER_CONTENT_ENCODING);
252
                    if (responseHeader!= null && ENCODING_GZIP.equals(responseHeader.getValue())) {
253
                    if (responseHeader!= null && ENCODING_GZIP.equals(responseHeader.getValue())) {
253
                        instream = new GZIPInputStream(instream);
254
                        InputStream tmpInput = new GZIPInputStream(instream); // tmp inputstream needs to hava a good counting
255
                        res.setResponseData(readResponse(res, tmpInput, (int) httpMethod.getResponseContentLength()));                        
256
                    } else {
257
                        res.setResponseData(readResponse(res, instream, (int) httpMethod.getResponseContentLength()));
254
                    }
258
                    }
255
                    res.setResponseData(readResponse(res, instream, (int) httpMethod.getResponseContentLength()));
256
                } finally {
259
                } finally {
257
                    JOrphanUtils.closeQuietly(instream);
260
                    JOrphanUtils.closeQuietly(instream);
258
                }
261
                }
Lines 290-300 Link Here
290
            }
293
            }
291
294
292
            // record some sizes to allow HTTPSampleResult.getBytes() with different options
295
            // record some sizes to allow HTTPSampleResult.getBytes() with different options
293
            res.setContentLength((int) httpMethod.getResponseContentLength());
296
            res.setBodySize(((CountingInputStream) instream).getCount());
294
            res.setHeadersSize(calculateHeadersSize(httpMethod));
297
            res.setHeadersSize(calculateHeadersSize(httpMethod));
295
            if (log.isDebugEnabled()) {
298
            if (log.isDebugEnabled()) {
296
                log.debug("ResponseHeadersSize=" + res.getHeadersSize() + " Content-Length=" + res.getContentLength()
299
                log.debug("Response headersSize=" + res.getHeadersSize() + " bodySize=" + res.getBodySize()
297
                        + " Total=" + (res.getHeadersSize() + res.getContentLength()));
300
                        + " Total=" + (res.getHeadersSize() + res.getBodySize()));
298
            }
301
            }
299
            
302
            
300
            // If we redirected automatically, the URL may have changed
303
            // If we redirected automatically, the URL may have changed
(-)src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java (-5 / +11 lines)
Lines 36-41 Link Here
36
import java.util.Map;
36
import java.util.Map;
37
37
38
import org.apache.http.Header;
38
import org.apache.http.Header;
39
import org.apache.http.HttpConnectionMetrics;
39
import org.apache.http.HttpEntity;
40
import org.apache.http.HttpEntity;
40
import org.apache.http.HttpHost;
41
import org.apache.http.HttpHost;
41
import org.apache.http.HttpRequest;
42
import org.apache.http.HttpRequest;
Lines 74-79 Link Here
74
import org.apache.http.entity.mime.content.StringBody;
75
import org.apache.http.entity.mime.content.StringBody;
75
import org.apache.http.impl.client.AbstractHttpClient;
76
import org.apache.http.impl.client.AbstractHttpClient;
76
import org.apache.http.impl.client.DefaultHttpClient;
77
import org.apache.http.impl.client.DefaultHttpClient;
78
import org.apache.http.impl.conn.AbstractClientConnAdapter;
77
import org.apache.http.message.BasicNameValuePair;
79
import org.apache.http.message.BasicNameValuePair;
78
import org.apache.http.params.BasicHttpParams;
80
import org.apache.http.params.BasicHttpParams;
79
import org.apache.http.params.CoreConnectionPNames;
81
import org.apache.http.params.CoreConnectionPNames;
Lines 83-89 Link Here
83
import org.apache.http.protocol.BasicHttpContext;
85
import org.apache.http.protocol.BasicHttpContext;
84
import org.apache.http.protocol.ExecutionContext;
86
import org.apache.http.protocol.ExecutionContext;
85
import org.apache.http.protocol.HttpContext;
87
import org.apache.http.protocol.HttpContext;
86
87
import org.apache.jmeter.protocol.http.control.AuthManager;
88
import org.apache.jmeter.protocol.http.control.AuthManager;
88
import org.apache.jmeter.protocol.http.control.Authorization;
89
import org.apache.jmeter.protocol.http.control.Authorization;
89
import org.apache.jmeter.protocol.http.control.CacheManager;
90
import org.apache.jmeter.protocol.http.control.CacheManager;
Lines 247-253 Link Here
247
                res.setQueryString(putBody);
248
                res.setQueryString(putBody);
248
            }
249
            }
249
            HttpResponse httpResponse = httpClient.execute(httpRequest, localContext); // perform the sample
250
            HttpResponse httpResponse = httpClient.execute(httpRequest, localContext); // perform the sample
250
251
            
252
            // Metrics to get raw size of response
253
            final HttpConnectionMetrics metrics = ((AbstractClientConnAdapter) localContext
254
                        .getAttribute(ExecutionContext.HTTP_CONNECTION)).getMetrics();
255
            
251
            // Needs to be done after execute to pick up all the headers
256
            // Needs to be done after execute to pick up all the headers
252
            res.setRequestHeaders(getConnectionHeaders((HttpRequest) localContext.getAttribute(ExecutionContext.HTTP_REQUEST)));
257
            res.setRequestHeaders(getConnectionHeaders((HttpRequest) localContext.getAttribute(ExecutionContext.HTTP_REQUEST)));
253
258
Lines 283-295 Link Here
283
            }
288
            }
284
289
285
            // record some sizes to allow HTTPSampleResult.getBytes() with different options
290
            // record some sizes to allow HTTPSampleResult.getBytes() with different options
286
            res.setContentLength((int) entity.getContentLength());
287
            res.setHeadersSize(res.getResponseHeaders().length() // condensed length
291
            res.setHeadersSize(res.getResponseHeaders().length() // condensed length
288
                    +httpResponse.getAllHeaders().length+1 // Add \r for each header and initial header
292
                    +httpResponse.getAllHeaders().length+1 // Add \r for each header and initial header
289
                    +2); // final \r\n before data
293
                    +2); // final \r\n before data
294
            // response data size = raw size (i.e. gzip or chunked or plain response) minus headers size
295
            res.setBodySize((int) metrics.getReceivedBytesCount() - res.getHeadersSize());
290
            if (log.isDebugEnabled()) {
296
            if (log.isDebugEnabled()) {
291
                log.debug("ResponseHeadersSize=" + res.getHeadersSize() + " Content-Length=" + res.getContentLength()
297
                log.debug("Response: headersSize=" + res.getHeadersSize() + " bodySize=" + res.getBodySize()
292
                        + " Total=" + (res.getHeadersSize() + res.getContentLength()));
298
                        + " Total=" + metrics.getReceivedBytesCount());
293
            }
299
            }
294
            
300
            
295
            // If we redirected automatically, the URL may have changed
301
            // If we redirected automatically, the URL may have changed

Return to bug 43363