Fix issues related to RawBody type not being maintained during sessions and tab switches
This commit is contained in:
parent
e943cf8ca9
commit
3dcb57070c
6 changed files with 82 additions and 43 deletions
|
@ -20,7 +20,6 @@ import com.rohitawate.everest.controllers.codearea.EverestCodeArea;
|
||||||
import com.rohitawate.everest.controllers.codearea.highlighters.HighlighterFactory;
|
import com.rohitawate.everest.controllers.codearea.highlighters.HighlighterFactory;
|
||||||
import com.rohitawate.everest.controllers.state.ComposerState;
|
import com.rohitawate.everest.controllers.state.ComposerState;
|
||||||
import com.rohitawate.everest.controllers.state.FieldState;
|
import com.rohitawate.everest.controllers.state.FieldState;
|
||||||
import com.rohitawate.everest.format.FormatterFactory;
|
|
||||||
import com.rohitawate.everest.misc.Services;
|
import com.rohitawate.everest.misc.Services;
|
||||||
import com.rohitawate.everest.misc.ThemeManager;
|
import com.rohitawate.everest.misc.ThemeManager;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
|
@ -29,6 +28,7 @@ import javafx.fxml.Initializable;
|
||||||
import javafx.scene.Parent;
|
import javafx.scene.Parent;
|
||||||
import javafx.scene.control.ComboBox;
|
import javafx.scene.control.ComboBox;
|
||||||
import javafx.scene.control.Tab;
|
import javafx.scene.control.Tab;
|
||||||
|
import javafx.scene.control.TabPane;
|
||||||
import javafx.scene.control.TextField;
|
import javafx.scene.control.TextField;
|
||||||
import javafx.scene.layout.VBox;
|
import javafx.scene.layout.VBox;
|
||||||
import javafx.stage.FileChooser;
|
import javafx.stage.FileChooser;
|
||||||
|
@ -54,12 +54,18 @@ public class BodyTabController implements Initializable {
|
||||||
@FXML
|
@FXML
|
||||||
TextField filePathField;
|
TextField filePathField;
|
||||||
@FXML
|
@FXML
|
||||||
|
private TabPane bodyTabPane;
|
||||||
|
@FXML
|
||||||
private VBox rawVBox;
|
private VBox rawVBox;
|
||||||
|
|
||||||
EverestCodeArea rawInputArea;
|
EverestCodeArea rawInputArea;
|
||||||
FormDataTabController formDataTabController;
|
FormDataTabController formDataTabController;
|
||||||
URLTabController urlTabController;
|
URLTabController urlTabController;
|
||||||
|
|
||||||
|
public enum BodyTab {
|
||||||
|
FORM, URL, RAW, BINARY
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(URL location, ResourceBundle resources) {
|
public void initialize(URL location, ResourceBundle resources) {
|
||||||
rawInputTypeBox.getItems().addAll("PLAIN TEXT", "JSON", "XML", "HTML");
|
rawInputTypeBox.getItems().addAll("PLAIN TEXT", "JSON", "XML", "HTML");
|
||||||
|
@ -74,14 +80,7 @@ public class BodyTabController implements Initializable {
|
||||||
String type = rawInputTypeBox.getValue();
|
String type = rawInputTypeBox.getValue();
|
||||||
|
|
||||||
if (type.equals("JSON")) {
|
if (type.equals("JSON")) {
|
||||||
try {
|
rawInputArea.setHighlighter(HighlighterFactory.getHighlighter(type));
|
||||||
rawInputArea.setText(rawInputArea.getText(),
|
|
||||||
FormatterFactory.getHighlighter(type),
|
|
||||||
HighlighterFactory.getHighlighter(type));
|
|
||||||
} catch (IOException e) {
|
|
||||||
Services.loggingService.logWarning("Response could not be parsed.", e, LocalDateTime.now());
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,33 +121,34 @@ public class BodyTabController implements Initializable {
|
||||||
public ComposerState getState() {
|
public ComposerState getState() {
|
||||||
ComposerState state = new ComposerState();
|
ComposerState state = new ComposerState();
|
||||||
|
|
||||||
state.rawBodyType = rawInputTypeBox.getValue();
|
|
||||||
state.rawBody = rawInputArea.getText();
|
|
||||||
state.urlStringTuples = urlTabController.getFieldStates();
|
state.urlStringTuples = urlTabController.getFieldStates();
|
||||||
state.formStringTuples = formDataTabController.getStringFieldStates();
|
state.formStringTuples = formDataTabController.getStringFieldStates();
|
||||||
state.formFileTuples = formDataTabController.getFileFieldStates();
|
state.formFileTuples = formDataTabController.getFileFieldStates();
|
||||||
state.binaryFilePath = filePathField.getText();
|
state.binaryFilePath = filePathField.getText();
|
||||||
|
|
||||||
if (rawTab.isSelected()) {
|
state.rawBody = rawInputArea.getText();
|
||||||
switch (rawInputTypeBox.getValue()) {
|
switch (rawInputTypeBox.getValue()) {
|
||||||
case "JSON":
|
case "JSON":
|
||||||
state.contentType = MediaType.APPLICATION_JSON;
|
state.rawBodyContentType = MediaType.APPLICATION_JSON;
|
||||||
break;
|
break;
|
||||||
case "XML":
|
case "XML":
|
||||||
state.contentType = MediaType.APPLICATION_XML;
|
state.rawBodyContentType = MediaType.APPLICATION_XML;
|
||||||
break;
|
break;
|
||||||
case "HTML":
|
case "HTML":
|
||||||
state.contentType = MediaType.TEXT_HTML;
|
state.rawBodyContentType = MediaType.TEXT_HTML;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
state.contentType = MediaType.TEXT_PLAIN;
|
state.rawBodyContentType = MediaType.TEXT_PLAIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (rawTab.isSelected()) {
|
||||||
|
state.visibleBodyTab = BodyTab.RAW;
|
||||||
} else if (formTab.isSelected()) {
|
} else if (formTab.isSelected()) {
|
||||||
state.contentType = MediaType.MULTIPART_FORM_DATA;
|
state.visibleBodyTab = BodyTab.FORM;
|
||||||
} else if (urlTab.isSelected()) {
|
} else if (urlTab.isSelected()) {
|
||||||
state.contentType = MediaType.APPLICATION_FORM_URLENCODED;
|
state.visibleBodyTab = BodyTab.URL;
|
||||||
} else {
|
} else {
|
||||||
state.contentType = MediaType.APPLICATION_OCTET_STREAM;
|
state.visibleBodyTab = BodyTab.BINARY;
|
||||||
}
|
}
|
||||||
|
|
||||||
return state;
|
return state;
|
||||||
|
@ -174,6 +174,26 @@ public class BodyTabController implements Initializable {
|
||||||
|
|
||||||
setRawTab(state);
|
setRawTab(state);
|
||||||
filePathField.setText(state.binaryFilePath);
|
filePathField.setText(state.binaryFilePath);
|
||||||
|
|
||||||
|
int tab;
|
||||||
|
if (state.visibleBodyTab != null) {
|
||||||
|
switch (state.visibleBodyTab) {
|
||||||
|
case BINARY:
|
||||||
|
tab = 3;
|
||||||
|
break;
|
||||||
|
case URL:
|
||||||
|
tab = 1;
|
||||||
|
break;
|
||||||
|
case RAW:
|
||||||
|
tab = 2;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
tab = 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
tab = 0;
|
||||||
|
}
|
||||||
|
bodyTabPane.getSelectionModel().select(tab);
|
||||||
}
|
}
|
||||||
|
|
||||||
void reset() {
|
void reset() {
|
||||||
|
@ -185,9 +205,26 @@ public class BodyTabController implements Initializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setRawTab(ComposerState state) {
|
private void setRawTab(ComposerState state) {
|
||||||
if (state.rawBodyType != null && state.rawBody != null) {
|
if (state.rawBodyContentType != null && state.rawBody != null) {
|
||||||
rawInputArea.setText(state.rawBody, HighlighterFactory.getHighlighter(state.rawBodyType));
|
// TODO: Remove this conversion
|
||||||
|
String simplifiedContentType;
|
||||||
|
switch (state.rawBodyContentType) {
|
||||||
|
case MediaType.APPLICATION_JSON:
|
||||||
|
simplifiedContentType = "JSON";
|
||||||
|
break;
|
||||||
|
case MediaType.APPLICATION_XML:
|
||||||
|
simplifiedContentType = "XML";
|
||||||
|
break;
|
||||||
|
case MediaType.TEXT_HTML:
|
||||||
|
simplifiedContentType = "HTML";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
simplifiedContentType = "PLAIN TEXT";
|
||||||
|
}
|
||||||
|
rawInputTypeBox.setValue(simplifiedContentType);
|
||||||
|
rawInputArea.setText(state.rawBody, HighlighterFactory.getHighlighter(simplifiedContentType));
|
||||||
} else {
|
} else {
|
||||||
|
rawInputTypeBox.setValue("PLAIN TEXT");
|
||||||
rawInputArea.setHighlighter(HighlighterFactory.getHighlighter("PLAIN TEXT"));
|
rawInputArea.setHighlighter(HighlighterFactory.getHighlighter("PLAIN TEXT"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,7 +99,7 @@ public class HistoryItemController implements Initializable, Searchable<Composer
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state.httpMethod.equals("POST") || state.httpMethod.equals("PUT")) {
|
if (state.httpMethod.equals("POST") || state.httpMethod.equals("PUT")) {
|
||||||
switch (state.contentType) {
|
switch (state.rawBodyContentType) {
|
||||||
case MediaType.TEXT_PLAIN:
|
case MediaType.TEXT_PLAIN:
|
||||||
case MediaType.APPLICATION_JSON:
|
case MediaType.APPLICATION_JSON:
|
||||||
case MediaType.APPLICATION_XML:
|
case MediaType.APPLICATION_XML:
|
||||||
|
|
|
@ -16,24 +16,25 @@
|
||||||
|
|
||||||
package com.rohitawate.everest.controllers.state;
|
package com.rohitawate.everest.controllers.state;
|
||||||
|
|
||||||
|
import com.rohitawate.everest.controllers.BodyTabController.BodyTab;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convenience class to abstract the state of the application.
|
* Convenience class to abstract the state of the application.
|
||||||
*/
|
*/
|
||||||
public class ComposerState {
|
public class ComposerState {
|
||||||
|
public BodyTab visibleBodyTab;
|
||||||
|
|
||||||
public String target;
|
public String target;
|
||||||
|
|
||||||
public String httpMethod;
|
public String httpMethod;
|
||||||
public ArrayList<FieldState> params;
|
public ArrayList<FieldState> params;
|
||||||
public ArrayList<FieldState> headers;
|
public ArrayList<FieldState> headers;
|
||||||
|
|
||||||
// Determined from the active tab within the Body tab
|
|
||||||
public String contentType;
|
|
||||||
|
|
||||||
// Body and content-type of requests with raw bodies
|
// Body and content-type of requests with raw bodies
|
||||||
public String rawBody;
|
public String rawBody;
|
||||||
public String rawBodyType;
|
public String rawBodyContentType;
|
||||||
|
|
||||||
// Tuples of URL-encoded requests
|
// Tuples of URL-encoded requests
|
||||||
public ArrayList<FieldState> urlStringTuples;
|
public ArrayList<FieldState> urlStringTuples;
|
||||||
|
|
|
@ -142,7 +142,7 @@ public class HistoryManager {
|
||||||
if (RS.next())
|
if (RS.next())
|
||||||
contentType = RS.getString("ContentType");
|
contentType = RS.getString("ContentType");
|
||||||
|
|
||||||
state.contentType = contentType;
|
state.rawBodyContentType = contentType;
|
||||||
|
|
||||||
// Retrieves body from corresponding table
|
// Retrieves body from corresponding table
|
||||||
switch (contentType) {
|
switch (contentType) {
|
||||||
|
@ -282,10 +282,10 @@ public class HistoryManager {
|
||||||
if (RS.next())
|
if (RS.next())
|
||||||
previousContentType = RS.getString("ContentType");
|
previousContentType = RS.getString("ContentType");
|
||||||
|
|
||||||
if (!newState.contentType.equals(previousContentType))
|
if (!newState.rawBodyContentType.equals(previousContentType))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
switch (newState.contentType) {
|
switch (newState.rawBodyContentType) {
|
||||||
case MediaType.TEXT_PLAIN:
|
case MediaType.TEXT_PLAIN:
|
||||||
case MediaType.APPLICATION_JSON:
|
case MediaType.APPLICATION_JSON:
|
||||||
case MediaType.APPLICATION_XML:
|
case MediaType.APPLICATION_XML:
|
||||||
|
@ -391,12 +391,12 @@ public class HistoryManager {
|
||||||
// Maps the request to its ContentType for faster retrieval
|
// Maps the request to its ContentType for faster retrieval
|
||||||
statement = conn.prepareStatement(EverestUtilities.trimString(queries.get("saveRequestContentPair").toString()));
|
statement = conn.prepareStatement(EverestUtilities.trimString(queries.get("saveRequestContentPair").toString()));
|
||||||
statement.setInt(1, requestID);
|
statement.setInt(1, requestID);
|
||||||
statement.setString(2, state.contentType);
|
statement.setString(2, state.rawBodyContentType);
|
||||||
|
|
||||||
statement.executeUpdate();
|
statement.executeUpdate();
|
||||||
|
|
||||||
// Determines where to fetch the body from, based on the ContentType
|
// Determines where to fetch the body from, based on the ContentType
|
||||||
switch (state.contentType) {
|
switch (state.rawBodyContentType) {
|
||||||
case MediaType.TEXT_PLAIN:
|
case MediaType.TEXT_PLAIN:
|
||||||
case MediaType.APPLICATION_JSON:
|
case MediaType.APPLICATION_JSON:
|
||||||
case MediaType.APPLICATION_XML:
|
case MediaType.APPLICATION_XML:
|
||||||
|
|
|
@ -74,6 +74,7 @@ public abstract class RequestManager extends Service<EverestResponse> {
|
||||||
|
|
||||||
private void appendHeaders() {
|
private void appendHeaders() {
|
||||||
request.getHeaders().forEach((key, value) -> requestBuilder.header(key, value));
|
request.getHeaders().forEach((key, value) -> requestBuilder.header(key, value));
|
||||||
|
requestBuilder.header("User-Agent", "Everest");
|
||||||
}
|
}
|
||||||
|
|
||||||
void processServerResponse(Response serverResponse)
|
void processServerResponse(Response serverResponse)
|
||||||
|
@ -81,7 +82,7 @@ public abstract class RequestManager extends Service<EverestResponse> {
|
||||||
if (serverResponse == null) {
|
if (serverResponse == null) {
|
||||||
throw new UnreliableResponseException("The server did not respond.",
|
throw new UnreliableResponseException("The server did not respond.",
|
||||||
"Like that crush from high school..");
|
"Like that crush from high school..");
|
||||||
} else if (serverResponse.getStatus() == 301) {
|
} else if (serverResponse.getStatus() == 301 || serverResponse.getStatus() == 302) {
|
||||||
throw new RedirectException(
|
throw new RedirectException(
|
||||||
serverResponse.getHeaderString("location"));
|
serverResponse.getHeaderString("location"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,9 +20,9 @@
|
||||||
<?import javafx.geometry.Insets?>
|
<?import javafx.geometry.Insets?>
|
||||||
<?import javafx.scene.control.*?>
|
<?import javafx.scene.control.*?>
|
||||||
<?import javafx.scene.layout.*?>
|
<?import javafx.scene.layout.*?>
|
||||||
<TabPane fx:id="bodyTabPane" prefHeight="100.0" prefWidth="1280.0" stylesheets="@../../css/Adreana.css"
|
<TabPane fx:id="bodyTabPane" stylesheets="@../../css/Adreana.css" tabClosingPolicy="UNAVAILABLE" tabMinWidth="150.0"
|
||||||
tabClosingPolicy="UNAVAILABLE" tabMinWidth="150.0" xmlns="http://javafx.com/javafx/8.0.141"
|
xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1"
|
||||||
xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.rohitawate.everest.controllers.BodyTabController">
|
fx:controller="com.rohitawate.everest.controllers.BodyTabController">
|
||||||
<tabs>
|
<tabs>
|
||||||
<Tab fx:id="formTab" text="FORM"/>
|
<Tab fx:id="formTab" text="FORM"/>
|
||||||
<Tab fx:id="urlTab" text="URL ENCODED"/>
|
<Tab fx:id="urlTab" text="URL ENCODED"/>
|
||||||
|
|
Loading…
Reference in a new issue