use of org.springframework.core.io.support.PathMatchingResourcePatternResolver in project jeesuite-libs by vakinge.
the class SchedulerFactoryBeanWrapper method scanAndRegisterAnnotationJobs.
private void scanAndRegisterAnnotationJobs(String[] scanBasePackages) {
String RESOURCE_PATTERN = "/**/*.class";
ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver();
for (String scanBasePackage : scanBasePackages) {
logger.info(">>begin scan package [{}] with Annotation[ScheduleConf] jobs ", scanBasePackage);
try {
String pattern = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + ClassUtils.convertClassNameToResourcePath(scanBasePackage) + RESOURCE_PATTERN;
org.springframework.core.io.Resource[] resources = resourcePatternResolver.getResources(pattern);
MetadataReaderFactory readerFactory = new CachingMetadataReaderFactory(resourcePatternResolver);
for (org.springframework.core.io.Resource resource : resources) {
if (resource.isReadable()) {
MetadataReader reader = readerFactory.getMetadataReader(resource);
String className = reader.getClassMetadata().getClassName();
Class<?> clazz = Class.forName(className);
if (clazz.isAnnotationPresent(ScheduleConf.class)) {
ScheduleConf annotation = clazz.getAnnotation(ScheduleConf.class);
AbstractJob job = (AbstractJob) context.getBean(clazz);
job.setCronExpr(annotation.cronExpr());
job.setExecuteOnStarted(annotation.executeOnStarted());
job.setGroup(groupName);
job.setJobName(annotation.jobName());
job.setRetries(annotation.retries());
if (!schedulers.contains(job)) {
schedulers.add(job);
logger.info("register new job:{}", ToStringBuilder.reflectionToString(job, ToStringStyle.JSON_STYLE));
} else {
logger.info("Job[{}] is registered", job.getJobName());
}
}
}
}
logger.info("<<scan package[" + scanBasePackage + "] finished!");
} catch (Exception e) {
if (e instanceof org.springframework.beans.factory.NoSuchBeanDefinitionException) {
throw (org.springframework.beans.factory.NoSuchBeanDefinitionException) e;
}
logger.error("<<scan package[" + scanBasePackage + "] error", e);
}
}
}
use of org.springframework.core.io.support.PathMatchingResourcePatternResolver in project pigatron-web by pigatron-industries.
the class AdminResourceConfig method findWebResources.
public WebResources findWebResources(String path) throws IOException {
WebResources webResources = new WebResources();
ClassLoader cl = this.getClass().getClassLoader();
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(cl);
Resource[] resources = resolver.getResources("classpath*:/static/" + path + "/*.js");
for (Resource resource : resources) {
webResources.addResource(resource.getFilename(), WebResourceType.JS);
}
resources = resolver.getResources("classpath*:/static/" + path + "/*.css");
for (Resource resource : resources) {
webResources.addResource(resource.getFilename(), WebResourceType.CSS);
}
webResources.sort();
return webResources;
}
use of org.springframework.core.io.support.PathMatchingResourcePatternResolver 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.PathMatchingResourcePatternResolver in project web3sdk by FISCO-BCOS.
the class ChannelConnections method initSslContext.
private SslContext initSslContext() throws SSLException {
SslContext sslCtx;
try {
if (!isEnableOpenSSL()) {
String property = System.getProperty("jdk.tls.namedGroups", "");
if (property == null || "".equals(property)) {
System.setProperty("jdk.tls.namedGroups", "secp256k1");
logger.info("jdk.tls.namedGroups has not been set, property: {}", property);
} else if (!property.contains("secp256k1")) {
System.setProperty("jdk.tls.namedGroups", property + ",secp256k1");
logger.info("jdk.tls.namedGroups not including secp256k1 has been set, property: {}", property);
} else {
logger.info("jdk.tls.namedGroups including secp256k1 has been set, property: {}", property);
}
}
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
// check ssl cert file
Resource caResource = getCaCert();
Resource keystorecaResource = getSslCert();
Resource keystorekeyResource = getSslKey();
// check if ca.crt exist
if (Objects.isNull(caResource) || !caResource.exists()) {
Resource resource = resolver.getResource(CA_CERT);
if (Objects.nonNull(resource) && resource.exists()) {
caResource = resource;
} else {
throw new RuntimeException((Objects.nonNull(caResource) ? "ca.crt" : caResource.getFilename()) + " not exist ");
}
}
// check if sdk.crt exist, if not , check the default value node.crt
if (Objects.isNull(keystorecaResource) || !keystorecaResource.exists()) {
Resource resource = resolver.getResource(SSL_CERT);
if (Objects.nonNull(resource) && resource.exists()) {
keystorecaResource = resource;
} else {
throw new RuntimeException((Objects.nonNull(keystorecaResource) ? "sdk.crt" : keystorecaResource.getFilename()) + " not exist ");
}
}
// check if sdk.key exist, if not, check the default value sdk.key
if (Objects.isNull(keystorekeyResource) || !keystorekeyResource.exists()) {
Resource resource = resolver.getResource(SSL_KEY);
if (Objects.nonNull(resource) && resource.exists()) {
keystorekeyResource = resource;
} else {
throw new RuntimeException((Objects.nonNull(keystorekeyResource) ? "sdk.key" : keystorekeyResource.getFilename()) + " not exist ");
}
}
logger.info(" ca certificate: {}, sdk certificate: {}, sdk key: {}, enableOpenSsl: {}", caResource.getFilename(), keystorecaResource.getFilename(), keystorekeyResource.getFilename(), isEnableOpenSSL());
sslCtx = SslContextBuilder.forClient().trustManager(caResource.getInputStream()).keyManager(keystorecaResource.getInputStream(), keystorekeyResource.getInputStream()).sslProvider(isEnableOpenSSL() ? SslProvider.OPENSSL : SslProvider.JDK).build();
} catch (Exception e) {
logger.error(" Failed to initialize the SSLContext, e: {} ", e.getCause());
throw new SSLException(" Failed to initialize the SSLContext: " + e.getMessage());
}
return sslCtx;
}
use of org.springframework.core.io.support.PathMatchingResourcePatternResolver in project web3sdk by FISCO-BCOS.
the class ChannelConnections method initSMSslContext.
/**
* init sm ssl context object
*
* @return
* @throws IOException
*/
public SslContext initSMSslContext() throws IOException, InvalidKeySpecException, CertificateException, NoSuchAlgorithmException, NoSuchProviderException {
// The client's SM SSL certificate exists
if ((getGmCaCert() != null && getGmCaCert().exists()) || (getGmEnSslCert() != null && getGmEnSslCert().exists()) || (getGmEnSslKey() != null && getGmEnSslKey().exists()) || (getGmSslCert() != null && getGmSslCert().exists()) || (getGmSslKey() != null && getGmSslKey().exists())) {
return SMSslClientContextFactory.build(getGmCaCert().getInputStream(), getGmEnSslCert().getInputStream(), getGmEnSslKey().getInputStream(), getGmSslCert().getInputStream(), getGmSslKey().getInputStream());
}
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
Resource gmCaResource = resolver.getResource(GM_CA_CERT);
Resource gmSslResource = resolver.getResource(GM_SSL_CERT);
Resource gmSslKeyResource = resolver.getResource(GM_SSL_KEY);
Resource gmEnSslResource = resolver.getResource(GM_EN_SSL_CERT);
Resource gmEnSslKeyResource = resolver.getResource(GM_EN_SSL_KEY);
// The client's SM SSL default certificate exists
if (gmCaResource.exists() && gmSslResource.exists() && gmSslKeyResource.exists() && gmEnSslKeyResource.exists() && gmEnSslResource.exists()) {
logger.info(" build SM ssl context by default certificate configuration ");
return SMSslClientContextFactory.build(gmCaResource.getInputStream(), gmEnSslResource.getInputStream(), gmEnSslKeyResource.getInputStream(), gmSslResource.getInputStream(), gmSslKeyResource.getInputStream());
}
logger.info(" there is no SM ssl certificate configuration ");
// The client's SM SSL certificate not exists or not configured correctly
return initSslContext();
}
Aggregations