diff --git a/.gitignore b/.gitignore index e660fd9..8dc6a2d 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ bin/ +out/ diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 87ce4fe..5929b0e 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,23 +2,21 @@ - + - - - - - - - - - - - + + + + + + + + + @@ -47,6 +45,7 @@ + @@ -103,6 +102,8 @@ + + diff --git a/bin/META-INF/MANIFEST.MF b/bin/META-INF/MANIFEST.MF deleted file mode 100644 index bd61d69..0000000 --- a/bin/META-INF/MANIFEST.MF +++ /dev/null @@ -1,3 +0,0 @@ -Manifest-Version: 1.0 -Main-Class: ovh.alexisdelhaie.curling.Runtime - diff --git a/bin/com/intellij/uiDesigner/core/AbstractLayout.class b/bin/com/intellij/uiDesigner/core/AbstractLayout.class deleted file mode 100644 index 474957a..0000000 Binary files a/bin/com/intellij/uiDesigner/core/AbstractLayout.class and /dev/null differ diff --git a/bin/com/intellij/uiDesigner/core/DimensionInfo.class b/bin/com/intellij/uiDesigner/core/DimensionInfo.class deleted file mode 100644 index 0db2f7d..0000000 Binary files a/bin/com/intellij/uiDesigner/core/DimensionInfo.class and /dev/null differ diff --git a/bin/com/intellij/uiDesigner/core/GridConstraints.class b/bin/com/intellij/uiDesigner/core/GridConstraints.class deleted file mode 100644 index 2e1afcc..0000000 Binary files a/bin/com/intellij/uiDesigner/core/GridConstraints.class and /dev/null differ diff --git a/bin/com/intellij/uiDesigner/core/GridLayoutManager.class b/bin/com/intellij/uiDesigner/core/GridLayoutManager.class deleted file mode 100644 index 94e3f41..0000000 Binary files a/bin/com/intellij/uiDesigner/core/GridLayoutManager.class and /dev/null differ diff --git a/bin/com/intellij/uiDesigner/core/HorizontalInfo.class b/bin/com/intellij/uiDesigner/core/HorizontalInfo.class deleted file mode 100644 index bdc1fe3..0000000 Binary files a/bin/com/intellij/uiDesigner/core/HorizontalInfo.class and /dev/null differ diff --git a/bin/com/intellij/uiDesigner/core/LayoutState.class b/bin/com/intellij/uiDesigner/core/LayoutState.class deleted file mode 100644 index 61494df..0000000 Binary files a/bin/com/intellij/uiDesigner/core/LayoutState.class and /dev/null differ diff --git a/bin/com/intellij/uiDesigner/core/Spacer.class b/bin/com/intellij/uiDesigner/core/Spacer.class deleted file mode 100644 index e534880..0000000 Binary files a/bin/com/intellij/uiDesigner/core/Spacer.class and /dev/null differ diff --git a/bin/com/intellij/uiDesigner/core/SupportCode$TextWithMnemonic.class b/bin/com/intellij/uiDesigner/core/SupportCode$TextWithMnemonic.class deleted file mode 100644 index 67909c5..0000000 Binary files a/bin/com/intellij/uiDesigner/core/SupportCode$TextWithMnemonic.class and /dev/null differ diff --git a/bin/com/intellij/uiDesigner/core/SupportCode.class b/bin/com/intellij/uiDesigner/core/SupportCode.class deleted file mode 100644 index 4950c35..0000000 Binary files a/bin/com/intellij/uiDesigner/core/SupportCode.class and /dev/null differ diff --git a/bin/com/intellij/uiDesigner/core/Util.class b/bin/com/intellij/uiDesigner/core/Util.class deleted file mode 100644 index 4866582..0000000 Binary files a/bin/com/intellij/uiDesigner/core/Util.class and /dev/null differ diff --git a/bin/com/intellij/uiDesigner/core/VerticalInfo.class b/bin/com/intellij/uiDesigner/core/VerticalInfo.class deleted file mode 100644 index 049e702..0000000 Binary files a/bin/com/intellij/uiDesigner/core/VerticalInfo.class and /dev/null differ diff --git a/bin/ovh/alexisdelhaie/curling/Runtime.class b/bin/ovh/alexisdelhaie/curling/Runtime.class deleted file mode 100644 index ea379e7..0000000 Binary files a/bin/ovh/alexisdelhaie/curling/Runtime.class and /dev/null differ diff --git a/bin/ovh/alexisdelhaie/curling/dataSet/HeaderModel.class b/bin/ovh/alexisdelhaie/curling/dataSet/HeaderModel.class deleted file mode 100644 index d8a3811..0000000 Binary files a/bin/ovh/alexisdelhaie/curling/dataSet/HeaderModel.class and /dev/null differ diff --git a/bin/ovh/alexisdelhaie/curling/web/Client$1.class b/bin/ovh/alexisdelhaie/curling/web/Client$1.class deleted file mode 100644 index 20a65e2..0000000 Binary files a/bin/ovh/alexisdelhaie/curling/web/Client$1.class and /dev/null differ diff --git a/bin/ovh/alexisdelhaie/curling/web/Client.class b/bin/ovh/alexisdelhaie/curling/web/Client.class deleted file mode 100644 index 29e17c1..0000000 Binary files a/bin/ovh/alexisdelhaie/curling/web/Client.class and /dev/null differ diff --git a/bin/ovh/alexisdelhaie/curling/web/Method.class b/bin/ovh/alexisdelhaie/curling/web/Method.class deleted file mode 100644 index 97df8fe..0000000 Binary files a/bin/ovh/alexisdelhaie/curling/web/Method.class and /dev/null differ diff --git a/bin/ovh/alexisdelhaie/curling/web/RequestError.class b/bin/ovh/alexisdelhaie/curling/web/RequestError.class deleted file mode 100644 index 375a8e2..0000000 Binary files a/bin/ovh/alexisdelhaie/curling/web/RequestError.class and /dev/null differ diff --git a/bin/ovh/alexisdelhaie/curling/windows/AddHeader$1.class b/bin/ovh/alexisdelhaie/curling/windows/AddHeader$1.class deleted file mode 100644 index 8fabaed..0000000 Binary files a/bin/ovh/alexisdelhaie/curling/windows/AddHeader$1.class and /dev/null differ diff --git a/bin/ovh/alexisdelhaie/curling/windows/AddHeader$2.class b/bin/ovh/alexisdelhaie/curling/windows/AddHeader$2.class deleted file mode 100644 index bfd0478..0000000 Binary files a/bin/ovh/alexisdelhaie/curling/windows/AddHeader$2.class and /dev/null differ diff --git a/bin/ovh/alexisdelhaie/curling/windows/AddHeader$3.class b/bin/ovh/alexisdelhaie/curling/windows/AddHeader$3.class deleted file mode 100644 index a85a13e..0000000 Binary files a/bin/ovh/alexisdelhaie/curling/windows/AddHeader$3.class and /dev/null differ diff --git a/bin/ovh/alexisdelhaie/curling/windows/AddHeader$4.class b/bin/ovh/alexisdelhaie/curling/windows/AddHeader$4.class deleted file mode 100644 index dc6ad9a..0000000 Binary files a/bin/ovh/alexisdelhaie/curling/windows/AddHeader$4.class and /dev/null differ diff --git a/bin/ovh/alexisdelhaie/curling/windows/AddHeader.class b/bin/ovh/alexisdelhaie/curling/windows/AddHeader.class deleted file mode 100644 index a017709..0000000 Binary files a/bin/ovh/alexisdelhaie/curling/windows/AddHeader.class and /dev/null differ diff --git a/bin/ovh/alexisdelhaie/curling/windows/BasicAuthenticationDialog$1.class b/bin/ovh/alexisdelhaie/curling/windows/BasicAuthenticationDialog$1.class deleted file mode 100644 index a1665f2..0000000 Binary files a/bin/ovh/alexisdelhaie/curling/windows/BasicAuthenticationDialog$1.class and /dev/null differ diff --git a/bin/ovh/alexisdelhaie/curling/windows/BasicAuthenticationDialog$2.class b/bin/ovh/alexisdelhaie/curling/windows/BasicAuthenticationDialog$2.class deleted file mode 100644 index 6432b5d..0000000 Binary files a/bin/ovh/alexisdelhaie/curling/windows/BasicAuthenticationDialog$2.class and /dev/null differ diff --git a/bin/ovh/alexisdelhaie/curling/windows/BasicAuthenticationDialog$3.class b/bin/ovh/alexisdelhaie/curling/windows/BasicAuthenticationDialog$3.class deleted file mode 100644 index 741dba1..0000000 Binary files a/bin/ovh/alexisdelhaie/curling/windows/BasicAuthenticationDialog$3.class and /dev/null differ diff --git a/bin/ovh/alexisdelhaie/curling/windows/BasicAuthenticationDialog$4.class b/bin/ovh/alexisdelhaie/curling/windows/BasicAuthenticationDialog$4.class deleted file mode 100644 index 91f6a4d..0000000 Binary files a/bin/ovh/alexisdelhaie/curling/windows/BasicAuthenticationDialog$4.class and /dev/null differ diff --git a/bin/ovh/alexisdelhaie/curling/windows/BasicAuthenticationDialog.class b/bin/ovh/alexisdelhaie/curling/windows/BasicAuthenticationDialog.class deleted file mode 100644 index ec41454..0000000 Binary files a/bin/ovh/alexisdelhaie/curling/windows/BasicAuthenticationDialog.class and /dev/null differ diff --git a/bin/ovh/alexisdelhaie/curling/windows/FormEncodedDialog$1.class b/bin/ovh/alexisdelhaie/curling/windows/FormEncodedDialog$1.class deleted file mode 100644 index 8cd9283..0000000 Binary files a/bin/ovh/alexisdelhaie/curling/windows/FormEncodedDialog$1.class and /dev/null differ diff --git a/bin/ovh/alexisdelhaie/curling/windows/FormEncodedDialog$2.class b/bin/ovh/alexisdelhaie/curling/windows/FormEncodedDialog$2.class deleted file mode 100644 index efb171d..0000000 Binary files a/bin/ovh/alexisdelhaie/curling/windows/FormEncodedDialog$2.class and /dev/null differ diff --git a/bin/ovh/alexisdelhaie/curling/windows/FormEncodedDialog$3.class b/bin/ovh/alexisdelhaie/curling/windows/FormEncodedDialog$3.class deleted file mode 100644 index eec62a7..0000000 Binary files a/bin/ovh/alexisdelhaie/curling/windows/FormEncodedDialog$3.class and /dev/null differ diff --git a/bin/ovh/alexisdelhaie/curling/windows/FormEncodedDialog$4.class b/bin/ovh/alexisdelhaie/curling/windows/FormEncodedDialog$4.class deleted file mode 100644 index 388dc88..0000000 Binary files a/bin/ovh/alexisdelhaie/curling/windows/FormEncodedDialog$4.class and /dev/null differ diff --git a/bin/ovh/alexisdelhaie/curling/windows/FormEncodedDialog.class b/bin/ovh/alexisdelhaie/curling/windows/FormEncodedDialog.class deleted file mode 100644 index 6af67a7..0000000 Binary files a/bin/ovh/alexisdelhaie/curling/windows/FormEncodedDialog.class and /dev/null differ diff --git a/bin/ovh/alexisdelhaie/curling/windows/MainWindow$1.class b/bin/ovh/alexisdelhaie/curling/windows/MainWindow$1.class deleted file mode 100644 index 3f41009..0000000 Binary files a/bin/ovh/alexisdelhaie/curling/windows/MainWindow$1.class and /dev/null differ diff --git a/bin/ovh/alexisdelhaie/curling/windows/MainWindow.class b/bin/ovh/alexisdelhaie/curling/windows/MainWindow.class deleted file mode 100644 index 5653f4f..0000000 Binary files a/bin/ovh/alexisdelhaie/curling/windows/MainWindow.class and /dev/null differ diff --git a/src/ovh/alexisdelhaie/curling/Runtime.java b/src/ovh/alexisdelhaie/curling/Runtime.java index 25dfed5..ea4e2cb 100644 --- a/src/ovh/alexisdelhaie/curling/Runtime.java +++ b/src/ovh/alexisdelhaie/curling/Runtime.java @@ -1,11 +1,24 @@ package ovh.alexisdelhaie.curling; import ovh.alexisdelhaie.curling.windows.MainWindow; +import javax.swing.plaf.synth.SynthLookAndFeel; import javax.swing.*; +import java.util.logging.Logger; public class Runtime { public static void main(String[] args) { + try { + UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } catch (InstantiationException e) { + Logger.getGlobal().warning(e.getMessage()); + } catch (IllegalAccessException e) { + Logger.getGlobal().warning(e.getMessage()); + } catch (UnsupportedLookAndFeelException e) { + Logger.getGlobal().warning(e.getMessage()); + } MainWindow window = new MainWindow(); window.showFrame(); } diff --git a/src/ovh/alexisdelhaie/curling/web/Client.java b/src/ovh/alexisdelhaie/curling/web/Client.java index 76932ec..a621d3a 100644 --- a/src/ovh/alexisdelhaie/curling/web/Client.java +++ b/src/ovh/alexisdelhaie/curling/web/Client.java @@ -1,22 +1,32 @@ package ovh.alexisdelhaie.curling.web; +import javax.net.ssl.*; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; +import java.security.KeyManagementException; +import java.security.NoSuchAlgorithmException; +import java.security.cert.X509Certificate; +import java.time.Duration; import java.util.List; import java.util.Map; +import java.util.Properties; import java.util.concurrent.CompletableFuture; public class Client { + public static long TIMEOUT = 10000; + private String body; private Map headers; private Method method; private String url; + private long timeout; + private boolean allowInvalidSSL; private RequestError error; private String log; @@ -58,17 +68,26 @@ public class Client { } public Client(String body, Map headers, Method method, String url) { + this(body, headers, method, url, false, TIMEOUT); + } + + public Client(String body, Map headers, Method method, String url, boolean allowInvalidSSL) { + this(body, headers, method, url, allowInvalidSSL, TIMEOUT); + } + + public Client(String body, Map headers, Method method, String url, boolean allowInvalidSSL, long timeout) { this.body = body; this.headers = headers; this.method = method; this.url = url; + this.timeout = timeout; + this.allowInvalidSSL = allowInvalidSSL; this.log = ""; } public CompletableFuture run() { - - HttpClient httpClient = HttpClient.newBuilder().build(); try { + HttpClient httpClient = getClient(); HttpRequest request = requestBuilder(); if (request != null) { @@ -86,9 +105,11 @@ public class Client { } result += String.format("\n%s", (String)r.body()); } catch (IOException e) { - e.printStackTrace(); + result += String.format("\n/!\\ %s", e.getMessage()); + error = new RequestError(e.getMessage(), e.getLocalizedMessage(), e); } catch (InterruptedException e) { - e.printStackTrace(); + result += String.format("\n/!\\ %s", e.getMessage()); + error = new RequestError("Thread interrupted", "The action was stopped (by you maybe)", e); } return result; @@ -100,6 +121,10 @@ public class Client { } catch (URISyntaxException e) { error = new RequestError("URL invalide", "Le format de l'URL est invalide", e); + } catch (NoSuchAlgorithmException e) { + e.printStackTrace(); + } catch (KeyManagementException e) { + e.printStackTrace(); } return null; @@ -123,6 +148,31 @@ public class Client { if(method == Method.POST || method == Method.PUT) { log += String.format("%s", body); } + b.timeout(Duration.ofMillis(timeout)); return b.build(); } + + private HttpClient getClient() throws KeyManagementException, NoSuchAlgorithmException { + HttpClient.Builder b = HttpClient.newBuilder(); + b.followRedirects(HttpClient.Redirect.NEVER); + b.version(HttpClient.Version.HTTP_2); + if(allowInvalidSSL) { + b.sslContext(getInvalidSSLConfig()); + } + return b.build(); + } + + private SSLContext getInvalidSSLConfig() throws NoSuchAlgorithmException, KeyManagementException { + TrustManager[] trustAllCerts = new TrustManager[]{ + new X509TrustManager() { + public java.security.cert.X509Certificate[] getAcceptedIssuers() {return null;} + public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType){} + public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType){} + } + }; + + SSLContext sc = SSLContext.getInstance("SSL"); + sc.init(null, trustAllCerts, new java.security.SecureRandom()); + return sc; + } } diff --git a/src/ovh/alexisdelhaie/curling/windows/FormEncodedDialog.form b/src/ovh/alexisdelhaie/curling/windows/FormEncodedDialog.form index 1c7fbda..0dc0f62 100644 --- a/src/ovh/alexisdelhaie/curling/windows/FormEncodedDialog.form +++ b/src/ovh/alexisdelhaie/curling/windows/FormEncodedDialog.form @@ -104,14 +104,6 @@ - - - - - - - - @@ -123,6 +115,19 @@ + + + + + + + + + + + + + diff --git a/src/ovh/alexisdelhaie/curling/windows/MainWindow.form b/src/ovh/alexisdelhaie/curling/windows/MainWindow.form index 73e0fbd..d9e92ae 100644 --- a/src/ovh/alexisdelhaie/curling/windows/MainWindow.form +++ b/src/ovh/alexisdelhaie/curling/windows/MainWindow.form @@ -1,24 +1,13 @@
- + - + - - - - - - - - - - - @@ -32,17 +21,9 @@ - - - - - - - - - + @@ -50,48 +31,15 @@ - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -104,7 +52,7 @@ - + @@ -115,19 +63,9 @@ - - - - - - - - - + @@ -141,6 +79,115 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/ovh/alexisdelhaie/curling/windows/MainWindow.java b/src/ovh/alexisdelhaie/curling/windows/MainWindow.java index 069076a..0d061f9 100644 --- a/src/ovh/alexisdelhaie/curling/windows/MainWindow.java +++ b/src/ovh/alexisdelhaie/curling/windows/MainWindow.java @@ -7,6 +7,8 @@ import ovh.alexisdelhaie.curling.web.Method; import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; import java.net.http.HttpClient; import java.util.HashMap; import java.util.Map; @@ -33,14 +35,17 @@ public class MainWindow extends JDialog { private JButton newHeaderButton; private JButton addAuthButton; private JButton runButton; + private JCheckBox allowInvalidSSLField; private DefaultListModel model; private Map headers; private Map params; + private boolean allowInvalidSSL; public MainWindow() { super((Dialog) null); setTitle(WINDOW_TITLE); + allowInvalidSSL = false; headers = new HashMap<>(); model = new DefaultListModel<>(); list1.setModel(model); @@ -49,6 +54,14 @@ public class MainWindow extends JDialog { setSize(WINDOW_WIDTH, WINDOW_HEIGHT); setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); + httpTypeBox.addActionListener((event) -> { + allowInvalidSSLField.setEnabled(httpTypeBox.getSelectedItem().equals("HTTPS")); + }); + + allowInvalidSSLField.addItemListener((event) -> { + allowInvalidSSL = (event.getStateChange() == ItemEvent.SELECTED); + }); + newHeaderButton.addActionListener((event) -> { AddHeader ah = new AddHeader(); HeaderModel h = ah.getValue(); @@ -92,7 +105,7 @@ public class MainWindow extends JDialog { private void start(ActionEvent ev) { startLoading(true); - Client c = new Client(bodyArea.getText(), headers, getMethod(), urlBuilder()); + Client c = new Client(bodyArea.getText(), headers, getMethod(), urlBuilder(), getAllowInvalidSSL()); CompletableFuture f = c.run(); new Thread(new Runnable() { @Override @@ -137,6 +150,15 @@ public class MainWindow extends JDialog { newHeaderButton.setEnabled(!b); addAuthButton.setEnabled(!b); runButton.setEnabled(!b); + allowInvalidSSLField.setEnabled(!b); + } + + private boolean getAllowInvalidSSL() { + if(httpTypeBox.getSelectedItem().equals("HTTPS")) { + return allowInvalidSSL; + } + + return false; } private void startLoading(boolean b) {