实现基本功能

This commit is contained in:
peng
2021-10-28 20:08:56 +08:00
parent 306664b3df
commit 6488cede83
40 changed files with 910 additions and 242 deletions

1
.gitignore vendored
View File

@@ -11,7 +11,6 @@
.mtj.tmp/
# Package Files #
*.jar
*.war
*.nar
*.ear

View File

Binary file not shown.

BIN
lib/jackson-core-2.12.5.jar Normal file
View File

Binary file not shown.

View File

Binary file not shown.

View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

View File

@@ -1,22 +1,37 @@
{
"projectName" : null,
"projectName" : "HTTP SERVER 模拟器",
"width" : 1200,
"height" : 800,
"stringLen" : 8,
"intLen" : 8,
"serverConfigs" : [ {
"serverName" : "测试接口",
"port" : 8080,
"serverName" : "WMS",
"port" : 8082,
"serverUrls" : [ {
"urlName" : "登",
"url" : "/logout",
"requestType" : "GET",
"responseBody" : "{\n \"username\": \"admin\",\n \"password\": \"123\"\n}",
"urlName" : "登",
"url" : "/login",
"serverName" : "WMS",
"requestType" : "POST",
"responseBody" : "{\n\t\"success\": \"$int$\"\n}",
"headerMap" : null
}, {
"urlName" : "查询1",
"url" : "/list1",
"requestType" : null,
"responseBody" : "{\n\t\"taskNo\": \"123\"\n}",
"urlName" : "退出",
"url" : "/logout",
"serverName" : "WMS",
"requestType" : "POST",
"responseBody" : "{\n\t\"id\": 1\n}",
"headerMap" : null
}, {
"urlName" : "登录2",
"url" : "/login22",
"serverName" : "WMS",
"requestType" : "POST",
"responseBody" : "",
"headerMap" : null
} ]
}, {
"serverName" : "WCS",
"port" : 8083,
"serverUrls" : [ ]
} ]
}

View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

View File

@@ -1,17 +1,9 @@
package com.dayrain;
import com.dayrain.entity.Configuration;
import com.dayrain.entity.RequestType;
import com.dayrain.entity.ServerConfig;
import com.dayrain.entity.ServerUrl;
import com.dayrain.utils.FileUtils;
import com.dayrain.views.HomePage;
import javafx.application.Application;
import javafx.stage.Stage;
import java.io.IOException;
import java.util.ArrayList;
public class ApplicationStarter extends Application {
@@ -19,33 +11,9 @@ public class ApplicationStarter extends Application {
launch(args);
}
private static Configuration configInit() {
Configuration configuration = new Configuration();
configuration.setServerConfigs(new ArrayList<ServerConfig>(){
{
add(new ServerConfig("测试", 8080, new ArrayList<ServerUrl>(){
{
add(new ServerUrl("登录", "/login", RequestType.GET, "{\n" +
" \"username\": \"admin\",\n" +
" \"password\": \"123\"\n" +
"}"));
add(new ServerUrl("登出", "/logout", RequestType.GET, "{\n" +
" \"username\": \"admin\",\n" +
" \"password\": \"123\"\n" +
"}"));
}
}));
}
});
configuration.setWidth(1200);
configuration.setHeight(800);
return configuration;
}
@Override
public void start(Stage primaryStage) throws Exception {
new HomePage(primaryStage).start();
}
}

View File

@@ -1,4 +1,4 @@
package com.dayrain.entity;
package com.dayrain.component;
import com.dayrain.utils.FileUtils;
@@ -15,4 +15,8 @@ public class ConfigHolder {
public static void save() {
FileUtils.saveConfig(configuration);
}
public static Configuration get() {
return configuration;
}
}

View File

@@ -1,17 +1,31 @@
package com.dayrain.entity;
package com.dayrain.component;
import java.util.List;
public class Configuration {
private String projectName;
private String projectName = "HTTP SERVER 模拟器";
private int width;
private int height;
private int stringLen;
private int intLen;
private List<ServerConfig>serverConfigs;
public Configuration() {
}
public Configuration(int width, int height, int stringLen, int intLen) {
this.width = width;
this.height = height;
this.stringLen = stringLen;
this.intLen = intLen;
}
public String getProjectName() {
return projectName;
}
@@ -43,4 +57,20 @@ public class Configuration {
public void setHeight(int height) {
this.height = height;
}
public int getStringLen() {
return stringLen;
}
public void setStringLen(int stringLen) {
this.stringLen = stringLen;
}
public int getIntLen() {
return intLen;
}
public void setIntLen(int intLen) {
this.intLen = intLen;
}
}

View File

@@ -0,0 +1,75 @@
package com.dayrain.component;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
public class ConsoleLog {
private static final HashMap<String, String> logs = new HashMap<>();
private static final String NO_REQUEST = "暂无请求";
private static LogArea logArea;
public static void setTextArea(LogArea area) {
logArea = area;
}
public static void log(ServerUrl serverUrl, String params, String resp) {
String log = logs.getOrDefault(serverUrl.getServerName(), null);
if(log == null || NO_REQUEST.equals(log)) {
log = "";
}
if(params == null || "".equals(params)) {
params = "";
}
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("[").append(now()).append("]");
stringBuilder.append(serverUrl.getUrlName()).append(" ");
stringBuilder.append(serverUrl.getUrl()).append(" ").append(serverUrl.getRequestType().name()).append("\n");
stringBuilder.append("参数: ").append("\n");
stringBuilder.append(params).append("\n");
stringBuilder.append("返回值: ").append("\n");
stringBuilder.append(resp);
stringBuilder.append("\n\n");
log += stringBuilder.toString();
logs.put(serverUrl.getServerName(), log);
if(serverUrl.getServerName().equals(logArea.getServerName())) {
if(NO_REQUEST.equals(logArea.getText())) {
logArea.setText(log);
}else {
logArea.appendText(log);
}
logArea.setScrollTop(Double.MAX_VALUE);
}
}
public static String getLog(String serverName) {
if(logs.containsKey(serverName)) {
return logs.get(serverName);
}
logs.put(serverName, NO_REQUEST);
return NO_REQUEST;
}
public static void resetTextArea(String serverName) {
if(!logs.containsKey(serverName)) {
logs.put(serverName, NO_REQUEST);
}
logArea.setServerName(serverName);
logArea.setText(logs.get(serverName));
logArea.appendText("");
logArea.setScrollTop(Double.MAX_VALUE);
}
private static String now() {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-DD-mm HH:mm:ss");
return simpleDateFormat.format(new Date());
}
}

View File

@@ -0,0 +1,15 @@
package com.dayrain.component;
import javafx.scene.control.TextArea;
public class LogArea extends TextArea {
private String serverName;
public String getServerName() {
return serverName;
}
public void setServerName(String serverName) {
this.serverName = serverName;
}
}

View File

@@ -0,0 +1,96 @@
package com.dayrain.component;
import com.dayrain.utils.FileUtils;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.util.UUID;
public class RequestHandler implements HttpHandler {
private static final String STRING_PATTERN = "$string$";
private static final String INT_PATTERN = "$int$";
private final ServerUrl serverUrl;
public RequestHandler(ServerUrl serverUrl) {
this.serverUrl = serverUrl;
}
@Override
public void handle(HttpExchange exchange) throws IOException {
RequestType requestType = serverUrl.getRequestType();
String param = null;
if(RequestType.GET.equals(requestType)) {
param = handleGetRequest(exchange);
}
if(RequestType.POST.equals(requestType)) {
param = handlePostRequest(exchange);
}
String resp = replaceResp(serverUrl.getResponseBody());
ConsoleLog.log(serverUrl, param, resp);
response(exchange, resp);
}
private String handleGetRequest(HttpExchange exchange) {
return exchange.getRequestURI().getQuery();
}
private String handlePostRequest(HttpExchange exchange) {
return FileUtils.getFromInputStream(exchange.getRequestBody());
}
private void response(HttpExchange exchange, String jsonBody) {
try {
exchange.sendResponseHeaders(200, jsonBody.length());
exchange.setAttribute("Content-Type","application/json; charset=utf-8");
OutputStream outputStream = exchange.getResponseBody();
outputStream.write(jsonBody.getBytes(StandardCharsets.UTF_8));
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
private String replaceResp(String resp) {
if(resp == null || "".equals(resp)) {
return resp;
}
Configuration configuration = ConfigHolder.get();
int stringLen = configuration.getStringLen();
int intLen = configuration.getIntLen();
while (resp.contains(STRING_PATTERN)) {
resp = resp.replace(STRING_PATTERN, randomString(stringLen));
}
while (resp.contains(INT_PATTERN)) {
resp = resp.replace(INT_PATTERN, String.valueOf(randomInt(intLen)));
}
return resp;
}
private String randomString(int len) {
String res = UUID.randomUUID().toString();
if(len > res.length()) {
len = res.length();
}
return UUID.randomUUID().toString().substring(0, len);
}
private int randomInt(int len) {
int res = (int) Math.pow(10, len - 1 );
return res + (int) (Math.pow(10, len - 1) * Math.random());
}
}

View File

@@ -1,4 +1,4 @@
package com.dayrain.entity;
package com.dayrain.component;
public enum RequestType {
GET,POST;

View File

@@ -1,4 +1,4 @@
package com.dayrain.entity;
package com.dayrain.component;
import com.sun.net.httpserver.HttpServer;

View File

@@ -1,4 +1,4 @@
package com.dayrain.entity;
package com.dayrain.component;
import java.util.List;

View File

@@ -1,6 +1,5 @@
package com.dayrain.entity;
package com.dayrain.component;
import java.util.HashMap;
import java.util.Map;
public class ServerUrl {
@@ -13,6 +12,10 @@ public class ServerUrl {
* 路径url
*/
private String url;
/**
* 服务名称
*/
private String serverName;
/**
* 请求类型
*/
@@ -29,7 +32,8 @@ public class ServerUrl {
public ServerUrl() {
}
public ServerUrl(String urlName, String url, RequestType requestType, String responseBody) {
public ServerUrl(String serverName, String urlName, String url, RequestType requestType, String responseBody) {
this.serverName = serverName;
this.urlName = urlName;
this.url = url;
this.requestType = requestType;
@@ -75,4 +79,12 @@ public class ServerUrl {
public void setResponseBody(String responseBody) {
this.responseBody = responseBody;
}
public String getServerName() {
return serverName;
}
public void setServerName(String serverName) {
this.serverName = serverName;
}
}

View File

@@ -1,58 +0,0 @@
package com.dayrain.entity;
import com.dayrain.utils.JackSonUtils;
import com.sun.net.httpserver.Headers;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
public class RequestHandler implements HttpHandler {
private final ServerUrl serverUrl;
public RequestHandler(ServerUrl serverUrl) {
this.serverUrl = serverUrl;
}
@Override
public void handle(HttpExchange exchange) throws IOException {
if(RequestType.GET == serverUrl.getRequestType()) {
handleGetRequest(exchange);
}else if(RequestType.POST == serverUrl.getRequestType()) {
handlePostRequest(exchange);
}
response(exchange, serverUrl.getResponseBody());
}
private void handleGetRequest(HttpExchange exchange) {
String queryString = exchange.getRequestURI().getQuery();
System.out.println(queryString);
}
private void handlePostRequest(HttpExchange exchange) {
String requestBody = JackSonUtils.getFromInputStream(exchange.getRequestBody());
System.out.println(requestBody);
}
private void response(HttpExchange exchange, String jsonBody) {
try {
exchange.sendResponseHeaders(200, jsonBody.length());
exchange.setAttribute("Content-Type","application/json; charset=utf-8");
OutputStream outputStream = exchange.getResponseBody();
outputStream.write(jsonBody.getBytes(StandardCharsets.UTF_8));
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}

View File

@@ -0,0 +1,88 @@
package com.dayrain.handle;
import com.dayrain.component.ConfigHolder;
import com.dayrain.component.Configuration;
import com.dayrain.component.ServerConfig;
import com.dayrain.style.ButtonFactory;
import com.dayrain.style.LabelFactory;
import com.dayrain.views.HomePage;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.stage.Modality;
import javafx.stage.Stage;
import java.util.ArrayList;
/**
* 添加server
* @author peng
* @date 2021/10/28
*/
public class AddServerHandler implements EventHandler<ActionEvent> {
private final Stage primaryStage;
private final Configuration configuration;
private final HomePage homePage;
public AddServerHandler(Stage primaryStage, Configuration configuration, HomePage homePage) {
this.primaryStage = primaryStage;
this.configuration = configuration;
this.homePage = homePage;
}
@Override
public void handle(ActionEvent event) {
Stage stage = new Stage();
Label nameLabel = LabelFactory.getLabel("服务名称:");
nameLabel.setPrefWidth(80);
TextField nameField = new TextField();
Label portLabel = LabelFactory.getLabel("端口号:");
TextField portField = new TextField();
portField.setPrefWidth(80);
HBox btnHBox = new HBox();
Button saveButton = ButtonFactory.getButton("保存");
btnHBox.getChildren().add(saveButton);
btnHBox.setAlignment(Pos.CENTER_RIGHT);
GridPane gridPane = new GridPane();
gridPane.add(nameLabel, 0, 0);
gridPane.add(nameField, 1, 0);
gridPane.add(portLabel, 0, 1);
gridPane.add(portField, 1, 1);
gridPane.add(btnHBox, 1, 3);
gridPane.setAlignment(Pos.CENTER);
gridPane.setHgap(20d);
gridPane.setVgap(10d);
stage.setWidth(500);
stage.setHeight(400);
stage.initOwner(primaryStage);
stage.initModality(Modality.WINDOW_MODAL);
stage.setScene(new Scene(gridPane));
stage.getIcons().addAll(primaryStage.getIcons());
stage.show();
saveButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
String name = nameField.getText();
String port = portField.getText();
ServerConfig serverConfig = new ServerConfig(name, Integer.parseInt(port), new ArrayList<>());
configuration.getServerConfigs().add(serverConfig);
homePage.refreshServerContainer();
ConfigHolder.save();
stage.close();
}
});
}
}

View File

@@ -1,15 +1,20 @@
package com.dayrain.handle;
import com.dayrain.entity.ConfigHolder;
import com.dayrain.entity.ServerConfig;
import com.dayrain.entity.ServerUrl;
import com.dayrain.component.ConfigHolder;
import com.dayrain.component.RequestType;
import com.dayrain.component.ServerConfig;
import com.dayrain.component.ServerUrl;
import com.dayrain.server.ServerThread;
import com.dayrain.style.ButtonFactory;
import com.dayrain.style.LabelFactory;
import com.dayrain.utils.ListViewHelper;
import javafx.collections.FXCollections;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.Label;
import javafx.scene.control.ListView;
import javafx.scene.control.TextArea;
@@ -47,39 +52,49 @@ public class AddUrlHandler implements EventHandler<ActionEvent> {
@Override
public void handle(ActionEvent event) {
Stage stage = new Stage();
Label nameLabel = new Label("接口名称:");
Label nameLabel = LabelFactory.getLabel("接口名称:");
nameLabel.setPrefWidth(80);
TextField nameField = new TextField();
Label urlLabel = new Label("接口地址:");
Label urlLabel = LabelFactory.getLabel("接口地址:");
TextField urlField = new TextField();
urlField.setPrefWidth(80);
Label respLabel = new Label("返回结果:");
Label methodLabel = LabelFactory.getLabel("请求方式:");
ChoiceBox<String>choiceBox = new ChoiceBox<>();
choiceBox.setItems(FXCollections.observableArrayList("POST", "GET"));
choiceBox.setValue("POST");
urlField.setPrefWidth(80);
Label respLabel = LabelFactory.getLabel("返回结果:");
TextArea textArea = new TextArea();
textArea.setPrefWidth(80);
HBox btnHBox = new HBox();
Button saveButton = new Button("保存");
Button saveButton = ButtonFactory.getButton("保存");
btnHBox.getChildren().add(saveButton);
btnHBox.setAlignment(Pos.CENTER_RIGHT);
GridPane gridPane = new GridPane();
gridPane.add(nameLabel, 0, 0);
gridPane.add(nameField, 1, 0);
gridPane.add(urlLabel, 0, 1);
gridPane.add(urlField, 1, 1);
gridPane.add(respLabel, 0, 2);
gridPane.add(textArea, 1, 2);
gridPane.add(btnHBox, 1, 3);
gridPane.add(methodLabel, 0, 0);
gridPane.add(choiceBox, 1, 0);
gridPane.add(nameLabel, 0, 1);
gridPane.add(nameField, 1, 1);
gridPane.add(urlLabel, 0, 2);
gridPane.add(urlField, 1, 2);
gridPane.add(respLabel, 0, 3);
gridPane.add(textArea, 1, 3);
gridPane.add(btnHBox, 1, 4);
gridPane.setAlignment(Pos.CENTER);
gridPane.setHgap(20d);
gridPane.setVgap(10d);
stage.setWidth(500);
stage.setHeight(400);
stage.setWidth(550);
stage.setHeight(500);
stage.initOwner(primaryStage);
stage.initModality(Modality.WINDOW_MODAL);
stage.setScene(new Scene(gridPane));
stage.getIcons().addAll(primaryStage.getIcons());
stage.show();
saveButton.setOnAction(new EventHandler<ActionEvent>() {
@@ -95,8 +110,8 @@ public class AddUrlHandler implements EventHandler<ActionEvent> {
String url = urlField.getText();
String resp = textArea.getText();
ServerUrl serverUrl = new ServerUrl(name, url, null, resp);
String type = choiceBox.getValue();
ServerUrl serverUrl = new ServerUrl(serverConfig.getServerName(), name, url, type.equals(RequestType.POST.name()) ? RequestType.POST : RequestType.GET, resp);
serverUrls.add(serverUrl);
ServerThread serverThread = threadMap.getOrDefault(serverConfig.getServerName(), null);
if(serverThread != null) {

View File

@@ -0,0 +1,45 @@
package com.dayrain.handle;
import com.dayrain.component.ConfigHolder;
import com.dayrain.component.Configuration;
import com.dayrain.component.ServerConfig;
import com.dayrain.views.HomePage;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonType;
import javafx.scene.image.ImageView;
import javafx.stage.Stage;
public class DeleteServerHandler implements EventHandler<ActionEvent> {
private final ServerConfig serverConfig;
private final Configuration configuration;
private final HomePage homePage;
public DeleteServerHandler(ServerConfig serverConfig, Configuration configuration, HomePage homePage) {
this.serverConfig = serverConfig;
this.configuration = configuration;
this.homePage = homePage;
}
@Override
public void handle(ActionEvent event) {
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setGraphic(new ImageView(homePage.getIcon()));
Stage stage = (Stage) alert.getDialogPane().getScene().getWindow();
stage.getIcons().add(homePage.getIcon());
alert.setHeaderText("是否确定删除该服务?");
Button okButton = (Button) alert.getDialogPane().lookupButton(ButtonType.OK);
okButton.setOnAction(event1 -> {
configuration.getServerConfigs().remove(serverConfig);
homePage.refreshServerContainer();
ConfigHolder.save();
});
alert.show();
}
}

View File

@@ -1,15 +1,19 @@
package com.dayrain.handle;
import com.dayrain.entity.ConfigHolder;
import com.dayrain.entity.ServerConfig;
import com.dayrain.entity.ServerUrl;
import com.dayrain.server.ServerThread;
import com.dayrain.component.ConfigHolder;
import com.dayrain.component.ServerConfig;
import com.dayrain.component.ServerUrl;
import com.dayrain.utils.ListViewHelper;
import com.dayrain.views.HomePage;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonType;
import javafx.scene.control.ListView;
import javafx.scene.image.ImageView;
import javafx.stage.Stage;
import java.util.HashMap;
import java.util.List;
/**
@@ -23,22 +27,31 @@ public class DeleteUrlHandler implements EventHandler<ActionEvent> {
private final ListView<ServerUrl> serverUrlListView;
private final HashMap<String, ServerThread> threadMap;
private final ServerUrl serverUrl;
public DeleteUrlHandler(ServerUrl serverUrl, ServerConfig serverConfig, ListView<ServerUrl> serverUrlListView, HashMap<String, ServerThread> threadMap) {
private final HomePage homePage;
public DeleteUrlHandler(ServerUrl serverUrl, ServerConfig serverConfig, ListView<ServerUrl> serverUrlListView, HomePage homePage) {
this.serverUrl = serverUrl;
this.serverConfig = serverConfig;
this.serverUrlListView = serverUrlListView;
this.threadMap = threadMap;
this.homePage = homePage;
}
@Override
public void handle(ActionEvent event) {
List<ServerUrl> serverUrls = serverConfig.getServerUrls();
serverUrls.remove(serverUrl);
ConfigHolder.save();
ListViewHelper.deleteAndRefresh(serverUrl, serverUrlListView);
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setGraphic(new ImageView(homePage.getIcon()));
Stage stage = (Stage) alert.getDialogPane().getScene().getWindow();
stage.getIcons().add(homePage.getIcon());
alert.setHeaderText("是否确定删除该接口?");
Button okButton = (Button) alert.getDialogPane().lookupButton(ButtonType.OK);
okButton.setOnAction(event1 -> {
List<ServerUrl> serverUrls = serverConfig.getServerUrls();
serverUrls.remove(serverUrl);
ConfigHolder.save();
ListViewHelper.deleteAndRefresh(serverUrl, serverUrlListView);
});
alert.show();
}
}

View File

@@ -0,0 +1,45 @@
package com.dayrain.handle;
import com.dayrain.component.Configuration;
import com.dayrain.utils.FileUtils;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
import java.io.File;
/**
* 导出配置文件
* @author peng
* @date 2021/10/28
*/
public class ExportConfigHandler implements EventHandler<ActionEvent> {
private final Stage primaryStage;
private final Configuration configuration;
public ExportConfigHandler(Stage primaryStage, Configuration configuration) {
this.primaryStage = primaryStage;
this.configuration = configuration;
}
@Override
public void handle(ActionEvent event) {
Stage stage = new Stage();
stage.initOwner(primaryStage);
FileChooser fileChooser = new FileChooser();
String projectName = configuration.getProjectName();
if(projectName == null) {
projectName = "";
}
projectName += "server";
fileChooser.setTitle("导出配置");
fileChooser.setInitialFileName(projectName + ".json");
File file = fileChooser.showSaveDialog(stage);
if(file != null) {
FileUtils.saveConfig(configuration, file);
}
}
}

View File

@@ -0,0 +1,46 @@
package com.dayrain.handle;
import com.dayrain.component.Configuration;
import com.dayrain.utils.FileUtils;
import com.dayrain.views.HomePage;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
import java.io.File;
/**
* 导入配置文件
* @author peng
* @date 2021/10/28
*/
public class ImportConfigHandler implements EventHandler<ActionEvent> {
private final Stage primaryStage;
private final HomePage homePage;
public ImportConfigHandler(Stage primaryStage, HomePage homePage) {
this.primaryStage = primaryStage;
this.homePage = homePage;
}
@Override
public void handle(ActionEvent event) {
Stage stage = new Stage();
stage.initOwner(primaryStage);
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("选择一个文件");
//过滤器
fileChooser.getExtensionFilters().addAll(new FileChooser.ExtensionFilter("只能导入json文件", "*.json"));
File file = fileChooser.showOpenDialog(stage);
if(file != null) {
Configuration loadConfig = FileUtils.load(file);
FileUtils.saveConfig(loadConfig);
homePage.replaceConfig(loadConfig);
homePage.restart();
}
}
}

View File

@@ -1,7 +1,7 @@
package com.dayrain.handle;
import com.dayrain.entity.Server;
import com.dayrain.entity.ServerConfig;
import com.dayrain.component.Server;
import com.dayrain.component.ServerConfig;
import com.dayrain.server.ServerThread;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;

View File

@@ -0,0 +1,76 @@
package com.dayrain.handle;
import com.dayrain.component.ConfigHolder;
import com.dayrain.component.Configuration;
import com.dayrain.component.ServerConfig;
import com.dayrain.style.ButtonFactory;
import com.dayrain.style.LabelFactory;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.stage.Modality;
import javafx.stage.Stage;
public class UpdateRandomLenHandler implements EventHandler<ActionEvent> {
private final Stage primaryStage;
public UpdateRandomLenHandler(Stage primaryStage) {
this.primaryStage = primaryStage;
}
@Override
public void handle(ActionEvent event) {
Configuration configuration = ConfigHolder.get();
Stage stage = new Stage();
Label strName = LabelFactory.getLabel("随机字符长度:");
strName.setPrefWidth(80);
TextField strField = new TextField(String.valueOf(configuration.getStringLen()));
Label intName = LabelFactory.getLabel("随机整数长度:");
TextField intField = new TextField(String.valueOf(configuration.getIntLen()));
intField.setPrefWidth(80);
HBox btnHBox = new HBox();
Button saveButton = ButtonFactory.getButton("保存");
btnHBox.getChildren().addAll(saveButton);
btnHBox.setAlignment(Pos.CENTER_RIGHT);
btnHBox.setSpacing(20d);
GridPane gridPane = new GridPane();
gridPane.add(strName, 0, 0);
gridPane.add(strField, 1, 0);
gridPane.add(intName, 0, 1);
gridPane.add(intField, 1, 1);
gridPane.add(btnHBox, 1, 3);
gridPane.setAlignment(Pos.CENTER);
gridPane.setHgap(20d);
gridPane.setVgap(10d);
stage.setWidth(500);
stage.setHeight(400);
stage.initOwner(primaryStage);
stage.initModality(Modality.WINDOW_MODAL);
stage.setScene(new Scene(gridPane));
stage.getIcons().addAll(primaryStage.getIcons());
stage.show();
saveButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
String strLen = strField.getText();
String intLen = intField.getText();
configuration.setStringLen(Integer.parseInt(strLen));
configuration.setIntLen(Integer.parseInt(intLen));
ConfigHolder.save();
stage.close();
}
});
}
}

View File

@@ -1,8 +1,9 @@
package com.dayrain.handle;
import com.dayrain.entity.ConfigHolder;
import com.dayrain.entity.ServerConfig;
import com.dayrain.utils.ListViewHelper;
import com.dayrain.component.ConfigHolder;
import com.dayrain.component.ServerConfig;
import com.dayrain.style.ButtonFactory;
import com.dayrain.style.LabelFactory;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
@@ -29,17 +30,16 @@ public class UpdateServerConfigHandler implements EventHandler<ActionEvent> {
@Override
public void handle(ActionEvent event) {
Stage stage = new Stage();
Label serverName = new Label("服务名称:");
Label serverName = LabelFactory.getLabel("服务名称:");
serverName.setPrefWidth(80);
TextField nameField = new TextField(serverConfig.getServerName());
Label portLabel = new Label("端口:");
Label portLabel = LabelFactory.getLabel("端口:");
TextField portField = new TextField(String.valueOf(serverConfig.getPort()));
portField.setPrefWidth(80);
HBox btnHBox = new HBox();
Label saveTips = new Label("重启后生效");
saveTips.setStyle("-fx-background-color: #ff0000");
Button saveButton = new Button("保存");
Label saveTips = LabelFactory.getLabel("重启后生效");
Button saveButton = ButtonFactory.getButton("保存");
btnHBox.getChildren().addAll(saveTips, saveButton);
btnHBox.setAlignment(Pos.CENTER_RIGHT);
btnHBox.setSpacing(20d);
@@ -55,11 +55,12 @@ public class UpdateServerConfigHandler implements EventHandler<ActionEvent> {
gridPane.setHgap(20d);
gridPane.setVgap(10d);
stage.setWidth(400);
stage.setHeight(300);
stage.setWidth(500);
stage.setHeight(400);
stage.initOwner(primaryStage);
stage.initModality(Modality.WINDOW_MODAL);
stage.setScene(new Scene(gridPane));
stage.getIcons().addAll(primaryStage.getIcons());
stage.show();
saveButton.setOnAction(new EventHandler<ActionEvent>() {

View File

@@ -1,15 +1,18 @@
package com.dayrain.handle;
import com.dayrain.entity.ConfigHolder;
import com.dayrain.entity.ServerConfig;
import com.dayrain.entity.ServerUrl;
import com.dayrain.server.ServerThread;
import com.dayrain.component.ConfigHolder;
import com.dayrain.component.RequestType;
import com.dayrain.component.ServerUrl;
import com.dayrain.style.ButtonFactory;
import com.dayrain.style.LabelFactory;
import com.dayrain.utils.ListViewHelper;
import javafx.collections.FXCollections;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.Label;
import javafx.scene.control.ListView;
import javafx.scene.control.TextArea;
@@ -19,7 +22,6 @@ import javafx.scene.layout.HBox;
import javafx.stage.Modality;
import javafx.stage.Stage;
import java.util.HashMap;
public class UpdateUrlHandler implements EventHandler<ActionEvent> {
@@ -38,42 +40,51 @@ public class UpdateUrlHandler implements EventHandler<ActionEvent> {
@Override
public void handle(ActionEvent event) {
Stage stage = new Stage();
Label nameLabel = new Label("接口名称:");
Label nameLabel = LabelFactory.getLabel("接口名称:");
nameLabel.setPrefWidth(80);
TextField nameField = new TextField(serverUrl.getUrlName());
Label urlLabel = new Label("接口地址:");
Label urlLabel = LabelFactory.getLabel("接口地址:");
TextField urlField = new TextField(serverUrl.getUrl());
urlField.setEditable(false);
urlField.setPrefWidth(80);
Label respLabel = new Label("返回结果:");
Label methodLabel = LabelFactory.getLabel("请求方式:");
ChoiceBox<String> choiceBox = new ChoiceBox<>();
choiceBox.setItems(FXCollections.observableArrayList("POST", "GET"));
choiceBox.setValue("POST");
urlField.setPrefWidth(80);
Label respLabel = LabelFactory.getLabel("返回结果:");
TextArea textArea = new TextArea(serverUrl.getResponseBody());
textArea.setPrefWidth(80);
HBox btnHBox = new HBox();
Label saveTips = new Label("重启后生效");
saveTips.setStyle("-fx-background-color: #ff0000");
Button saveButton = new Button("保存");
btnHBox.getChildren().addAll(saveTips, saveButton);
Button saveButton = ButtonFactory.getButton("保存");
btnHBox.getChildren().addAll(saveButton);
btnHBox.setAlignment(Pos.CENTER_RIGHT);
btnHBox.setSpacing(20d);
GridPane gridPane = new GridPane();
gridPane.add(nameLabel, 0, 0);
gridPane.add(nameField, 1, 0);
gridPane.add(urlLabel, 0, 1);
gridPane.add(urlField, 1, 1);
gridPane.add(respLabel, 0, 2);
gridPane.add(textArea, 1, 2);
gridPane.add(btnHBox, 1, 3);
gridPane.add(methodLabel, 0, 0);
gridPane.add(choiceBox, 1, 0);
gridPane.add(nameLabel, 0, 1);
gridPane.add(nameField, 1, 1);
gridPane.add(urlLabel, 0, 2);
gridPane.add(urlField, 1, 2);
gridPane.add(respLabel, 0, 3);
gridPane.add(textArea, 1, 3);
gridPane.add(btnHBox, 1, 4);
gridPane.setAlignment(Pos.CENTER);
gridPane.setHgap(20d);
gridPane.setVgap(10d);
stage.setWidth(500);
stage.setHeight(400);
stage.setWidth(550);
stage.setHeight(450);
stage.initOwner(primaryStage);
stage.initModality(Modality.WINDOW_MODAL);
stage.setScene(new Scene(gridPane));
stage.getIcons().addAll(primaryStage.getIcons());
stage.show();
saveButton.setOnAction(new EventHandler<ActionEvent>() {
@@ -82,9 +93,11 @@ public class UpdateUrlHandler implements EventHandler<ActionEvent> {
String name = nameField.getText();
String url = urlField.getText();
String resp = textArea.getText();
String type = choiceBox.getValue();
serverUrl.setUrlName(name);
serverUrl.setUrl(url);
serverUrl.setResponseBody(resp);
serverUrl.setRequestType(type.equals(RequestType.POST.name()) ? RequestType.POST : RequestType.GET);
ListViewHelper.refresh(serverUrlListView);
ConfigHolder.save();

View File

@@ -1,7 +1,7 @@
package com.dayrain.server;
import com.dayrain.entity.Server;
import com.dayrain.entity.ServerUrl;
import com.dayrain.component.Server;
import com.dayrain.component.ServerUrl;
public class ServerThread extends Thread {
private final Server server;

View File

@@ -0,0 +1,26 @@
package com.dayrain.style;
import javafx.geometry.Insets;
import javafx.scene.control.Button;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.CornerRadii;
import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
import javafx.scene.text.Font;
public class ButtonFactory {
public static Button getButton(String text) {
BackgroundFill bgf = new BackgroundFill(Paint.valueOf("#145b7d"), new CornerRadii(10), new Insets(5));
Button button = new Button();
button.setText(text);
button.setPrefWidth(100);
button.setPrefHeight(50);
button.setFont(Font.font("Microsoft YaHei",15));
button.setTextFill(Color.WHITE);
button.setBackground(new Background(bgf));
return button;
}
}

View File

@@ -0,0 +1,13 @@
package com.dayrain.style;
import javafx.scene.control.Label;
import javafx.scene.text.Font;
public class LabelFactory {
public static Label getLabel(String text) {
Label label = new Label(text);
label.setFont(Font.font("Microsoft YaHei",18));
return label;
}
}

View File

@@ -1,21 +1,27 @@
package com.dayrain.utils;
import com.dayrain.entity.Configuration;
import com.dayrain.component.Configuration;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
public class FileUtils{
private static String configPath = Thread.currentThread().getContextClassLoader().getResource("resources/config.json").getFile();
private static String configPath = getResourcePath("config.json");
public static void saveConfig(Configuration configuration){
saveConfig(configuration, new File(configPath));
}
public static void saveConfig(Configuration configuration, File file){
FileWriter fileWriter = null;
try {
fileWriter = new FileWriter(configPath);
fileWriter = new FileWriter(file);
String config = new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(configuration);
fileWriter.write(config);
fileWriter.flush();
@@ -30,19 +36,22 @@ public class FileUtils{
e.printStackTrace();
}
}
}
public static Configuration load() {
return load(new File(configPath));
}
public static Configuration load(File file) {
BufferedReader bufferedReader = null;
try {
StringBuilder configStr = new StringBuilder();
bufferedReader = new BufferedReader(new FileReader(configPath));
bufferedReader = new BufferedReader(new FileReader(file));
String buf = null;
while ((buf = bufferedReader.readLine()) != null) {
configStr.append(buf);
}
return new ObjectMapper().readValue(configStr.toString(), Configuration.class);
return "".equals(configStr.toString()) ? new Configuration(1200, 800, 8, 8) : new ObjectMapper().readValue(configStr.toString(), Configuration.class);
} catch (IOException e) {
e.printStackTrace();
}finally {
@@ -56,4 +65,31 @@ public class FileUtils{
}
return null;
}
public static String getFromInputStream(InputStream inputStream) {
try {
byte[]buf = new byte[4096];
int len = 0;
StringBuilder stringBuilder = new StringBuilder();
while ((len = inputStream.read(buf)) != -1) {
stringBuilder.append(new String(buf, 0, len));
}
return stringBuilder.toString();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
public static String getResourcePath(String fileName) {
String file = Thread.currentThread().getContextClassLoader().getResource("resources/" + fileName).getFile();
return new File(file).toString();
}
public static String getResourcePathWithProtocol(String fileName) {
String file = Thread.currentThread().getContextClassLoader().getResource("resources/" + fileName).getFile();
return "file:" + File.separator + new File(file);
}
}

View File

@@ -1,19 +0,0 @@
package com.dayrain.utils;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.io.InputStream;
public class JackSonUtils {
public static String getFromInputStream(InputStream inputStream) {
try {
return new ObjectMapper().readValue(inputStream, String.class);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}

View File

@@ -1,6 +1,6 @@
package com.dayrain.utils;
import com.dayrain.entity.ServerUrl;
import com.dayrain.component.ServerUrl;
import javafx.collections.ObservableList;
import javafx.scene.control.ListView;

View File

@@ -1,20 +1,28 @@
package com.dayrain.views;
import com.dayrain.entity.ConfigHolder;
import com.dayrain.entity.Configuration;
import com.dayrain.entity.Server;
import com.dayrain.entity.ServerConfig;
import com.dayrain.entity.ServerUrl;
import com.dayrain.handle.UpdateRandomLenHandler;
import com.dayrain.style.ButtonFactory;
import com.dayrain.component.ConfigHolder;
import com.dayrain.component.Configuration;
import com.dayrain.component.ConsoleLog;
import com.dayrain.component.LogArea;
import com.dayrain.component.ServerConfig;
import com.dayrain.component.ServerUrl;
import com.dayrain.handle.AddServerHandler;
import com.dayrain.handle.AddUrlHandler;
import com.dayrain.handle.DeleteServerHandler;
import com.dayrain.handle.DeleteUrlHandler;
import com.dayrain.handle.ExportConfigHandler;
import com.dayrain.handle.ImportConfigHandler;
import com.dayrain.handle.StartServerHandler;
import com.dayrain.handle.UpdateServerConfigHandler;
import com.dayrain.handle.UpdateUrlHandler;
import com.dayrain.server.ServerThread;
import com.dayrain.style.LabelFactory;
import com.dayrain.utils.FileUtils;
import javafx.beans.binding.Bindings;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
@@ -26,19 +34,23 @@ import javafx.scene.control.ListView;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.control.MenuItem;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.control.TitledPane;
import javafx.scene.image.Image;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.CornerRadii;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.text.Font;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;
import javafx.util.Callback;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -47,12 +59,16 @@ public class HomePage {
private Stage primaryStage;
private final Configuration configuration = ConfigHolder.init();
private Configuration configuration = ConfigHolder.init();
private HashMap<String, ServerThread> threadMap = new HashMap<>();
private List<ListView<ServerUrl>> listViews = new ArrayList<>();
private VBox serverContainer;
private LogArea logArea;
public HomePage(Stage primaryStage) {
this.primaryStage = primaryStage;
}
@@ -68,48 +84,62 @@ public class HomePage {
MenuItem menuItem2 = new MenuItem("导入");
MenuItem menuItem3 = new MenuItem("导出");
menu1.getItems().addAll(menuItem1, menuItem2, menuItem3);
Menu menu2 = new Menu("日志");
Menu menu2 = new Menu("设置");
MenuItem menuItem21 = new MenuItem("随机值长度");
menu2.getItems().add(menuItem21);
Menu menu3 = new Menu("帮助");
menuBar.getMenus().addAll(menu1, menu2, menu3);
menuBar.getMenus().addAll(menu1, menu2, menu3);
borderPane.setTop(menuBar);
//渲染服务列表
VBox serverContainer = new VBox();
List<ServerConfig> serverConfigs = configuration.getServerConfigs();
for (ServerConfig serverConfig : serverConfigs) {
drawServerPanel(serverContainer, serverConfig, primaryStage);
}
this.serverContainer = new VBox();
refreshServerContainer();
menuItem1.setOnAction(new AddServerHandler(primaryStage, configuration, this));
menuItem2.setOnAction(new ImportConfigHandler(primaryStage, this));
menuItem3.setOnAction(new ExportConfigHandler(primaryStage, configuration));
menuItem21.setOnAction(new UpdateRandomLenHandler(primaryStage));
borderPane.setLeft(serverContainer);
primaryStage.setScene(new Scene(borderPane));
//日志
logArea = new LogArea();
logArea.setEditable(false);
logArea.setFont(Font.font("Microsoft YaHei", 20));
logArea.setPrefWidth(582);
logArea.setPrefHeight(600);
ConsoleLog.setTextArea(logArea);
borderPane.setRight(logArea);
menuBar.setBackground(getBackGround());
Scene scene = new Scene(borderPane);
primaryStage.setTitle(configuration.getProjectName());
primaryStage.setScene(scene);
primaryStage.setWidth(configuration.getWidth());
primaryStage.setHeight(configuration.getHeight());
primaryStage.getIcons().add(getIcon());
primaryStage.show();
primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() {
@Override
public void handle(WindowEvent event) {
FileUtils.saveConfig(configuration);
}
});
primaryStage.setOnCloseRequest(event -> FileUtils.saveConfig(configuration));
}
public void drawServerPanel(VBox serverContainer, ServerConfig serverConfig, Stage primaryStage) {
VBox vBox = new VBox();
HBox headBox = new HBox();
Button editButton = new Button("配置参数");
Button openButton = new Button("开启服务");
Button addButton = new Button("添加接口");
Button editButton = ButtonFactory.getButton("修改配置");
Button openButton = ButtonFactory.getButton("开启服务");
Button deleteButton = ButtonFactory.getButton("删除服务");
Button addButton = ButtonFactory.getButton("添加接口");
Circle statusCircle = new Circle();
statusCircle.setRadius(10);
statusCircle.setFill(Color.RED);
//设置服务启动与关闭
openButton.setOnAction(new StartServerHandler(openButton, statusCircle, serverConfig, threadMap));
editButton.setOnAction(new UpdateServerConfigHandler(serverConfig, primaryStage));
headBox.getChildren().addAll(openButton, editButton, addButton, statusCircle);
deleteButton.setOnAction(new DeleteServerHandler(serverConfig, configuration, this));
headBox.getChildren().addAll(openButton, editButton, deleteButton, addButton, statusCircle);
HBox.setMargin(statusCircle, new Insets(0,0,0,30));
headBox.setSpacing(20d);
headBox.setAlignment(Pos.CENTER);
@@ -122,14 +152,30 @@ public class HomePage {
VBox.setMargin(headBox, new Insets(10, 0, 0, 0));
vBox.setPadding(Insets.EMPTY);
TitledPane titledPane = new TitledPane(serverConfig.getServerName(), vBox);
titledPane.setFont(Font.font("Microsoft YaHei", 18));
titledPane.setPrefWidth(600d);
titledPane.setExpanded(false);
titledPane.setBackground(getBackGround());
titledPane.setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
if(!serverConfig.getServerName().equals(logArea.getServerName())) {
ConsoleLog.resetTextArea(serverConfig.getServerName());
}
}
});
HBox hBox = new HBox();
hBox.setPrefHeight(60d);
titledPane.setGraphic(hBox);
serverContainer.getChildren().add(titledPane);
}
public ListView<ServerUrl> drawUrlPanel(List<ServerUrl> serverUrls, ServerConfig serverConfig) {
ObservableList<ServerUrl> urlList = FXCollections.observableArrayList(serverUrls);
ListView<ServerUrl> serverListViews = new ListView<>(urlList);
listViews.add(serverListViews);
serverListViews.setCellFactory(new Callback<ListView<ServerUrl>, ListCell<ServerUrl>>() {
@Override
public ListCell<ServerUrl> call(ListView<ServerUrl> param) {
@@ -145,24 +191,26 @@ public class HomePage {
BorderPane urlPane = new BorderPane();
HBox labelBox = new HBox();
Label nameLabel = new Label(item.getUrlName());
Label nameLabel = LabelFactory.getLabel(item.getUrlName());
nameLabel.setPrefWidth(100d);
Label urlLabel = new Label(item.getUrl());
Label urlLabel = LabelFactory.getLabel(item.getUrl());
labelBox.getChildren().addAll(nameLabel, urlLabel);
labelBox.setAlignment(Pos.CENTER_LEFT);
HBox btnBox = new HBox();
Button configButton = new Button("配置");
Button deleteButton = new Button("删除");
Button configButton = ButtonFactory.getButton("配置");
Button deleteButton = ButtonFactory.getButton("删除");
btnBox.setSpacing(15d);
btnBox.getChildren().addAll(configButton, deleteButton);
HBox.setMargin(deleteButton, new Insets(0, 20,0,0));
deleteButton.setOnAction(new DeleteUrlHandler(item, serverConfig, serverListViews, threadMap));
deleteButton.setOnAction(new DeleteUrlHandler(item, serverConfig, serverListViews, HomePage.this));
configButton.setOnAction(new UpdateUrlHandler(item, serverListViews, primaryStage));
urlPane.setLeft(labelBox);
urlPane.setRight(btnBox);
this.setGraphic(urlPane);
}
}
};
@@ -170,7 +218,52 @@ public class HomePage {
}
});
serverListViews.prefHeightProperty().bind(Bindings.size(urlList).multiply(60));
serverListViews.setFocusTraversable(false);
return serverListViews;
}
public void refreshServerContainer() {
serverContainer.getChildren().removeAll(serverContainer.getChildren());
List<ServerConfig> serverConfigs = configuration.getServerConfigs();
if(serverConfigs == null || serverConfigs.size() == 0) {
serverConfigs = new ArrayList<>();
configuration.setServerConfigs(serverConfigs);
}
for (ServerConfig serverConfig : serverConfigs) {
drawServerPanel(serverContainer, serverConfig, primaryStage);
}
}
public void restart() {
cleanUp();
start();
}
public void cleanUp() {
for (String name : threadMap.keySet()) {
threadMap.get(name).stopServer();
}
}
public void replaceConfig(Configuration configuration) {
this.configuration = configuration;
}
public Image getIcon() {
try {
return new Image(new FileInputStream(FileUtils.getResourcePath("panda.png")));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
return null;
}
public Background getBackGround() {
BackgroundFill backgroundFill = new BackgroundFill(Color.GRAY, new CornerRadii(1),
new Insets(0.0,0.0,0.0,0.0));
return new Background(backgroundFill);
}
}

BIN
src/resources/close.png Normal file
View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

View File

@@ -0,0 +1,21 @@
{
"projectName" : "HTTP SERVER 模拟器",
"width" : 1200,
"height" : 800,
"serverConfigs" : [ {
"serverName" : "WMS",
"port" : 8082,
"serverUrls" : [ {
"urlName" : "登录",
"url" : "/login",
"serverName" : "WMS",
"requestType" : "POST",
"responseBody" : "{\n\t\"success\": \"ok\"\n}",
"headerMap" : null
} ]
}, {
"serverName" : "WCS",
"port" : 8083,
"serverUrls" : [ ]
} ]
}

BIN
src/resources/min.png Normal file
View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

BIN
src/resources/panda.png Normal file
View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB