Skip to content

Commit

Permalink
add dao alone redis
Browse files Browse the repository at this point in the history
  • Loading branch information
naah69 committed Oct 21, 2022
1 parent cf87a12 commit 69189f6
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,19 @@ public SaRequestForResteasy() {

@Override
public Object getSource() {

return this.context;
}

/**
* if there is not @FormParam in Endpoint,the form data will not parsing.
* @see <a href="https://github.com/quarkusio/quarkus/discussions/25103">RESTEasy Reactive - get all form data</a>
* @see <a href="https://github.com/quarkusio/quarkus/issues/22444">RESTEasy Reactive: make body-reading filters force reading the body</a>
* @param name param name
* @return param value
*/
@Override
public String getParam(String name) {
return Optional.ofNullable(this.context.getQueryParameter(name, true, true))
return Optional.ofNullable(this.context.getQueryParameter(name, true, false))
.or(() -> Optional.ofNullable(this.context.getFormParameter(name, true, true)))
.map(Object::toString)
.orElse(null);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
sa-token.exception-mapper-enabled=true
quarkus.application.name=sa-token-dao-alone-redis
quarkus.redisson.single-server-config.address=redis://127.0.0.1:63790
quarkus.redisson.single-server-config.database=0
quarkus.redisson.codec=org.redisson.codec.JsonJacksonCodec
quarkus.redis.devservices.enabled=true
quarkus.redis.devservices.port=63790
sa-token.alone-redis.redisson.single-server-config.address=redis://127.0.0.1:63791
sa-token.alone-redis.redisson.single-server-config.address=redis://127.0.0.1:63790
sa-token.alone-redis.redisson.single-server-config.database=0
sa-token.alone-redis.redisson.codec=org.redisson.codec.JsonJacksonCodec
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@
import io.quarkiverse.satoken.core.context.SaTokenContextForQuarkus;
import io.quarkiverse.satoken.core.utils.AntPathMatcher;
import io.quarkiverse.satoken.resteasy.utils.SoMap;
import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.junit.QuarkusTest;

@QuarkusTest
@QuarkusTestResource(RedisResource.class)
//@QuarkusTestResource(RedisResource.class)
public class BasicTest extends AbstractRequestTest {

// 持久化Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import cn.dev33.satoken.session.TokenSign;
import cn.dev33.satoken.stp.StpLogic;
import cn.dev33.satoken.stp.StpUtil;
import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.junit.QuarkusTest;

/**
Expand All @@ -23,7 +22,7 @@
* @date 2022/4/12 2:11 PM
*/
@QuarkusTest
@QuarkusTestResource(RedisResource.class)
//@QuarkusTestResource(RedisResource.class)
public class ManyLoginTest extends AbstractRequestTest {
// 持久化Bean
SaTokenDao dao = SaManager.getSaTokenDao();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* @author nayan
* @date 2022/10/20 10:42
*/
@Deprecated
public class RedisResource implements QuarkusTestResourceLifecycleManager {

//准备Redis容器,使用withExposedPorts方法暴露端口
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@
import org.junit.jupiter.api.Test;

import io.quarkiverse.satoken.resteasy.AbstractRequestTest;
import io.quarkiverse.satoken.resteasy.RedisResource;
import io.quarkiverse.satoken.resteasy.utils.SoMap;
import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.response.ValidatableResponse;

@QuarkusTest
@QuarkusTestResource(RedisResource.class)
//@QuarkusTestResource(RedisResource.class)
public class LoginResourceTest extends AbstractRequestTest {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
import org.junit.jupiter.api.Test;

import io.quarkiverse.satoken.resteasy.AbstractRequestTest;
import io.quarkiverse.satoken.resteasy.RedisResource;
import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.junit.QuarkusTest;

@QuarkusTest
@QuarkusTestResource(RedisResource.class)
//@QuarkusTestResource(RedisResource.class)
public class MoreResourceTest extends AbstractRequestTest {

// 基础API测试
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
import cn.dev33.satoken.router.SaRouter;
import cn.dev33.satoken.router.SaRouterStaff;
import io.quarkiverse.satoken.resteasy.AbstractRequestTest;
import io.quarkiverse.satoken.resteasy.RedisResource;
import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.QuarkusTestProfile;
import io.quarkus.test.junit.TestProfile;
Expand All @@ -24,7 +22,7 @@
*/
@QuarkusTest
@TestProfile(RouteResourceTest.RouteTestProfile.class)
@QuarkusTestResource(RedisResource.class)
//@QuarkusTestResource(RedisResource.class)
public class RouteResourceTest extends AbstractRequestTest {

// 基础API测试
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import org.junit.jupiter.api.Test;

import io.quarkiverse.satoken.resteasy.AbstractRequestTest;
import io.quarkiverse.satoken.resteasy.RedisResource;
import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.QuarkusTestProfile;
import io.quarkus.test.junit.TestProfile;
Expand All @@ -18,7 +16,7 @@
*/
@QuarkusTest
@TestProfile(SaAnnotationResourceTest.AnnotationTestProfile.class)
@QuarkusTestResource(RedisResource.class)
//@QuarkusTestResource(RedisResource.class)
public class SaAnnotationResourceTest extends AbstractRequestTest {

// 校验通过的情况
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import cn.dev33.satoken.exception.IdTokenInvalidException;
import cn.dev33.satoken.id.SaIdUtil;
import io.quarkiverse.satoken.resteasy.AbstractRequestTest;
import io.quarkiverse.satoken.resteasy.RedisResource;
import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.http.Header;
import io.restassured.response.ValidatableResponse;
Expand All @@ -24,7 +22,7 @@
* @date 2022/10/8 14:29
*/
@QuarkusTest
@QuarkusTestResource(RedisResource.class)
//@QuarkusTestResource(RedisResource.class)
public class SaIdTokenResourceTest extends AbstractRequestTest {

// 获取信息
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import javax.annotation.PostConstruct;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.enterprise.inject.spi.CDI;

import org.redisson.api.RBucket;
import org.redisson.api.RedissonClient;
Expand Down Expand Up @@ -36,9 +36,28 @@ public class SaTokenDaoRedisJackson implements SaTokenDao {
*/
public boolean isInit;

@Inject
@PostConstruct
public void init( RedissonClient redissonClient) {
public void init() {
if (!this.isInit) {
// try {
// Arc.container().instance(RedissonClientProducer.class).get();
// } catch (Exception e) {
// LOG.debug("redisson init error");
// }
try {
CDI.current().select(RedissonClient.class).stream().findAny().ifPresent(r -> {
init(r);
LOG.debug("satoken redisson init");
});
} catch (Exception e) {
LOG.debug("satoken redisson init error!");
}
} else {
LOG.debug("satoken redisson had inited!");
}
}

public void init(RedissonClient redissonClient) {
this.redissonClient = redissonClient;
// 指定相应的序列化方案
// 通过反射获取Mapper对象, 增加一些配置, 增强兼容性
Expand All @@ -48,7 +67,7 @@ public void init( RedissonClient redissonClient) {
} catch (Exception e) {
LOG.error("sa token redis jackson init failed", e);
}
if (Objects.nonNull(this.redissonClient)&&Objects.nonNull(SaStrategy.me.createSession)){
if (Objects.nonNull(this.redissonClient) && Objects.nonNull(SaStrategy.me.createSession)) {
this.isInit = true;
}

Expand Down

0 comments on commit 69189f6

Please sign in to comment.