mirror of
https://github.com/qaiu/netdisk-fast-download.git
synced 2025-12-17 04:43:02 +00:00
first commit ZZZzzzzzz
This commit is contained in:
13
web/assembly.xml
Normal file
13
web/assembly.xml
Normal file
@@ -0,0 +1,13 @@
|
||||
<assembly>
|
||||
<id>bin</id>
|
||||
<formats>
|
||||
<format>zip</format>
|
||||
</formats>
|
||||
<fileSets>
|
||||
<!-- 从目标目录拷贝文件去压缩 -->
|
||||
<fileSet>
|
||||
<directory>target/package/</directory>
|
||||
<outputDirectory>/</outputDirectory>
|
||||
</fileSet>
|
||||
</fileSets>
|
||||
</assembly>
|
||||
0
web/logs/20230420/run.log
Normal file
0
web/logs/20230420/run.log
Normal file
198
web/pom.xml
Normal file
198
web/pom.xml
Normal file
@@ -0,0 +1,198 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>lz-cow-api</artifactId>
|
||||
<groupId>cn.qaiu</groupId>
|
||||
<version>0.0.1</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<version>0.0.1</version>
|
||||
<artifactId>web</artifactId>
|
||||
|
||||
<properties>
|
||||
<packageDirectory>${project.basedir}/target/package</packageDirectory>
|
||||
<java.version>17</java.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<slf4j.version>2.0.5</slf4j.version>
|
||||
<vertx-jooq.version>6.1.0</vertx-jooq.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>cn.qaiu</groupId>
|
||||
<artifactId>core</artifactId>
|
||||
<version>1.0.8</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.26</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!--logback日志实现-->
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<version>1.4.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>${slf4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.13.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<directory>${project.basedir}/target/</directory>
|
||||
<outputDirectory>${project.build.directory}/classes</outputDirectory>
|
||||
<finalName>${project.artifactId}-${project.version}</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<source>${java.version}</source>
|
||||
<target>${java.version}</target>
|
||||
<!-- 代码生成器 -->
|
||||
<annotationProcessors>
|
||||
<annotationProcessor>lombok.launch.AnnotationProcessorHider$AnnotationProcessor</annotationProcessor>
|
||||
<annotationProcessor>io.vertx.codegen.CodeGenProcessor</annotationProcessor>
|
||||
</annotationProcessors>
|
||||
<generatedSourcesDirectory>
|
||||
${project.basedir}/src/main/generated
|
||||
</generatedSourcesDirectory>
|
||||
<compilerArgs>
|
||||
<arg>-AoutputDirectory=${project.basedir}/src/main -Xlint:unchecked</arg>
|
||||
</compilerArgs>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<!--打包jar-->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>3.2.0</version>
|
||||
<configuration>
|
||||
<!--不打包资源文件-->
|
||||
<excludes>
|
||||
<exclude>*.**</exclude>
|
||||
<exclude>*/*.xml</exclude>
|
||||
<exclude>conf/**</exclude>
|
||||
</excludes>
|
||||
<archive>
|
||||
<manifest>
|
||||
<addClasspath>true</addClasspath>
|
||||
<!--MANIFEST.MF 中 Class-Path 加入前缀-->
|
||||
<classpathPrefix>lib/</classpathPrefix>
|
||||
<!--jar包不包含唯一版本标识-->
|
||||
<useUniqueVersions>false</useUniqueVersions>
|
||||
<!--指定入口类-->
|
||||
<mainClass>cn.com.yhinfo.real.AppMain</mainClass>
|
||||
</manifest>
|
||||
<manifestEntries>
|
||||
<!--MANIFEST.MF 中 Class-Path 加入资源文件目录-->
|
||||
<Class-Path>./resources/</Class-Path>
|
||||
</manifestEntries>
|
||||
</archive>
|
||||
<outputDirectory>${packageDirectory}</outputDirectory>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<!--拷贝依赖 copy-dependencies-->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<version>3.1.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy-dependencies</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>copy-dependencies</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<!--打包时排除的依赖作用域-->
|
||||
<excludeScope>test</excludeScope>
|
||||
<excludeScope>provided</excludeScope>
|
||||
<outputDirectory>
|
||||
${packageDirectory}/lib/
|
||||
</outputDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<!--拷贝资源文件 copy-resources-->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<version>3.2.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy-resources</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>copy-resources</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
</resource>
|
||||
</resources>
|
||||
<outputDirectory>${packageDirectory}/resources</outputDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-clean-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<configuration>
|
||||
<!--<skip>true</skip>-->
|
||||
<!--<failOnError>false</failOnError>-->
|
||||
<!--当配置true时,只清理filesets里的文件,构建目录中得文件不被清理.默认是flase.-->
|
||||
<excludeDefaultDirectories>false</excludeDefaultDirectories>
|
||||
<filesets>
|
||||
<fileset>
|
||||
<!--要清理的目录位置-->
|
||||
<directory>${basedir}/src/main/generated</directory>
|
||||
<!--是否跟随符号链接 (symbolic links)-->
|
||||
<followSymlinks>false</followSymlinks>
|
||||
</fileset>
|
||||
</filesets>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<!-- 自定义打zip包 -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<version>3.3.0</version>
|
||||
<configuration>
|
||||
<descriptors>
|
||||
<descriptor>assembly.xml</descriptor>
|
||||
</descriptors>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>make-assembly</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,28 @@
|
||||
package cn.com.yhinfo.real.common.model;
|
||||
|
||||
/**
|
||||
* Mapper for {@link MyData}.
|
||||
* NOTE: This class has been automatically generated from the {@link MyData} original class using Vert.x codegen.
|
||||
*/
|
||||
@io.vertx.codegen.annotations.VertxGen
|
||||
public interface MyDataParametersMapper extends io.vertx.sqlclient.templates.TupleMapper<MyData> {
|
||||
|
||||
MyDataParametersMapper INSTANCE = new MyDataParametersMapper() {};
|
||||
|
||||
default io.vertx.sqlclient.Tuple map(java.util.function.Function<Integer, String> mapping, int size, MyData params) {
|
||||
java.util.Map<String, Object> args = map(params);
|
||||
Object[] array = new Object[size];
|
||||
for (int i = 0;i < array.length;i++) {
|
||||
String column = mapping.apply(i);
|
||||
array[i] = args.get(column);
|
||||
}
|
||||
return io.vertx.sqlclient.Tuple.wrap(array);
|
||||
}
|
||||
|
||||
default java.util.Map<String, Object> map(MyData obj) {
|
||||
java.util.Map<String, Object> params = new java.util.HashMap<>();
|
||||
params.put("id", obj.getId());
|
||||
params.put("max_size", obj.getMaxSize());
|
||||
return params;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package cn.com.yhinfo.real.common.model;
|
||||
|
||||
/**
|
||||
* Mapper for {@link MyData}.
|
||||
* NOTE: This class has been automatically generated from the {@link MyData} original class using Vert.x codegen.
|
||||
*/
|
||||
@io.vertx.codegen.annotations.VertxGen
|
||||
public interface MyDataRowMapper extends io.vertx.sqlclient.templates.RowMapper<MyData> {
|
||||
|
||||
@io.vertx.codegen.annotations.GenIgnore
|
||||
MyDataRowMapper INSTANCE = new MyDataRowMapper() { };
|
||||
|
||||
@io.vertx.codegen.annotations.GenIgnore
|
||||
java.util.stream.Collector<io.vertx.sqlclient.Row, ?, java.util.List<MyData>> COLLECTOR = java.util.stream.Collectors.mapping(INSTANCE::map, java.util.stream.Collectors.toList());
|
||||
|
||||
@io.vertx.codegen.annotations.GenIgnore
|
||||
default MyData map(io.vertx.sqlclient.Row row) {
|
||||
MyData obj = new MyData();
|
||||
Object val;
|
||||
int idx;
|
||||
if ((idx = row.getColumnIndex("id")) != -1 && (val = row.getString(idx)) != null) {
|
||||
obj.setId((java.lang.String)val);
|
||||
}
|
||||
if ((idx = row.getColumnIndex("max_size")) != -1 && (val = row.getString(idx)) != null) {
|
||||
obj.setMaxSize((java.lang.String)val);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package cn.com.yhinfo.real.common.model;
|
||||
|
||||
/**
|
||||
* Mapper for {@link UserInfo}.
|
||||
* NOTE: This class has been automatically generated from the {@link UserInfo} original class using Vert.x codegen.
|
||||
*/
|
||||
@io.vertx.codegen.annotations.VertxGen
|
||||
public interface UserInfoParametersMapper extends io.vertx.sqlclient.templates.TupleMapper<UserInfo> {
|
||||
|
||||
UserInfoParametersMapper INSTANCE = new UserInfoParametersMapper() {};
|
||||
|
||||
default io.vertx.sqlclient.Tuple map(java.util.function.Function<Integer, String> mapping, int size, UserInfo params) {
|
||||
java.util.Map<String, Object> args = map(params);
|
||||
Object[] array = new Object[size];
|
||||
for (int i = 0;i < array.length;i++) {
|
||||
String column = mapping.apply(i);
|
||||
array[i] = args.get(column);
|
||||
}
|
||||
return io.vertx.sqlclient.Tuple.wrap(array);
|
||||
}
|
||||
|
||||
default java.util.Map<String, Object> map(UserInfo obj) {
|
||||
java.util.Map<String, Object> params = new java.util.HashMap<>();
|
||||
params.put("permission", obj.getPermission());
|
||||
params.put("pwd_crc32", obj.getPwdCrc32());
|
||||
params.put("username", obj.getUsername());
|
||||
params.put("uuid", obj.getUuid());
|
||||
return params;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package cn.com.yhinfo.real.common.model;
|
||||
|
||||
/**
|
||||
* Mapper for {@link UserInfo}.
|
||||
* NOTE: This class has been automatically generated from the {@link UserInfo} original class using Vert.x codegen.
|
||||
*/
|
||||
@io.vertx.codegen.annotations.VertxGen
|
||||
public interface UserInfoRowMapper extends io.vertx.sqlclient.templates.RowMapper<UserInfo> {
|
||||
|
||||
@io.vertx.codegen.annotations.GenIgnore
|
||||
UserInfoRowMapper INSTANCE = new UserInfoRowMapper() { };
|
||||
|
||||
@io.vertx.codegen.annotations.GenIgnore
|
||||
java.util.stream.Collector<io.vertx.sqlclient.Row, ?, java.util.List<UserInfo>> COLLECTOR = java.util.stream.Collectors.mapping(INSTANCE::map, java.util.stream.Collectors.toList());
|
||||
|
||||
@io.vertx.codegen.annotations.GenIgnore
|
||||
default UserInfo map(io.vertx.sqlclient.Row row) {
|
||||
UserInfo obj = new UserInfo();
|
||||
Object val;
|
||||
int idx;
|
||||
if ((idx = row.getColumnIndex("permission")) != -1 && (val = row.getString(idx)) != null) {
|
||||
obj.setPermission((java.lang.String)val);
|
||||
}
|
||||
if ((idx = row.getColumnIndex("pwd_crc32")) != -1 && (val = row.getString(idx)) != null) {
|
||||
obj.setPwdCrc32((java.lang.String)val);
|
||||
}
|
||||
if ((idx = row.getColumnIndex("username")) != -1 && (val = row.getString(idx)) != null) {
|
||||
obj.setUsername((java.lang.String)val);
|
||||
}
|
||||
if ((idx = row.getColumnIndex("uuid")) != -1 && (val = row.getString(idx)) != null) {
|
||||
obj.setUuid((java.lang.String)val);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright 2014 Red Hat, Inc.
|
||||
*
|
||||
* Red Hat licenses this file to you under the Apache License, version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package cn.com.yhinfo.real.web.service;
|
||||
|
||||
import io.vertx.core.eventbus.DeliveryOptions;
|
||||
import io.vertx.core.Vertx;
|
||||
import io.vertx.core.Future;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import io.vertx.core.json.JsonArray;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.function.Function;
|
||||
import io.vertx.serviceproxy.ServiceException;
|
||||
import io.vertx.serviceproxy.ServiceExceptionMessageCodec;
|
||||
import io.vertx.serviceproxy.ProxyUtils;
|
||||
|
||||
import cn.com.yhinfo.real.common.model.UserInfo;
|
||||
import cn.com.yhinfo.core.base.BaseAsyncService;
|
||||
import io.vertx.core.Future;
|
||||
/*
|
||||
Generated Proxy code - DO NOT EDIT
|
||||
@author Roger the Robot
|
||||
*/
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
public class DbServiceVertxEBProxy implements DbService {
|
||||
private Vertx _vertx;
|
||||
private String _address;
|
||||
private DeliveryOptions _options;
|
||||
private boolean closed;
|
||||
|
||||
public DbServiceVertxEBProxy(Vertx vertx, String address) {
|
||||
this(vertx, address, null);
|
||||
}
|
||||
|
||||
public DbServiceVertxEBProxy(Vertx vertx, String address, DeliveryOptions options) {
|
||||
this._vertx = vertx;
|
||||
this._address = address;
|
||||
this._options = options;
|
||||
try {
|
||||
this._vertx.eventBus().registerDefaultCodec(ServiceException.class, new ServiceExceptionMessageCodec());
|
||||
} catch (IllegalStateException ex) {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Future<JsonObject> sayOk(String data){
|
||||
if (closed) return io.vertx.core.Future.failedFuture("Proxy is closed");
|
||||
JsonObject _json = new JsonObject();
|
||||
_json.put("data", data);
|
||||
|
||||
DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions();
|
||||
_deliveryOptions.addHeader("action", "sayOk");
|
||||
return _vertx.eventBus().<JsonObject>request(_address, _json, _deliveryOptions).map(msg -> {
|
||||
return msg.body();
|
||||
});
|
||||
}
|
||||
@Override
|
||||
public Future<JsonObject> sayOk2(String data, UserInfo holder){
|
||||
if (closed) return io.vertx.core.Future.failedFuture("Proxy is closed");
|
||||
JsonObject _json = new JsonObject();
|
||||
_json.put("data", data);
|
||||
_json.put("holder", holder != null ? holder.toJson() : null);
|
||||
|
||||
DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions();
|
||||
_deliveryOptions.addHeader("action", "sayOk2");
|
||||
return _vertx.eventBus().<JsonObject>request(_address, _json, _deliveryOptions).map(msg -> {
|
||||
return msg.body();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
/*
|
||||
* Copyright 2014 Red Hat, Inc.
|
||||
*
|
||||
* Red Hat licenses this file to you under the Apache License, version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package cn.com.yhinfo.real.web.service;
|
||||
|
||||
import cn.com.yhinfo.real.web.service.DbService;
|
||||
import io.vertx.core.Vertx;
|
||||
import io.vertx.core.Handler;
|
||||
import io.vertx.core.AsyncResult;
|
||||
import io.vertx.core.eventbus.EventBus;
|
||||
import io.vertx.core.eventbus.Message;
|
||||
import io.vertx.core.eventbus.MessageConsumer;
|
||||
import io.vertx.core.eventbus.DeliveryOptions;
|
||||
import io.vertx.core.eventbus.ReplyException;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import io.vertx.core.json.JsonArray;
|
||||
import java.util.Collection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
import io.vertx.serviceproxy.ProxyHandler;
|
||||
import io.vertx.serviceproxy.ServiceException;
|
||||
import io.vertx.serviceproxy.ServiceExceptionMessageCodec;
|
||||
import io.vertx.serviceproxy.HelperUtils;
|
||||
import io.vertx.serviceproxy.ServiceBinder;
|
||||
|
||||
import cn.com.yhinfo.real.common.model.UserInfo;
|
||||
import cn.com.yhinfo.core.base.BaseAsyncService;
|
||||
import io.vertx.core.Future;
|
||||
/*
|
||||
Generated Proxy code - DO NOT EDIT
|
||||
@author Roger the Robot
|
||||
*/
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
public class DbServiceVertxProxyHandler extends ProxyHandler {
|
||||
|
||||
public static final long DEFAULT_CONNECTION_TIMEOUT = 5 * 60; // 5 minutes
|
||||
private final Vertx vertx;
|
||||
private final DbService service;
|
||||
private final long timerID;
|
||||
private long lastAccessed;
|
||||
private final long timeoutSeconds;
|
||||
private final boolean includeDebugInfo;
|
||||
|
||||
public DbServiceVertxProxyHandler(Vertx vertx, DbService service){
|
||||
this(vertx, service, DEFAULT_CONNECTION_TIMEOUT);
|
||||
}
|
||||
|
||||
public DbServiceVertxProxyHandler(Vertx vertx, DbService service, long timeoutInSecond){
|
||||
this(vertx, service, true, timeoutInSecond);
|
||||
}
|
||||
|
||||
public DbServiceVertxProxyHandler(Vertx vertx, DbService service, boolean topLevel, long timeoutInSecond){
|
||||
this(vertx, service, true, timeoutInSecond, false);
|
||||
}
|
||||
|
||||
public DbServiceVertxProxyHandler(Vertx vertx, DbService service, boolean topLevel, long timeoutSeconds, boolean includeDebugInfo) {
|
||||
this.vertx = vertx;
|
||||
this.service = service;
|
||||
this.includeDebugInfo = includeDebugInfo;
|
||||
this.timeoutSeconds = timeoutSeconds;
|
||||
try {
|
||||
this.vertx.eventBus().registerDefaultCodec(ServiceException.class,
|
||||
new ServiceExceptionMessageCodec());
|
||||
} catch (IllegalStateException ex) {}
|
||||
if (timeoutSeconds != -1 && !topLevel) {
|
||||
long period = timeoutSeconds * 1000 / 2;
|
||||
if (period > 10000) {
|
||||
period = 10000;
|
||||
}
|
||||
this.timerID = vertx.setPeriodic(period, this::checkTimedOut);
|
||||
} else {
|
||||
this.timerID = -1;
|
||||
}
|
||||
accessed();
|
||||
}
|
||||
|
||||
|
||||
private void checkTimedOut(long id) {
|
||||
long now = System.nanoTime();
|
||||
if (now - lastAccessed > timeoutSeconds * 1000000000) {
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
if (timerID != -1) {
|
||||
vertx.cancelTimer(timerID);
|
||||
}
|
||||
super.close();
|
||||
}
|
||||
|
||||
private void accessed() {
|
||||
this.lastAccessed = System.nanoTime();
|
||||
}
|
||||
|
||||
public void handle(Message<JsonObject> msg) {
|
||||
try{
|
||||
JsonObject json = msg.body();
|
||||
String action = msg.headers().get("action");
|
||||
if (action == null) throw new IllegalStateException("action not specified");
|
||||
accessed();
|
||||
switch (action) {
|
||||
case "sayOk": {
|
||||
service.sayOk((java.lang.String)json.getValue("data")).onComplete(HelperUtils.createHandler(msg, includeDebugInfo));
|
||||
break;
|
||||
}
|
||||
case "sayOk2": {
|
||||
service.sayOk2((java.lang.String)json.getValue("data"),
|
||||
json.getJsonObject("holder") != null ? new cn.com.yhinfo.real.common.model.UserInfo((JsonObject)json.getJsonObject("holder")) : null).onComplete(HelperUtils.createHandler(msg, includeDebugInfo));
|
||||
break;
|
||||
}
|
||||
default: throw new IllegalStateException("Invalid action: " + action);
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
if (includeDebugInfo) msg.reply(new ServiceException(500, t.getMessage(), HelperUtils.generateDebugInfo(t)));
|
||||
else msg.reply(new ServiceException(500, t.getMessage()));
|
||||
throw t;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright 2014 Red Hat, Inc.
|
||||
*
|
||||
* Red Hat licenses this file to you under the Apache License, version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package cn.com.yhinfo.real.web.service;
|
||||
|
||||
import io.vertx.core.eventbus.DeliveryOptions;
|
||||
import io.vertx.core.Vertx;
|
||||
import io.vertx.core.Future;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import io.vertx.core.json.JsonArray;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.function.Function;
|
||||
import io.vertx.serviceproxy.ServiceException;
|
||||
import io.vertx.serviceproxy.ServiceExceptionMessageCodec;
|
||||
import io.vertx.serviceproxy.ProxyUtils;
|
||||
|
||||
import cn.com.yhinfo.core.base.BaseAsyncService;
|
||||
import cn.com.yhinfo.real.web.model.RealUser;
|
||||
import io.vertx.core.Future;
|
||||
/*
|
||||
Generated Proxy code - DO NOT EDIT
|
||||
@author Roger the Robot
|
||||
*/
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
public class UserServiceVertxEBProxy implements UserService {
|
||||
private Vertx _vertx;
|
||||
private String _address;
|
||||
private DeliveryOptions _options;
|
||||
private boolean closed;
|
||||
|
||||
public UserServiceVertxEBProxy(Vertx vertx, String address) {
|
||||
this(vertx, address, null);
|
||||
}
|
||||
|
||||
public UserServiceVertxEBProxy(Vertx vertx, String address, DeliveryOptions options) {
|
||||
this._vertx = vertx;
|
||||
this._address = address;
|
||||
this._options = options;
|
||||
try {
|
||||
this._vertx.eventBus().registerDefaultCodec(ServiceException.class, new ServiceExceptionMessageCodec());
|
||||
} catch (IllegalStateException ex) {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Future<String> login(RealUser user){
|
||||
if (closed) return io.vertx.core.Future.failedFuture("Proxy is closed");
|
||||
JsonObject _json = new JsonObject();
|
||||
_json.put("user", user != null ? user.toJson() : null);
|
||||
|
||||
DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions();
|
||||
_deliveryOptions.addHeader("action", "login");
|
||||
return _vertx.eventBus().<String>request(_address, _json, _deliveryOptions).map(msg -> {
|
||||
return msg.body();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
/*
|
||||
* Copyright 2014 Red Hat, Inc.
|
||||
*
|
||||
* Red Hat licenses this file to you under the Apache License, version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package cn.com.yhinfo.real.web.service;
|
||||
|
||||
import cn.com.yhinfo.real.web.service.UserService;
|
||||
import io.vertx.core.Vertx;
|
||||
import io.vertx.core.Handler;
|
||||
import io.vertx.core.AsyncResult;
|
||||
import io.vertx.core.eventbus.EventBus;
|
||||
import io.vertx.core.eventbus.Message;
|
||||
import io.vertx.core.eventbus.MessageConsumer;
|
||||
import io.vertx.core.eventbus.DeliveryOptions;
|
||||
import io.vertx.core.eventbus.ReplyException;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import io.vertx.core.json.JsonArray;
|
||||
import java.util.Collection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
import io.vertx.serviceproxy.ProxyHandler;
|
||||
import io.vertx.serviceproxy.ServiceException;
|
||||
import io.vertx.serviceproxy.ServiceExceptionMessageCodec;
|
||||
import io.vertx.serviceproxy.HelperUtils;
|
||||
import io.vertx.serviceproxy.ServiceBinder;
|
||||
|
||||
import cn.com.yhinfo.core.base.BaseAsyncService;
|
||||
import cn.com.yhinfo.real.web.model.RealUser;
|
||||
import io.vertx.core.Future;
|
||||
/*
|
||||
Generated Proxy code - DO NOT EDIT
|
||||
@author Roger the Robot
|
||||
*/
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
public class UserServiceVertxProxyHandler extends ProxyHandler {
|
||||
|
||||
public static final long DEFAULT_CONNECTION_TIMEOUT = 5 * 60; // 5 minutes
|
||||
private final Vertx vertx;
|
||||
private final UserService service;
|
||||
private final long timerID;
|
||||
private long lastAccessed;
|
||||
private final long timeoutSeconds;
|
||||
private final boolean includeDebugInfo;
|
||||
|
||||
public UserServiceVertxProxyHandler(Vertx vertx, UserService service){
|
||||
this(vertx, service, DEFAULT_CONNECTION_TIMEOUT);
|
||||
}
|
||||
|
||||
public UserServiceVertxProxyHandler(Vertx vertx, UserService service, long timeoutInSecond){
|
||||
this(vertx, service, true, timeoutInSecond);
|
||||
}
|
||||
|
||||
public UserServiceVertxProxyHandler(Vertx vertx, UserService service, boolean topLevel, long timeoutInSecond){
|
||||
this(vertx, service, true, timeoutInSecond, false);
|
||||
}
|
||||
|
||||
public UserServiceVertxProxyHandler(Vertx vertx, UserService service, boolean topLevel, long timeoutSeconds, boolean includeDebugInfo) {
|
||||
this.vertx = vertx;
|
||||
this.service = service;
|
||||
this.includeDebugInfo = includeDebugInfo;
|
||||
this.timeoutSeconds = timeoutSeconds;
|
||||
try {
|
||||
this.vertx.eventBus().registerDefaultCodec(ServiceException.class,
|
||||
new ServiceExceptionMessageCodec());
|
||||
} catch (IllegalStateException ex) {}
|
||||
if (timeoutSeconds != -1 && !topLevel) {
|
||||
long period = timeoutSeconds * 1000 / 2;
|
||||
if (period > 10000) {
|
||||
period = 10000;
|
||||
}
|
||||
this.timerID = vertx.setPeriodic(period, this::checkTimedOut);
|
||||
} else {
|
||||
this.timerID = -1;
|
||||
}
|
||||
accessed();
|
||||
}
|
||||
|
||||
|
||||
private void checkTimedOut(long id) {
|
||||
long now = System.nanoTime();
|
||||
if (now - lastAccessed > timeoutSeconds * 1000000000) {
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
if (timerID != -1) {
|
||||
vertx.cancelTimer(timerID);
|
||||
}
|
||||
super.close();
|
||||
}
|
||||
|
||||
private void accessed() {
|
||||
this.lastAccessed = System.nanoTime();
|
||||
}
|
||||
|
||||
public void handle(Message<JsonObject> msg) {
|
||||
try{
|
||||
JsonObject json = msg.body();
|
||||
String action = msg.headers().get("action");
|
||||
if (action == null) throw new IllegalStateException("action not specified");
|
||||
accessed();
|
||||
switch (action) {
|
||||
case "login": {
|
||||
service.login(json.getJsonObject("user") != null ? new cn.com.yhinfo.real.web.model.RealUser((JsonObject)json.getJsonObject("user")) : null).onComplete(HelperUtils.createHandler(msg, includeDebugInfo));
|
||||
break;
|
||||
}
|
||||
default: throw new IllegalStateException("Invalid action: " + action);
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
if (includeDebugInfo) msg.reply(new ServiceException(500, t.getMessage(), HelperUtils.generateDebugInfo(t)));
|
||||
else msg.reply(new ServiceException(500, t.getMessage()));
|
||||
throw t;
|
||||
}
|
||||
}
|
||||
}
|
||||
29
web/src/main/java/cn/com/yhinfo/real/AppMain.java
Normal file
29
web/src/main/java/cn/com/yhinfo/real/AppMain.java
Normal file
@@ -0,0 +1,29 @@
|
||||
package cn.com.yhinfo.real;
|
||||
|
||||
import cn.com.yhinfo.core.Deploy;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
|
||||
|
||||
/**
|
||||
* 程序入口
|
||||
* <br>Create date 2021-05-08 13:00:01
|
||||
*
|
||||
* @author qiu
|
||||
*/
|
||||
public class AppMain {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// 注册枚举类型转换器
|
||||
Deploy.instance().start(args, AppMain::exec);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param jsonObject 配置
|
||||
*/
|
||||
private static void exec(JsonObject jsonObject) {
|
||||
//
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
22
web/src/main/java/cn/com/yhinfo/real/common/ToJson.java
Normal file
22
web/src/main/java/cn/com/yhinfo/real/common/ToJson.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package cn.com.yhinfo.real.common;
|
||||
|
||||
import io.vertx.core.json.JsonObject;
|
||||
|
||||
/**
|
||||
* sinoreal2-web <br>
|
||||
* 实现此接口 POJO转JSON对象
|
||||
*
|
||||
* @author <a href="https://qaiu.top">QAIU</a>
|
||||
* <br>Create date 2021/8/27 11:40
|
||||
*/
|
||||
public interface ToJson {
|
||||
|
||||
/**
|
||||
* POJO转JSON对象
|
||||
*
|
||||
* @return Json Object
|
||||
*/
|
||||
default JsonObject toJson() {
|
||||
return JsonObject.mapFrom(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package cn.com.yhinfo.real.common.interceptorImpl;
|
||||
|
||||
import cn.com.yhinfo.core.base.BaseHttpApi;
|
||||
import cn.com.yhinfo.core.interceptor.Interceptor;
|
||||
import cn.com.yhinfo.core.model.JsonResult;
|
||||
import cn.com.yhinfo.core.util.CommonUtil;
|
||||
import cn.com.yhinfo.core.util.SharedDataUtil;
|
||||
import cn.com.yhinfo.core.util.VertxHolder;
|
||||
import io.vertx.core.json.JsonArray;
|
||||
import io.vertx.core.shareddata.LocalMap;
|
||||
import io.vertx.ext.web.RoutingContext;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import lombok.val;
|
||||
|
||||
/**
|
||||
* 默认拦截器实现
|
||||
* 校验用户是否合法 <br>
|
||||
* TODO 暂时只做简单实现
|
||||
*/
|
||||
@Slf4j
|
||||
public class DefaultInterceptor implements Interceptor, BaseHttpApi {
|
||||
|
||||
private final JsonArray ignores = SharedDataUtil.getJsonArrayForCustomConfig("ignoresReg");
|
||||
|
||||
@Override
|
||||
public void handle(RoutingContext ctx) {
|
||||
|
||||
// 判断是否忽略
|
||||
if (CommonUtil.matchRegList(ignores.getList(), ctx.request().path())) {
|
||||
ctx.next();
|
||||
return;
|
||||
}
|
||||
// 执行拦截
|
||||
val token = ctx.request().getHeader("token");
|
||||
|
||||
|
||||
LocalMap<String, String> tokenMap = SharedDataUtil.getLocalMapWithCast("token");
|
||||
if (token != null && tokenMap != null && tokenMap.containsKey(token)) {
|
||||
VertxHolder.getVertxInstance().getOrCreateContext().put("username", tokenMap.get(token));
|
||||
ctx.next();
|
||||
} else {
|
||||
fireJsonResponse(ctx, JsonResult.error("没有权限", 401));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package cn.com.yhinfo.real.common.model;
|
||||
|
||||
import io.vertx.codegen.annotations.DataObject;
|
||||
import io.vertx.codegen.format.SnakeCase;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import io.vertx.sqlclient.templates.annotations.ParametersMapped;
|
||||
import io.vertx.sqlclient.templates.annotations.RowMapped;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="https://qaiu.top">QAIU</a>
|
||||
* <br>Create date 2021/7/22 3:34
|
||||
*/
|
||||
@DataObject
|
||||
@RowMapped(formatter = SnakeCase.class)
|
||||
@ParametersMapped(formatter = SnakeCase.class)
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class MyData implements Serializable {
|
||||
public static final long serialVersionUID = 1L;
|
||||
|
||||
private String id;
|
||||
|
||||
private String maxSize;
|
||||
|
||||
|
||||
public MyData(JsonObject jsonObject) {
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package cn.com.yhinfo.real.common.model;
|
||||
|
||||
import cn.com.yhinfo.real.common.ToJson;
|
||||
import io.vertx.codegen.annotations.DataObject;
|
||||
import io.vertx.codegen.format.SnakeCase;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import io.vertx.sqlclient.templates.annotations.ParametersMapped;
|
||||
import io.vertx.sqlclient.templates.annotations.RowMapped;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* sinoreal2-web
|
||||
*
|
||||
* @author <a href="https://qaiu.top">QAIU</a>
|
||||
* <br>Create date 2021/8/10 11:10
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@DataObject
|
||||
@RowMapped(formatter = SnakeCase.class)
|
||||
@ParametersMapped(formatter = SnakeCase.class)
|
||||
public class UserInfo implements ToJson {
|
||||
|
||||
private String username;
|
||||
|
||||
private String permission;
|
||||
|
||||
private String pwdCrc32;
|
||||
|
||||
private String uuid;
|
||||
|
||||
public UserInfo(JsonObject jsonObject) {
|
||||
this.username = jsonObject.getString("username");
|
||||
this.permission = jsonObject.getString("permission");
|
||||
this.pwdCrc32 = jsonObject.getString("pwdCrc32");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package cn.com.yhinfo.real.common.util;
|
||||
|
||||
public class ArrayUtil {
|
||||
|
||||
public static int[] parseIntArray(String[] arr) {
|
||||
int[] ints = new int[arr.length];
|
||||
for (int i = 0; i < ints.length; i++) {
|
||||
ints[i] = Integer.parseInt(arr[i]);
|
||||
}
|
||||
return ints;
|
||||
}
|
||||
|
||||
public static float[] parseFloatArray(String[] arr) {
|
||||
float[] ints = new float[arr.length];
|
||||
for (int i = 0; i < ints.length; i++) {
|
||||
ints[i] = Float.parseFloat(arr[i]);
|
||||
}
|
||||
return ints;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package cn.com.yhinfo.real.common.util;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* 获取连接
|
||||
*
|
||||
* @author <a href="https://qaiu.top">QAIU</a>
|
||||
*/
|
||||
public enum ConnectUtil {
|
||||
|
||||
// 实现枚举单例
|
||||
INSTANCE;
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ConnectUtil.class);
|
||||
|
||||
|
||||
}
|
||||
10
web/src/main/java/cn/com/yhinfo/real/package-info.java
Normal file
10
web/src/main/java/cn/com/yhinfo/real/package-info.java
Normal file
@@ -0,0 +1,10 @@
|
||||
/**
|
||||
* sinoreal2-web
|
||||
* <br>Create date 2021/7/8 13:29
|
||||
*
|
||||
* @author <a href="https://qaiu.top">QAIU</a>
|
||||
*/
|
||||
@ModuleGen(name = "proxy", groupPackage = "cn.com.yhinfo.real", useFutures = true)
|
||||
package cn.com.yhinfo.real;
|
||||
|
||||
import io.vertx.codegen.annotations.ModuleGen;
|
||||
76
web/src/main/java/cn/com/yhinfo/real/web/http/ServerApi.java
Normal file
76
web/src/main/java/cn/com/yhinfo/real/web/http/ServerApi.java
Normal file
@@ -0,0 +1,76 @@
|
||||
package cn.com.yhinfo.real.web.http;
|
||||
|
||||
import cn.com.yhinfo.core.annotaions.RouteHandler;
|
||||
import cn.com.yhinfo.core.annotaions.RouteMapping;
|
||||
import cn.com.yhinfo.core.annotaions.SockRouteMapper;
|
||||
import cn.com.yhinfo.core.enums.RouteMethod;
|
||||
import cn.com.yhinfo.core.model.JsonResult;
|
||||
import cn.com.yhinfo.core.util.AsyncServiceUtil;
|
||||
import cn.com.yhinfo.core.util.SnowflakeIdWorker;
|
||||
import cn.com.yhinfo.core.util.VertxHolder;
|
||||
import cn.com.yhinfo.real.web.model.RealUser;
|
||||
import cn.com.yhinfo.real.web.service.UserService;
|
||||
import io.vertx.core.Future;
|
||||
import io.vertx.ext.web.handler.sockjs.SockJSSocket;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* 连接服务API
|
||||
* <br>Create date 2021/4/28 9:15
|
||||
*
|
||||
* @author <a href="https://qaiu.top">QAIU</a>
|
||||
*/
|
||||
@Slf4j
|
||||
@RouteHandler("serverApi")
|
||||
public class ServerApi {
|
||||
|
||||
private final UserService userService = AsyncServiceUtil.getAsyncServiceInstance(UserService.class);
|
||||
|
||||
@RouteMapping(value = "/login", method = RouteMethod.POST)
|
||||
public Future<String> login(RealUser user) {
|
||||
log.info("<------- login: {}", user.getUsername());
|
||||
return userService.login(user);
|
||||
}
|
||||
|
||||
long sid = 0;
|
||||
|
||||
@SockRouteMapper(value = "/test")
|
||||
public void test02(SockJSSocket sock) {
|
||||
String s = sock.writeHandlerID();
|
||||
System.out.println("客户端连接 --> " + s);
|
||||
sock.handler(sock::write);
|
||||
sock.endHandler(v -> System.out.println("客户端断开"));
|
||||
String id = sock.writeHandlerID();
|
||||
System.out.println("客户端连接 --> " + id);
|
||||
// sock.handler(sock::write);
|
||||
sock.handler(buffer -> {
|
||||
sock.write("服务端开始处理------->");
|
||||
final String msg = buffer.toString();
|
||||
if ("1".equals(msg)) {
|
||||
sid = VertxHolder.getVertxInstance().setPeriodic(1000, v ->
|
||||
sock.write(v + "-->" + SnowflakeIdWorker.idWorker().nextId()));
|
||||
} else {
|
||||
if (sid != 0) {
|
||||
if (VertxHolder.getVertxInstance().cancelTimer(sid)) {
|
||||
sock.write(sid + " -----> 定时推送取消");
|
||||
}
|
||||
} else {
|
||||
|
||||
sock.write(msg + "----- ok");
|
||||
}
|
||||
}
|
||||
});
|
||||
sock.endHandler(v -> {
|
||||
System.out.println("客户端断开");
|
||||
if (VertxHolder.getVertxInstance().cancelTimer(sid)) {
|
||||
sock.write(sid + " -----> 定时推送取消");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@RouteMapping(value = "/test2", method = RouteMethod.GET)
|
||||
public JsonResult<String> test01() {
|
||||
return JsonResult.data("ok");
|
||||
}
|
||||
|
||||
}
|
||||
22
web/src/main/java/cn/com/yhinfo/real/web/model/RealUser.java
Normal file
22
web/src/main/java/cn/com/yhinfo/real/web/model/RealUser.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package cn.com.yhinfo.real.web.model;
|
||||
|
||||
import cn.com.yhinfo.real.common.ToJson;
|
||||
import io.vertx.codegen.annotations.DataObject;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@DataObject
|
||||
public class RealUser implements ToJson {
|
||||
private String username;
|
||||
private String password;
|
||||
|
||||
public RealUser(JsonObject json) {
|
||||
this.username = json.getString("username");
|
||||
this.password = json.getString("password");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package cn.com.yhinfo.real.web.service;
|
||||
|
||||
import cn.com.yhinfo.core.base.BaseAsyncService;
|
||||
import cn.com.yhinfo.real.common.model.UserInfo;
|
||||
import io.vertx.codegen.annotations.ProxyGen;
|
||||
import io.vertx.core.Future;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
|
||||
/**
|
||||
* sinoreal2-web
|
||||
* <br>Create date 2021/7/12 17:16
|
||||
*
|
||||
* @author <a href="https://qaiu.top">QAIU</a>
|
||||
*/
|
||||
@ProxyGen
|
||||
public interface DbService extends BaseAsyncService {
|
||||
Future<JsonObject> sayOk(String data);
|
||||
Future<JsonObject> sayOk2(String data, UserInfo holder);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package cn.com.yhinfo.real.web.service;
|
||||
|
||||
import cn.com.yhinfo.core.util.CastUtil;
|
||||
|
||||
import java.lang.reflect.Proxy;
|
||||
|
||||
/**
|
||||
* JDK代理类工厂
|
||||
*/
|
||||
public class JdkProxyFactory {
|
||||
public static <T> T getProxy(T target) {
|
||||
return CastUtil.cast(Proxy.newProxyInstance(
|
||||
target.getClass().getClassLoader(),
|
||||
target.getClass().getInterfaces(),
|
||||
new ServiceJdkProxy<>(target))
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package cn.com.yhinfo.real.web.service;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* sinoreal2-web
|
||||
* <br>Create date 2021/8/25 14:28
|
||||
*
|
||||
* @author <a href="https://qaiu.top">QAIU</a>
|
||||
*/
|
||||
@Slf4j
|
||||
public class ServiceJdkProxy<T> implements InvocationHandler {
|
||||
|
||||
private final T target;
|
||||
|
||||
public ServiceJdkProxy(T target) {
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object invoke(Object proxy, Method method, Object[] args) throws InvocationTargetException, IllegalAccessException {
|
||||
return method.invoke(target, args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package cn.com.yhinfo.real.web.service;
|
||||
|
||||
import cn.com.yhinfo.core.base.BaseAsyncService;
|
||||
import cn.com.yhinfo.real.web.model.RealUser;
|
||||
import io.vertx.codegen.annotations.ProxyGen;
|
||||
import io.vertx.core.Future;
|
||||
|
||||
/**
|
||||
* sinoreal2-web
|
||||
* <br>Create date 2021/8/27 14:06
|
||||
*
|
||||
* @author <a href="https://qaiu.top">QAIU</a>
|
||||
*/
|
||||
@ProxyGen
|
||||
public interface UserService extends BaseAsyncService {
|
||||
Future<String> login(RealUser user);
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package cn.com.yhinfo.real.web.service.impl;
|
||||
|
||||
import cn.com.yhinfo.core.annotaions.Service;
|
||||
import cn.com.yhinfo.core.model.JsonResult;
|
||||
import cn.com.yhinfo.real.common.model.UserInfo;
|
||||
import cn.com.yhinfo.real.web.service.DbService;
|
||||
import io.vertx.core.Future;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* sinoreal2-web
|
||||
* <br>Create date 2021/7/12 17:26
|
||||
*
|
||||
* @author <a href="https://qaiu.top">QAIU</a>
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class DbServiceImpl implements DbService {
|
||||
@Override
|
||||
public Future<JsonObject> sayOk(String data) {
|
||||
log.info("say ok1 -> wait...");
|
||||
try {
|
||||
Thread.sleep(4000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return Future.succeededFuture(JsonObject.mapFrom(JsonResult.data("Hi: " + data)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Future<JsonObject> sayOk2(String data, UserInfo holder) {
|
||||
// val context = VertxHolder.getVertxInstance().getOrCreateContext();
|
||||
// log.info("say ok2 -> " + context.get("username"));
|
||||
// log.info("--> {}", holder.toString());
|
||||
return Future.succeededFuture(JsonObject.mapFrom(JsonResult.data("Hi: " + data)));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package cn.com.yhinfo.real.web.service.impl;
|
||||
|
||||
import cn.com.yhinfo.core.annotaions.Service;
|
||||
import cn.com.yhinfo.real.web.model.RealUser;
|
||||
import cn.com.yhinfo.real.web.service.UserService;
|
||||
import io.vertx.core.Future;
|
||||
|
||||
/**
|
||||
* sinoreal2-web
|
||||
* <br>Create date 2021/8/27 14:09
|
||||
*
|
||||
* @author <a href="https://qaiu.top">QAIU</a>
|
||||
*/
|
||||
@Service
|
||||
public class UserServiceImpl implements UserService {
|
||||
|
||||
@Override
|
||||
public Future<String> login(RealUser user) {
|
||||
|
||||
return Future.succeededFuture("111");
|
||||
}
|
||||
}
|
||||
163
web/src/main/resources/1.http
Normal file
163
web/src/main/resources/1.http
Normal file
@@ -0,0 +1,163 @@
|
||||
|
||||
###
|
||||
POST http://127.0.0.1:8088/real/serverApi/login
|
||||
Content-Type: application/x-www-form-urlencoded
|
||||
|
||||
username=sa&password=sinoreal
|
||||
|
||||
###
|
||||
POST http://47.114.185.111:8088/real/serverApi/login
|
||||
Content-Type: application/x-www-form-urlencoded
|
||||
|
||||
username=sa&password=sinoreal
|
||||
|
||||
###
|
||||
|
||||
GET http://127.0.0.1:8088/real/basePointApi/getTables
|
||||
token: cab5bcd2fc250f27c3984205fbffc46e
|
||||
Content-Type: application/json
|
||||
|
||||
###
|
||||
|
||||
GET http://127.0.0.1:8088/real/basePointApi/getTags?tablemask=JTdevice
|
||||
token: 7670b1a3da5e22ffc42a1e738ea4f0f6
|
||||
|
||||
###
|
||||
GET http://127.0.0.1:8088/real/basePointApi/getSnapshotDataByTag/adasd?aaa=3
|
||||
token: 7670b1a3da5e22ffc42a1e738ea4f0f6
|
||||
|
||||
###
|
||||
|
||||
POST http://127.0.0.1:8088/real/serverApi/login
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"username": "sa",
|
||||
"password": "sinoreal"
|
||||
}
|
||||
|
||||
###
|
||||
|
||||
POST http://127.0.0.1:8088/real/basePointApi/updateTag
|
||||
token: cab5bcd2fc250f27c3984205fbffc46e
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"userints": [123223,35356],
|
||||
"id": 123,
|
||||
"equation": "asd",
|
||||
"trigger": "RTDB_EVENT_TRIGGER",
|
||||
"shutdown": true
|
||||
}
|
||||
|
||||
|
||||
|
||||
###
|
||||
|
||||
GET http://127.0.0.1:8088/real/basePointApi/getTagById/753
|
||||
token: eb7d391ad89d4bb4a81897af8829f0e8
|
||||
|
||||
###
|
||||
|
||||
GET http://127.0.0.1:8088/real/basePointApi/aaaa
|
||||
token: cab5bcd2fc250f27c3984205fbffc46e
|
||||
|
||||
###
|
||||
|
||||
GET http://127.0.0.1:8088/real/serverApi/test
|
||||
|
||||
###
|
||||
|
||||
POST http://127.0.0.1:8088/real/serverApi/addUser
|
||||
Content-Type: application/x-www-form-urlencoded
|
||||
token: 2b4769b63c90adb6490cfe6e449da90b
|
||||
|
||||
username=sa1&password=sinoreal&permission=3
|
||||
|
||||
|
||||
###
|
||||
POST http://127.0.0.1:8088/real/serverApi/removeUser
|
||||
Content-Type: application/x-www-form-urlencoded
|
||||
token: 2b4769b63c90adb6490cfe6e449da90b
|
||||
|
||||
username=sa1
|
||||
|
||||
|
||||
###
|
||||
|
||||
POST http://127.0.0.1:8088/real/serverApi/updatePassword
|
||||
Content-Type: application/x-www-form-urlencoded
|
||||
token: 33c21f7cf053b90a713f1f9e124d0335
|
||||
|
||||
oldPassword=sinoreal1&newPassword=sinoreal
|
||||
|
||||
|
||||
###
|
||||
|
||||
POST http://127.0.0.1:8088/real/serverApi/changePriv
|
||||
Content-Type: application/x-www-form-urlencoded
|
||||
token: 2b4769b63c90adb6490cfe6e449da90b
|
||||
|
||||
username=sa1&permission=3
|
||||
|
||||
|
||||
###
|
||||
POST http://127.0.0.1:8088/real/serverApi/addAuthorization
|
||||
Content-Type: application/x-www-form-urlencoded
|
||||
token: 2b4769b63c90adb6490cfe6e449da90b
|
||||
|
||||
addr=192.168.1.56&mask=255.255.255.255&permission=3&description=测试信任666111
|
||||
|
||||
|
||||
###
|
||||
POST http://127.0.0.1:8088/real/serverApi/removeAuthorization
|
||||
Content-Type: application/x-www-form-urlencoded
|
||||
token: 2b4769b63c90adb6490cfe6e449da90b
|
||||
|
||||
addr=192.168.1.56&mask=255.255.255.255
|
||||
|
||||
|
||||
###
|
||||
POST http://127.0.0.1:8088/real/historyApi/getHistory
|
||||
Content-Type: application/x-www-form-urlencoded
|
||||
token: 2b4769b63c90adb6490cfe6e449da90b
|
||||
|
||||
startDate=2021-05-17 11:03&endDate=2021-05-17 11:04&interval=3
|
||||
|
||||
###
|
||||
POST http://127.0.0.1:8088/real/historyApi/getHistory
|
||||
Content-Type: application/x-www-form-urlencoded
|
||||
token: 2b4769b63c90adb6490cfe6e449da90b
|
||||
|
||||
startDate=2021-05-17 11:03
|
||||
|
||||
###
|
||||
GET http://127.0.0.1:8088/real/dict/getDictByName?name=dict2
|
||||
token: 7670b1a3da5e22ffc42a1e738ea4f0f6
|
||||
|
||||
###
|
||||
tagmask=*&desc=*&_PointType=Every&_ValueTypeString=*&_TimeAccuracy=-1&_SearchCondition=SEARCH_NULL&SearchMaskValue=*&source=*&instrument=*&
|
||||
|
||||
###
|
||||
http://127.0.0.1:8088/real/basePointApi/getTags?tablemask=demo02&tagmask=*&desc=*&_PointType=Every&_ValueTypeString=*&_TimeAccuracy=-1&_SearchCondition=SEARCH_NULL&SearchMaskValue=*&source=*&instrument=*&pageNumber=1&pageSize=10
|
||||
token: eb7d391ad89d4bb4a81897af8829f0e8
|
||||
|
||||
###
|
||||
http://127.0.0.1:8088/real/serverApi/getFile?path=D:
|
||||
token: 7670b1a3da5e22ffc42a1e738ea4f0f6
|
||||
|
||||
###
|
||||
#http://127.0.0.1:8088/real/serverApi/hello1/:msg
|
||||
http://127.0.0.1:8088/real/serverApi/hello1/ok1
|
||||
token: a3cada4c97be40d3bc35cfe6ec1288ab
|
||||
|
||||
###
|
||||
http://127.0.0.1:8088/real/serverApi/hello2/ok2
|
||||
token: a3cada4c97be40d3bc35cfe6ec1288ab
|
||||
|
||||
|
||||
|
||||
|
||||
###
|
||||
http://127.0.0.1:8085/real/basePointApi/getTags?tablemask=demo02&tagmask=*&desc=*&unit=*&pointType=Every&valueTypeString=*&timeAccuracy=-1&searchCondition=SEARCH_NULL&SearchMaskValue=*&source=*&instrument=*&pageNumber=1&pageSize=10&accurateSearch=
|
||||
token: c423c04a55964571bd34aaa1683229e8
|
||||
47
web/src/main/resources/2.http
Normal file
47
web/src/main/resources/2.http
Normal file
@@ -0,0 +1,47 @@
|
||||
###
|
||||
http://127.0.0.1:8088/real/test
|
||||
|
||||
###
|
||||
POST http://127.0.0.1:8088/real/serverApi/login
|
||||
Content-Type: application/x-www-form-urlencoded
|
||||
|
||||
username=sa&password=sinoreal
|
||||
###
|
||||
POST http://47.114.185.111:8070/real/serverApi/login
|
||||
Content-Type: application/x-www-form-urlencoded
|
||||
|
||||
username=sa&password=sinoreal
|
||||
|
||||
###
|
||||
http://127.0.0.1:8088/real/serverApi/hello2/ok2
|
||||
token: 11f1a7ad9dd907bf1fa6a9e79277d053
|
||||
|
||||
|
||||
|
||||
###
|
||||
http://127.0.0.1:8088/real/test2
|
||||
|
||||
|
||||
###
|
||||
POST http://127.0.0.1:8088/real/serverApi/getConnections
|
||||
token: 370ba165d3164049b7704e8b3d595930
|
||||
|
||||
###
|
||||
POST http://127.0.0.1:8085/real/serverApi/getConnectionInfo
|
||||
token: 21f99c6080074ae79cda2e988ab2bdb8
|
||||
|
||||
###
|
||||
http://127.0.0.1:7070/demo/foo
|
||||
|
||||
###
|
||||
http://127.0.0.1:8085/api/foo
|
||||
|
||||
|
||||
###
|
||||
http://127.0.0.1:8085/real/serverApi/thread-test
|
||||
token: c1b89b3193bd4498be77b6e782e0df38
|
||||
|
||||
|
||||
###
|
||||
http://127.0.0.1:8085/
|
||||
Accept: application/json
|
||||
33
web/src/main/resources/app-dev.yml
Normal file
33
web/src/main/resources/app-dev.yml
Normal file
@@ -0,0 +1,33 @@
|
||||
# 服务配置
|
||||
server:
|
||||
port: 6400
|
||||
contextPath: /api
|
||||
enableStaticHtmlService: false
|
||||
staticResourcePath: webroot/
|
||||
# 反向代理服务器配置路径(不用加后缀)
|
||||
proxyConf: server-proxy
|
||||
|
||||
vertx:
|
||||
eventLoopPoolSize: 8
|
||||
workerPoolSize: 20
|
||||
custom:
|
||||
asyncServiceInstances: 8
|
||||
routerLocations: cn.com.yhinfo.real.web.http
|
||||
interceptorClassPath: cn.com.yhinfo.real.common.interceptorImpl.DefaultInterceptor
|
||||
handlerLocations: cn.com.yhinfo.real.web.service
|
||||
ignoresReg:
|
||||
- .*/login$
|
||||
- .*/test.*$
|
||||
entityPackagesReg:
|
||||
- ^cn\.com\.yhinfo\.real\.web\.model\..*
|
||||
- ^sinereal\.core\..*
|
||||
otherConfig:
|
||||
- dictionaries.json
|
||||
errorPage404: /index.html
|
||||
indexPage: /test2
|
||||
sharedLogin: true
|
||||
lzConfig:
|
||||
config: '111'
|
||||
|
||||
cowConfig:
|
||||
config: '111'
|
||||
7
web/src/main/resources/app.yml
Normal file
7
web/src/main/resources/app.yml
Normal file
@@ -0,0 +1,7 @@
|
||||
# 要激活的配置: dev--连接本地数据库; prod连接线上数据库
|
||||
active: dev
|
||||
# 框架版本号 和主版本号
|
||||
version_vertx: 4.1.3
|
||||
version_app: 0.0.1
|
||||
# 公司名称 -> LOGO版权文字
|
||||
copyright: QAIU
|
||||
3
web/src/main/resources/conf/dictionaries.json
Normal file
3
web/src/main/resources/conf/dictionaries.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
|
||||
}
|
||||
3
web/src/main/resources/curl/curl.sh
Normal file
3
web/src/main/resources/curl/curl.sh
Normal file
@@ -0,0 +1,3 @@
|
||||
curl -F "file=@C:\Users\qaiu\Desktop\real\sinoreal2-web\web\src\main\resources\logback.xml" -i -XPOST 127.0.0.1:8088/demo/basePointApi/importTags
|
||||
|
||||
curl -F "file=@C:\Users\qaiu\Desktop\3.csv" -i -XPOST 127.0.0.1:8088/demo/basePointApi/importTags
|
||||
30
web/src/main/resources/server-proxy.yml
Normal file
30
web/src/main/resources/server-proxy.yml
Normal file
@@ -0,0 +1,30 @@
|
||||
# 反向代理
|
||||
server-name: Vert.x-proxy-server(v4.1.2)
|
||||
|
||||
proxy:
|
||||
- listen: 8085
|
||||
# 404的路径
|
||||
404: webroot/real-html/index.html
|
||||
static:
|
||||
path: /
|
||||
# add-headers:
|
||||
# x-token: ABC
|
||||
root: webroot/real-html/
|
||||
index: realIndex
|
||||
location:
|
||||
- path: /real/
|
||||
origin: 127.0.0.1:8088
|
||||
- path: /api/
|
||||
origin: 127.0.0.1:7070/demo/
|
||||
|
||||
- listen: 8086
|
||||
static:
|
||||
path: /t2/
|
||||
root: webroot/test/
|
||||
index: sockTest.html
|
||||
# location:
|
||||
# - path: /real/
|
||||
# origin: 127.0.0.1:8088
|
||||
# sock:
|
||||
# - path: /real/
|
||||
# origin: 127.0.0.1:8088
|
||||
42
web/src/test/java/cn/com/yhinfo/test/StompTest.java
Normal file
42
web/src/test/java/cn/com/yhinfo/test/StompTest.java
Normal file
@@ -0,0 +1,42 @@
|
||||
package cn.com.yhinfo.test;
|
||||
|
||||
import io.vertx.core.Future;
|
||||
import io.vertx.core.Vertx;
|
||||
import io.vertx.core.http.HttpServer;
|
||||
import io.vertx.core.http.HttpServerOptions;
|
||||
import io.vertx.ext.stomp.StompServer;
|
||||
import io.vertx.ext.stomp.StompServerHandler;
|
||||
import io.vertx.ext.stomp.StompServerOptions;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* sinoreal2-web
|
||||
* <p>create 2021/9/18 12:10</p>
|
||||
*
|
||||
* @author <a href="https://qaiu.top">QAIU</a>
|
||||
*/
|
||||
public class StompTest {
|
||||
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
Vertx vertx = Vertx.vertx();
|
||||
|
||||
StompServer stompServer = StompServer.create(vertx, new StompServerOptions()
|
||||
.setPort(-1) // 禁用 tcp 端口,这一项是可选的
|
||||
.setWebsocketBridge(true) // 开启 websocket 支持
|
||||
.setWebsocketPath("/stomp")) // 配置 websocket 路径,默认是 /stomp
|
||||
.handler(StompServerHandler.create(vertx));
|
||||
Future<HttpServer> http = vertx.createHttpServer(
|
||||
new HttpServerOptions().setWebSocketSubProtocols(Arrays.asList("v10.stomp", "v11.stomp"))
|
||||
)
|
||||
.webSocketHandler(stompServer.webSocketHandler())
|
||||
.listen(8080);
|
||||
http.onSuccess(res->{
|
||||
System.out.println("okk");
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
223
web/src/test/java/cn/com/yhinfo/test/Test01.java
Normal file
223
web/src/test/java/cn/com/yhinfo/test/Test01.java
Normal file
@@ -0,0 +1,223 @@
|
||||
package cn.com.yhinfo.test;
|
||||
|
||||
import io.vertx.ext.web.RoutingContext;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.beanutils.BeanUtils;
|
||||
import org.apache.commons.beanutils.ConvertUtils;
|
||||
import org.apache.commons.beanutils.Converter;
|
||||
import org.apache.commons.lang3.time.DateFormatUtils;
|
||||
import org.apache.commons.lang3.time.DateUtils;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.text.ParseException;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <br>Create date 2021/4/29 15:27
|
||||
*
|
||||
* @author <a href="https://qaiu.top">QAIU</a>
|
||||
*/
|
||||
@Slf4j
|
||||
public class Test01 {
|
||||
|
||||
public static class A {
|
||||
String name;
|
||||
String num;
|
||||
String num2;
|
||||
String num3;
|
||||
|
||||
Integer num5;
|
||||
|
||||
public Integer getNum5() {
|
||||
return num5;
|
||||
}
|
||||
|
||||
public void setNum5(Integer num5) {
|
||||
this.num5 = num5;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getNum() {
|
||||
return num;
|
||||
}
|
||||
|
||||
public void setNum(String num) {
|
||||
this.num = num;
|
||||
}
|
||||
|
||||
public String getNum2() {
|
||||
return num2;
|
||||
}
|
||||
|
||||
public void setNum2(String num2) {
|
||||
this.num2 = num2;
|
||||
}
|
||||
|
||||
public String getNum3() {
|
||||
return num3;
|
||||
}
|
||||
|
||||
public void setNum3(String num3) {
|
||||
this.num3 = num3;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class B0 {
|
||||
int num;
|
||||
|
||||
public int getNum() {
|
||||
return num;
|
||||
}
|
||||
|
||||
public void setNum(int num) {
|
||||
this.num = num;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class B extends B0 {
|
||||
String name;
|
||||
|
||||
boolean flag;
|
||||
int num4;
|
||||
Date date;
|
||||
String dateStr;
|
||||
|
||||
Integer num5;
|
||||
|
||||
public Boolean getFlag() {
|
||||
return flag;
|
||||
}
|
||||
|
||||
public void setFlag(Boolean flag) {
|
||||
this.flag = flag;
|
||||
}
|
||||
|
||||
public Integer getNum5() {
|
||||
return num5;
|
||||
}
|
||||
|
||||
public void setNum5(Integer num5) {
|
||||
this.num5 = num5;
|
||||
}
|
||||
|
||||
public Date getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
public void setDate(Date date) {
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
public String getDateStr() {
|
||||
return dateStr;
|
||||
}
|
||||
|
||||
public void setDateStr(String dateStr) {
|
||||
this.dateStr = dateStr;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getNum4() {
|
||||
return num4;
|
||||
}
|
||||
|
||||
public void setNum4(int num4) {
|
||||
this.num4 = num4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "B{" +
|
||||
"num=" + num +
|
||||
", name='" + name + '\'' +
|
||||
", flag=" + flag +
|
||||
", num4=" + num4 +
|
||||
", date=" + date +
|
||||
", dateStr='" + dateStr + '\'' +
|
||||
", num5=" + num5 +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static <T> T getParamsToBean(RoutingContext ctx, Class<T> tClass) {
|
||||
// ObjectUtils.identityToString()
|
||||
return null;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test01() throws InvocationTargetException, IllegalAccessException, NoSuchMethodException {
|
||||
|
||||
A a = new A();
|
||||
a.setName("asd");
|
||||
a.setNum("123");
|
||||
a.setNum2("123");
|
||||
a.setNum3("123");
|
||||
a.setNum5(9999);
|
||||
B b = new B();
|
||||
BeanUtils.copyProperties(b, a);
|
||||
System.out.println(b);
|
||||
a.setNum5(233);
|
||||
System.out.println(b);
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("name", "小米");
|
||||
map.put("flag", "1");
|
||||
map.put("num", "553454344");
|
||||
map.put("num2", "123");
|
||||
map.put("num4", "q");
|
||||
map.put("dateStr", new Date());
|
||||
map.put("date", "2021-01-01");
|
||||
B b1 = new B();
|
||||
|
||||
ConvertUtils.register(
|
||||
new Converter() {
|
||||
@Override
|
||||
public <T> T convert(Class<T> clazz, Object value) {
|
||||
//字符串转换为日期
|
||||
try {
|
||||
return (T) DateUtils.parseDate(value.toString(), "yyyy-MM-dd");
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}, Date.class);
|
||||
|
||||
|
||||
ConvertUtils.register(
|
||||
new Converter() {
|
||||
@Override
|
||||
public <T> T convert(Class<T> clazz, Object value) {
|
||||
//日期->字符串
|
||||
try {
|
||||
return (T) DateFormatUtils.format((Date) value, "yyyy-MM-dd");
|
||||
} catch (Exception e) {
|
||||
return (T) value;
|
||||
}
|
||||
}
|
||||
}, String.class);
|
||||
|
||||
BeanUtils.populate(b1, map);
|
||||
log.info("---------> {}", b1);
|
||||
}
|
||||
|
||||
}
|
||||
85
web/src/test/java/cn/com/yhinfo/test/Test02.java
Normal file
85
web/src/test/java/cn/com/yhinfo/test/Test02.java
Normal file
@@ -0,0 +1,85 @@
|
||||
package cn.com.yhinfo.test;
|
||||
|
||||
import javassist.ClassPool;
|
||||
import javassist.CtClass;
|
||||
import javassist.CtMethod;
|
||||
import javassist.NotFoundException;
|
||||
import javassist.bytecode.CodeAttribute;
|
||||
import javassist.bytecode.ExceptionsAttribute;
|
||||
import javassist.bytecode.LocalVariableAttribute;
|
||||
import javassist.bytecode.MethodInfo;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class Test02 {
|
||||
|
||||
|
||||
public String[] getParameterName(Class<?> className, String method) {
|
||||
String[] paramNames = null;
|
||||
try {
|
||||
ClassPool pool = ClassPool.getDefault();
|
||||
CtClass ctClass = pool.get(className.getName());
|
||||
CtMethod cm = ctClass.getDeclaredMethod(method);
|
||||
MethodInfo methodInfo = cm.getMethodInfo();
|
||||
CtClass[] parameterTypes = cm.getParameterTypes();
|
||||
|
||||
for (CtClass parameterType : parameterTypes) {
|
||||
System.out.println(parameterType.getDeclaringClass());
|
||||
System.out.println(parameterType.getName() + "----" + parameterType.getSimpleName());
|
||||
}
|
||||
CodeAttribute codeAttribute = methodInfo.getCodeAttribute();
|
||||
LocalVariableAttribute attr = (LocalVariableAttribute) codeAttribute
|
||||
.getAttribute(LocalVariableAttribute.tag);
|
||||
paramNames = new String[cm.getParameterTypes().length];
|
||||
CtClass[] exceptionTypes = cm.getExceptionTypes();
|
||||
ExceptionsAttribute exceptionsAttribute = methodInfo.getExceptionsAttribute();
|
||||
|
||||
for (int j = 0; j < paramNames.length; j++) {
|
||||
String s = attr.variableName(attr.tableLength() - paramNames.length + j);
|
||||
paramNames[j] = s;
|
||||
}
|
||||
|
||||
} catch (NotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return paramNames;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test01() throws NoSuchMethodException {
|
||||
|
||||
//
|
||||
// Method[] methods = RealUser.class.getMethods();
|
||||
// for (Method m : methods) {
|
||||
// if (m.getName().equals("setUsername2")) {
|
||||
// Class<?>[] parameterTypes = m.getParameterTypes();
|
||||
// for (Class<?> type : parameterTypes) {
|
||||
// System.out.println(type + "--"+type.getName());
|
||||
// System.out.println(type.isPrimitive());
|
||||
// System.out.println("------------");
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test2() {
|
||||
System.out.println(("java.lang.Double".matches("^java\\.lang\\.((Integer)|(Double))$")));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void test3() {
|
||||
Map map = new LinkedHashMap();
|
||||
map.put("1", "1");
|
||||
map.put("2", "11");
|
||||
map.put("3", "111");
|
||||
|
||||
System.out.println(map);
|
||||
map.put("1", "12");
|
||||
System.out.println(map);
|
||||
|
||||
}
|
||||
}
|
||||
161
web/src/test/java/cn/com/yhinfo/test/TestOS.java
Normal file
161
web/src/test/java/cn/com/yhinfo/test/TestOS.java
Normal file
@@ -0,0 +1,161 @@
|
||||
package cn.com.yhinfo.test;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.InetAddress;
|
||||
import java.net.NetworkInterface;
|
||||
import java.net.URL;
|
||||
import java.util.*;
|
||||
|
||||
public class TestOS {
|
||||
//通过截取cmd流方式得到计算机的配置信息(不好)
|
||||
public static List<String> getIpAddress() {
|
||||
Process p = null;
|
||||
List<String> address = new ArrayList<String>();
|
||||
try {
|
||||
p = new ProcessBuilder("ipconfig", "/all").start();
|
||||
} catch (Exception e) {
|
||||
return address;
|
||||
}
|
||||
StringBuffer sb = new StringBuffer();
|
||||
//读取进程输出值
|
||||
InputStream inputStream = p.getInputStream();
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
|
||||
String s = "";
|
||||
try {
|
||||
while ((s = br.readLine()) != null) {
|
||||
sb.append(s + "\n");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
inputStream.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
System.out.println(sb);
|
||||
return address;
|
||||
}
|
||||
|
||||
public static void getIpconfig() {
|
||||
Map<String, String> map = System.getenv();
|
||||
System.out.println(map.get("USERNAME"));//获取username
|
||||
System.out.println(map.get("COMPUTERNAME"));//获取计算机名
|
||||
System.out.println(map.get("USERDOMAIN"));//获取计算机域名
|
||||
}
|
||||
|
||||
//得到计算机的ip地址和mac地址
|
||||
public static void getConfig() {
|
||||
try {
|
||||
InetAddress address = InetAddress.getLocalHost();
|
||||
NetworkInterface ni = NetworkInterface.getByInetAddress(address);
|
||||
//ni.getInetAddresses().nextElement().getAddress();
|
||||
byte[] mac = ni.getHardwareAddress();
|
||||
String sIP = address.getHostAddress();
|
||||
String sMAC = "";
|
||||
Formatter formatter = new Formatter();
|
||||
for (int i = 0; i < mac.length; i++) {
|
||||
sMAC = formatter.format(Locale.getDefault(), "%02X%s", mac[i],
|
||||
(i < mac.length - 1) ?
|
||||
"-" : "").toString();
|
||||
}
|
||||
System.out.println("IP:" + sIP);
|
||||
System.out.println("MAC:" + sMAC);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
//得到计算机的ip,名称,操作系统名称,操作系统版本号
|
||||
public static void Config() {
|
||||
try {
|
||||
InetAddress addr = InetAddress.getLocalHost();
|
||||
String ip = addr.getHostAddress().toString(); //获取本机ip
|
||||
String hostName = addr.getHostName().toString(); //获取本机计算机名称
|
||||
System.out.println("本机IP:" + ip + "\n本机名称:" + hostName);
|
||||
Properties props = System.getProperties();
|
||||
System.out.println("操作系统的名称:" + props.getProperty("os.name"));
|
||||
System.out.println("操作系统的版本号:" + props.getProperty("os.version"));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
//其他的一些东西,会实用到的时候的
|
||||
public static void all() {
|
||||
Properties props = System.getProperties();
|
||||
System.out.println("Java的执行环境版本号:" + props.getProperty("java.version"));
|
||||
System.out.println("Java的执行环境供应商:" + props.getProperty("java.vendor"));
|
||||
System.out.println("Java供应商的URL:" + props.getProperty("java.vendor.url"));
|
||||
System.out.println("Java的安装路径:" + props.getProperty("java.home"));
|
||||
System.out.println("Java的虚拟机规范版本号:" + props.getProperty("java.vm.specification.version"));
|
||||
System.out.println("Java的虚拟机规范供应商:" + props.getProperty("java.vm.specification.vendor"));
|
||||
System.out.println("Java的虚拟机规范名称:" + props.getProperty("java.vm.specification.name"));
|
||||
System.out.println("Java的虚拟机实现版本号:" + props.getProperty("java.vm.version"));
|
||||
System.out.println("Java的虚拟机实现供应商:" + props.getProperty("java.vm.vendor"));
|
||||
System.out.println("Java的虚拟机实现名称:" + props.getProperty("java.vm.name"));
|
||||
System.out.println("Java执行时环境规范版本号:" + props.getProperty("java.specification.version"));
|
||||
System.out.println("Java执行时环境规范供应商:" + props.getProperty("java.specification.vender"));
|
||||
System.out.println("Java执行时环境规范名称:" + props.getProperty("java.specification.name"));
|
||||
System.out.println("Java的类格式版本号号:" + props.getProperty("java.class.version"));
|
||||
System.out.println("Java的类路径:" + props.getProperty("java.class.path"));
|
||||
System.out.println("载入库时搜索的路径列表:" + props.getProperty("java.library.path"));
|
||||
System.out.println("默认的暂时文件路径:" + props.getProperty("java.io.tmpdir"));
|
||||
System.out.println("一个或多个扩展文件夹的路径:" + props.getProperty("java.ext.dirs"));
|
||||
System.out.println("操作系统的名称:" + props.getProperty("os.name"));
|
||||
System.out.println("操作系统的构架:" + props.getProperty("os.arch"));
|
||||
System.out.println("操作系统的版本号:" + props.getProperty("os.version"));
|
||||
System.out.println("文件分隔符:" + props.getProperty("file.separator"));
|
||||
//在 unix 系统中是"/"
|
||||
System.out.println("路径分隔符:" + props.getProperty("path.separator"));
|
||||
//在 unix 系统中是":"
|
||||
System.out.println("行分隔符:" + props.getProperty("line.separator"));
|
||||
//在 unix 系统中是"/n"
|
||||
System.out.println("用户的账户名称:" + props.getProperty("user.name"));
|
||||
System.out.println("用户的主文件夹:" + props.getProperty("user.home"));
|
||||
System.out.println("用户的当前工作文件夹:" + props.getProperty("user.dir"));
|
||||
}
|
||||
|
||||
|
||||
public void showURL() throws IOException {
|
||||
|
||||
// 第一种:获取类加载的根路径 D:\git\daotie\daotie\target\classes
|
||||
File f = new File(this.getClass().getResource("/").getPath());
|
||||
System.out.println(f);
|
||||
|
||||
// 获取当前类的所在工程路径; 如果不加“/” 获取当前类的加载目录 D:\git\daotie\daotie\target\classes\my
|
||||
File f2 = new File(this.getClass().getResource("").getPath());
|
||||
System.out.println(f2);
|
||||
|
||||
// 第二种:获取项目路径 D:\git\daotie\daotie
|
||||
File directory = new File("");// 参数为空
|
||||
String courseFile = directory.getCanonicalPath();
|
||||
System.out.println(courseFile);
|
||||
|
||||
|
||||
// 第三种: file:/D:/git/daotie/daotie/target/classes/
|
||||
URL xmlpath = this.getClass().getClassLoader().getResource("");
|
||||
System.out.println(xmlpath);
|
||||
|
||||
|
||||
// 第四种: D:\git\daotie\daotie
|
||||
System.out.println(System.getProperty("user.dir"));
|
||||
/*
|
||||
* 结果: C:\Documents and Settings\Administrator\workspace\projectName
|
||||
* 获取当前工程路径
|
||||
*/
|
||||
|
||||
// 第五种: 获取所有的类路径 包括jar包的路径
|
||||
System.out.println(System.getProperty("java.class.path"));
|
||||
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
// getConfig();
|
||||
// Config();
|
||||
// all();
|
||||
// new TestOS().showURL();
|
||||
System.out.println(File.separator);
|
||||
}
|
||||
}
|
||||
169
web/src/test/java/cn/com/yhinfo/test/WebProxyExamples.java
Normal file
169
web/src/test/java/cn/com/yhinfo/test/WebProxyExamples.java
Normal file
@@ -0,0 +1,169 @@
|
||||
package cn.com.yhinfo.test;
|
||||
|
||||
import io.vertx.core.Vertx;
|
||||
import io.vertx.core.http.HttpClient;
|
||||
import io.vertx.core.http.HttpMethod;
|
||||
import io.vertx.core.http.HttpServer;
|
||||
import io.vertx.ext.web.Router;
|
||||
import io.vertx.ext.web.RoutingContext;
|
||||
import io.vertx.ext.web.handler.StaticHandler;
|
||||
import io.vertx.ext.web.proxy.handler.ProxyHandler;
|
||||
import io.vertx.httpproxy.HttpProxy;
|
||||
import io.vertx.httpproxy.ProxyRequest;
|
||||
import io.vertx.httpproxy.ProxyResponse;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:emad.albloushi@gmail.com">Emad Alblueshi</a>
|
||||
*/
|
||||
|
||||
public class WebProxyExamples {
|
||||
|
||||
public void origin() {
|
||||
HttpServer backendServer = vertx.createHttpServer();
|
||||
|
||||
Router backendRouter = Router.router(vertx);
|
||||
backendRouter.route().handler(ctx -> {
|
||||
System.out.println(ctx.request().path());
|
||||
ctx.next();
|
||||
});
|
||||
|
||||
backendRouter.route(HttpMethod.GET, "/demo/foo").handler(rc -> rc.response()
|
||||
.putHeader("content-type", "text/html")
|
||||
.end("<html><body><h1>I'm the target resource111!</h1></body></html>"));
|
||||
backendRouter.route(HttpMethod.GET, "/demo/a")
|
||||
.handler(rc -> rc.response().putHeader("content-type", "text/html").end("AAA"));
|
||||
backendRouter.route(HttpMethod.GET, "/demo/b")
|
||||
.handler(rc -> rc.response().putHeader("content-type", "text/html").end("BBB"));
|
||||
|
||||
backendServer.requestHandler(backendRouter).listen(7070);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
/a -> 7070/foo/a
|
||||
/aaa/b -> '7070/foo/' -> 7070/foo/b
|
||||
/aaa/b -> /foo/b -> 7070/foo/b
|
||||
|
||||
/aaa/b -> '7070/foo' -> 7070/foob
|
||||
/aaa/a -> '7070/' -> 7070/aaa/a
|
||||
/aaa/a -> '7070/aaa/' -> 7070/aaa/a
|
||||
|
||||
|
||||
*/
|
||||
|
||||
public Vertx vertx = Vertx.vertx();
|
||||
public HttpClient proxyClient = vertx.createHttpClient();
|
||||
// 创建 http代理处理器
|
||||
HttpProxy httpProxy = HttpProxy.reverseProxy(proxyClient);
|
||||
// 代理处理器绑定到路由
|
||||
Router proxyRouter = Router.router(vertx);
|
||||
|
||||
public void route() {
|
||||
httpProxy.origin(7070, "localhost");
|
||||
|
||||
proxyRouter.route("/demo/*").handler(ProxyHandler.create(httpProxy));
|
||||
proxyRouter.route("/api/*").handler(ctx -> ctx.reroute(ctx.request().path().replaceAll("^/api/", "/demo/")));
|
||||
|
||||
// Router r1 = Router.router(vertx);
|
||||
// r1.route().handler(ctx -> {
|
||||
// int statusCode = ctx.response().getStatusCode();
|
||||
// if (statusCode == 404) {
|
||||
// ctx.response().write("subRouter ---------------> 404");
|
||||
// ctx.end();
|
||||
// }
|
||||
// });
|
||||
|
||||
proxyRouter.route("/*").handler(StaticHandler.create("webroot/test"));
|
||||
|
||||
proxyRouter.errorHandler(404, this::handle404);
|
||||
|
||||
// proxyRouter.route("/api/*").handler(ctx -> ctx.end("123123"));
|
||||
// 路由绑定到代理服务器
|
||||
HttpServer proxyServer = vertx.createHttpServer();
|
||||
proxyServer.requestHandler(proxyRouter);
|
||||
proxyServer.listen(1080);
|
||||
}
|
||||
|
||||
private void handle404(RoutingContext routingContext) {
|
||||
routingContext.end(routingContext.request().path() + "-------> 404");
|
||||
}
|
||||
|
||||
public void routeShort(Vertx vertx, Router proxyRouter) {
|
||||
HttpClient proxyClient = vertx.createHttpClient();
|
||||
|
||||
HttpProxy httpProxy = HttpProxy.reverseProxy(proxyClient);
|
||||
|
||||
proxyRouter
|
||||
.route(HttpMethod.GET, "/*")
|
||||
.handler(ProxyHandler.create(httpProxy, 7070, "localhost"));
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void lowLevel() {
|
||||
HttpServer proxyServer = vertx.createHttpServer();
|
||||
proxyServer.requestHandler(outboundRequest -> {
|
||||
ProxyRequest proxyRequest = ProxyRequest.reverseProxy(outboundRequest);
|
||||
|
||||
proxyClient.request(proxyRequest.getMethod(), 443, "qaiu.top", proxyRequest.getURI())
|
||||
.compose(proxyRequest::send)
|
||||
// Send the proxy response
|
||||
.onSuccess(ProxyResponse::send)
|
||||
.onFailure(err -> {
|
||||
// Release the request
|
||||
proxyRequest.release();
|
||||
|
||||
// Send error
|
||||
outboundRequest.response().setStatusCode(500)
|
||||
.send();
|
||||
});
|
||||
}).listen(8181);
|
||||
}
|
||||
|
||||
|
||||
public void multi(Vertx vertx, Router proxyRouter) {
|
||||
HttpClient proxyClient = vertx.createHttpClient();
|
||||
|
||||
HttpProxy httpProxy1 = HttpProxy.reverseProxy(proxyClient);
|
||||
httpProxy1.origin(7070, "localhost");
|
||||
|
||||
HttpProxy httpProxy2 = HttpProxy.reverseProxy(proxyClient);
|
||||
httpProxy2.origin(6060, "localhost");
|
||||
|
||||
proxyRouter
|
||||
.route(HttpMethod.GET, "/foo").handler(ProxyHandler.create(httpProxy1));
|
||||
|
||||
proxyRouter
|
||||
.route(HttpMethod.GET, "/bar").handler(ProxyHandler.create(httpProxy2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test1() throws IOException, URISyntaxException {
|
||||
// URL url = new URL("www.runoob.com/html/html-tutorial.html");
|
||||
URI uri = new URI("http://www.runoob.com");
|
||||
|
||||
System.out.println(StringUtils.isEmpty(uri.getPath()));
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
final WebProxyExamples examples = new WebProxyExamples();
|
||||
examples.vertx.executeBlocking(rs -> {
|
||||
rs.complete();
|
||||
examples.origin();
|
||||
});
|
||||
examples.vertx.executeBlocking(rs -> {
|
||||
rs.complete();
|
||||
examples.route();
|
||||
});
|
||||
System.out.println("ok");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user