You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jmeter-dev@jakarta.apache.org by se...@apache.org on 2004/02/22 15:49:31 UTC

cvs commit: jakarta-jmeter/src/components/org/apache/jmeter/visualizers ViewResultsFullVisualizer.java

sebb        2004/02/22 06:49:31

  Modified:    src/components/org/apache/jmeter/visualizers
                        ViewResultsFullVisualizer.java
  Log:
  Factor out common code to convert result to string;
  use actual sample encoding instead of utf-8
  use default encoding if all else fails
  
  Revision  Changes    Path
  1.39      +51 -69    jakarta-jmeter/src/components/org/apache/jmeter/visualizers/ViewResultsFullVisualizer.java
  
  Index: ViewResultsFullVisualizer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jmeter/src/components/org/apache/jmeter/visualizers/ViewResultsFullVisualizer.java,v
  retrieving revision 1.38
  retrieving revision 1.39
  diff -u -r1.38 -r1.39
  --- ViewResultsFullVisualizer.java	13 Feb 2004 01:48:46 -0000	1.38
  +++ ViewResultsFullVisualizer.java	22 Feb 2004 14:49:30 -0000	1.39
  @@ -224,6 +224,7 @@
               if (node != null)
               {
                   SampleResult res = (SampleResult) node.getUserObject();
  +                byte[] responseBytes = res.getResponseData();
   
                   if (log.isDebugEnabled())
                   {
  @@ -305,49 +306,20 @@
   						"\nHTTP response headers:\n" + res.getResponseHeaders() + "\n",
   						null);
   
  -                    // get the text response and image icon
  -                    // to determine which is NOT null
  -                    byte[] responseBytes = (byte[]) res.getResponseData();
  -
  -                    if (res.getDataType() != null
  -                        && res.getDataType().equals(SampleResult.TEXT))
  +                    String response = getResponseAsString(res);
  +                    if (textMode)
                       {
  -                        String response = null;
  -                        try
  -                        {
  -							// Showing large strings can be VERY costly, so we will avoid doing so if the response
  -							// data is larger than 200K. TODO: instead, we could delay doing the result.setText
  -							// call until the user chooses the "Response data" tab. Plus we could warn the user
  -							// if this happens and revert the choice if he doesn't confirm he's ready to wait.
  -							if (responseBytes.length > 200*1024)
  -							{
  -								response= 
  -									("Response too large to be displayed ("+responseBytes.length+" bytes).");
  -							}
  -							else
  -							{
  -								response = new String(responseBytes, "UTF-8");
  -							}
  -                        }
  -                        catch (UnsupportedEncodingException err)
  -                        {
  -                            throw new Error(err.toString()); // UTF-8 not supported? Com'on!
  -                        }
  -
  -                        if (textMode)
  -                        {
  -                            showTextResponse(response);
  -                        }
  -                        else
  -                        {
  -                            showRenderedResponse(response);
  -                        }
  +                        showTextResponse(response);
                       }
  -                    else if (responseBytes != null)
  +                    else
                       {
  -                        showImage(new ImageIcon(responseBytes));
  +                        showRenderedResponse(response);
                       }
                   }
  +                else if (responseBytes != null)
  +                {
  +                    showImage(new ImageIcon(responseBytes));
  +                }
               }
           }
           catch (BadLocationException exc)
  @@ -377,6 +349,44 @@
           htmlButton.setEnabled(true);
       }
   
  +    private static String getResponseAsString(SampleResult res)
  +	{
  +    	
  +        byte[] responseBytes = res.getResponseData();
  +        String response = null;
  +//        System.out.println("grasDE="+res.getDataEncoding());
  +//        System.out.println("grasCT="+res.getContentType());
  +//        System.out.println("grasDT="+res.getDataType());
  +        if (res.getDataType() != null
  +            && res.getDataType().equals(SampleResult.TEXT))
  +        {
  +            try
  +            {
  +				// Showing large strings can be VERY costly, so we will avoid doing so if the response
  +				// data is larger than 200K. TODO: instead, we could delay doing the result.setText
  +				// call until the user chooses the "Response data" tab. Plus we could warn the user
  +				// if this happens and revert the choice if he doesn't confirm he's ready to wait.
  +				if (responseBytes.length > 200*1024)
  +				{
  +					response= 
  +						("Response too large to be displayed ("+responseBytes.length+" bytes).");
  +					log.warn("Response too large to display.");
  +				}
  +				else
  +				{
  +					response = 
  +						new String(responseBytes,res.getDataEncoding());
  +				}
  +            }
  +            catch (UnsupportedEncodingException err)
  +            {
  +            	log.warn("Could not decode response "+err);
  +				response = 	new String(responseBytes);// Try the default encoding instead
  +            }
  +        }
  +    	return response;
  +    }
  +
       /**
        * Display the response as text or as rendered HTML.  Change the
        * text on the button appropriate to the current display.
  @@ -408,35 +418,7 @@
               }
   
               SampleResult res = (SampleResult) node.getUserObject();
  -            byte[] responseBytes = (byte[]) res.getResponseData();
  -            String response = null;
  -
  -            if (res.getDataType() != null
  -                && res.getDataType().equals(SampleResult.TEXT))
  -            {
  -                try
  -                {
  -					// Showing large strings can be VERY costly, so we will avoid doing so if the response
  -					// data is larger than 200K. TODO: instead, we could delay doing the result.setText
  -					// call until the user chooses the "Response data" tab. Plus we could warn the user
  -					// if this happens and revert the choice if he doesn't confirm he's ready to wait.
  -					if (responseBytes.length > 200*1024)
  -					{
  -						response= 
  -							("Response too large to be displayed ("+responseBytes.length+" bytes).");
  -						log.warn("Response too large to display.");
  -					}
  -					else
  -					{
  -						response = new String(responseBytes, "UTF-8");
  -					}
  -                }
  -                catch (UnsupportedEncodingException err)
  -                {
  -                	throw new Error(err.toString()); // UTF-8 unsupported? Com'on!
  -                }
  -            }
  -
  +            String response = getResponseAsString(res);
               if (textMode)
               {
                   showTextResponse(response);
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-dev-help@jakarta.apache.org