neth 01/08/29 04:44:02
Modified: src/org/apache/jmeter/visualizers
ViewResultsFullVisualizer.java
Log:
Fix NullPointerException which occurs when displaying results for pages without
components (images etc).
Revision Changes Path
1.3 +175 -172
jakarta-jmeter/src/org/apache/jmeter/visualizers/ViewResultsFullVisualizer.java
Index: ViewResultsFullVisualizer.java
===================================================================
RCS file:
/home/cvs/jakarta-jmeter/src/org/apache/jmeter/visualizers/ViewResultsFullVisualizer.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ViewResultsFullVisualizer.java 2001/08/16 23:36:57 1.2
+++ ViewResultsFullVisualizer.java 2001/08/29 11:44:02 1.3
@@ -77,7 +77,7 @@
*
*@author Khor Soon Hin
*@created 2001/07/25
- *@version $Revision: 1.2 $ $Date: 2001/08/16 23:36:57 $
+ *@version $Revision: 1.3 $ $Date: 2001/08/29 11:44:02 $
*/
public class ViewResultsFullVisualizer extends ViewResultsVisualizer implements
TreeSelectionListener, ModelSupported
@@ -111,10 +111,10 @@
}
/**
- * Set the reporter type this visualizer will work with
- *
- * @param model reporter instance
- */
+ * Set the reporter type this visualizer will work with
+ *
+ * @param model reporter instance
+ */
public void setModel(Object model)
{
catClass.debug("Start : setModel1");
@@ -125,8 +125,8 @@
}
/**
- * Initialize this visualizer
- */
+ * Initialize this visualizer
+ */
private void init()
{
catClass.debug("Start : init1");
@@ -150,187 +150,190 @@
}
/**
- * Update the visualizer with new data
- */
+ * Update the visualizer with new data
+ */
public void updateGui()
{
- catClass.debug("Start : updateGui1");
- SampleResult res = null;
- model.next();
- if((res = model.getCurrentSample()) != null)
- {
- DefaultMutableTreeNode currNode = new DefaultMutableTreeNode(res);
- treeModel.insertNodeInto(currNode, root, childIndex++);
- ArrayList arrayList =
(ArrayList)res.getValue(HTTPSamplerFull.RESULT_LIST);
- Iterator iter = arrayList.iterator();
- int leafIndex = 0;
- while(iter.hasNext())
- {
- SampleResult child = (SampleResult)iter.next();
- if(catClass.isDebugEnabled())
- {
- catClass.debug("updateGui1 : child sample result - " + child);
- }
- DefaultMutableTreeNode leafNode =
- new DefaultMutableTreeNode(child);
- treeModel.insertNodeInto(leafNode, currNode, leafIndex++);
- }
- }
- catClass.debug("End : updateGui1");
+ catClass.debug("Start : updateGui1");
+ SampleResult res = null;
+ while((res = model.getCurrentSample()) != null)
+ {
+ DefaultMutableTreeNode currNode = new DefaultMutableTreeNode(res);
+ treeModel.insertNodeInto(currNode, root, childIndex++);
+ ArrayList arrayList = (ArrayList)res.getValue(HTTPSamplerFull.RESULT_LIST);
+ if(arrayList != null)
+ {
+ Iterator iter = arrayList.iterator();
+ int leafIndex = 0;
+ while(iter.hasNext())
+ {
+ SampleResult child = (SampleResult)iter.next();
+ if(catClass.isDebugEnabled())
+ {
+ catClass.debug("updateGui1 : child sample result - " + child);
+ }
+ DefaultMutableTreeNode leafNode =
+ new DefaultMutableTreeNode(child);
+ treeModel.insertNodeInto(leafNode, currNode, leafIndex++);
+ }
+ }
+ model.next();
+ }
+ catClass.debug("End : updateGui1");
}
- /**
- * Clears the visualizer
- */
- public void clear()
- {
+ /**
+ * Clears the visualizer
+ */
+ public void clear()
+ {
catClass.debug("Start : clear1");
int totalChild = root.getChildCount();
if(catClass.isDebugEnabled())
{
catClass.debug("clear1 : total child - " + totalChild);
- }
- for(int i = 0; i < totalChild; i++)
- {
- // the child to be removed will always be 0 'cos as the nodes are
removed
- // the nth node will become (n-1)th
- treeModel.removeNodeFromParent(
- (DefaultMutableTreeNode)root.getChildAt(0));
- }
- resultPanel.removeAll();
- // reset the child index
- childIndex = 0;
- catClass.debug("End : clear1");
- }
+ }
+ for(int i = 0; i < totalChild; i++)
+ {
+ // the child to be removed will always be 0 'cos as the nodes
are removed
+ // the nth node will become (n-1)th
+ treeModel.removeNodeFromParent(
+ (DefaultMutableTreeNode)root.getChildAt(0));
+ }
+ resultPanel.removeAll();
+ // reset the child index
+ childIndex = 0;
+ catClass.debug("End : clear1");
+ }
- /**
- * Returns the description of this visualizer
- *
- * @return description of this visualizer
- */
- public String toString()
- {
- String desc = "Shows the text results of sampling in tree form";
- if(catClass.isDebugEnabled())
- {
+ /**
+ * Returns the description of this visualizer
+ *
+ * @return description of this visualizer
+ */
+ public String toString()
+ {
+ String desc = "Shows the text results of sampling in tree form";
+ if(catClass.isDebugEnabled())
+ {
catClass.debug("toString1 : Returning description - " + desc);
- }
- return desc;
- }
+ }
+ return desc;
+ }
- /**
- * Sets the bottom pane to correspond to the selected node of the top
- * tree
- */
- public void valueChanged(TreeSelectionEvent e)
- {
- catClass.debug("Start : valueChanged1");
- DefaultMutableTreeNode node =
(DefaultMutableTreeNode)jTree.getLastSelectedPathComponent();
- if(catClass.isDebugEnabled())
- {
- catClass.debug("valueChanged : selected node - " + node);
- }
- if(node != null)
- {
- SampleResult res = (SampleResult)node.getUserObject();
+ /**
+ * Sets the bottom pane to correspond to the selected node of the top
+ * tree
+ */
+ public void valueChanged(TreeSelectionEvent e)
+ {
+ catClass.debug("Start : valueChanged1");
+ DefaultMutableTreeNode node =
(DefaultMutableTreeNode)jTree.getLastSelectedPathComponent();
if(catClass.isDebugEnabled())
{
- catClass.debug("valueChanged1 : sample result - " + res);
+ catClass.debug("valueChanged : selected node - " + node);
}
- if(res != null)
+ if(node != null)
{
- resultPanel.removeAll();
- // load time label
- JLabel loadTime = new JLabel();
- loadTime.setText("Load time : " + res.getTime());
- gbc.gridx = 0;
- gbc.gridy = 0;
- // keep all of the labels to the left
- gbc.anchor = GridBagConstraints.WEST;
- // with weightx != 0.0, components won't clump in the center
- gbc.weightx = 1.0;
- // pad a bit from the display area
- gbc.insets = new Insets(0, 10, 0, 0);
- gridBag.setConstraints(loadTime, gbc);
- resultPanel.add(loadTime);
- // response code label
- JLabel httpResponseCode = new JLabel();
- String responseCode = (String)res.getValue(Sampler.RESPONSE_CODE);
- int responseLevel = 0;
- if(responseCode != null)
- {
- try
- {
- responseLevel = Integer.parseInt(responseCode)/100;
- }
- catch(NumberFormatException numberFormatException)
- {
- // no need to change the foreground color
- }
- }
- switch(responseLevel)
- {
- case 3 : httpResponseCode.setForeground(REDIRECT_COLOR);
- case 4 : httpResponseCode.setForeground(CLIENT_ERROR_COLOR);
- case 5 : httpResponseCode.setForeground(SERVER_ERROR_COLOR);
- }
- httpResponseCode.setText("HTTP response code : " +
- responseCode);
- gbc.gridx = 0;
- gbc.gridy = 1;
- gridBag.setConstraints(httpResponseCode, gbc);
- resultPanel.add(httpResponseCode);
- // response message label
- JLabel httpResponseMsg = new JLabel();
- httpResponseMsg.setText("HTTP response message : " +
- (String)res.getValue(Sampler.RESPONSE_MESSAGE));
- gbc.gridx = 0;
- gbc.gridy = 2;
- gridBag.setConstraints(httpResponseMsg, gbc);
- resultPanel.add(httpResponseMsg);
-
- // get the text response and image icon
- // to determine which is NOT null
- String response = (String)res.getValue(SampleResult.TEXT_RESPONSE);
- ImageIcon icon = (ImageIcon)res.getValue(HTTPSamplerFull.IMAGE);
- if(catClass.isDebugEnabled())
- {
- if(response != null)
- {
- // only first 5 chars are printed 'cos for binary files
- // it may be quite long to print the whole content,
- // moreover they contain non-printable chars
- catClass.debug("valueChanged1 : http response - " +
- response.substring(0,5));
- }
- else
- {
- catClass.debug("valueChanged1 : http response - " +
response);
- }
- }
- if(response != null)
- {
- JTextArea textArea = new JTextArea();
- textArea.setText(response);
- gbc.gridx = 0;
- gbc.gridy = 4;
- gridBag.setConstraints(textArea, gbc);
- resultPanel.add(textArea);
- }
- else if(icon != null)
- {
- JLabel image = new JLabel();
- image.setIcon(icon);
- gbc.gridx = 0;
- gbc.gridy = 4;
- gridBag.setConstraints(image, gbc);
- resultPanel.add(image);
- }
- resultPanel.repaint();
- resultPanel.revalidate();
+ SampleResult res = (SampleResult)node.getUserObject();
+ if(catClass.isDebugEnabled())
+ {
+ catClass.debug("valueChanged1 : sample result - " +
res);
+ }
+ if(res != null)
+ {
+ resultPanel.removeAll();
+ // load time label
+ JLabel loadTime = new JLabel();
+ loadTime.setText("Load time : " + res.getTime());
+ gbc.gridx = 0;
+ gbc.gridy = 0;
+ // keep all of the labels to the left
+ gbc.anchor = GridBagConstraints.WEST;
+ // with weightx != 0.0, components won't clump in the
center
+ gbc.weightx = 1.0;
+ // pad a bit from the display area
+ gbc.insets = new Insets(0, 10, 0, 0);
+ gridBag.setConstraints(loadTime, gbc);
+ resultPanel.add(loadTime);
+ // response code label
+ JLabel httpResponseCode = new JLabel();
+ String responseCode =
(String)res.getValue(Sampler.RESPONSE_CODE);
+ int responseLevel = 0;
+ if(responseCode != null)
+ {
+ try
+ {
+ responseLevel =
Integer.parseInt(responseCode)/100;
+ }
+ catch(NumberFormatException
numberFormatException)
+ {
+ // no need to change the foreground
color
+ }
+ }
+ switch(responseLevel)
+ {
+ case 3 :
httpResponseCode.setForeground(REDIRECT_COLOR);
+ case 4 :
httpResponseCode.setForeground(CLIENT_ERROR_COLOR);
+ case 5 :
httpResponseCode.setForeground(SERVER_ERROR_COLOR);
+ }
+ httpResponseCode.setText("HTTP response code : " +
+ responseCode);
+ gbc.gridx = 0;
+ gbc.gridy = 1;
+ gridBag.setConstraints(httpResponseCode, gbc);
+ resultPanel.add(httpResponseCode);
+ // response message label
+ JLabel httpResponseMsg = new JLabel();
+ httpResponseMsg.setText("HTTP response message : " +
+
(String)res.getValue(Sampler.RESPONSE_MESSAGE));
+ gbc.gridx = 0;
+ gbc.gridy = 2;
+ gridBag.setConstraints(httpResponseMsg, gbc);
+ resultPanel.add(httpResponseMsg);
+
+ // get the text response and image icon
+ // to determine which is NOT null
+ String response =
(String)res.getValue(SampleResult.TEXT_RESPONSE);
+ ImageIcon icon =
(ImageIcon)res.getValue(HTTPSamplerFull.IMAGE);
+ if(catClass.isDebugEnabled())
+ {
+ if(response != null)
+ {
+ // only first 5 chars are printed 'cos
for binary files
+ // it may be quite long to print the
whole content,
+ // moreover they contain non-printable
chars
+ catClass.debug("valueChanged1 : http
response - " +
+ response.substring(0,5));
+ }
+ else
+ {
+ catClass.debug("valueChanged1 : http
response - " + response);
+ }
+ }
+ if(response != null)
+ {
+ JTextArea textArea = new JTextArea();
+ textArea.setText(response);
+ gbc.gridx = 0;
+ gbc.gridy = 4;
+ gridBag.setConstraints(textArea, gbc);
+ resultPanel.add(textArea);
+ }
+ else if(icon != null)
+ {
+ JLabel image = new JLabel();
+ image.setIcon(icon);
+ gbc.gridx = 0;
+ gbc.gridy = 4;
+ gridBag.setConstraints(image, gbc);
+ resultPanel.add(image);
+ }
+ resultPanel.repaint();
+ resultPanel.revalidate();
+ }
}
- }
- catClass.debug("End : valueChanged1");
- }
+ catClass.debug("End : valueChanged1");
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]