Commit 91b817a9ecd1b22d2ea1ee5e0aa1a17f4b2bbd43

Authored by 安浩浩
1 parent 0245aac5

【功能修改】IoT:删除 WelcomePlugin,新增 HttpPlugin 以支持 HTTP 服务器功能

yudao-module-iot/pom.xml
... ... @@ -10,8 +10,8 @@
10 10 <modules>
11 11 <module>yudao-module-iot-api</module>
12 12 <module>yudao-module-iot-biz</module>
13   - <module>yudao-module-iot-plugin</module>
14 13 <module>yudao-module-iot-plugin-api</module>
  14 + <module>yudao-module-iot-plugin</module>
15 15 </modules>
16 16 <modelVersion>4.0.0</modelVersion>
17 17  
... ...
yudao-module-iot/yudao-module-iot-plugin-api/pom.xml
1 1 <?xml version="1.0" encoding="UTF-8"?>
2   -<project xmlns="http://maven.apache.org/POM/4.0.0"
3   - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2 +<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3 + xmlns="http://maven.apache.org/POM/4.0.0"
4 4 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5 5 <modelVersion>4.0.0</modelVersion>
6 6 <groupId>cn.iocoder.boot</groupId>
... ...
yudao-module-iot/yudao-module-iot-plugin/pom.xml
1 1 <?xml version="1.0" encoding="UTF-8"?>
2 2 <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3   - xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="
4   - http://maven.apache.org/POM/4.0.0
5   - http://maven.apache.org/xsd/maven-4.0.0.xsd">
  3 + xmlns="http://maven.apache.org/POM/4.0.0"
  4 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
6 5 <modelVersion>4.0.0</modelVersion>
7 6 <groupId>cn.iocoder.boot</groupId>
8 7 <artifactId>yudao-module-iot-plugin</artifactId>
9 8 <version>0.0.1</version>
10   - <packaging>jar</packaging>
  9 + <packaging>pom</packaging>
11 10  
12   - <name>${project.artifactId}</name>
13   - <description>物联网 模块 - 插件</description>
14   -
15   - <properties>
16   - <!-- 插件相关 -->
17   - <plugin.id>iot-plugin-http</plugin.id>
18   - <plugin.class>cn.iocoder.yudao.module.iot.plugin.WelcomePlugin</plugin.class>
19   - <plugin.version>0.0.1</plugin.version>
20   - <plugin.provider>ahh</plugin.provider>
21   - <plugin.dependencies/>
22   -
23   - <!-- Maven 相关 -->
24   - <java.version>17</java.version>
25   - <maven.compiler.source>${java.version}</maven.compiler.source>
26   - <maven.compiler.target>${java.version}</maven.compiler.target>
27   - <maven-antrun-plugin.version>1.6</maven-antrun-plugin.version>
28   - <maven-assembly-plugin.version>2.3</maven-assembly-plugin.version>
29   - <maven-jar-plugin.version>2.4</maven-jar-plugin.version>
30   - <pf4j-spring.version>0.9.0</pf4j-spring.version>
31   - <!-- 看看咋放到 bom 里 -->
32   - <spring.boot.version>3.3.1</spring.boot.version>
33   - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
34   - </properties>
35   -
36   - <dependencies>
37   - <!-- 其他依赖项 -->
38   - <dependency>
39   - <groupId>org.springframework.boot</groupId>
40   - <artifactId>spring-boot-starter-web</artifactId>
41   - <version>${spring.boot.version}</version>
42   - <scope>provided</scope>
43   - </dependency>
44   - <!-- PF4J Spring 集成 -->
45   - <dependency>
46   - <groupId>org.pf4j</groupId>
47   - <artifactId>pf4j-spring</artifactId>
48   - <version>${pf4j-spring.version}</version>
49   - <scope>provided</scope>
50   - </dependency>
51   - <!-- 项目依赖 -->
52   - <dependency>
53   - <groupId>cn.iocoder.boot</groupId>
54   - <artifactId>yudao-module-iot-plugin-api</artifactId>
55   - <version>${project.version}</version>
56   - </dependency>
57   - </dependencies>
  11 + <modules>
  12 + <module>yudao-module-iot-http-plugin</module>
  13 + </modules>
