Skip to content

Commit

Permalink
fix: automatically configure the bean "DefaultApplicationConfig" (#336)
Browse files Browse the repository at this point in the history
  • Loading branch information
coryhh authored Jul 19, 2024
1 parent 5bee83f commit 279fbd0
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.arextest.schedule.beans;

import com.arextest.common.config.ConfigProvider;
import com.arextest.common.config.DefaultApplicationConfig;
import com.arextest.common.config.DefaultConfigProvider;
import com.arextest.common.jwt.JWTService;
import com.arextest.common.jwt.JWTServiceImpl;
import com.arextest.schedule.aspect.AppAuthAspectExecutor;
Expand All @@ -17,6 +20,7 @@
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.data.mongodb.core.MongoTemplate;

@Configuration
Expand Down Expand Up @@ -58,4 +62,16 @@ public JWTService jwtService() {
return new JWTServiceImpl(ACCESS_EXPIRE_TIME, REFRESH_EXPIRE_TIME, tokenSecret);
}

@Bean
@ConditionalOnMissingBean(ConfigProvider.class)
public ConfigProvider defaultConfigProvider(Environment environment) {
return new DefaultConfigProvider(environment);
}

@Bean
public DefaultApplicationConfig defaultApplicationConfig(ConfigProvider configProvider) {
return new DefaultApplicationConfig(configProvider);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.arextest.common.model.response.GenericResponseType;
import com.arextest.schedule.client.HttpWepServiceApiClient;
import com.arextest.schedule.common.JsonUtils;
import com.arextest.schedule.mdc.MDCTracer;
import com.arextest.schedule.model.ReplayActionItem;
import com.arextest.schedule.model.ReplayPlan;
import com.arextest.schedule.model.config.ComparisonInterfaceConfig;
Expand Down Expand Up @@ -110,6 +111,8 @@ public void preload(ReplayPlan plan) {
if (actionItem.getReplayCaseCount() == 0) {
continue;
}

MDCTracer.addPlanItemId(actionItem.getId());
String operationId = actionItem.getOperationId();

ReplayComparisonConfig config = operationCompareConfig.getOrDefault(operationId,
Expand All @@ -125,6 +128,7 @@ public void preload(ReplayPlan plan) {

LOGGER.info("prepare load compare config, action id:{}, config:{}", actionItem.getId(),
configValue);
MDCTracer.removePlanItemId();
}
progressEvent.onCompareConfigLoaded(plan);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,13 @@ public static void addPlanItemId(String planItemId) {
MDC.put(PLAN_ITEM_ID, planItemId);
}

public static void addPlanId(long planId) {
addAppType();
add(PLAN_ID, planId);
}

public static void addActionId(String actionId) {
addAppType();
MDC.put(PLAN_ID, actionId);
public static void removePlanItemId() {
MDC.remove(PLAN_ITEM_ID);
}

public static void addActionId(long actionId) {
public static void addPlanId(long planId) {
addAppType();
add(ACTION_ID, actionId);
add(PLAN_ID, planId);
}

public static void addDetailId(String detailId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public HttpSenderContent buildRequestContent(SenderParameters senderParameters)
final HttpEntity<?> httpEntity;
if (shouldApplyHttpBody(httpMethod)) {
Object decodeMessage = DecodeUtils.decode(requestMessage);
if (byte[].class == decodeMessage.getClass()) {
if (decodeMessage instanceof byte[]) {
responseType = byte[].class;
}
httpEntity = new HttpEntity<>(decodeMessage, httpHeaders);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,21 @@

import java.util.Base64;
import java.util.regex.Pattern;
import org.apache.commons.lang3.StringUtils;

/**
* @author wildeslam.
* @create 2023/11/30 20:43
*/
public class DecodeUtils {

private static final String PATTERN_STRING = "^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)?$";
private static final Pattern BASE_64_PATTERN = Pattern.compile(PATTERN_STRING);

public static Object decode(String requestMessage) {
if (StringUtils.isEmpty(requestMessage)) {
return requestMessage;
}
if (BASE_64_PATTERN.matcher(requestMessage).matches()) {
return Base64.getDecoder().decode(requestMessage);
}
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@
</sonar.exclusions>
<arex-storage-config.version>1.1.36</arex-storage-config.version>
<web-contract.version>0.6.4.13</web-contract.version>
<arex-common.version>0.2.2</arex-common.version>
<arex-common.version>0.2.3</arex-common.version>
<redisson.version>3.20.1</redisson.version>
</properties>

Expand Down

0 comments on commit 279fbd0

Please sign in to comment.