if (log.isDebugEnabled()) {
log.debug("valueChanged : selected node - " + node);
}
StyledDocument statsDoc = stats.getStyledDocument();
try {
statsDoc.remove(0, statsDoc.getLength());
sampleDataField.setText(""); // $NON-NLS-1$
results.setText(""); // $NON-NLS-1$
if (node != null) {
Object userObject = node.getUserObject();
if(userObject instanceof SampleResult) {
SampleResult res = (SampleResult) userObject;
// We are displaying a SampleResult
setupTabPaneForSampleResult();
if (log.isDebugEnabled()) {
log.debug("valueChanged1 : sample result - " + res);
}
// load time label
log.debug("valueChanged1 : load time - " + res.getTime());
String sd = res.getSamplerData();
if (sd != null) {
String rh = res.getRequestHeaders();
if (rh != null) {
StringBuffer sb = new StringBuffer(sd.length() + rh.length()+20);
sb.append(sd);
sb.append("\nRequest Headers:\n");
sb.append(rh);
sd = sb.toString();
}
sampleDataField.setText(sd);
}
StringBuffer statsBuff = new StringBuffer(200);
statsBuff.append("Thread Name: ").append(res.getThreadName()).append(NL);
String startTime = dateFormat.format(new Date(res.getStartTime()));
statsBuff.append("Sample Start: ").append(startTime).append(NL);
statsBuff.append("Load time: ").append(res.getTime()).append(NL);
statsBuff.append("Latency: ").append(res.getLatency()).append(NL);
statsBuff.append("Size in bytes: ").append(res.getBytes()).append(NL);
statsBuff.append("Sample Count: ").append(res.getSampleCount()).append(NL);
statsBuff.append("Error Count: ").append(res.getErrorCount()).append(NL);
statsDoc.insertString(statsDoc.getLength(), statsBuff.toString(), null);
statsBuff = new StringBuffer(); //reset for reuse
String responseCode = res.getResponseCode();
log.debug("valueChanged1 : response code - " + responseCode);
int responseLevel = 0;
if (responseCode != null) {
try {
responseLevel = Integer.parseInt(responseCode) / 100;
} catch (NumberFormatException numberFormatException) {
// no need to change the foreground color
}
}
Style style = null;
switch (responseLevel) {
case 3:
style = statsDoc.getStyle(STYLE_REDIRECT);
break;
case 4:
style = statsDoc.getStyle(STYLE_CLIENT_ERROR);
break;
case 5:
style = statsDoc.getStyle(STYLE_SERVER_ERROR);
break;
}
statsBuff.append("Response code: ").append(responseCode).append(NL);
statsDoc.insertString(statsDoc.getLength(), statsBuff.toString(), style);
statsBuff = new StringBuffer(100); //reset for reuse
// response message label
String responseMsgStr = res.getResponseMessage();
log.debug("valueChanged1 : response message - " + responseMsgStr);
statsBuff.append("Response message: ").append(responseMsgStr).append(NL);
statsBuff.append(NL).append("Response headers:").append(NL);
statsBuff.append(res.getResponseHeaders()).append(NL);
statsDoc.insertString(statsDoc.getLength(), statsBuff.toString(), null);
statsBuff = null; // Done
// get the text response and image icon
// to determine which is NOT null
if ((SampleResult.TEXT).equals(res.getDataType())) // equals(null) is OK
{
String response = getResponseAsString(res);
if (command.equals(TEXT_COMMAND)) {
showTextResponse(response);
} else if (command.equals(HTML_COMMAND)) {
showRenderedResponse(response, res);
} else if (command.equals(JSON_COMMAND)) {
showRenderJSONResponse(response);
} else if (command.equals(XML_COMMAND)) {
showRenderXMLResponse(res);
}
} else {
byte[] responseBytes = res.getResponseData();
if (responseBytes != null) {
showImage(new ImageIcon(responseBytes)); //TODO implement other non-text types
}
}
}
else if(userObject instanceof AssertionResult) {
AssertionResult res = (AssertionResult) userObject;
// We are displaying an AssertionResult
setupTabPaneForAssertionResult();
if (log.isDebugEnabled()) {
log.debug("valueChanged1 : sample result - " + res);
}
StringBuffer statsBuff = new StringBuffer(100);
statsBuff.append("Assertion error: ").append(res.isError()).append(NL);
statsBuff.append("Assertion failure: ").append(res.isFailure()).append(NL);
statsBuff.append("Assertion failure message : ").append(res.getFailureMessage()).append(NL);
statsDoc.insertString(statsDoc.getLength(), statsBuff.toString(), null);
statsBuff = null;
}
}
} catch (BadLocationException exc) {
log.error("Error setting statistics text", exc);