-
Notifications
You must be signed in to change notification settings - Fork 2
feat(common): Add HttpTool #2142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
eceefde
feat(common): Add HttpTool
unknowIfGuestInDream 4a24945
feat(common): Add HttpTool
unknowIfGuestInDream d04d2d9
feat(common): Add HttpTool
unknowIfGuestInDream 1da8494
feat(common): Add HttpTool
unknowIfGuestInDream 247eb45
feat(common): Add HttpTool
unknowIfGuestInDream 94efefe
feat(common): Add HttpTool
unknowIfGuestInDream 4837b8e
feat(common): Add HttpTool
unknowIfGuestInDream 111c038
feat(common): Add HttpTool
unknowIfGuestInDream 0cd1d1d
feat(common): Add HttpTool
unknowIfGuestInDream File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
380 changes: 380 additions & 0 deletions
380
common/src/main/java/com/tlcsdm/jfxcommon/debug/HttpTool.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
176 changes: 176 additions & 0 deletions
176
common/src/main/resources/com/tlcsdm/jfxcommon/fxml/httpTool.fxml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<!-- | ||
~ Copyright (c) 2024 unknowIfGuestInDream. | ||
~ All rights reserved. | ||
~ | ||
~ Redistribution and use in source and binary forms, with or without | ||
~ modification, are permitted provided that the following conditions are met: | ||
~ * Redistributions of source code must retain the above copyright | ||
~ notice, this list of conditions and the following disclaimer. | ||
~ * Redistributions in binary form must reproduce the above copyright | ||
~ notice, this list of conditions and the following disclaimer in the | ||
~ documentation and/or other materials provided with the distribution. | ||
~ * Neither the name of unknowIfGuestInDream, any associated website, nor the | ||
~ names of its contributors may be used to endorse or promote products | ||
~ derived from this software without specific prior written permission. | ||
~ | ||
~ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
~ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
~ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
~ DISCLAIMED. IN NO EVENT SHALL UNKNOWIFGUESTINDREAM BE LIABLE FOR ANY | ||
~ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
~ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
~ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
~ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
~ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
~ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
--> | ||
|
||
|
||
<?import com.tlcsdm.core.javafx.richtext.InformationArea?> | ||
<?import com.tlcsdm.core.javafx.richtext.JsonCodeArea?> | ||
<?import javafx.geometry.Insets?> | ||
<?import javafx.scene.control.Button?> | ||
<?import javafx.scene.control.CheckBox?> | ||
<?import javafx.scene.control.ChoiceBox?> | ||
<?import javafx.scene.control.Label?> | ||
<?import javafx.scene.control.Tab?> | ||
<?import javafx.scene.control.TableColumn?> | ||
<?import javafx.scene.control.TableView?> | ||
<?import javafx.scene.control.TabPane?> | ||
<?import javafx.scene.control.TextArea?> | ||
<?import javafx.scene.control.TextField?> | ||
<?import javafx.scene.layout.AnchorPane?> | ||
<?import javafx.scene.layout.BorderPane?> | ||
<?import javafx.scene.layout.HBox?> | ||
<?import javafx.scene.layout.StackPane?> | ||
<?import javafx.scene.layout.VBox?> | ||
<?import org.fxmisc.flowless.VirtualizedScrollPane?> | ||
<AnchorPane prefHeight="520.0" prefWidth="854.0" xmlns="http://javafx.com/javafx/8.0.171" | ||
xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.tlcsdm.jfxcommon.debug.HttpTool"> | ||
<children> | ||
<BorderPane prefHeight="200.0" prefWidth="200.0" AnchorPane.bottomAnchor="10.0" AnchorPane.leftAnchor="10.0" | ||
AnchorPane.rightAnchor="10.0" AnchorPane.topAnchor="10.0"> | ||
<top> | ||
<HBox alignment="CENTER" spacing="5.0" BorderPane.alignment="CENTER"> | ||
<children> | ||
<Label text="Url:"/> | ||
<TextField fx:id="urlTextField" promptText="请输入Url" | ||
text="https://api.github.com" HBox.hgrow="ALWAYS"/> | ||
<Label text="Method:"/> | ||
<ChoiceBox fx:id="methodChoiceBox" prefWidth="150.0"/> | ||
<Button fx:id="sendButton" mnemonicParsing="false" onAction="#sendAction" text="Send"/> | ||
<Button fx:id="toBrowerButton" mnemonicParsing="false" onAction="#toBrowerAction" | ||
text="在浏览器中打开"/> | ||
</children> | ||
</HBox> | ||
</top> | ||
<left> | ||
<VBox spacing="5.0" BorderPane.alignment="CENTER"> | ||
<children> | ||
<HBox alignment="CENTER_LEFT" spacing="5.0"> | ||
<children> | ||
<CheckBox fx:id="paramsDataCheckBox" mnemonicParsing="false" selected="true" | ||
text="请求参数"/> | ||
<Button fx:id="addParamsDataButton" mnemonicParsing="false" | ||
onAction="#addParamsDataAction" text="添加"/> | ||
<CheckBox fx:id="paramsDataIsStringCheckBox" mnemonicParsing="false" text="字符串"/> | ||
</children> | ||
</HBox> | ||
<StackPane> | ||
<children> | ||
<TextArea fx:id="paramsDataTextArea" prefHeight="200.0" prefWidth="200.0" | ||
visible="false"/> | ||
<TableView fx:id="paramsDataTableView" editable="true"> | ||
<columns> | ||
<TableColumn fx:id="paramsDataNameTableColumn" prefWidth="59.0" text="参数名"/> | ||
<TableColumn fx:id="paramsDataValueTableColumn" prefWidth="73.0" text="参数值"/> | ||
<TableColumn fx:id="paramsDataRemarkTableColumn" prefWidth="75.0" text="备注"/> | ||
</columns> | ||
<columnResizePolicy> | ||
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY"/> | ||
</columnResizePolicy> | ||
</TableView> | ||
</children> | ||
</StackPane> | ||
<HBox alignment="CENTER_LEFT" spacing="5.0"> | ||
<children> | ||
<CheckBox fx:id="paramsHeaderCheckBox" mnemonicParsing="false" selected="true" | ||
text="请求Header"/> | ||
<Button fx:id="addParamsHeaderButton" mnemonicParsing="false" | ||
onAction="#addParamsHeaderAction" text="添加"/> | ||
</children> | ||
</HBox> | ||
<TableView fx:id="paramsHeaderTableView" editable="true"> | ||
<columns> | ||
<TableColumn fx:id="paramsHeaderNameTableColumn" prefWidth="75.0" text="参数名"/> | ||
<TableColumn fx:id="paramsHeaderValueTableColumn" prefWidth="75.0" text="参数值"/> | ||
<TableColumn fx:id="paramsHeaderRemarkTableColumn" prefWidth="75.0" text="备注"/> | ||
</columns> | ||
<columnResizePolicy> | ||
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY"/> | ||
</columnResizePolicy> | ||
</TableView> | ||
<HBox alignment="CENTER_LEFT" spacing="5.0"> | ||
<children> | ||
<CheckBox fx:id="paramsCookieCheckBox" mnemonicParsing="false" selected="true" | ||
text="请求Cookie"/> | ||
<Button fx:id="addParamsCookieButton" mnemonicParsing="false" | ||
onAction="#addParamsCookieAction" text="添加"/> | ||
</children> | ||
</HBox> | ||
<TableView fx:id="paramsCookieTableView" editable="true"> | ||
<columns> | ||
<TableColumn fx:id="paramsCookieNameTableColumn" prefWidth="75.0" text="参数名"/> | ||
<TableColumn fx:id="paramsCookieValueTableColumn" prefWidth="75.0" text="参数值"/> | ||
<TableColumn fx:id="paramsCookieRemarkTableColumn" prefWidth="75.0" text="备注"/> | ||
</columns> | ||
<columnResizePolicy> | ||
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY"/> | ||
</columnResizePolicy> | ||
</TableView> | ||
</children> | ||
</VBox> | ||
</left> | ||
<center> | ||
<TabPane prefHeight="200.0" prefWidth="200.0" tabClosingPolicy="UNAVAILABLE" | ||
BorderPane.alignment="CENTER"> | ||
<tabs> | ||
<Tab text="响应内容"> | ||
<content> | ||
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0"> | ||
<children> | ||
<VirtualizedScrollPane AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" | ||
AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"> | ||
<content> | ||
<JsonCodeArea fx:id="ResponseBodyTextArea"/> | ||
</content> | ||
</VirtualizedScrollPane> | ||
</children> | ||
</AnchorPane> | ||
</content> | ||
</Tab> | ||
<Tab text="响应头部"> | ||
<content> | ||
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0"> | ||
<children> | ||
<VirtualizedScrollPane AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" | ||
AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"> | ||
<content> | ||
<InformationArea fx:id="ResponseHeaderTextArea"/> | ||
</content> | ||
</VirtualizedScrollPane> | ||
</children> | ||
</AnchorPane> | ||
</content> | ||
</Tab> | ||
</tabs> | ||
<BorderPane.margin> | ||
<Insets left="10.0" top="10.0"/> | ||
</BorderPane.margin> | ||
</TabPane> | ||
</center> | ||
</BorderPane> | ||
</children> | ||
</AnchorPane> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
core/src/main/java/com/tlcsdm/core/javafx/richtext/JsonCodeArea.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
* Copyright (c) 2025 unknowIfGuestInDream. | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* * Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* * Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* * Neither the name of unknowIfGuestInDream, any associated website, nor the | ||
* names of its contributors may be used to endorse or promote products | ||
* derived from this software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
* DISCLAIMED. IN NO EVENT SHALL UNKNOWIFGUESTINDREAM BE LIABLE FOR ANY | ||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
package com.tlcsdm.core.javafx.richtext; | ||
|
||
import org.fxmisc.richtext.CodeArea; | ||
import org.fxmisc.richtext.LineNumberFactory; | ||
import org.fxmisc.richtext.model.StyleSpans; | ||
import org.fxmisc.richtext.model.StyleSpansBuilder; | ||
|
||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
/** | ||
* SON Code Area | ||
* | ||
* @author unknowIfGuestInDream | ||
*/ | ||
public class JsonCodeArea extends CodeArea { | ||
|
||
//匹配 JSON 的 key | ||
private static final String KEY_PATTERN = "\"(\\w+)\"(?=\\s*:)"; | ||
//匹配 JSON 的 value(支持字符串、数字、布尔值和 null) | ||
private static final String VALUE_PATTERN = ":\\s*(\".*?\"|\\d+|true|false|null)"; | ||
//匹配 JSON 的结构符号(如大括号、中括号、逗号等) | ||
private static final String BRACE_PATTERN = "\\{|\\}"; | ||
private static final String BRACKET_PATTERN = "\\[|\\]"; | ||
private static final String COMMA_PATTERN = ","; | ||
private static final String COLON_PATTERN = ":"; | ||
|
||
private static final Pattern PATTERN = Pattern.compile( | ||
"(?<KEY>" + KEY_PATTERN + ")" + | ||
"|(?<VALUE>" + VALUE_PATTERN + ")" + | ||
"|(?<BRACE>" + BRACE_PATTERN + ")" + | ||
"|(?<BRACKET>" + BRACKET_PATTERN + ")" + | ||
"|(?<COMMA>" + COMMA_PATTERN + ")" + | ||
"|(?<COLON>" + COLON_PATTERN + ")"); | ||
|
||
public JsonCodeArea() { | ||
super(); | ||
getStyleClass().add("text-json-area"); | ||
getStylesheets().add( | ||
getClass().getResource("/com/tlcsdm/core/static/javafx/richtext/json-keywords.css").toExternalForm()); | ||
this.setParagraphGraphicFactory(LineNumberFactory.get(this)); | ||
this.textProperty().addListener((obs, oldText, newText) -> { | ||
this.setStyleSpans(0, computeHighlighting(newText)); | ||
}); | ||
} | ||
|
||
private static StyleSpans<Collection<String>> computeHighlighting(String text) { | ||
Matcher matcher = PATTERN.matcher(text); | ||
int lastKwEnd = 0; | ||
StyleSpansBuilder<Collection<String>> spansBuilder = new StyleSpansBuilder<>(); | ||
while (matcher.find()) { | ||
String styleClass = matcher.group("KEY") != null ? "key" | ||
: matcher.group("VALUE") != null ? "value" | ||
: matcher.group("BRACE") != null ? "brace" | ||
: matcher.group("BRACKET") != null ? "bracket" | ||
: matcher.group("COMMA") != null ? "comma" | ||
: matcher.group("COLON") != null ? "colon" : null; | ||
assert styleClass != null; | ||
spansBuilder.add(Collections.emptyList(), matcher.start() - lastKwEnd); | ||
spansBuilder.add(Collections.singleton(styleClass), matcher.end() - matcher.start()); | ||
lastKwEnd = matcher.end(); | ||
} | ||
spansBuilder.add(Collections.emptyList(), text.length() - lastKwEnd); | ||
return spansBuilder.create(); | ||
} | ||
|
||
public void setText(String text) { | ||
replaceText(0, getLength(), text); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.