sac/sf-vertx/src/main/java/com/sf/vertx/handle/ApiMockHandlerImpl.java

32 lines
886 B
Java
Raw Normal View History

2024-05-21 14:17:59 +08:00
package com.sf.vertx.handle;
import com.sf.vertx.api.pojo.AppConfig;
import com.sf.vertx.api.pojo.MockResponse;
import com.sf.vertx.constans.SacErrorCode;
import io.vertx.ext.web.RoutingContext;
import io.vertx.ext.web.handler.HttpException;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
@Slf4j
public class ApiMockHandlerImpl implements ApiMockHandler {
@Override
public void handle(RoutingContext rc) {
try {
String cacheKey = AppConfigHandler.getApiCodeConfigCacheKey(rc);
// mock
MockResponse mockResponse = AppConfigHandler.mock(cacheKey,rc);
if (mockResponse != null) {
rc.fail(new MockException(mockResponse.getHttpStatus(), mockResponse.getMockResponse()));
return;
}
} catch (Exception e) {
e.printStackTrace();
rc.fail(new HttpException(SacErrorCode.DEFAULT_ERROR_CODE));
return;
}
rc.next();
}
}