Changement de la MainWindow de JDialog a JFrame & correction de la checkbox SSL qui était disponible en HTTP après avoir fait une requete

This commit is contained in:
Alexis Delhaie
2019-10-28 20:37:24 +01:00
parent 8d3c2d3214
commit 75cf088512
2 changed files with 33 additions and 11 deletions

View File

@@ -92,7 +92,7 @@ public class Client {
if (request != null) {
return CompletableFuture.supplyAsync(() -> {
String result = String.format("%s\n\n", log);
String result = String.format("%s\n---- HTTP Response ----\n", log);
try {
HttpResponse r = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
result += String.format("> Status : %d\n", r.statusCode());
@@ -103,7 +103,7 @@ public class Client {
}
result += "\n";
}
result += String.format("\n%s", (String)r.body());
result += String.format("\n---- Body ----\n%s", (String)r.body());
} catch (IOException e) {
result += String.format("\n/!\\ %s", e.getMessage());
error = new RequestError(e.getMessage(), e.getLocalizedMessage(), e);
@@ -143,10 +143,10 @@ public class Client {
log += String.format(" %s\n", url);
for (Map.Entry<String, String> header : headers.entrySet()) {
b.setHeader(header.getKey(), header.getValue());
log += String.format("< %s: %s", header.getKey(), header.getValue());
log += String.format("< %s: %s\n", header.getKey(), header.getValue());
}
if(method == Method.POST || method == Method.PUT) {
log += String.format("%s", body);
log += String.format("\n---- Body ----\n%s", body);
}
b.timeout(Duration.ofMillis(timeout));
return b.build();

View File

@@ -15,7 +15,7 @@ import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
public class MainWindow extends JDialog {
public class MainWindow extends JFrame {
public static int WINDOW_HEIGHT = 700;
public static int WINDOW_WIDTH = 1100;
@@ -43,7 +43,7 @@ public class MainWindow extends JDialog {
private boolean allowInvalidSSL;
public MainWindow() {
super((Dialog) null);
super();
setTitle(WINDOW_TITLE);
allowInvalidSSL = false;
headers = new HashMap<>();
@@ -52,7 +52,7 @@ public class MainWindow extends JDialog {
setContentPane(contentPane);
setMinimumSize(new Dimension(WINDOW_WIDTH, WINDOW_HEIGHT));
setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
httpTypeBox.addActionListener((event) -> {
allowInvalidSSLField.setEnabled(httpTypeBox.getSelectedItem().equals("HTTPS"));
@@ -86,9 +86,11 @@ public class MainWindow extends JDialog {
xFormEncodedButton.addActionListener((event) -> {
FormEncodedDialog fe = new FormEncodedDialog();
String datas = fe.showDialog();
if(!datas.isBlank()) {
bodyArea.setText(datas);
headers.put(CONTENT_TYPE, WWW_FORM_URLENCODED);
updateHeaderList();
}
});
runButton.addActionListener(this::start);
@@ -104,6 +106,10 @@ public class MainWindow extends JDialog {
}
private void start(ActionEvent ev) {
if(urlField.getText().isBlank()) {
JOptionPane.showMessageDialog(this, "L'URL est manquante");
return;
}
startLoading(true);
Client c = new Client(bodyArea.getText(), headers, getMethod(), urlBuilder(), getAllowInvalidSSL());
CompletableFuture<String> f = c.run();
@@ -150,7 +156,15 @@ public class MainWindow extends JDialog {
newHeaderButton.setEnabled(!b);
addAuthButton.setEnabled(!b);
runButton.setEnabled(!b);
allowInvalidSSLField.setEnabled(!b);
setEnableAllowInvalidSSLField(!b);
}
private void setEnableAllowInvalidSSLField(boolean b) {
if(httpTypeBox.getSelectedItem().equals("HTTPS")) {
allowInvalidSSLField.setEnabled(b);
} else {
allowInvalidSSLField.setEnabled(false);
}
}
private boolean getAllowInvalidSSL() {
@@ -169,5 +183,13 @@ public class MainWindow extends JDialog {
public void showFrame() {
pack();
setVisible(true);
centerFrame();
}
private void centerFrame() {
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
int y = (int)( screen.getHeight() / 2 ) - this.getHeight() / 2;
int x = (int)( screen.getWidth() / 2 ) - this.getWidth() / 2;
this.setLocation(x, y);
}
}