Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade ozhera-app to JDK21 #151

Merged
merged 4 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ozhera-app-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ on:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
check-build-8:
check-build-21:
name: ozhera-app test
runs-on: ubuntu-latest
steps:
- name: Setup Maven Action
uses: s4u/setup-maven-action@v1.7.0
with:
java-version: 8
java-version: 21
#settings-properties: '[{"propertyName1": "propertyValue1"}, {"propertyName2": "propertyValue2"}]'

- run: echo '<settings> <interactiveMode>false</interactiveMode> <profiles> <profile> <repositories> <repository> <snapshots /> <id>ossrh</id> <name>ossrh-snapshot</name> <url>https://s01.oss.sonatype.org/content/repositories/snapshots</url> </repository> </repositories> <pluginRepositories> <pluginRepository> <snapshots /> <id>ossrh</id> <name>ossrh-snapshot</name> <url>https://s01.oss.sonatype.org/content/repositories/snapshots</url> </pluginRepository> </pluginRepositories> <id>artifactory</id> </profile> </profiles> <activeProfiles> <activeProfile>artifactory</activeProfile> </activeProfiles> <servers> <server> <id>github</id> <username>${env.GITHUB_ACTOR}</username> <password>${env.GITHUB_TOKEN}</password> </server> </servers> <mirrors/> <proxies/></settings>' > ~/.m2/settings.xml

- run: cd ozhera-app; mvn -U clean package --fail-at-end -Dmaven.test.skip=true
- run: cd ozhera-app; mvn -U clean package --fail-at-end -Dmaven.test.skip=true
7 changes: 1 addition & 6 deletions ozhera-app/app-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,12 @@
<parent>
<groupId>run.mone</groupId>
<artifactId>hera-app</artifactId>
<version>1.4-SNAPSHOT</version>
<version>1.4-jdk21-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>app-api</artifactId>
<version>${hera-app.release.version}</version>

<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>run.mone</groupId>
Expand Down
7 changes: 1 addition & 6 deletions ozhera-app/app-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,12 @@
<parent>
<artifactId>hera-app</artifactId>
<groupId>run.mone</groupId>
<version>1.4-SNAPSHOT</version>
<version>1.4-jdk21-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>app-common</artifactId>
<version>${hera-app.release.version}</version>

<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
Expand Down
7 changes: 4 additions & 3 deletions ozhera-app/app-server/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
FROM openjdk:8
FROM openjdk:21-jdk-bookworm

RUN echo 'Asia/Shanghai' >/etc/timezone

RUN mkdir -p /home/work/app-server/
RUN mkdir -p /home/work/log/app-server/
COPY ./target/app-server-1.4-SNAPSHOT.jar /home/work/app-server/app-server-1.4-SNAPSHOT.jar
ENTRYPOINT ["java","-XX:+HeapDumpOnOutOfMemoryError","-XX:HeapDumpPath=/home/work/log/hera-app","-jar","/home/work/app-server/app-server-1.4-SNAPSHOT.jar"]
COPY ./target/app-server-1.4-jdk21-SNAPSHOT.jar /home/work/app-server/app-server-1.4-SNAPSHOT.jar

ENTRYPOINT ["sh","-c","java -XX:+UseZGC --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.math=ALL-UNNAMED --add-opens java.base/sun.reflect=ALL-UNNAMED --add-opens java.base/java.xml=ALL-UNNAMED --add-exports java.base/sun.reflect.annotation=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED --add-exports java.xml/com.sun.org.apache.xerces.internal.impl.dv.util=ALL-UNNAMED -Duser.timezone=Asia/Shanghai -jar /home/work/app-server/app-server-1.4-SNAPSHOT.jar"]
4 changes: 2 additions & 2 deletions ozhera-app/app-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>hera-app</artifactId>
<groupId>run.mone</groupId>
<version>1.4-SNAPSHOT</version>
<version>1.4-jdk21-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down Expand Up @@ -44,7 +44,7 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>2.2.1.RELEASE</version>
<version>2.7.15</version>
<scope>test</scope>
<exclusions>
<exclusion>
Expand Down
4 changes: 2 additions & 2 deletions ozhera-app/app-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>hera-app</artifactId>
<groupId>run.mone</groupId>
<version>1.4-SNAPSHOT</version>
<version>1.4-jdk21-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>app-service</artifactId>
Expand Down Expand Up @@ -51,7 +51,7 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>5.0.6.RELEASE</version>
<version>5.3.29</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.concurrent.locks.ReentrantLock;

