use of org.springframework.core.io.support.ResourcePatternResolver in project web3sdk by FISCO-BCOS.
the class ChannelConnections method startConnect.
public void startConnect() {
if (running) {
logger.debug("服务已启动");
return;
}
logger.debug("初始化connections connect");
// 初始化netty
EventLoopGroup workerGroup = new NioEventLoopGroup();
bootstrap.group(workerGroup);
bootstrap.channel(NioSocketChannel.class);
bootstrap.option(ChannelOption.SO_KEEPALIVE, true);
final ChannelConnections selfService = this;
final ThreadPoolTaskExecutor selfThreadPool = threadPool;
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
final Resource keystoreResource = resolver.getResource(getClientKeystorePath());
final Resource caResource = resolver.getResource(getCaCertPath());
bootstrap.handler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel ch) throws Exception {
KeyStore ks = KeyStore.getInstance("JKS");
InputStream ksInputStream = keystoreResource.getInputStream();
ks.load(ksInputStream, getKeystorePassWord().toCharArray());
/*
* 每次连接使用新的handler 连接信息从socketChannel中获取
*/
ChannelHandler handler = new ChannelHandler();
handler.setConnections(selfService);
handler.setIsServer(false);
handler.setThreadPool(selfThreadPool);
SslContext sslCtx = SslContextBuilder.forClient().trustManager(caResource.getFile()).keyManager((PrivateKey) ks.getKey("client", getClientCertPassWord().toCharArray()), (X509Certificate) ks.getCertificate("client")).build();
ch.pipeline().addLast(sslCtx.newHandler(ch.alloc()), new LengthFieldBasedFrameDecoder(1024 * 1024 * 4, 0, 4, -4, 0), new IdleStateHandler(idleTimeout, idleTimeout, idleTimeout, TimeUnit.MILLISECONDS), handler);
}
});
running = true;
Thread loop = new Thread() {
public void run() {
try {
while (true) {
if (!running) {
return;
}
// 尝试重连
reconnect();
Thread.sleep(heartBeatDelay);
}
} catch (InterruptedException e) {
logger.error("系统错误", e);
}
}
};
loop.start();
}
use of org.springframework.core.io.support.ResourcePatternResolver in project web3sdk by FISCO-BCOS.
the class P12Manager method load.
public void load() throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException, NoSuchProviderException {
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
keyStore = KeyStore.getInstance("PKCS12", "BC");
Resource keyStoreResource = resolver.getResource(p12File);
keyStore.load(keyStoreResource.getInputStream(), password.toCharArray());
// logger.debug(" p12 load, keyStore: {}", keyStore);
}
use of org.springframework.core.io.support.ResourcePatternResolver in project cuba by cuba-platform.
the class ScriptScanner method getScripts.
public List<ScriptResource> getScripts(ScriptType scriptType, @Nullable String moduleName) {
try {
ResourcePatternResolver resourceResolver = createAppropriateResourceResolver();
String rootPath = String.format("%s/%s/%s/%s/", dbScriptsDirectoryForSearch(), moduleDirectory(moduleName), scriptTypeDirectory(scriptType), dbmsType);
String urlPattern = String.format("%s**/*%s.*", rootPath, scriptType == ScriptType.INIT ? "create-db" : "");
String urlPatternWithDbmsVersion = null;
String rootPathWithDbmsVersion = null;
if (StringUtils.isNotBlank(dbmsVersion)) {
rootPathWithDbmsVersion = String.format("%s/%s/%s/%s-%s/", dbScriptsDirectoryForSearch(), moduleDirectory(moduleName), scriptTypeDirectory(scriptType), dbmsType, dbmsVersion);
urlPatternWithDbmsVersion = String.format("%s**/*%s.*", rootPathWithDbmsVersion, scriptType == ScriptType.INIT ? "create-db" : "");
}
Map<String, ScriptResource> scriptResources = findResourcesByUrlPattern(resourceResolver, urlPattern, rootPath);
if (StringUtils.isNotBlank(urlPatternWithDbmsVersion)) {
Map<String, ScriptResource> additionalResources = findResourcesByUrlPattern(resourceResolver, urlPatternWithDbmsVersion, rootPathWithDbmsVersion);
scriptResources.putAll(additionalResources);
}
List<ScriptResource> results = new ArrayList<>(scriptResources.values());
results.sort((ScriptResource r1, ScriptResource r2) -> {
if (r1.getDir().equals(r2.getDir())) {
return r1.getName().compareTo(r2.getName());
} else {
String dbmsTypeAndVersion = dbmsType + "-" + dbmsVersion;
String separator1 = r1.getPath().contains(dbmsTypeAndVersion) ? dbmsTypeAndVersion : dbmsType;
String separator2 = r2.getPath().contains(dbmsTypeAndVersion) ? dbmsTypeAndVersion : dbmsType;
String pathAfterDbms1 = StringUtils.substringAfter(r1.getPath(), separator1);
String pathBeforeDbms1 = StringUtils.substringBefore(r1.getPath(), separator1);
String pathAfterDbms2 = StringUtils.substringAfter(r2.getPath(), separator2);
String pathBeforeDbms2 = StringUtils.substringBefore(r2.getPath(), separator2);
return pathBeforeDbms1.equals(pathBeforeDbms2) ? pathAfterDbms1.compareTo(pathAfterDbms2) : pathBeforeDbms1.compareTo(pathBeforeDbms2);
}
});
return results;
} catch (IOException e) {
throw new RuntimeException("An error occurred while loading scripts", e);
}
}
use of org.springframework.core.io.support.ResourcePatternResolver in project cuba by cuba-platform.
the class AbstractScanConfiguration method scanPackage.
protected Stream<MetadataReader> scanPackage(String packageName) {
String packageSearchPath = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + resolveBasePackage(packageName) + '/' + DEFAULT_CLASS_RESOURCE_PATTERN;
ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver(getResourceLoader());
Resource[] resources;
try {
resources = resourcePatternResolver.getResources(packageSearchPath);
} catch (IOException e) {
throw new RuntimeException("Unable to scan package " + packageName, e);
}
return Arrays.stream(resources).filter(Resource::isReadable).map(resource -> {
try {
return getMetadataReaderFactory().getMetadataReader(resource);
} catch (IOException e) {
throw new RuntimeException("Unable to read resource " + resource, e);
}
});
}
use of org.springframework.core.io.support.ResourcePatternResolver in project tomee by apache.
the class SpringClasspathScanner method findResourcesInternal.
@Override
protected List<URL> findResourcesInternal(Collection<String> basePackages, String extension, ClassLoader loader) throws IOException {
final List<URL> resourceURLs = new ArrayList<>();
if (basePackages == null || basePackages.isEmpty()) {
return resourceURLs;
}
ResourcePatternResolver resolver = getResolver(loader);
for (final String basePackage : basePackages) {
final boolean scanAllPackages = basePackage.equals(WILDCARD);
String theBasePackage = basePackage;
if (theBasePackage.startsWith(CLASSPATH_URL_SCHEME)) {
theBasePackage = theBasePackage.substring(CLASSPATH_URL_SCHEME.length());
}
final String packageSearchPath = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + (scanAllPackages ? "" : basePackage.contains(WILDCARD) ? basePackage : ClassUtils.convertClassNameToResourcePath(theBasePackage)) + ALL_FILES + "." + extension;
final Resource[] resources = resolver.getResources(packageSearchPath);
for (final Resource resource : resources) {
resourceURLs.add(resource.getURL());
}
}
return resourceURLs;
}
Aggregations