You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by pm...@apache.org on 2016/01/14 14:35:04 UTC

svn commit: r1724605 - in /jmeter/trunk: src/components/org/apache/jmeter/visualizers/ src/protocol/http/org/apache/jmeter/protocol/http/visualizers/ xdocs/

Author: pmouawad
Date: Thu Jan 14 13:35:03 2016
New Revision: 1724605

URL: http://svn.apache.org/viewvc?rev=1724605&view=rev
Log:
Bug 58849 - View Results Tree : Add a search panel to the request http view to be able to search in the parameters table
#resolve #73
Bugzilla Id: 58849

Modified:
    jmeter/trunk/src/components/org/apache/jmeter/visualizers/SamplerResultTab.java
    jmeter/trunk/src/components/org/apache/jmeter/visualizers/SearchTextExtension.java
    jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/visualizers/RequestViewHTTP.java
    jmeter/trunk/xdocs/changes.xml

Modified: jmeter/trunk/src/components/org/apache/jmeter/visualizers/SamplerResultTab.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/components/org/apache/jmeter/visualizers/SamplerResultTab.java?rev=1724605&r1=1724604&r2=1724605&view=diff
==============================================================================
--- jmeter/trunk/src/components/org/apache/jmeter/visualizers/SamplerResultTab.java (original)
+++ jmeter/trunk/src/components/org/apache/jmeter/visualizers/SamplerResultTab.java Thu Jan 14 13:35:03 2016
@@ -87,15 +87,22 @@ public abstract class SamplerResultTab i
 
     private JTextPane stats;
 
-    private JPanel resultsPane; /** Response Data pane */
-    protected JScrollPane resultsScrollPane; /** Contains results; contained in resultsPane */
-    protected JEditorPane results; /** Response Data shown here */
+    /** Response Data pane */
+    private JPanel resultsPane;
+    
+    /** Contains results; contained in resultsPane */
+    protected JScrollPane resultsScrollPane;
+    
+    /** Response Data shown here */
+    protected JEditorPane results;
 
     private JLabel imageLabel;
 
-    private RequestPanel requestPanel; /** request pane content */
+    /** request pane content */
+    private RequestPanel requestPanel;
 
-    protected JTabbedPane rightSide; /** holds the tabbed panes */
+    /** holds the tabbed panes */
+    protected JTabbedPane rightSide;
 
     private int lastSelectedTab;
 

Modified: jmeter/trunk/src/components/org/apache/jmeter/visualizers/SearchTextExtension.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/components/org/apache/jmeter/visualizers/SearchTextExtension.java?rev=1724605&r1=1724604&r2=1724605&view=diff
==============================================================================
--- jmeter/trunk/src/components/org/apache/jmeter/visualizers/SearchTextExtension.java (original)
+++ jmeter/trunk/src/components/org/apache/jmeter/visualizers/SearchTextExtension.java Thu Jan 14 13:35:03 2016
@@ -65,48 +65,34 @@ public class SearchTextExtension impleme
 
     private static final String SEARCH_TEXT_COMMAND = "search_text"; // $NON-NLS-1$
 
-    private static volatile int LAST_POSITION_DEFAULT = 0;
-
-    private int lastPosition = LAST_POSITION_DEFAULT;
-
-    private static final Color HILIT_COLOR = Color.LIGHT_GRAY;
-
-    private Highlighter selection;
-
-    private Highlighter.HighlightPainter painter;
-
     private JLabel label;
 
     private JButton findButton;
 
     private JTextField textToFindField;
 
-    private  JCheckBox caseChkBox;
+    private JCheckBox caseChkBox;
 
     private JCheckBox regexpChkBox;
 
-    private String lastTextTofind;
-
-    private boolean newSearch = false;
-
-    private JEditorPane results;
-
     private JPanel searchPanel;
+    
+    private String lastTextTofind;
+    
+    private ISearchTextExtensionProvider searchProvider;
 
-
-    public void init(JPanel resultsPane) {
-    }
+    public void init(JPanel resultsPane) {}
 
     public void setResults(JEditorPane results) {
-        if (this.results != null) {
-            newSearch = true;
-            resetTextToFind();
-        }
-        this.results = results;
-        // prepare highlighter to show text find with search command
-        selection = new DefaultHighlighter();
-        painter = new DefaultHighlighter.DefaultHighlightPainter(HILIT_COLOR);
-        results.setHighlighter(selection);
+        setSearchProvider(new JEditorPaneSearchProvider(results));
+    }
+    
+    public void setSearchProvider(ISearchTextExtensionProvider searchProvider) {
+        if (this.searchProvider != null) {
+            this.searchProvider.resetTextToFind();
+        }
+        
+        this.searchProvider = searchProvider;
     }
 
     /**
@@ -114,55 +100,32 @@ public class SearchTextExtension impleme
      */
     private void executeAndShowTextFind() {
         String textToFind = textToFindField.getText();
-        if (results != null && results.getText().length() > 0
-                && textToFind.length() > 0) {
-
+        if (this.searchProvider != null) {
             // new search?
             if (lastTextTofind != null && !lastTextTofind.equals(textToFind)) {
-                lastPosition = LAST_POSITION_DEFAULT;
+                searchProvider.resetTextToFind();
             }
-
-            if (log.isDebugEnabled()) {
-                log.debug("lastPosition=" + lastPosition);
-            }
-            Matcher matcher = null;
+            
             try {
-                Pattern pattern = createPattern(textToFind);
-                Document contentDoc = results.getDocument();
-                String body = contentDoc.getText(lastPosition,
-                        (contentDoc.getLength() - lastPosition));
-                matcher = pattern.matcher(body);
-
-                if ((matcher != null) && (matcher.find())) {
-                    selection.removeAllHighlights();
-                    selection.addHighlight(lastPosition + matcher.start(),
-                            lastPosition + matcher.end(), painter);
-                    results.setCaretPosition(lastPosition + matcher.end());
-
-                    // save search position
-                    lastPosition = lastPosition + matcher.end();
-                    findButton.setText(JMeterUtils
-                            .getResString("search_text_button_next"));// $NON-NLS-1$
+                Pattern pattern = createPattern(textToFindField.getText());
+                boolean found = searchProvider.executeAndShowTextFind(pattern);
+                if(found) {
+                    findButton.setText(JMeterUtils.getResString("search_text_button_next"));// $NON-NLS-1$
                     lastTextTofind = textToFind;
-                    newSearch = true;
-                } else {
-                    // Display not found message and reset search
+                }
+                else {
+                    findButton.setText(JMeterUtils.getResString("search_text_button_find"));// $NON-NLS-1$
+                    // Display not found message
                     JOptionPane.showMessageDialog(null, JMeterUtils
                             .getResString("search_text_msg_not_found"),// $NON-NLS-1$
                             JMeterUtils.getResString("search_text_title_not_found"), // $NON-NLS-1$
                             JOptionPane.INFORMATION_MESSAGE);
-                    lastPosition = LAST_POSITION_DEFAULT;
-                    findButton.setText(JMeterUtils
-                            .getResString("search_text_button_find"));// $NON-NLS-1$
-                    results.setCaretPosition(0);
                 }
             } catch (PatternSyntaxException pse) {
                 JOptionPane.showMessageDialog(null, 
                         pse.toString(),// $NON-NLS-1$
                         JMeterUtils.getResString("error_title"), // $NON-NLS-1$
                         JOptionPane.WARNING_MESSAGE);
-            } catch (BadLocationException ble) {
-                log.error("Location exception in text find", ble);// $NON-NLS-1$
             }
         }
     }
@@ -217,7 +180,7 @@ public class SearchTextExtension impleme
         return searchPanel;
     }
 
-    JPanel createSearchTextExtensionPane() {
+    public JPanel createSearchTextExtensionPane() {
         JPanel pane = new JPanel();
         pane.setLayout(new BoxLayout(pane, BoxLayout.X_AXIS));
         pane.add(createSearchTextPanel());
@@ -228,8 +191,7 @@ public class SearchTextExtension impleme
      * Display the response as text or as rendered HTML. Change the text on the
      * button appropriate to the current display.
      *
-     * @param e
-     *            the ActionEvent being processed
+     * @param e the ActionEvent being processed
      */
     @Override
     public void actionPerformed(ActionEvent e) {
@@ -267,26 +229,24 @@ public class SearchTextExtension impleme
         resetTextToFind();
     }
 
-    void resetTextToFind() {
-        if (newSearch) {
-            log.debug("reset pass");
-            // Reset search
-            lastPosition = LAST_POSITION_DEFAULT;
-            lastTextTofind = null;
-            findButton.setText(JMeterUtils
-                    .getResString("search_text_button_find"));// $NON-NLS-1$
-            selection.removeAllHighlights();
-            results.setCaretPosition(0);
-            newSearch = false;
+    public void resetTextToFind() {
+        if (this.searchProvider != null) {
+            searchProvider.resetTextToFind();
         }
+        lastTextTofind = null;
+        findButton.setText(JMeterUtils.getResString("search_text_button_find"));// $NON-NLS-1$
     }
 
     private Pattern createPattern(String textToFind) {
-        // desactivate or not specials regexp char
-        String textToFindQ = Pattern.quote(textToFind);
+        String textToFindQ = null;
         if (regexpChkBox.isSelected()) {
             textToFindQ = textToFind;
         }
+        else {
+            // desactivate or not specials regexp char
+            textToFindQ = Pattern.quote(textToFind);
+        }
+        
         Pattern pattern = null;
         if (caseChkBox.isSelected()) {
             pattern = Pattern.compile(textToFindQ);
@@ -295,4 +255,93 @@ public class SearchTextExtension impleme
         }
         return pattern;
     }
+    
+    /**
+     * Search provider definition
+     * Allow the search extension to search on any component
+     */
+    public static interface ISearchTextExtensionProvider {
+        
+        /**
+         * reset the provider
+         */
+        void resetTextToFind();
+        
+        /**
+         * Launch find text engine on target component
+         * @return true if there was a match, false otherwise
+         */
+        boolean executeAndShowTextFind(Pattern pattern);
+    }
+    
+    /**
+     * JEditorPane search provider
+     * Should probably be moved in its on file
+     */
+    private static class JEditorPaneSearchProvider implements ISearchTextExtensionProvider {
+
+        private static volatile int LAST_POSITION_DEFAULT = 0;
+        private static final Color HILIT_COLOR = Color.LIGHT_GRAY;
+        private JEditorPane results;
+        private Highlighter selection;
+        private Highlighter.HighlightPainter painter;
+        private int lastPosition = LAST_POSITION_DEFAULT;
+        
+        public JEditorPaneSearchProvider(JEditorPane results) {
+            this.results = results;
+            
+            // prepare highlighter to show text find with search command
+            selection = new DefaultHighlighter();
+            painter = new DefaultHighlighter.DefaultHighlightPainter(HILIT_COLOR);
+            results.setHighlighter(selection);
+        }
+
+        @Override
+        public void resetTextToFind() {
+            // Reset search
+            lastPosition = LAST_POSITION_DEFAULT;
+            selection.removeAllHighlights();
+            results.setCaretPosition(0);
+        }
+
+        @Override
+        public boolean executeAndShowTextFind(Pattern pattern) {
+            boolean found = false;
+            if (results != null && results.getText().length() > 0
+                    && pattern != null) {
+
+                if (log.isDebugEnabled()) {
+                    log.debug("lastPosition=" + lastPosition);
+                }
+                
+                Matcher matcher = null;
+                try {
+                    Document contentDoc = results.getDocument();
+                    String body = contentDoc.getText(lastPosition, (contentDoc.getLength() - lastPosition));
+                    matcher = pattern.matcher(body);
+
+                    if ((matcher != null) && (matcher.find())) {
+                        selection.removeAllHighlights();
+                        selection.addHighlight(lastPosition + matcher.start(),
+                                lastPosition + matcher.end(), painter);
+                        results.setCaretPosition(lastPosition + matcher.end());
+
+                        // save search position
+                        lastPosition = lastPosition + matcher.end();
+                        found = true;
+                    }
+                    else {
+                        // reset search
+                        lastPosition = LAST_POSITION_DEFAULT;
+                        results.setCaretPosition(0);
+                    }
+                } catch (BadLocationException ble) {
+                    log.error("Location exception in text find", ble);// $NON-NLS-1$
+                }
+            }
+            
+            return found;
+        }
+        
+    }
 }

Modified: jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/visualizers/RequestViewHTTP.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/visualizers/RequestViewHTTP.java?rev=1724605&r1=1724604&r2=1724605&view=diff
==============================================================================
--- jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/visualizers/RequestViewHTTP.java (original)
+++ jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/visualizers/RequestViewHTTP.java Thu Jan 14 13:35:03 2016
@@ -28,6 +28,8 @@ import java.util.LinkedHashMap;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import javax.swing.JPanel;
 import javax.swing.JSplitPane;
@@ -41,6 +43,8 @@ import org.apache.jmeter.protocol.http.s
 import org.apache.jmeter.util.JMeterUtils;
 import org.apache.jmeter.visualizers.RequestView;
 import org.apache.jmeter.visualizers.SamplerResultTab.RowResult;
+import org.apache.jmeter.visualizers.SearchTextExtension;
+import org.apache.jmeter.visualizers.SearchTextExtension.ISearchTextExtensionProvider;
 import org.apache.jorphan.gui.GuiUtils;
 import org.apache.jorphan.gui.ObjectTableModel;
 import org.apache.jorphan.gui.RendererUtils;
@@ -106,6 +110,8 @@ public class RequestViewHTTP implements
             null, // Value
     };
 
+    private SearchTextExtension searchTextExtension;
+
     /**
      * Pane to view HTTP request sample in view results tree
      */
@@ -140,6 +146,13 @@ public class RequestViewHTTP implements
     public void init() {
         paneParsed = new JPanel(new BorderLayout(0, 5));
         paneParsed.add(createRequestPane());
+        this.searchTextExtension = new SearchTextExtension();
+        this.searchTextExtension.init(paneParsed);
+        JPanel searchPanel = this.searchTextExtension.createSearchTextExtensionPane();
+        searchPanel.setBorder(null);
+        this.searchTextExtension.setSearchProvider(new RequestViewHttpSearchProvider());
+        searchPanel.setVisible(true);
+        paneParsed.add(searchPanel, BorderLayout.PAGE_END);
     }
 
     /* (non-Javadoc)
@@ -158,6 +171,7 @@ public class RequestViewHTTP implements
     @Override
     public void setSamplerResult(Object objectResult) {
 
+        this.searchTextExtension.resetTextToFind();
         if (objectResult instanceof HTTPSampleResult) {
             HTTPSampleResult sampleResult = (HTTPSampleResult) objectResult;
 
@@ -367,4 +381,50 @@ public class RequestViewHTTP implements
     public String getLabel() {
         return JMeterUtils.getResString(KEY_LABEL);
     }
+    
+    /**
+     * Search implementation for the http parameter table
+     */
+    private class RequestViewHttpSearchProvider implements ISearchTextExtensionProvider {
+
+        private int lastPosition = -1;
+        
+        @Override
+        public void resetTextToFind() {
+            lastPosition = -1;
+            if(tableParams != null) {
+                tableParams.clearSelection();
+            }
+        }
+
+        @Override
+        public boolean executeAndShowTextFind(Pattern pattern) {
+            boolean found =  false;
+            if(tableParams != null) {
+                tableParams.clearSelection();
+                outerloop:
+                for (int i = lastPosition+1; i < tableParams.getRowCount(); i++) {
+                    for (int j = 0; j < COLUMNS_PARAMS.length; j++) {
+                        Object o = tableParams.getModel().getValueAt(i, j);
+                        if(o instanceof String) {
+                            Matcher matcher = pattern.matcher((String) o);
+                            if ((matcher != null) && (matcher.find())) {
+                                found =  true;
+                                tableParams.setRowSelectionInterval(i, i);
+                                tableParams.scrollRectToVisible(tableParams.getCellRect(i, 0, true));
+                                lastPosition = i;
+                                break outerloop;
+                            }
+                        }
+                    }
+                }
+                
+                if(!found) {
+                    resetTextToFind();
+                }
+            }
+            return found;
+        }
+        
+    }
 }

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1724605&r1=1724604&r2=1724605&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml (original)
+++ jmeter/trunk/xdocs/changes.xml Thu Jan 14 13:35:03 2016
@@ -125,6 +125,7 @@ Summary
 <li><bug>58681</bug>GraphiteBackendListener : Don't send data if no sampling occured</li>
 <li><bug>58776</bug>Summariser should display a more readable duration</li>
 <li><bug>58791</bug>Deprecate listeners:Distribution Graph (alpha) and Spline Visualizer</li>
+<li><bug>58849</bug>View Results Tree : Add a search panel to the request http view to be able to search in the parameters table. Contributed by Benoit Wiart (benoit dot wiart at gmail.com)</li>
 </ul>
 
 <h3>Timers, Assertions, Config, Pre- &amp; Post-Processors</h3>