58 14  
59   - <build>
60   - <plugins>
61   - <!-- DOESN'T WORK WITH MAVEN 3 (I defined the plugin metadata in properties section)
62   - <plugin>
63   - <groupId>org.codehaus.mojo</groupId>
64   - <artifactId>properties-maven-plugin</artifactId>
65   - <version>1.0-alpha-2</version>
66   - <executions>
67   - <execution>
68   - <phase>initialize</phase>
69   - <goals>
70   - <goal>read-project-properties</goal>
71   - </goals>
72   - <configuration>
73   - <files>
74   - <file>plugin.properties</file>
75   - </files>
76   - </configuration>
77   - </execution>
78   - </executions>
79   - </plugin>
80   - -->
81   -
82   - <plugin>
83   - <groupId>org.apache.maven.plugins</groupId>
84   - <artifactId>maven-antrun-plugin</artifactId>
85   - <version>${maven-antrun-plugin.version}</version>
86   - <executions>
87   - <execution>
88   - <id>unzip jar file</id>
89   - <phase>package</phase>
90   - <configuration>
91   - <target>
92   - <unzip src="target/${project.artifactId}-${project.version}.${project.packaging}" dest="target/plugin-classes" />
93   - </target>
94   - </configuration>
95   - <goals>
96   - <goal>run</goal>
97   - </goals>
98   - </execution>
99   - </executions>
100   - </plugin>
101   -
102   - <plugin>
103   - <artifactId>maven-assembly-plugin</artifactId>
104   - <version>${maven-assembly-plugin.version}</version>
105   - <configuration>
106   - <descriptors>
107   - <descriptor>
108   - src/main/assembly/assembly.xml
109   - </descriptor>
110   - </descriptors>
111   - <appendAssemblyId>false</appendAssemblyId>
112   - </configuration>
113   - <executions>
114   - <execution>
115   - <id>make-assembly</id>
116   - <phase>package</phase>
117   - <goals>
118   - <goal>attached</goal>
119   - </goals>
120   - </execution>
121   - </executions>
122   - </plugin>
123   -
124   - <plugin>
125   - <groupId>org.apache.maven.plugins</groupId>
126   - <artifactId>maven-jar-plugin</artifactId>
127   - <version>${maven-jar-plugin.version}</version>
128   - <configuration>
129   - <archive>
130   - <manifestEntries>
131   - <Plugin-Id>${plugin.id}</Plugin-Id>
132   - <Plugin-Class>${plugin.class}</Plugin-Class>
133   - <Plugin-Version>${plugin.version}</Plugin-Version>
134   - <Plugin-Provider>${plugin.provider}</Plugin-Provider>
135   - <Plugin-Dependencies>${plugin.dependencies}</Plugin-Dependencies>
136   - </manifestEntries>
137   - </archive>
138   - </configuration>
139   - </plugin>
  15 + <name>${project.artifactId}</name>
  16 + <description>
  17 + 物联网模块 - 插件模块
  18 + </description>
140 19  
141   - <plugin>
142   - <artifactId>maven-deploy-plugin</artifactId>
143   - <configuration>
144   - <skip>true</skip>
145   - </configuration>
146   - </plugin>
147   - </plugins>
148   - </build>
149 20 </project>
150 21 \ No newline at end of file
... ...
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   -
25   -/**
26   - * 打招呼 测试用例
27   - */
28   -public class WelcomePlugin extends Plugin {
29   -
30   - public WelcomePlugin(PluginWrapper wrapper) {
31   - super(wrapper);
32   - }
33   -
34   - @Override
35   - public void start() {
36   - System.out.println("WelcomePlugin.start()");
37   - // for testing the development mode
38   - if (RuntimeMode.DEVELOPMENT.equals(wrapper.getRuntimeMode())) {
39   - System.out.println(StringUtils.upperCase("WelcomePlugin"));
40   - }
41   - }
42   -
43   - @Override
44   - public void stop() {
45   - System.out.println("WelcomePlugin.stop()");
46   - }
47   -
48   - @Extension
49   - public static class WelcomeGreeting implements Greeting {
50   -
51   - @Override
52   - public String getGreeting() {
53   - return "Welcome to PF4J";
54   - }
55   -
56   - }
57   -
58   -}
59 0 \ No newline at end of file
yudao-module-iot/yudao-module-iot-plugin/plugin.properties renamed to yudao-module-iot/yudao-module-iot-plugin/yudao-module-iot-http-plugin/plugin.properties
1   -plugin.id=iot-plugin-hppt
2   -plugin.class=cn.iocoder.yudao.module.iot.plugin.WelcomePlugin
  1 +plugin.id=http-plugin
  2 +plugin.class=cn.iocoder.yudao.module.iot.plugin.HttpPlugin
