Use HTTP status code description logic from previous commit in DashboardController

This commit is contained in:
Rohit Awate 2018-08-21 18:51:15 +05:30
parent 8a179b9a9c
commit 2c2f05f1b1
No known key found for this signature in database
GPG key ID: 1051D7B79CF2EE25
2 changed files with 17 additions and 16 deletions

View file

@ -56,7 +56,6 @@ import org.fxmisc.flowless.VirtualizedScrollPane;
import javax.ws.rs.ProcessingException; import javax.ws.rs.ProcessingException;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.awt.*; import java.awt.*;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
@ -187,13 +186,9 @@ public class DashboardController implements Initializable {
String type = responseTypeBox.getValue(); String type = responseTypeBox.getValue();
if (type.equals(HTTPConstants.JSON)) { if (type.equals(HTTPConstants.JSON)) {
try { responseArea.setText(responseArea.getText(),
responseArea.setText(responseArea.getText(), FormatterFactory.getHighlighter(type),
FormatterFactory.getHighlighter(type), HighlighterFactory.getHighlighter(type));
HighlighterFactory.getHighlighter(type));
} catch (IOException e) {
LoggingService.logWarning("Response could not be parsed.", e, LocalDateTime.now());
}
return; return;
} }
@ -396,7 +391,7 @@ public class DashboardController implements Initializable {
prettifyResponseBody(response); prettifyResponseBody(response);
statusCode.setText(Integer.toString(response.getStatusCode())); statusCode.setText(Integer.toString(response.getStatusCode()));
statusCodeDescription.setText(Response.Status.fromStatusCode(response.getStatusCode()).getReasonPhrase()); statusCodeDescription.setText(EverestResponse.getReasonPhrase(response.getStatusCode()));
responseTime.setText(Long.toString(response.getTime()) + " ms"); responseTime.setText(Long.toString(response.getTime()) + " ms");
responseSize.setText(Integer.toString(response.getSize()) + " B"); responseSize.setText(Integer.toString(response.getSize()) + " B");
responseHeadersViewer.populate(response); responseHeadersViewer.populate(response);
@ -404,8 +399,8 @@ public class DashboardController implements Initializable {
private void showResponse(DashboardState state) { private void showResponse(DashboardState state) {
prettifyResponseBody(state.responseBody, state.responseType); prettifyResponseBody(state.responseBody, state.responseType);
statusCode.setText(Integer.toString(state.responseCode)); statusCode.setText(Integer.toString(state.statusCode));
statusCodeDescription.setText(Response.Status.fromStatusCode(state.responseCode).getReasonPhrase()); statusCodeDescription.setText(EverestResponse.getReasonPhrase(state.statusCode));
responseTime.setText(Long.toString(state.responseTime) + " ms"); responseTime.setText(Long.toString(state.responseTime) + " ms");
responseSize.setText(Integer.toString(state.responseSize) + " B"); responseSize.setText(Integer.toString(state.responseSize) + " B");
responseHeadersViewer.populate(state.responseHeaders); responseHeadersViewer.populate(state.responseHeaders);
@ -676,7 +671,7 @@ public class DashboardController implements Initializable {
case RESPONSE: case RESPONSE:
dashboardState.visibleResponseTab = getVisibleResponseTab(); dashboardState.visibleResponseTab = getVisibleResponseTab();
dashboardState.responseHeaders = responseHeadersViewer.getHeaders(); dashboardState.responseHeaders = responseHeadersViewer.getHeaders();
dashboardState.responseCode = Integer.parseInt(statusCode.getText()); dashboardState.statusCode = Integer.parseInt(statusCode.getText());
String temp = responseSize.getText(); String temp = responseSize.getText();
temp = temp.substring(0, temp.length() - 2); temp = temp.substring(0, temp.length() - 2);

View file

@ -63,14 +63,20 @@ public class EverestCodeArea extends CodeArea {
* Formats the text with the provided Formatter if it is not null, * Formats the text with the provided Formatter if it is not null,
* sets the text and then computes the highlighting. * sets the text and then computes the highlighting.
* *
* @throws IOException If the formatter fails to format the text given a syntactic error.
*/ */
public void setText(String text, Formatter formatter, Highlighter highlighter) throws IOException { public void setText(String text, Formatter formatter, Highlighter highlighter) {
clear(); clear();
String formattedText = text; String formattedText = text;
if (formatter != null) if (formatter != null) {
formattedText = formatter.format(text); try {
formattedText = formatter.format(text);
} catch (IOException e) {
clear();
appendText(text);
return;
}
}
appendText(formattedText); appendText(formattedText);
setHighlighter(highlighter); setHighlighter(highlighter);