Commit b9436832 authored by hubin's avatar hubin

增加一个简易自动脚本

parent 78baaeee
...@@ -10,9 +10,9 @@ spring: ...@@ -10,9 +10,9 @@ spring:
nacos: nacos:
discovery: discovery:
server-addr: qw.hungraim.com:31158 server-addr: qw.hungraim.com:31158
namespace: 87d6f6f1-6583-46ea-ad02-7e8125f03c90 namespace: 0e0f834a-a665-4d27-ae04-9d53c2e02140
config: config:
namespace: 87d6f6f1-6583-46ea-ad02-7e8125f03c90 namespace: 0e0f834a-a665-4d27-ae04-9d53c2e02140
server-addr: qw.hungraim.com:31158 server-addr: qw.hungraim.com:31158
file-extension: yaml # 必须修改成yaml file-extension: yaml # 必须修改成yaml
extension-configs: extension-configs:
......
...@@ -10,9 +10,9 @@ spring: ...@@ -10,9 +10,9 @@ spring:
nacos: nacos:
discovery: discovery:
server-addr: qw.hungraim.com:31158 server-addr: qw.hungraim.com:31158
namespace: 87d6f6f1-6583-46ea-ad02-7e8125f03c90 namespace: 0e0f834a-a665-4d27-ae04-9d53c2e02140
config: config:
namespace: 87d6f6f1-6583-46ea-ad02-7e8125f03c90 namespace: 0e0f834a-a665-4d27-ae04-9d53c2e02140
server-addr: qw.hungraim.com:31158 server-addr: qw.hungraim.com:31158
file-extension: yaml # 必须修改成yaml file-extension: yaml # 必须修改成yaml
extension-configs: extension-configs:
......
...@@ -10,9 +10,9 @@ spring: ...@@ -10,9 +10,9 @@ spring:
nacos: nacos:
discovery: discovery:
server-addr: qw.hungraim.com:31158 server-addr: qw.hungraim.com:31158
namespace: 87d6f6f1-6583-46ea-ad02-7e8125f03c90 namespace: 0e0f834a-a665-4d27-ae04-9d53c2e02140
config: config:
namespace: 87d6f6f1-6583-46ea-ad02-7e8125f03c90 namespace: 0e0f834a-a665-4d27-ae04-9d53c2e02140
server-addr: qw.hungraim.com:31158 server-addr: qw.hungraim.com:31158
file-extension: yaml # 必须修改成yaml file-extension: yaml # 必须修改成yaml
extension-configs: extension-configs:
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>common-core</artifactId> <artifactId>common-core</artifactId>
<packaging>jar</packaging>
<build> <build>
<plugins> <plugins>
<plugin> <plugin>
......
package com.hungraim.ltc.util;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.hungraim.ltc.constant.AuthConstants;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpHead;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.apache.logging.log4j.util.Strings;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import sun.misc.BASE64Decoder;
import javax.servlet.http.HttpServletRequest;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.Objects;
/**
* @author hubin
*/
@Slf4j
public class RequestUtils {
public static HttpServletRequest getRequest() {
return ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
}
public static JSONObject getJwtPayload() {
String jwtPayload = getRequest().getHeader(AuthConstants.JWT_PAYLOAD_KEY);
return JSONUtil.parseObj(jwtPayload);
}
@SneakyThrows
public static String getAuthClientId() {
String clientId;
HttpServletRequest request = getRequest();
// 从请求路径中获取
clientId = request.getParameter(AuthConstants.CLIENT_ID_KEY);
if (StrUtil.isNotBlank(clientId)) {
return clientId;
}
// 从请求头获取
String basic = request.getHeader(AuthConstants.AUTHORIZATION_KEY);
if (StrUtil.isNotBlank(basic) && basic.startsWith(AuthConstants.BASIC_PREFIX)) {
basic = basic.replace(AuthConstants.BASIC_PREFIX, Strings.EMPTY);
String basicPlainText = new String(new BASE64Decoder().decodeBuffer(basic), StandardCharsets.UTF_8);
//client:secret
clientId = basicPlainText.split(":")[0];
}
return clientId;
}
/**
* 发起http post请求
*
* @param url 请求地址
* @param entity 请求参数
* @return 返回信息,出错返回空
*/
@SneakyThrows
public static String post(String url, JSONObject entity, Map<String, String> header) {
CloseableHttpClient httpClient = HttpClients.createDefault();
CloseableHttpResponse response = null;
try {
HttpPost httpPost = new HttpPost(url);
HttpHead httpHead = new HttpHead();
//设置head
if (header != null) {
header.forEach(httpHead::setHeader);
}
StringEntity se = new StringEntity(entity.toString(), "UTF-8");
se.setContentType("application/json");
httpPost.setEntity(se);
response = httpClient.execute(httpPost);
HttpEntity entity1 = response.getEntity();
String resStr = null;
if (entity1 != null) {
resStr = EntityUtils.toString(entity1, StandardCharsets.UTF_8);
}
httpClient.close();
response.close();
return resStr;
} catch (Exception e) {
log.error("POST请求:{},出现错误:{}", url, e.getMessage());
e.printStackTrace();
} finally {
if (httpClient != null) {
httpClient.close();
}
if (response != null) {
response.close();
}
}
return "";
}
/**
* 发起http get请求
*
* @param url 请求地址
* @return 返回信息,出错返回空
*/
@SneakyThrows
public static String get(String url) {
CloseableHttpClient httpClient = HttpClients.createDefault();
CloseableHttpResponse response = null;
try {
HttpGet httpGet = new HttpGet(url);
response = httpClient.execute(httpGet);
HttpEntity entity1 = response.getEntity();
String resStr = null;
if (entity1 != null) {
resStr = EntityUtils.toString(entity1, StandardCharsets.UTF_8);
}
httpClient.close();
response.close();
return resStr;
} catch (Exception e) {
log.error("get请求:{},出现错误:{}", url, e.getMessage());
e.printStackTrace();
} finally {
if (httpClient != null) {
httpClient.close();
}
if (response != null) {
response.close();
}
}
return "";
}
}
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>common-mybatis</artifactId> <artifactId>common-mybatis</artifactId>
<packaging>jar</packaging>
<properties> <properties>
<maven.compiler.source>8</maven.compiler.source> <maven.compiler.source>8</maven.compiler.source>
...@@ -23,11 +24,13 @@ ...@@ -23,11 +24,13 @@
<artifactId>mybatis-plus-boot-starter</artifactId> <artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.3.1</version> <version>3.3.1</version>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/com.oracle.database.jdbc/ojdbc6 -->
<dependency> <dependency>
<groupId>com.oracle</groupId> <groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc6</artifactId> <artifactId>ojdbc6</artifactId>
<version>11.2.0.3</version> <version>11.2.0.4</version>
</dependency> </dependency>
<!-- 引用Mybatis 和 Mysql驱动结束 --> <!-- 引用Mybatis 和 Mysql驱动结束 -->
</dependencies> </dependencies>
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>common-redis</artifactId> <artifactId>common-redis</artifactId>
<packaging>jar</packaging>
<properties> <properties>
<maven.compiler.source>8</maven.compiler.source> <maven.compiler.source>8</maven.compiler.source>
......
...@@ -9,9 +9,9 @@ spring: ...@@ -9,9 +9,9 @@ spring:
nacos: nacos:
discovery: discovery:
server-addr: qw.hungraim.com:31158 server-addr: qw.hungraim.com:31158
namespace: 87d6f6f1-6583-46ea-ad02-7e8125f03c90 namespace: 0e0f834a-a665-4d27-ae04-9d53c2e02140
config: config:
namespace: 87d6f6f1-6583-46ea-ad02-7e8125f03c90 namespace: 0e0f834a-a665-4d27-ae04-9d53c2e02140
server-addr: qw.hungraim.com:31158 server-addr: qw.hungraim.com:31158
file-extension: yaml # 必须修改成yaml file-extension: yaml # 必须修改成yaml
extension-configs: extension-configs:
......
...@@ -9,9 +9,9 @@ spring: ...@@ -9,9 +9,9 @@ spring:
nacos: nacos:
discovery: discovery:
server-addr: qw.hungraim.com:31158 server-addr: qw.hungraim.com:31158
namespace: 87d6f6f1-6583-46ea-ad02-7e8125f03c90 namespace: 0e0f834a-a665-4d27-ae04-9d53c2e02140
config: config:
namespace: 87d6f6f1-6583-46ea-ad02-7e8125f03c90 namespace: 0e0f834a-a665-4d27-ae04-9d53c2e02140
server-addr: qw.hungraim.com:31158 server-addr: qw.hungraim.com:31158
file-extension: yaml # 必须修改成yaml file-extension: yaml # 必须修改成yaml
extension-configs: extension-configs:
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
<module>system</module> <module>system</module>
<module>apply</module> <module>apply</module>
<module>governance</module> <module>governance</module>
<module>assessment</module>
</modules> </modules>
<parent> <parent>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
...@@ -20,7 +21,6 @@ ...@@ -20,7 +21,6 @@
<groupId>com.hungraim.ltc</groupId> <groupId>com.hungraim.ltc</groupId>
<artifactId>ltc</artifactId> <artifactId>ltc</artifactId>
<version>0.0.1</version> <version>0.0.1</version>
<name>spring-cloud-init</name>
<description>parent</description> <description>parent</description>
<properties> <properties>
......
#!/bin/bash
git pull
mvn install
docker stop ltc-poc
docker rmi ltc:latest
docker build -t ltc .
docker run -d --name ltc-poc -p 9999:8001 -m 2G ltc
#指定依赖的镜像 #指定依赖的镜像
FROM localhost:9999/library/java:8 FROM java:8
#springboot #springboot
VOLUME /tmp VOLUME /tmp
#容器使用端口 #容器使用端口
......
...@@ -10,9 +10,9 @@ spring: ...@@ -10,9 +10,9 @@ spring:
nacos: nacos:
discovery: discovery:
server-addr: qw.hungraim.com:31158 server-addr: qw.hungraim.com:31158
namespace: 87d6f6f1-6583-46ea-ad02-7e8125f03c90 namespace: 0e0f834a-a665-4d27-ae04-9d53c2e02140
config: config:
namespace: 87d6f6f1-6583-46ea-ad02-7e8125f03c90 namespace: 0e0f834a-a665-4d27-ae04-9d53c2e02140
server-addr: qw.hungraim.com:31158 server-addr: qw.hungraim.com:31158
file-extension: yaml # 必须修改成yaml file-extension: yaml # 必须修改成yaml
extension-configs: extension-configs:
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>system-api</artifactId> <artifactId>system-api</artifactId>
<packaging>jar</packaging>
<dependencies> <dependencies>
<dependency> <dependency>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment