Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (C) 2020 the original author or authors.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
package com.fizzgate.fizz;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.fizzgate.config.AppConfigProperties;
import com.fizzgate.fizz.input.ClientInputConfig;
import com.fizzgate.fizz.input.Input;
import com.fizzgate.fizz.input.InputFactory;
import com.fizzgate.fizz.input.InputType;
import com.fizzgate.util.Consts;
import com.fizzgate.util.ReactorUtils;
import com.fizzgate.util.UrlTransformUtils;
import org.apache.commons.io.FileUtils;
import org.apache.logging.log4j.ThreadContext;
import org.noear.snack.ONode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.data.redis.core.ReactiveStringRedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.lang.ref.SoftReference;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
import static com.fizzgate.config.AggregateRedisConfig.AGGREGATE_REACTIVE_REDIS_TEMPLATE;
import static com.fizzgate.util.Consts.S.FORWARD_SLASH;
import static com.fizzgate.util.Consts.S.FORWARD_SLASH_STR;
/**
*
* @author Francis Dong
* @author zhongjie
*
*/
@Component
public class ConfigLoader {
/**
* legacy aggregate formal path prefix
*/
private static final String LEGACY_FORMAL_PATH_PREFIX = "/proxy";
/**
* legacy aggregate test path prefix
*/
private static final String LEGACY_TEST_PATH_PREFIX = "/proxytest";
/**
* aggregate test path prefix
*/
private static final String TEST_PATH_PREFIX = "/_proxytest";
/**
* aggregate test path service name start index
*/
private static final int TEST_PATH_SERVICE_NAME_START_INDEX = TEST_PATH_PREFIX.length() + 1;
@Autowired
public ConfigurableApplicationContext appContext;
private static final Logger LOGGER = LoggerFactory.getLogger(ConfigLoader.class);
/**
* 聚合配置存放Hash的Key
*/
private static final String AGGREGATE_HASH_KEY = "fizz_aggregate_config";
private static Map aggregateResources = null;
private static Map resourceKey2ConfigInfoMap = null;
private static Map aggregateId2ResourceKeyMap = null;
@Resource
private AppConfigProperties appConfigProperties;
@Resource(name = AGGREGATE_REACTIVE_REDIS_TEMPLATE)
private ReactiveStringRedisTemplate reactiveStringRedisTemplate;
@Resource
private ConfigLoaderProperties configLoaderProperties;
private String formalPathPrefix;
private int formalPathServiceNameStartIndex;
public Input createInput(String configStr) throws IOException {
ONode cfgNode = ONode.loadStr(configStr);
Input input = new Input();
input.setName(cfgNode.select("$.name").getString());
ClientInputConfig clientInputConfig = new ClientInputConfig();
clientInputConfig.setDataMapping(cfgNode.select("$.dataMapping").toObject(Map.class));
clientInputConfig.setHeaders(cfgNode.select("$.headers").toObject(Map.class));
clientInputConfig.setMethod(cfgNode.select("$.method").getString());
clientInputConfig.setPath(cfgNode.select("$.path").getString());
if (clientInputConfig.getPath().startsWith(TEST_PATH_PREFIX)) {
// always enable debug for testing
clientInputConfig.setDebug(true);
} else {
if (cfgNode.select("$.debug") != null) {
clientInputConfig.setDebug(cfgNode.select("$.debug").getBoolean());
}
}
clientInputConfig.setType(InputType.valueOf(cfgNode.select("$.type").getString()));
clientInputConfig.setLangDef(cfgNode.select("$.langDef").toObject(Map.class));
clientInputConfig.setBodyDef(cfgNode.select("$.bodyDef").toObject(Map.class));
clientInputConfig.setHeadersDef(cfgNode.select("$.headersDef").toObject(Map.class));
clientInputConfig.setParamsDef(cfgNode.select("$.paramsDef").toObject(Map.class));
clientInputConfig.setScriptValidate(cfgNode.select("$.scriptValidate").toObject(Map.class));
clientInputConfig.setValidateResponse(cfgNode.select("$.validateResponse").toObject(Map.class));
clientInputConfig.setContentType(cfgNode.select("$.contentType").getString());
clientInputConfig.setXmlArrPaths(cfgNode.select("$.xmlArrPaths").getString());
input.setConfig(clientInputConfig);
return input;
}
public Pipeline createPipeline(String configStr) throws IOException {
ONode cfgNode = ONode.loadStr(configStr);
Pipeline pipeline = new Pipeline();
pipeline.setApplicationContext(appContext);
List