/**
* @author gaoxihui
Expand All @@ -38,6 +39,8 @@ public class AuthorizationService {

private static DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

private final ReentrantLock lock = new ReentrantLock();

public Result fetchToken(String user, String sign, Long timestamp){

log.info("fetchToken user : {} , timestamp : {}",user,df.format(timestamp));
Expand Down Expand Up @@ -110,36 +113,40 @@ public Result checkAuthorization(String token){

}

public synchronized Integer checkAuthorizationWithSeq(String token,Integer accessSeq){

if(StringUtils.isBlank(token)){
log.error("checkAuthorization error!token is null!");
return null;
}
public Integer checkAuthorizationWithSeq(String token,Integer accessSeq){

if(redisService.get(token) == null){
log.error("checkAuthorization token is error or expired!");
return null;
}
lock.lock();
try {
if (StringUtils.isBlank(token)) {
log.error("checkAuthorization error!token is null!");
return null;
}

String accessNumStr = redisService.get(token);
Integer accessNum = Integer.valueOf(accessNumStr);
if (redisService.get(token) == null) {
log.error("checkAuthorization token is error or expired!");
return null;
}

if(accessSeq <= accessNum){
log.error("token accessSeq has expired!accessSeq:{}, currentNum:{}",accessSeq,accessNum);
return null;
}
String accessNumStr = redisService.get(token);
Integer accessNum = Integer.valueOf(accessNumStr);

if(accessSeq - accessNum > 1){
log.error("token accessSeq error!accessSeq:{}, currentNum:{}",accessSeq,accessNum);
return null;
}
if (accessSeq <= accessNum) {
log.error("token accessSeq has expired!accessSeq:{}, currentNum:{}", accessSeq, accessNum);
return null;
}

long ttl = redisService.ttl(token);
if (accessSeq - accessNum > 1) {
log.error("token accessSeq error!accessSeq:{}, currentNum:{}", accessSeq, accessNum);
return null;
}

redisService.set(token,String.valueOf(accessSeq),ttl);
long ttl = redisService.ttl(token);

return accessSeq + 1;
redisService.set(token, String.valueOf(accessSeq), ttl);

return accessSeq + 1;
} finally {
lock.unlock();
}
}
}
27 changes: 9 additions & 18 deletions ozhera-app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.2</version>
<version>2.7.15</version>
</parent>

<groupId>run.mone</groupId>
<artifactId>hera-app</artifactId>
<version>1.4-SNAPSHOT</version>
<version>1.4-jdk21-SNAPSHOT</version>
<packaging>pom</packaging>

<modules>
Expand All @@ -23,9 +23,7 @@
</modules>

<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<hera-app.release.version>1.4-SNAPSHOT</hera-app.release.version>
<hera-app.release.version>1.4-jdk21-SNAPSHOT</hera-app.release.version>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -63,7 +61,7 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.4</version>
<version>1.18.30</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
Expand Down Expand Up @@ -98,22 +96,15 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<version>3.11.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<fork>true</fork>
<verbose>true</verbose>
<encoding>UTF-8</encoding>
<compilerArguments>
<sourcepath>
${project.basedir}/src/main/java
</sourcepath>
</compilerArguments>
<compilerVersion>21</compilerVersion>
<source>21</source>
<target>21</target>
</configuration>
</plugin>
</plugins>

</plugins>
</build>


Expand Down