Commit 1a3c6756ab12b9eae2c8e7b71c71ad7c4fc2c2af
1 parent
0e20ca34
【代码优化】IoT: HTTP 插件模块,删除测试代码
Showing
1 changed file
with
0 additions
and
91 deletions
yudao-module-iot/yudao-module-iot-plugin/src/main/java/cn/iocoder/yudao/module/iot/plugin/WelcomePlugin.java deleted
| 1 | -/* | ||
| 2 | - * Copyright (C) 2012-present the original author or authors. | ||
| 3 | - * | ||
| 4 | - * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | - * you may not use this file except in compliance with the License. | ||
| 6 | - * You may obtain a copy of the License at | ||
| 7 | - * | ||
| 8 | - * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | - * | ||
| 10 | - * Unless required by applicable law or agreed to in writing, software | ||
| 11 | - * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | - * See the License for the specific language governing permissions and | ||
| 14 | - * limitations under the License. | ||
| 15 | - */ | ||
| 16 | -package cn.iocoder.yudao.module.iot.plugin; | ||
| 17 | - | ||
| 18 | -import cn.iocoder.yudao.module.iot.api.Greeting; | ||
| 19 | -import org.apache.commons.lang.StringUtils; | ||
| 20 | -import org.pf4j.Extension; | ||
| 21 | -import org.pf4j.Plugin; | ||
| 22 | -import org.pf4j.PluginWrapper; | ||
| 23 | -import org.pf4j.RuntimeMode; | ||
| 24 | -import com.sun.net.httpserver.HttpServer; | ||
| 25 | -import java.io.IOException; | ||
| 26 | -import java.io.OutputStream; | ||
| 27 | -import java.net.InetSocketAddress; | ||
| 28 | - | ||
| 29 | -/** | ||
| 30 | - * 打招呼 测试用例 | ||
| 31 | - */ | ||
| 32 | -public class WelcomePlugin extends Plugin { | ||
| 33 | - | ||
| 34 | - private HttpServer server; | ||
| 35 | - | ||
| 36 | - public WelcomePlugin(PluginWrapper wrapper) { | ||
| 37 | - super(wrapper); | ||
| 38 | - } | ||
| 39 | - | ||
| 40 | - @Override | ||
| 41 | - public void start() { | ||
| 42 | - System.out.println("WelcomePlugin.start()"); | ||
| 43 | - // for testing the development mode | ||
| 44 | - if (RuntimeMode.DEVELOPMENT.equals(wrapper.getRuntimeMode())) { | ||
| 45 | - System.out.println(StringUtils.upperCase("WelcomePlugin")); | ||
| 46 | - } | ||
| 47 | - startHttpServer(); | ||
| 48 | - } | ||
| 49 | - | ||
| 50 | - @Override | ||
| 51 | - public void stop() { | ||
| 52 | - System.out.println("WelcomePlugin.stop()"); | ||
| 53 | - stopHttpServer(); | ||
| 54 | - } | ||
| 55 | - | ||
| 56 | - private void startHttpServer() { | ||
| 57 | - try { | ||
| 58 | - server = HttpServer.create(new InetSocketAddress(9081), 0); | ||
| 59 | - server.createContext("/", exchange -> { | ||
| 60 | - String response = "Welcome to PF4J HTTP Server"; | ||
| 61 | - exchange.sendResponseHeaders(200, response.getBytes().length); | ||
| 62 | - OutputStream os = exchange.getResponseBody(); | ||
| 63 | - os.write(response.getBytes()); | ||
| 64 | - os.close(); | ||
| 65 | - }); | ||
| 66 | - server.setExecutor(null); | ||
| 67 | - server.start(); | ||
| 68 | - System.out.println("HTTP server started on port 9081"); | ||
| 69 | - } catch (IOException e) { | ||
| 70 | - e.printStackTrace(); | ||
| 71 | - } | ||
| 72 | - } | ||
| 73 | - | ||
| 74 | - private void stopHttpServer() { | ||
| 75 | - if (server != null) { | ||
| 76 | - server.stop(0); | ||
| 77 | - System.out.println("HTTP server stopped"); | ||
| 78 | - } | ||
| 79 | - } | ||
| 80 | - | ||
| 81 | - @Extension | ||
| 82 | - public static class WelcomeGreeting implements Greeting { | ||
| 83 | - | ||
| 84 | - @Override | ||
| 85 | - public String getGreeting() { | ||
| 86 | - return "Welcome to PF4J"; | ||
| 87 | - } | ||
| 88 | - | ||
| 89 | - } | ||
| 90 | - | ||
| 91 | -} | ||
| 92 | \ No newline at end of file | 0 | \ No newline at end of file |