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:
@@ -92,7 +92,7 @@ public class Client {
|
|||||||
|
|
||||||
if (request != null) {
|
if (request != null) {
|
||||||
return CompletableFuture.supplyAsync(() -> {
|
return CompletableFuture.supplyAsync(() -> {
|
||||||
String result = String.format("%s\n\n", log);
|
String result = String.format("%s\n---- HTTP Response ----\n", log);
|
||||||
try {
|
try {
|
||||||
HttpResponse r = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
|
HttpResponse r = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
|
||||||
result += String.format("> Status : %d\n", r.statusCode());
|
result += String.format("> Status : %d\n", r.statusCode());
|
||||||
@@ -103,7 +103,7 @@ public class Client {
|
|||||||
}
|
}
|
||||||
result += "\n";
|
result += "\n";
|
||||||
}
|
}
|
||||||
result += String.format("\n%s", (String)r.body());
|
result += String.format("\n---- Body ----\n%s", (String)r.body());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
result += String.format("\n/!\\ %s", e.getMessage());
|
result += String.format("\n/!\\ %s", e.getMessage());
|
||||||
error = new RequestError(e.getMessage(), e.getLocalizedMessage(), e);
|
error = new RequestError(e.getMessage(), e.getLocalizedMessage(), e);
|
||||||
@@ -143,10 +143,10 @@ public class Client {
|
|||||||
log += String.format(" %s\n", url);
|
log += String.format(" %s\n", url);
|
||||||
for (Map.Entry<String, String> header : headers.entrySet()) {
|
for (Map.Entry<String, String> header : headers.entrySet()) {
|
||||||
b.setHeader(header.getKey(), header.getValue());
|
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) {
|
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));
|
b.timeout(Duration.ofMillis(timeout));
|
||||||
return b.build();
|
return b.build();
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import java.util.Map;
|
|||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.ExecutionException;
|
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_HEIGHT = 700;
|
||||||
public static int WINDOW_WIDTH = 1100;
|
public static int WINDOW_WIDTH = 1100;
|
||||||
@@ -43,7 +43,7 @@ public class MainWindow extends JDialog {
|
|||||||
private boolean allowInvalidSSL;
|
private boolean allowInvalidSSL;
|
||||||
|
|
||||||
public MainWindow() {
|
public MainWindow() {
|
||||||
super((Dialog) null);
|
super();
|
||||||
setTitle(WINDOW_TITLE);
|
setTitle(WINDOW_TITLE);
|
||||||
allowInvalidSSL = false;
|
allowInvalidSSL = false;
|
||||||
headers = new HashMap<>();
|
headers = new HashMap<>();
|
||||||
@@ -52,7 +52,7 @@ public class MainWindow extends JDialog {
|
|||||||
setContentPane(contentPane);
|
setContentPane(contentPane);
|
||||||
setMinimumSize(new Dimension(WINDOW_WIDTH, WINDOW_HEIGHT));
|
setMinimumSize(new Dimension(WINDOW_WIDTH, WINDOW_HEIGHT));
|
||||||
setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
|
setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
|
||||||
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
|
||||||
httpTypeBox.addActionListener((event) -> {
|
httpTypeBox.addActionListener((event) -> {
|
||||||
allowInvalidSSLField.setEnabled(httpTypeBox.getSelectedItem().equals("HTTPS"));
|
allowInvalidSSLField.setEnabled(httpTypeBox.getSelectedItem().equals("HTTPS"));
|
||||||
@@ -86,9 +86,11 @@ public class MainWindow extends JDialog {
|
|||||||
xFormEncodedButton.addActionListener((event) -> {
|
xFormEncodedButton.addActionListener((event) -> {
|
||||||
FormEncodedDialog fe = new FormEncodedDialog();
|
FormEncodedDialog fe = new FormEncodedDialog();
|
||||||
String datas = fe.showDialog();
|
String datas = fe.showDialog();
|
||||||
|
if(!datas.isBlank()) {
|
||||||
bodyArea.setText(datas);
|
bodyArea.setText(datas);
|
||||||
headers.put(CONTENT_TYPE, WWW_FORM_URLENCODED);
|
headers.put(CONTENT_TYPE, WWW_FORM_URLENCODED);
|
||||||
updateHeaderList();
|
updateHeaderList();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
runButton.addActionListener(this::start);
|
runButton.addActionListener(this::start);
|
||||||
@@ -104,6 +106,10 @@ public class MainWindow extends JDialog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void start(ActionEvent ev) {
|
private void start(ActionEvent ev) {
|
||||||
|
if(urlField.getText().isBlank()) {
|
||||||
|
JOptionPane.showMessageDialog(this, "L'URL est manquante");
|
||||||
|
return;
|
||||||
|
}
|
||||||
startLoading(true);
|
startLoading(true);
|
||||||
Client c = new Client(bodyArea.getText(), headers, getMethod(), urlBuilder(), getAllowInvalidSSL());
|
Client c = new Client(bodyArea.getText(), headers, getMethod(), urlBuilder(), getAllowInvalidSSL());
|
||||||
CompletableFuture<String> f = c.run();
|
CompletableFuture<String> f = c.run();
|
||||||
@@ -150,7 +156,15 @@ public class MainWindow extends JDialog {
|
|||||||
newHeaderButton.setEnabled(!b);
|
newHeaderButton.setEnabled(!b);
|
||||||
addAuthButton.setEnabled(!b);
|
addAuthButton.setEnabled(!b);
|
||||||
runButton.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() {
|
private boolean getAllowInvalidSSL() {
|
||||||
@@ -169,5 +183,13 @@ public class MainWindow extends JDialog {
|
|||||||
public void showFrame() {
|
public void showFrame() {
|
||||||
pack();
|
pack();
|
||||||
setVisible(true);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user