3 3 plugin.version=0.0.1
4 4 plugin.provider=ahh
5 5 plugin.dependencies=
... ...
yudao-module-iot/yudao-module-iot-plugin/yudao-module-iot-http-plugin/pom.xml 0 → 100644
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3 + xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="
  4 + http://maven.apache.org/POM/4.0.0
  5 + http://maven.apache.org/xsd/maven-4.0.0.xsd">
  6 + <modelVersion>4.0.0</modelVersion>
  7 + <groupId>cn.iocoder.boot</groupId>
  8 + <artifactId>yudao-module-iot-http-plugin</artifactId>
  9 + <version>0.0.1</version>
  10 + <packaging>jar</packaging>
  11 +
  12 + <name>${project.artifactId}</name>
  13 + <description>物联网 模块 - http 插件</description>
  14 +
  15 + <properties>
  16 + <!-- 插件相关 -->
  17 + <plugin.id>http-plugin</plugin.id>
  18 + <plugin.class>cn.iocoder.yudao.module.iot.plugin.HttpPlugin</plugin.class>
  19 + <plugin.version>0.0.1</plugin.version>
  20 + <plugin.provider>ahh</plugin.provider>
  21 + <plugin.dependencies/>
  22 +
  23 + <!-- Maven 相关 -->
  24 + <java.version>17</java.version>
  25 + <maven.compiler.source>${java.version}</maven.compiler.source>
  26 + <maven.compiler.target>${java.version}</maven.compiler.target>
  27 + <maven-antrun-plugin.version>1.6</maven-antrun-plugin.version>
  28 + <maven-assembly-plugin.version>2.3</maven-assembly-plugin.version>
  29 + <maven-jar-plugin.version>2.4</maven-jar-plugin.version>
  30 + <pf4j-spring.version>0.9.0</pf4j-spring.version>
  31 + <!-- 看看咋放到 bom 里 -->
  32 + <lombok.version>1.18.34</lombok.version>
  33 + <spring.boot.version>3.3.1</spring.boot.version>
  34 + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  35 + </properties>
  36 +
  37 + <dependencies>
  38 + <!-- 其他依赖项 -->
  39 + <dependency>
  40 + <groupId>org.springframework.boot</groupId>
  41 + <artifactId>spring-boot-starter-web</artifactId>
  42 + <version>${spring.boot.version}</version>
  43 + <scope>provided</scope>
  44 + </dependency>
  45 + <!-- PF4J Spring 集成 -->
  46 + <dependency>
  47 + <groupId>org.pf4j</groupId>
  48 + <artifactId>pf4j-spring</artifactId>
  49 + <version>${pf4j-spring.version}</version>
  50 + <scope>provided</scope>
  51 + </dependency>
  52 + <!-- 项目依赖 -->
  53 + <dependency>
  54 + <groupId>cn.iocoder.boot</groupId>
  55 + <artifactId>yudao-module-iot-plugin-api</artifactId>
  56 + <version>${project.version}</version>
  57 + </dependency>
  58 + <dependency>
  59 + <groupId>org.projectlombok</groupId>
  60 + <artifactId>lombok</artifactId>
  61 + <version>${lombok.version}</version>
  62 + <scope>provided</scope>
  63 + </dependency>
  64 + </dependencies>
  65 +
  66 + <build>
  67 + <plugins>
  68 + <!-- DOESN'T WORK WITH MAVEN 3 (I defined the plugin metadata in properties section)
  69 + <plugin>
  70 + <groupId>org.codehaus.mojo</groupId>
  71 + <artifactId>properties-maven-plugin</artifactId>
  72 + <version>1.0-alpha-2</version>
  73 + <executions>
  74 + <execution>
  75 + <phase>initialize</phase>
  76 + <goals>
  77 + <goal>read-project-properties</goal>
  78 + </goals>
  79 + <configuration>
  80 + <files>
  81 + <file>plugin.properties</file>
  82 + </files>
  83 + </configuration>
  84 + </execution>
  85 + </executions>
  86 + </plugin>
  87 + -->
  88 +
  89 + <plugin>
  90 + <groupId>org.apache.maven.plugins</groupId>
  91 + <artifactId>maven-antrun-plugin</artifactId>
  92 + <version>${maven-antrun-plugin.version}</version>
  93 + <executions>
  94 + <execution>
  95 + <id>unzip jar file</id>
  96 + <phase>package</phase>
  97 + <configuration>
  98 + <target>
  99 + <unzip src="target/${project.artifactId}-${project.version}.${project.packaging}" dest="target/plugin-classes" />
  100 + </target>
  101 + </configuration>
  102 + <goals>
  103 + <goal>run</goal>
  104 + </goals>
  105 + </execution>
  106 + </executions>
  107 + </plugin>
  108 +
  109 + <plugin>
  110 + <artifactId>maven-assembly-plugin</artifactId>
  111 + <version>${maven-assembly-plugin.version}</version>
  112 + <configuration>
  113 + <descriptors>
  114 + <descriptor>
  115 + src/main/assembly/assembly.xml
  116 + </descriptor>
  117 + </descriptors>
  118 + <appendAssemblyId>false</appendAssemblyId>
  119 + </configuration>
  120 + <executions>
  121 + <execution>
  122 + <id>make-assembly</id>
  123 + <phase>package</phase>
  124 + <goals>
  125 + <goal>attached</goal>
  126 + </goals>
  127 + </execution>
  128 + </executions>
  129 + </plugin>
  130 +
  131 + <plugin>
  132 + <groupId>org.apache.maven.plugins</groupId>
  133 + <artifactId>maven-jar-plugin</artifactId>
  134 + <version>${maven-jar-plugin.version}</version>
  135 + <configuration>
  136 + <archive>
  137 + <manifestEntries>
  138 + <Plugin-Id>${plugin.id}</Plugin-Id>
  139 + <Plugin-Class>${plugin.class}</Plugin-Class>
  140 + <Plugin-Version>${plugin.version}</Plugin-Version>
  141 + <Plugin-Provider>${plugin.provider}</Plugin-Provider>
  142 + <Plugin-Dependencies>${plugin.dependencies}</Plugin-Dependencies>
  143 + </manifestEntries>
  144 + </archive>
  145 + </configuration>
  146 + </plugin>
  147 +
  148 + <plugin>
  149 + <artifactId>maven-deploy-plugin</artifactId>
  150 + <configuration>
  151 + <skip>true</skip>
  152 + </configuration>
  153 + </plugin>
  154 + </plugins>
  155 + </build>
  156 +</project>
