Created
June 3, 2023 09:11
-
-
Save ilwsm/f9deab4c9fb006fddbe95a81d9a3a088 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package executor.service.utl; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
public class ErrorHandler { | |
private static final Logger LOGGER = LoggerFactory.getLogger(ErrorHandler.class); | |
public static Logger getLogger() { | |
return LOGGER; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package executor.service.maintenance.plugin.proxy; | |
import executor.service.model.ProxyConfigHolderDto; | |
import executor.service.model.ProxyCredentialsDTO; | |
import executor.service.model.ProxyNetworkConfigDTO; | |
import executor.service.utl.ErrorHandler; | |
import executor.service.utl.Json; | |
import java.io.IOException; | |
import java.io.InputStream; | |
import java.util.ArrayList; | |
import java.util.List; | |
public class JsonProxySources implements ProxySources { | |
private static final String PROXY_LIST_FILENAME = "proxy_list.json"; | |
private final List<ProxyConfigHolderDto> proxyConfigHolderDtoList = new ArrayList<>(); | |
public JsonProxySources() { | |
parse(PROXY_LIST_FILENAME); | |
} | |
JsonProxySources(String filename) { | |
parse(filename); | |
} | |
static InputStream getResourceStream(String filename) { | |
return JsonProxySources.class.getResourceAsStream("/" + filename); | |
} | |
@Override | |
public List<ProxyConfigHolderDto> getProxyConfigHolders() { | |
return proxyConfigHolderDtoList; | |
} | |
private void parse(String filename) { | |
JsonModel[] arr; | |
try { | |
arr = Json.parseToArrayOrThrow(getResourceStream(filename), JsonModel.class); | |
} catch (Exception e) { | |
ErrorHandler.getLogger().warn(e.getMessage(), e); | |
return; | |
} | |
for (JsonModel model : arr) { | |
for (ProxyCredentialsDTO credentials : model.credential) { | |
ProxyConfigHolderDto holder = new ProxyConfigHolderDto( | |
new ProxyNetworkConfigDTO(model.hostname, model.port), credentials | |
); | |
proxyConfigHolderDtoList.add(holder); | |
} | |
} | |
} | |
private static class JsonModel { | |
public String hostname; | |
public Integer port; | |
public List<ProxyCredentialsDTO> credential; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment