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

(-)src/components/org/apache/jmeter/visualizers/SamplerResultTab.java (-73 / +23 lines)
Lines 38-44 Link Here
38
import javax.swing.JSplitPane;
38
import javax.swing.JSplitPane;
39
import javax.swing.JTabbedPane;
39
import javax.swing.JTabbedPane;
40
import javax.swing.JTable;
40
import javax.swing.JTable;
41
import javax.swing.JTextArea;
42
import javax.swing.JTextPane;
41
import javax.swing.JTextPane;
43
import javax.swing.table.TableCellRenderer;
42
import javax.swing.table.TableCellRenderer;
44
import javax.swing.table.TableColumn;
43
import javax.swing.table.TableColumn;
Lines 56-61 Link Here
56
import org.apache.jorphan.gui.RendererUtils;
55
import org.apache.jorphan.gui.RendererUtils;
57
import org.apache.jorphan.reflect.Functor;
56
import org.apache.jorphan.reflect.Functor;
58
57
58
/**
59
 * Right side in View Results Tree
60
 *
61
 */
59
public abstract class SamplerResultTab implements ResultRenderer {
62
public abstract class SamplerResultTab implements ResultRenderer {
60
63
61
    // N.B. these are not multi-threaded, so don't make it static
64
    // N.B. these are not multi-threaded, so don't make it static
Lines 70-75 Link Here
70
    public static final Color REDIRECT_COLOR = Color.green;
73
    public static final Color REDIRECT_COLOR = Color.green;
71
74
72
    protected static final String TEXT_COMMAND = "text"; // $NON-NLS-1$
75
    protected static final String TEXT_COMMAND = "text"; // $NON-NLS-1$
76
    
77
    protected static final String REQUEST_VIEW_COMMAND = "change_request_view"; // $NON-NLS-1$
73
78
74
    private static final String STYLE_SERVER_ERROR = "ServerError"; // $NON-NLS-1$
79
    private static final String STYLE_SERVER_ERROR = "ServerError"; // $NON-NLS-1$
75
80
Lines 85-93 Link Here
85
90
86
    private JLabel imageLabel;
91
    private JLabel imageLabel;
87
92
88
    private JPanel requestPane;
93
    private RequestPanel requestPanel; /** request pane content */
89
90
    private JTextArea sampleDataField; /** request pane content */
91
94
92
    protected JTabbedPane rightSide; /** holds the tabbed panes */
95
    protected JTabbedPane rightSide; /** holds the tabbed panes */
93
96
Lines 186-198 Link Here
186
189
187
    public void clearData() {
190
    public void clearData() {
188
        results.setText("");// Response Data // $NON-NLS-1$
191
        results.setText("");// Response Data // $NON-NLS-1$
189
        sampleDataField.setText("");// Request Data // $NON-NLS-1$
192
        requestPanel.clearData();// Request Data // $NON-NLS-1$
190
    }
193
    }
191
194
192
    public void init() {
195
    public void init() {
193
        rightSide.addTab(JMeterUtils.getResString("view_results_tab_sampler"), createResponseMetadataPanel()); // $NON-NLS-1$
196
        rightSide.addTab(JMeterUtils.getResString("view_results_tab_sampler"), createResponseMetadataPanel()); // $NON-NLS-1$
194
        // Create the panels for the other tabs
197
        // Create the panels for the other tabs
195
        requestPane = createRequestPanel();
198
        requestPanel = new RequestPanel();
196
        resultsPane = createResponseDataPanel();
199
        resultsPane = createResponseDataPanel();
197
    }
200
    }
198
201
Lines 200-228 Link Here
200
    public void setupTabPane() {
203
    public void setupTabPane() {
201
        StyledDocument statsDoc = stats.getStyledDocument();
204
        StyledDocument statsDoc = stats.getStyledDocument();
202
        try {
205
        try {
206
            // Clear data before display a new
203
            statsDoc.remove(0, statsDoc.getLength());
207
            statsDoc.remove(0, statsDoc.getLength());
204
            sampleDataField.setText(""); // $NON-NLS-1$
208
            requestPanel.clearData();
205
            results.setText(""); // $NON-NLS-1$
209
            results.setText(""); // $NON-NLS-1$
206
            if (userObject instanceof SampleResult) {
210
            if (userObject instanceof SampleResult) {
207
                sampleResult = (SampleResult) userObject;
211
                sampleResult = (SampleResult) userObject;
208
                // We are displaying a SampleResult
212
                // We are displaying a SampleResult
209
                setupTabPaneForSampleResult();
213
                setupTabPaneForSampleResult();
210
214
                requestPanel.setSamplerResult(sampleResult);                
211
                // load time label
212
                String sd = sampleResult.getSamplerData();
213
                if (sd != null) {
214
                    String rh = sampleResult.getRequestHeaders();
215
                    if (rh != null) {
216
                        StringBuilder sb = new StringBuilder(sd.length() + rh.length() + 20);
217
                        sb.append(sd);
218
                        sb.append("\n"); //$NON-NLS-1$
219
                        sb.append(JMeterUtils.getResString("view_results_request_headers")); //$NON-NLS-1$
220
                        sb.append("\n"); //$NON-NLS-1$
221
                        sb.append(rh);
222
                        sd = sb.toString();
223
                    }
224
                    sampleDataField.setText(sd);
225
                }
226
215
227
                final String samplerClass = sampleResult.getClass().getName();
216
                final String samplerClass = sampleResult.getClass().getName();
228
                String typeResult = samplerClass.substring(1 + samplerClass.lastIndexOf('.'));
217
                String typeResult = samplerClass.substring(1 + samplerClass.lastIndexOf('.'));
Lines 284-302 Link Here
284
                // Tabbed results      
273
                // Tabbed results      
285
                resultModel.clearData(); // clear results table before filling
274
                resultModel.clearData(); // clear results table before filling
286
                // fill table
275
                // fill table
287
                resultModel.addRow(new RowResult(getParsedLabel("view_results_thread_name"), sampleResult.getThreadName())); //$NON-NLS-1$
276
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_thread_name"), sampleResult.getThreadName())); //$NON-NLS-1$
288
                resultModel.addRow(new RowResult(getParsedLabel("view_results_sample_start"), startTime)); //$NON-NLS-1$
277
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_sample_start"), startTime)); //$NON-NLS-1$
289
                resultModel.addRow(new RowResult(getParsedLabel("view_results_load_time"), sampleResult.getTime())); //$NON-NLS-1$
278
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_load_time"), sampleResult.getTime())); //$NON-NLS-1$
290
                resultModel.addRow(new RowResult(getParsedLabel("view_results_latency"), sampleResult.getLatency())); //$NON-NLS-1$
279
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_latency"), sampleResult.getLatency())); //$NON-NLS-1$
291
                resultModel.addRow(new RowResult(getParsedLabel("view_results_size_in_bytes"), sampleResult.getBytes())); //$NON-NLS-1$
280
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_size_in_bytes"), sampleResult.getBytes())); //$NON-NLS-1$
292
                resultModel.addRow(new RowResult(getParsedLabel("view_results_sample_count"), sampleResult.getSampleCount())); //$NON-NLS-1$
281
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_sample_count"), sampleResult.getSampleCount())); //$NON-NLS-1$
293
                resultModel.addRow(new RowResult(getParsedLabel("view_results_error_count"), sampleResult.getErrorCount())); //$NON-NLS-1$
282
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_error_count"), sampleResult.getErrorCount())); //$NON-NLS-1$
294
                resultModel.addRow(new RowResult(getParsedLabel("view_results_response_code"), responseCode)); //$NON-NLS-1$
283
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_response_code"), responseCode)); //$NON-NLS-1$
295
                resultModel.addRow(new RowResult(getParsedLabel("view_results_response_message"), responseMsgStr)); //$NON-NLS-1$
284
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_response_message"), responseMsgStr)); //$NON-NLS-1$
296
                
285
                
297
                resHeadersModel.clearData(); // clear response table before filling
286
                resHeadersModel.clearData(); // clear response table before filling
298
                // Parsed response headers
287
                // Parsed response headers
299
                LinkedHashMap<String, String> lhm = parseResponseHeaders(sampleResult.getResponseHeaders());
288
                LinkedHashMap<String, String> lhm = JMeterUtils.parseHeaders(sampleResult.getResponseHeaders());
300
                Set<String> keySet = lhm.keySet();
289
                Set<String> keySet = lhm.keySet();
301
                for (String key : keySet) {
290
                for (String key : keySet) {
302
                    resHeadersModel.addRow(new RowResult(key, lhm.get(key)));
291
                    resHeadersModel.addRow(new RowResult(key, lhm.get(key)));
Lines 340-346 Link Here
340
        rightSide.setTitleAt(0, JMeterUtils.getResString("view_results_tab_sampler")); //$NON-NLS-1$
329
        rightSide.setTitleAt(0, JMeterUtils.getResString("view_results_tab_sampler")); //$NON-NLS-1$
341
        // Add the other tabs if not present
330
        // Add the other tabs if not present
342
        if(rightSide.indexOfTab(JMeterUtils.getResString("view_results_tab_request")) < 0) { // $NON-NLS-1$
331
        if(rightSide.indexOfTab(JMeterUtils.getResString("view_results_tab_request")) < 0) { // $NON-NLS-1$
343
            rightSide.addTab(JMeterUtils.getResString("view_results_tab_request"), requestPane); // $NON-NLS-1$
332
            rightSide.addTab(JMeterUtils.getResString("view_results_tab_request"), requestPanel.getPanel()); // $NON-NLS-1$
344
        }
333
        }
345
        if(rightSide.indexOfTab(JMeterUtils.getResString("view_results_tab_response")) < 0) { // $NON-NLS-1$
334
        if(rightSide.indexOfTab(JMeterUtils.getResString("view_results_tab_response")) < 0) { // $NON-NLS-1$
346
            rightSide.addTab(JMeterUtils.getResString("view_results_tab_response"), resultsPane); // $NON-NLS-1$
335
            rightSide.addTab(JMeterUtils.getResString("view_results_tab_response"), resultsPane); // $NON-NLS-1$
Lines 437-453 Link Here
437
        return panel;
426
        return panel;
438
    }
427
    }
439
428
440
    private JPanel createRequestPanel() {
441
        sampleDataField = new JTextArea();
442
        sampleDataField.setEditable(false);
443
        sampleDataField.setLineWrap(true);
444
        sampleDataField.setWrapStyleWord(true);
445
446
        JPanel pane = new JPanel(new BorderLayout(0, 5));
447
        pane.add(GuiUtils.makeScrollPane(sampleDataField));
448
        return pane;
449
    }
450
451
    private JPanel createResponseDataPanel() {
429
    private JPanel createResponseDataPanel() {
452
        results = new JEditorPane();
430
        results = new JEditorPane();
453
        results.setEditable(false);
431
        results.setEditable(false);
Lines 499-537 Link Here
499
        this.backGround = backGround;
477
        this.backGround = backGround;
500
    }
478
    }
501
    
479
    
502
    /**
503
     * To get I18N label from properties file
504
     * @param key in messages.properties
505
     * @return I18N label without (if exists) last colon ':' and spaces
506
     */
507
    private String getParsedLabel(String key) {
508
        String value = JMeterUtils.getResString(key);
509
        return value.replaceFirst("(?m)\\s*?:\\s*$", ""); // $NON-NLS-1$ $NON-NLS-2$
510
    }
511
    
512
    private void setFirstColumnPreferredSize(JTable table) {
480
    private void setFirstColumnPreferredSize(JTable table) {
513
        TableColumn column = table.getColumnModel().getColumn(0);
481
        TableColumn column = table.getColumnModel().getColumn(0);
514
        column.setMaxWidth(300);
482
        column.setMaxWidth(300);
515
        column.setPreferredWidth(180);
483
        column.setPreferredWidth(180);
516
    }
484
    }
517
518
    /**
519
     * Split line into name/value pairs and remove colon ':'
520
     */
521
    private LinkedHashMap<String, String> parseResponseHeaders(String responseHeaders) {
522
        LinkedHashMap<String, String> linkedHeaders = new LinkedHashMap<String, String>();
523
        String[] list = responseHeaders.split(NL);
524
        for (String header : list) {
525
            int colon = header.indexOf(':'); // $NON-NLS-1$
526
            if (colon <= 0) {
527
                linkedHeaders.put(header, ""); // Empty value // $NON-NLS-1$
528
            } else {
529
                linkedHeaders.put(header.substring(0, colon).trim(), header
530
                        .substring(colon + 1).trim());
531
            }
532
        }
533
        return linkedHeaders;
534
    }
535
    
485
    
536
    /**
486
    /**
537
     * For model table
487
     * For model table
(-)src/core/org/apache/jmeter/resources/messages.properties (+14 lines)
Lines 980-985 Link Here
980
view_results_table_fields_value=Value
980
view_results_table_fields_value=Value
981
view_results_table_headers_key=Response header
981
view_results_table_headers_key=Response header
982
view_results_table_headers_value=Value
982
view_results_table_headers_value=Value
983
view_results_table_request_headers_key=Request header
984
view_results_table_request_headers_value=Value
985
view_results_table_request_http_cookie=Cookie
986
view_results_table_request_http_host=Host
987
view_results_table_request_http_method=Method
988
view_results_table_request_http_nohttp=No HTTP Sample
989
view_results_table_request_http_path=Path
990
view_results_table_request_http_port=Port
991
view_results_table_request_http_protocol=Protocol
992
view_results_table_request_raw_nodata=No data to display
993
view_results_table_request_params_key=Parameter name
994
view_results_table_request_params_value=Value
995
view_results_table_request_tab_http=HTTP
996
view_results_table_request_tab_raw=Raw
983
view_results_table_result_tab_parsed=Parsed
997
view_results_table_result_tab_parsed=Parsed
984
view_results_table_result_tab_raw=Raw
998
view_results_table_result_tab_raw=Raw
985
view_results_thread_name=Thread Name: 
999
view_results_thread_name=Thread Name: 

Return to bug 37156