0 157 \ No newline at end of file
... ...
yudao-module-iot/yudao-module-iot-plugin/src/main/assembly/assembly.xml renamed to yudao-module-iot/yudao-module-iot-plugin/yudao-module-iot-http-plugin/src/main/assembly/assembly.xml
yudao-module-iot/yudao-module-iot-plugin/yudao-module-iot-http-plugin/src/main/java/cn/iocoder/yudao/module/iot/plugin/HttpPlugin.java 0 → 100644
  1 +package cn.iocoder.yudao.module.iot.plugin;
  2 +
  3 +import cn.iocoder.yudao.module.iot.api.Greeting;
  4 +import com.sun.net.httpserver.HttpServer;
  5 +import lombok.extern.slf4j.Slf4j;
  6 +import org.apache.commons.lang.StringUtils;
  7 +import org.pf4j.Extension;
  8 +import org.pf4j.Plugin;
  9 +import org.pf4j.PluginWrapper;
  10 +import org.pf4j.RuntimeMode;
  11 +
  12 +import java.io.IOException;
  13 +import java.io.OutputStream;
  14 +import java.net.InetSocketAddress;
  15 +
  16 +/**
  17 + * 一个启动 HTTP 服务器的简单插件。
  18 + */
  19 +@Slf4j
  20 +public class HttpPlugin extends Plugin {
  21 +
  22 + private HttpServer server;
  23 +
  24 + public HttpPlugin(PluginWrapper wrapper) {
  25 + super(wrapper);
  26 + }
  27 +
  28 + @Override
  29 + public void start() {
  30 + log.info("HttpPlugin.start()");
  31 + // for testing the development mode
  32 + if (RuntimeMode.DEVELOPMENT.equals(wrapper.getRuntimeMode())) {
  33 + log.info("HttpPlugin in DEVELOPMENT mode");
  34 + }
  35 + startHttpServer();
  36 + }
  37 +
  38 + @Override
  39 + public void stop() {
  40 + log.info("HttpPlugin.stop()");
  41 + stopHttpServer();
  42 + }
  43 +
  44 + private void startHttpServer() {
  45 + try {
  46 + server = HttpServer.create(new InetSocketAddress(9081), 0);
  47 + server.createContext("/", exchange -> {
  48 + String response = "Welcome to PF4J HTTP Server";
  49 + exchange.sendResponseHeaders(200, response.getBytes().length);
  50 + OutputStream os = exchange.getResponseBody();
  51 + os.write(response.getBytes());
  52 + os.close();
  53 + });
  54 + server.setExecutor(null);
  55 + server.start();
  56 + log.info("HTTP server started on port 9081");
  57 + } catch (IOException e) {
  58 + log.error("Error starting HTTP server", e);
  59 + }
  60 + }
  61 +
  62 + private void stopHttpServer() {
  63 + if (server != null) {
  64 + server.stop(0);
  65 + log.info("HTTP server stopped");
  66 + }
  67 + }
  68 +
  69 + @Extension
  70 + public static class WelcomeGreeting implements Greeting {
  71 +
  72 + @Override
  73 + public String getGreeting() {
  74 + return "Welcome to PF4J";
  75 + }
  76 +
  77 + }
  78 +
  79 +}
0 80 \ No newline at end of file
... ...