Add params and headers

This commit is contained in:
Alexis Delhaie
2020-10-25 21:50:45 +01:00
parent 78fb958c22
commit 679fff5e63
20 changed files with 720 additions and 120 deletions

View File

@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: ovh.alexisdelhaie.endpoint.Application

View File

@@ -5,10 +5,11 @@ import ovh.alexisdelhaie.endpoint.utils.Tools;
import javax.swing.*;
import java.awt.*;
import java.io.IOException;
public class Application {
public static void main(String[] args) throws UnsupportedLookAndFeelException {
public static void main(String[] args) throws UnsupportedLookAndFeelException, IOException {
UIManager.setLookAndFeel(new FlatIntelliJLaf());
MainWindow dialog = new MainWindow();
dialog.pack();

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="ovh.alexisdelhaie.endpoint.MainWindow">
<grid id="cbd77" binding="contentPane" layout-manager="GridLayoutManager" row-count="4" column-count="9" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="cbd77" binding="contentPane" layout-manager="GridLayoutManager" row-count="4" column-count="16" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="10" left="10" bottom="10" right="10"/>
<constraints>
<xy x="48" y="54" width="1098" height="665"/>
@@ -10,7 +10,9 @@
<children>
<component id="d63fe" class="javax.swing.JComboBox" binding="methodBox">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="69" height="30"/>
</grid>
</constraints>
<properties>
<model>
@@ -24,7 +26,7 @@
</component>
<component id="4f0bf" class="javax.swing.JTextField" binding="urlField">
<constraints>
<grid row="0" column="1" row-span="1" col-span="7" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<grid row="0" column="1" row-span="1" col-span="14" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
@@ -32,7 +34,7 @@
</component>
<component id="842fb" class="javax.swing.JButton" binding="sendButton">
<constraints>
<grid row="0" column="8" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<grid row="0" column="15" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Send"/>
@@ -40,7 +42,7 @@
</component>
<tabbedpane id="59105" binding="tabbedPane1" default-binding="true">
<constraints>
<grid row="2" column="0" row-span="1" col-span="9" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
<grid row="2" column="0" row-span="1" col-span="16" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
<preferred-size width="200" height="200"/>
</grid>
</constraints>
@@ -50,51 +52,76 @@
</tabbedpane>
<component id="269e7" class="javax.swing.JButton" binding="newTabButton">
<constraints>
<grid row="1" column="8" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<grid row="1" column="15" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="+"/>
</properties>
</component>
<component id="865d3" class="javax.swing.JProgressBar" binding="progressBar1" default-binding="true">
<hspacer id="99ebb">
<constraints>
<grid row="3" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<grid row="3" column="10" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<hspacer id="61410">
<constraints>
<grid row="3" column="11" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<hspacer id="a631b">
<constraints>
<grid row="3" column="12" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<hspacer id="a9cf4">
<constraints>
<grid row="3" column="13" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<hspacer id="98507">
<constraints>
<grid row="3" column="14" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<component id="8a044" class="javax.swing.JProgressBar" binding="progressBar1" default-binding="true">
<constraints>
<grid row="3" column="0" row-span="1" col-span="5" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
<component id="d8db9" class="javax.swing.JLabel" binding="statusLabel">
<constraints>
<grid row="3" column="5" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<indeterminate value="true"/>
<font style="1"/>
<text value="Execute request to get status"/>
<visible value="false"/>
</properties>
</component>
<hspacer id="99ebb">
<constraints>
<grid row="3" column="3" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<hspacer id="106fa">
<constraints>
<grid row="3" column="4" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<hspacer id="82267">
<constraints>
<grid row="3" column="5" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<hspacer id="b9351">
<constraints>
<grid row="3" column="6" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<hspacer id="14145">
<hspacer id="ddb06">
<constraints>
<grid row="3" column="7" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<hspacer id="330cc">
<hspacer id="205f4">
<constraints>
<grid row="3" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<grid row="3" column="8" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<hspacer id="8678b">
<constraints>
<grid row="3" column="9" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<component id="45ca1" class="javax.swing.JButton" binding="settingsButton" default-binding="true">
<constraints>
<grid row="1" column="14" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Settings"/>
</properties>
</component>
</children>
</grid>
</form>

View File

@@ -1,6 +1,7 @@
package ovh.alexisdelhaie.endpoint;
import ovh.alexisdelhaie.endpoint.builder.TabBuilder;
import ovh.alexisdelhaie.endpoint.configuration.ConfigurationDialog;
import ovh.alexisdelhaie.endpoint.configuration.ConfigurationProperties;
import ovh.alexisdelhaie.endpoint.http.HttpClient;
import ovh.alexisdelhaie.endpoint.http.Request;
@@ -8,9 +9,8 @@ import ovh.alexisdelhaie.endpoint.http.RequestBuilder;
import ovh.alexisdelhaie.endpoint.http.Response;
import ovh.alexisdelhaie.endpoint.utils.MessageDialog;
import javax.imageio.ImageIO;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import java.awt.*;
@@ -22,9 +22,28 @@ import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
public class MainWindow extends JFrame {
private enum StatusColor {
INFORMATION("#53baf5"),
SUCCESS("#7ccf16"),
REDIRECTION("#b153f5"),
ERROR_CLIENT("#f5ca53"),
ERROR_SERVER("#f55353");
private final String hex;
StatusColor(String s) {
hex = s;
}
public String getHex() {
return hex;
}
}
// Constants
public final static int WIDTH = 1280;
public final static int HEIGHT = 720;
@@ -36,27 +55,45 @@ public class MainWindow extends JFrame {
private JTabbedPane tabbedPane1;
private JButton newTabButton;
private JProgressBar progressBar1;
private JLabel statusLabel;
private JButton settingsButton;
private final ConfigurationProperties props;
private final HashMap<Integer, String> urls;
public MainWindow() {
private final ConcurrentHashMap<Integer, Boolean> controlState;
private final ConcurrentHashMap<Integer, Response> responses;
public MainWindow() throws IOException {
props = new ConfigurationProperties();
controlState = new ConcurrentHashMap<>();
responses = new ConcurrentHashMap<>();
urls = new HashMap<>();
setIconImage(ImageIO.read(MainWindow.class.getResource("/icon.png")));
setContentPane(contentPane);
setMinimumSize(new Dimension(WIDTH, HEIGHT));
setSize(WIDTH, HEIGHT);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
TabBuilder.create(tabbedPane1, "New request", urls);
TabBuilder.create(tabbedPane1, "New request", urls, urlField);
Component tab = tabbedPane1.getSelectedComponent();
urls.put(tab.hashCode(), "");
enableControl(true, tab.hashCode());
settingsButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
super.mouseClicked(e);
ConfigurationDialog.showDialog(props);
}
});
newTabButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
super.mouseClicked(e);
TabBuilder.create(tabbedPane1, "New request", urls);
TabBuilder.create(tabbedPane1, "New request", urls, urlField);
Component tab = tabbedPane1.getSelectedComponent();
urls.put(tab.hashCode(), "");
enableControl(true, tab.hashCode());
showStatus(tab.hashCode());
}
});
sendButton.addMouseListener(new MouseAdapter() {
@@ -70,11 +107,12 @@ public class MainWindow extends JFrame {
}
}
});
tabbedPane1.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
if (tabbedPane1.getSelectedIndex() != -1) {
urlField.setText(urls.get(tabbedPane1.getSelectedComponent().hashCode()));
}
tabbedPane1.addChangeListener(e -> {
if (tabbedPane1.getSelectedIndex() != -1) {
int hashCode = tabbedPane1.getSelectedComponent().hashCode();
urlField.setText(urls.get(hashCode));
enableControl(controlState.get(hashCode), hashCode);
showStatus(tab.hashCode());
}
});
urlField.getDocument().addDocumentListener(new DocumentListener() {
@@ -100,32 +138,44 @@ public class MainWindow extends JFrame {
Optional<JSplitPane> possibleTab = getSelectedTab();
if (possibleTab.isPresent()) {
JSplitPane tab = possibleTab.get();
int tabHashCode = tab.hashCode();
statusLabel.setVisible(false);
enableControl(false, tabHashCode);
int i = tabbedPane1.indexOfComponent(tab);
JTextArea bodyField = TabBuilder.getResponseArea(i);
progressBar1.setVisible(true);
JTextArea responseBody = TabBuilder.getResponseArea(i);
responseBody.setForeground(Color.black);
responseBody.setText("");
JTextArea bodyField = TabBuilder.getBody(i);
new Thread(() -> {
try {
String url = urlField.getText();
HttpClient h = new HttpClient(props);
Request r = new RequestBuilder(url)
.setCustomHeaders(TabBuilder.getHeaders(i))
.build();
Optional<Response> possibleRes = Optional.empty();
switch ((String) Objects.requireNonNull(methodBox.getSelectedItem())) {
case "GET" -> possibleRes = h.get(r);
case "POST" -> possibleRes = h.post(r, "");
case "PUT" -> possibleRes = h.put(r, "");
case "POST" -> possibleRes = h.post(r, bodyField.getText());
case "PUT" -> possibleRes = h.put(r, bodyField.getText());
case "DELETE" -> possibleRes = h.delete(r);
case "HEAD" -> possibleRes = h.head(r);
}
if (possibleRes.isPresent()) {
Response res = possibleRes.get();
bodyField.setText(res.getBody());
responses.put(tabHashCode, res);
responseBody.setText(res.getBody());
}
} catch (KeyManagementException | IOException | NoSuchAlgorithmException e) {
bodyField.setText(e.getMessage());
responseBody.setForeground(Color.red);
responseBody.setText(e.getMessage());
if (responses.containsKey(tabHashCode)) {
responses.remove(tabHashCode);
showStatus(tabHashCode);
}
} finally {
progressBar1.setVisible(false);
enableControl(true, tabHashCode);
showStatus(tabHashCode);
}
}).start();
} else {
@@ -133,6 +183,55 @@ public class MainWindow extends JFrame {
}
}
private void enableControl(Boolean state, int hashCode) {
if (Objects.nonNull(state)) {
controlState.put(hashCode, state);
if (tabbedPane1.getSelectedComponent().hashCode() == hashCode) {
sendButton.setEnabled(state);
urlField.setEnabled(state);
methodBox.setEnabled(state);
progressBar1.setIndeterminate(!state);
}
}
}
private void showStatus(int hashCode) {
if (controlState.get(hashCode) && responses.containsKey(hashCode) &&
tabbedPane1.getSelectedComponent().hashCode() == hashCode) {
statusLabel.setForeground(Color.BLACK);
Response res = responses.get(hashCode);
final StringBuilder sb = new StringBuilder();
if (res.getStatusCode() != -1) {
sb.append(res.getStatusCode())
.append(" ")
.append(res.getStatus())
.append(" (in ")
.append(res.getTime())
.append(" ms)");
if (res.getStatusCode() >= 100 && res.getStatusCode() < 200) {
statusLabel.setForeground(Color.decode(StatusColor.INFORMATION.getHex()));
} else if (res.getStatusCode() >= 200 && res.getStatusCode() < 300) {
statusLabel.setForeground(Color.decode(StatusColor.SUCCESS.getHex()));
} else if (res.getStatusCode() >= 300 && res.getStatusCode() < 400) {
statusLabel.setForeground(Color.decode(StatusColor.REDIRECTION.getHex()));
} else if (res.getStatusCode() >= 400 && res.getStatusCode() < 500) {
statusLabel.setForeground(Color.decode(StatusColor.ERROR_CLIENT.getHex()));
} else if (res.getStatusCode() >= 500) {
statusLabel.setForeground(Color.decode(StatusColor.ERROR_SERVER.getHex()));
}
} else {
sb.append("in ")
.append(res.getTime())
.append(" ms");
}
statusLabel.setText(sb.toString());
statusLabel.setVisible(true);
} else {
statusLabel.setVisible(false);
}
}
private Optional<JSplitPane> getSelectedTab() {
Component c = tabbedPane1.getSelectedComponent();
if (c instanceof JSplitPane) {

View File

@@ -1,30 +1,24 @@
package ovh.alexisdelhaie.endpoint.builder;
import ovh.alexisdelhaie.endpoint.utils.InsertToTableDialog;
import ovh.alexisdelhaie.endpoint.utils.KeyValuePair;
import ovh.alexisdelhaie.endpoint.utils.Tools;
import ovh.alexisdelhaie.endpoint.utils.adapter.CustomDeleteMouseAdapter;
import ovh.alexisdelhaie.endpoint.utils.adapter.CustomNewMouseAdapter;
import ovh.alexisdelhaie.endpoint.utils.adapter.DeleteParamMouseAdapter;
import ovh.alexisdelhaie.endpoint.utils.adapter.NewParamMouseAdapter;
import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.IOException;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
public class TabBuilder {
private static HashMap<String, Component> indexes = new HashMap<>();
private static final HashMap<String, Component> indexes = new HashMap<>();
public static void create(JTabbedPane tab, String label, HashMap<Integer, String> urls) {
Component c = tab.add("", buildMainPanel());
public static void create(JTabbedPane tab, String label, HashMap<Integer, String> urls, JTextField urlField) {
Component c = tab.add("", buildMainPanel(urlField));
int index = tab.indexOfComponent(c);
updateIndexes(index);
tab.setTabComponentAt(index, buildTabPanel(tab, c, label, urls));
@@ -33,7 +27,13 @@ public class TabBuilder {
private static void updateIndexes(int index) {
indexes.put("main[" + index + "].responseTextArea", indexes.get("main[waiting].responseTextArea"));
indexes.put("main[" + index + "].body", indexes.get("main[waiting].body"));
indexes.put("main[" + index + "].params", indexes.get("main[waiting].params"));
indexes.put("main[" + index + "].headers", indexes.get("main[waiting].headers"));
indexes.remove("main[waiting].responseTextArea");
indexes.remove("main[waiting].body");
indexes.remove("main[waiting].params");
indexes.remove("main[waiting].headers");
}
private static JPanel buildTabPanel(JTabbedPane tab, Component c, String label, HashMap<Integer, String> urls) {
@@ -68,7 +68,7 @@ public class TabBuilder {
return b;
}
private static JSplitPane buildMainPanel() {
private static JSplitPane buildMainPanel(JTextField urlField) {
JTextArea t = new JTextArea();
t.setBackground(Color.WHITE);
t.setEditable(false);
@@ -76,73 +76,57 @@ public class TabBuilder {
indexes.put("main[waiting].responseTextArea", t);
return new JSplitPane(
JSplitPane.VERTICAL_SPLIT,
buildParametersTabbedPane(),
buildParametersTabbedPane(urlField),
sp
);
}
private static JTabbedPane buildParametersTabbedPane() {
private static JTabbedPane buildParametersTabbedPane(JTextField urlField) {
JTabbedPane p = new JTabbedPane();
p.add("Params", buildParamsTab());
p.add("Params", buildParamsTab(true, urlField));
p.add("Authorization", new JPanel());
p.add("Headers", buildParamsTab());
p.add("Body", new JTextArea());
p.add("Headers", buildParamsTab(false, null));
JTextArea body = new JTextArea();
indexes.put("main[waiting].body", body);
p.add("Body", body);
return p;
}
private static JTable buildTable() {
JTable t = new JTable();
TableColumn keyCol = new TableColumn();
keyCol.setHeaderValue("Keys");
TableColumn valCol = new TableColumn();
valCol.setHeaderValue("Values");
t.addColumn(keyCol);
t.addColumn(valCol);
return t;
}
public static JTextArea getResponseArea(int index) {
return (JTextArea) indexes.get("main[" + index + "].responseTextArea");
}
private static JPanel buildParamsTab() {
public static JTextArea getBody(int index) {
return (JTextArea) indexes.get("main[" + index + "].body");
}
public static HashMap<String, String> getParams(int index) {
JTable t = (JTable) indexes.get("main[" + index + "].params");
return Tools.tableToHashMap(t);
}
public static HashMap<String, String> getHeaders(int index) {
JTable t = (JTable) indexes.get("main[" + index + "].headers");
return Tools.tableToHashMap(t);
}
private static JPanel buildParamsTab(boolean isParam, JTextField urlField) {
String[] headers = {"Keys", "Values"};
Object[][] datas = {};
DefaultTableModel model = new DefaultTableModel(datas, headers);
DefaultTableModel model = new DefaultTableModel(new Object[][]{}, headers);
JPanel p = new JPanel();
JTable t = new JTable(model);
JButton addButton = new JButton("Add new parameter");
JButton delButton = new JButton("Delete parameter");
indexes.put((isParam) ? "main[waiting].params" : "main[waiting].headers", t);
JButton addButton = new JButton("New");
JButton delButton = new JButton("Remove");
delButton.setEnabled(false);
t.getSelectionModel().addListSelectionListener(new ListSelectionListener(){
public void valueChanged(ListSelectionEvent event) {
delButton.setEnabled(t.getSelectedRows().length > 0);
}
});
addButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
super.mouseClicked(e);
Optional<KeyValuePair> result = InsertToTableDialog.showDialog("Enter value");
if (result.isPresent()) {
DefaultTableModel m = (DefaultTableModel) t.getModel();
m.addRow(new Object[]{result.get().getKey(), result.get().getValue()});
}
}
});
delButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
super.mouseClicked(e);
int n = t.getSelectedRows().length;
if (n > 0) {
DefaultTableModel m = (DefaultTableModel) t.getModel();
for(int i = 0; i < n; i++) {
m.removeRow(t.getSelectedRow());
}
}
}
});
t.getSelectionModel().addListSelectionListener(event -> delButton.setEnabled(t.getSelectedRows().length > 0));
if (isParam) {
addButton.addMouseListener(new NewParamMouseAdapter(t, urlField));
delButton.addMouseListener(new DeleteParamMouseAdapter(t, urlField));
} else {
addButton.addMouseListener(new CustomNewMouseAdapter(t));
delButton.addMouseListener(new CustomDeleteMouseAdapter(t));
}
p.add(addButton);
p.add(delButton);
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));

View File

@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="ovh.alexisdelhaie.endpoint.configuration.AboutDialog">
<grid id="cbd77" binding="contentPane" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="10" left="10" bottom="10" right="10"/>
<constraints>
<xy x="48" y="54" width="451" height="414"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="e3588" layout-manager="GridLayoutManager" row-count="5" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="9d713" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Author: Alexis Delhaie (@alexlegarnd)"/>
</properties>
</component>
<component id="b3568" class="javax.swing.JLabel" binding="version">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Version: 0.0.0 (Unrecognized)"/>
</properties>
</component>
<component id="444e9" class="javax.swing.JLabel" binding="javaVersion">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Software: Java version not recognized"/>
</properties>
</component>
<component id="40714" class="javax.swing.JLabel">
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Installer: Delphi 10.3.3 Community"/>
</properties>
</component>
<component id="93468" class="javax.swing.JLabel">
<constraints>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Installer Bootstrap: Python 3.8.5 [MSC v.1924 (AMD64)]"/>
</properties>
</component>
</children>
</grid>
</children>
</grid>
</form>

View File

@@ -0,0 +1,37 @@
package ovh.alexisdelhaie.endpoint.configuration;
import ovh.alexisdelhaie.endpoint.utils.Tools;
import javax.swing.*;
import java.awt.*;
public class AboutDialog extends JDialog {
public static final int WIDTH = 450;
public static final int HEIGHT = 500;
public static final String VERSION = "0.1.3";
private JPanel contentPane;
private JLabel version;
private JLabel javaVersion;
private AboutDialog() {
setContentPane(contentPane);
setModal(true);
setTitle("About EndPoint");
version.setText("Version: " + VERSION + " (NOT FINISHED)");
javaVersion.setText("Software: Java " + System.getProperty("java.version") + " (GUI: Java Swing)");
}
public static void showDialog() {
AboutDialog dialog = new AboutDialog();
dialog.setModal(true);
dialog.setMinimumSize(new Dimension(WIDTH, HEIGHT));
dialog.setMaximumSize(new Dimension(WIDTH, HEIGHT));
dialog.setResizable(false);
Tools.centerFrame(dialog);
dialog.setVisible(true);
}
}

View File

@@ -0,0 +1,175 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="ovh.alexisdelhaie.endpoint.configuration.ConfigurationDialog">
<grid id="cbd77" binding="contentPane" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="10" left="10" bottom="10" right="10"/>
<constraints>
<xy x="48" y="54" width="436" height="548"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="94766" layout-manager="GridLayoutManager" row-count="1" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<hspacer id="98af6">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<grid id="9538f" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="e7465" class="javax.swing.JButton" binding="buttonOK">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="OK"/>
</properties>
</component>
</children>
</grid>
<component id="6ce6a" class="javax.swing.JButton" binding="aboutButton" default-binding="true">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="About"/>
</properties>
</component>
</children>
</grid>
<grid id="e3588" layout-manager="GridLayoutManager" row-count="7" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="bd5a4" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font style="1"/>
<text value="SSL"/>
</properties>
</component>
<hspacer id="cead8">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<vspacer id="d1324">
<constraints>
<grid row="6" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="c7f68" class="javax.swing.JLabel">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Allow invalid SSL certificate"/>
</properties>
</component>
<component id="29186" class="javax.swing.JLabel">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Downgrade when SSL failed"/>
</properties>
</component>
<component id="6b9a8" class="javax.swing.JLabel">
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font style="1"/>
<text value="Requests"/>
</properties>
</component>
<component id="a81f8" class="javax.swing.JLabel">
<constraints>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="HTTP Version"/>
</properties>
</component>
<hspacer id="b74d9">
<constraints>
<grid row="2" column="1" row-span="1" col-span="3" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<hspacer id="a9ad8">
<constraints>
<grid row="4" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<component id="747d1" class="javax.swing.JComboBox" binding="httpVersion">
<constraints>
<grid row="4" column="2" row-span="1" col-span="3" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<model>
<item value="HTTP/1.0"/>
<item value="HTTP/1.1"/>
</model>
</properties>
</component>
<hspacer id="c9d2e">
<constraints>
<grid row="1" column="1" row-span="1" col-span="3" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<component id="51da5" class="javax.swing.JLabel">
<constraints>
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Timeout (TTL)"/>
</properties>
</component>
<component id="fb7c" class="javax.swing.JCheckBox" binding="allowInvalidSsl">
<constraints>
<grid row="1" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value=""/>
</properties>
</component>
<component id="3d1d" class="javax.swing.JCheckBox" binding="allowDowngrade">
<constraints>
<grid row="2" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<hideActionText value="true"/>
<horizontalAlignment value="10"/>
<selected value="true"/>
<text value=""/>
</properties>
</component>
<component id="e63f7" class="javax.swing.JSpinner" binding="timeout">
<constraints>
<grid row="5" column="2" row-span="1" col-span="3" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
</children>
</grid>
</children>
</grid>
</form>

View File

@@ -0,0 +1,64 @@
package ovh.alexisdelhaie.endpoint.configuration;
import ovh.alexisdelhaie.endpoint.utils.Tools;
import javax.swing.*;
import java.awt.*;
public class ConfigurationDialog extends JDialog {
public static final int WIDTH = 450;
public static final int HEIGHT = 700;
private JPanel contentPane;
private JButton buttonOK;
private JCheckBox allowInvalidSsl;
private JCheckBox allowDowngrade;
private JComboBox<String> httpVersion;
private JSpinner timeout;
private JButton aboutButton;
private final ConfigurationProperties props;
private ConfigurationDialog(ConfigurationProperties props) {
setContentPane(contentPane);
setModal(true);
getRootPane().setDefaultButton(buttonOK);
setTitle("Settings");
this.props = props;
buttonOK.addActionListener(e -> onOK());
aboutButton.addActionListener(e -> AboutDialog.showDialog());
allowInvalidSsl.setSelected(this.props.getBooleanProperty("allowInvalidSsl", false));
allowDowngrade.setSelected(this.props.getBooleanProperty("allowDowngrade", true));
httpVersion.setSelectedItem(this.props.getStringProperty("httpVersion", "HTTP/1.0"));
timeout.setValue(this.props.getIntegerProperty("timeout", 10000));
allowInvalidSsl.addActionListener((e) -> {
this.props.setProperty("allowInvalidSsl", String.valueOf(allowInvalidSsl.isSelected()));
});
allowDowngrade.addActionListener((e) -> {
this.props.setProperty("allowDowngrade", String.valueOf(allowDowngrade.isSelected()));
});
httpVersion.addActionListener((e) -> {
this.props.setProperty("httpVersion", (String) httpVersion.getSelectedItem());
});
timeout.addChangeListener((e) -> {
this.props.setProperty("timeout", String.valueOf(timeout.getValue()));
});
}
private void onOK() {
dispose();
}
public static void showDialog(ConfigurationProperties props) {
ConfigurationDialog dialog = new ConfigurationDialog(props);
dialog.setModal(true);
dialog.setMinimumSize(new Dimension(WIDTH, HEIGHT));
dialog.setMaximumSize(new Dimension(WIDTH, HEIGHT));
dialog.setResizable(false);
Tools.centerFrame(dialog);
dialog.setVisible(true);
}
}

View File

@@ -52,6 +52,13 @@ public class ConfigurationProperties {
return defaultB;
}
public int getIntegerProperty(String key, int defaultI) {
if (properties.containsKey(key)) {
return Integer.parseInt(properties.get(key));
}
return defaultI;
}
private void save() {
try {
mapper.writeValue(new File(filepath), properties);

View File

@@ -27,12 +27,16 @@ public class HttpClient {
private final boolean allowInvalidSsl;
private final boolean allowDowngrade;
private final String httpVersion;
private final int timeout;
private boolean downgraded;
public HttpClient(ConfigurationProperties props) {
this.allowInvalidSsl = props.getBooleanProperty("allowInvalidSsl", DEFAULT_ALLOW_INVALID_SSL);
this.allowDowngrade = props.getBooleanProperty("allowDowngrade", DEFAULT_ALLOW_DOWNGRADE);
this.httpVersion = props.getStringProperty("httpVersion", DEFAULT_HTTP_VERSION);
this.timeout = props.getIntegerProperty("timeout", DEFAULT_TIMEOUT);
this.downgraded = false;
}
@@ -99,7 +103,7 @@ public class HttpClient {
private Socket buildSocket(String host, int port) throws IOException {
Socket s = new Socket(host, port);
s.setKeepAlive(false);
s.setSoTimeout(DEFAULT_TIMEOUT);
s.setSoTimeout(timeout);
return s;
}
@@ -124,7 +128,7 @@ public class HttpClient {
SSLSocket s = (SSLSocket) factory.createSocket(host, port);
s.setEnabledProtocols(new String[] { "SSLv3", "TLSv1", "TLSv1.1", "TLSv1.2" });
s.setKeepAlive(false);
s.setSoTimeout(DEFAULT_TIMEOUT);
s.setSoTimeout(timeout);
if (allowDowngrade) {
try {
s.startHandshake();

View File

@@ -1,6 +1,9 @@
package ovh.alexisdelhaie.endpoint.utils;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.util.HashMap;
public class Tools {
@@ -18,4 +21,15 @@ public class Tools {
frame.setLocation(x, y);
}
public static HashMap<String, String> tableToHashMap(JTable table) {
HashMap<String, String> result = new HashMap<>();
DefaultTableModel m = (DefaultTableModel) table.getModel();
for (int i = 0; i < m.getRowCount(); i++) {
String key = (String) m.getValueAt(i, 0);
String value = (String) m.getValueAt(i, 1);
result.put(key, value);
}
return result;
}
}

View File

@@ -0,0 +1,34 @@
package ovh.alexisdelhaie.endpoint.utils.adapter;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class CustomDeleteMouseAdapter extends MouseAdapter {
protected final JTable table;
protected boolean valid = false;
public CustomDeleteMouseAdapter(JTable table) {
this.table = table;
}
@Override
public void mouseClicked(MouseEvent e) {
super.mouseClicked(e);
updateTable();
}
private void updateTable() {
int n = table.getSelectedRows().length;
if (n > 0) {
DefaultTableModel m = (DefaultTableModel) table.getModel();
for(int i = 0; i < n; i++) {
m.removeRow(table.getSelectedRow());
}
valid = true;
}
}
}

View File

@@ -0,0 +1,36 @@
package ovh.alexisdelhaie.endpoint.utils.adapter;
import ovh.alexisdelhaie.endpoint.utils.InsertToTableDialog;
import ovh.alexisdelhaie.endpoint.utils.KeyValuePair;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Optional;
public class CustomNewMouseAdapter extends MouseAdapter {
protected final JTable table;
protected boolean valid = false;
public CustomNewMouseAdapter(JTable table) {
this.table = table;
}
@Override
public void mouseClicked(MouseEvent e) {
super.mouseClicked(e);
updateTable();
}
private void updateTable() {
Optional<KeyValuePair> result = InsertToTableDialog.showDialog("Enter value");
if (result.isPresent()) {
DefaultTableModel m = (DefaultTableModel) table.getModel();
m.addRow(new Object[]{result.get().getKey(), result.get().getValue()});
valid = true;
}
}
}

View File

@@ -0,0 +1,26 @@
package ovh.alexisdelhaie.endpoint.utils.adapter;
import ovh.alexisdelhaie.endpoint.url.URLGenerator;
import ovh.alexisdelhaie.endpoint.utils.Tools;
import javax.swing.*;
import java.awt.event.MouseEvent;
public class DeleteParamMouseAdapter extends CustomDeleteMouseAdapter {
private final JTextField urlField;
public DeleteParamMouseAdapter(JTable table, JTextField urlField) {
super(table);
this.urlField = urlField;
}
@Override
public void mouseClicked(MouseEvent e) {
super.mouseClicked(e);
if (super.valid) {
urlField.setText(URLGenerator.processNewUrl(Tools.tableToHashMap(super.table), urlField.getText()));
}
}
}

View File

@@ -0,0 +1,26 @@
package ovh.alexisdelhaie.endpoint.utils.adapter;
import ovh.alexisdelhaie.endpoint.url.URLGenerator;
import ovh.alexisdelhaie.endpoint.utils.Tools;
import javax.swing.*;
import java.awt.event.MouseEvent;
public class NewParamMouseAdapter extends CustomNewMouseAdapter {
private final JTextField urlField;
public NewParamMouseAdapter(JTable table, JTextField urlField) {
super(table);
this.urlField = urlField;
}
@Override
public void mouseClicked(MouseEvent e) {
super.mouseClicked(e);
if (super.valid) {
urlField.setText(URLGenerator.processNewUrl(Tools.tableToHashMap(super.table), urlField.getText()));
}
}
}