Search in sources :

Example 46 with ResourcePatternResolver

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();
}
Also used : NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) SocketChannel(io.netty.channel.socket.SocketChannel) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) InputStream(java.io.InputStream) Resource(org.springframework.core.io.Resource) KeyStore(java.security.KeyStore) EventLoopGroup(io.netty.channel.EventLoopGroup) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) IdleStateHandler(io.netty.handler.timeout.IdleStateHandler) ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) LengthFieldBasedFrameDecoder(io.netty.handler.codec.LengthFieldBasedFrameDecoder) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) SslContext(io.netty.handler.ssl.SslContext)

Example 47 with ResourcePatternResolver

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);
}
Also used : PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) Resource(org.springframework.core.io.Resource) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver)

Example 48 with ResourcePatternResolver

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);
    }
}
Also used : ServletContextResourcePatternResolver(org.springframework.web.context.support.ServletContextResourcePatternResolver) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) IOException(java.io.IOException)

Example 49 with ResourcePatternResolver

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);
        }
    });
}
Also used : PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) Resource(org.springframework.core.io.Resource) IOException(java.io.IOException) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver)

Example 50 with ResourcePatternResolver

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;
}
Also used : PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) ArrayList(java.util.ArrayList) Resource(org.springframework.core.io.Resource) URL(java.net.URL)

Aggregations

ResourcePatternResolver (org.springframework.core.io.support.ResourcePatternResolver)68 PathMatchingResourcePatternResolver (org.springframework.core.io.support.PathMatchingResourcePatternResolver)65 Resource (org.springframework.core.io.Resource)52 IOException (java.io.IOException)15 ArrayList (java.util.ArrayList)11 Bean (org.springframework.context.annotation.Bean)11 PageHelper (com.github.pagehelper.PageHelper)9 File (java.io.File)9 SqlSessionFactoryBean (org.mybatis.spring.SqlSessionFactoryBean)9 CachingMetadataReaderFactory (org.springframework.core.type.classreading.CachingMetadataReaderFactory)9 MetadataReader (org.springframework.core.type.classreading.MetadataReader)9 MetadataReaderFactory (org.springframework.core.type.classreading.MetadataReaderFactory)9 Properties (java.util.Properties)8 InputStream (java.io.InputStream)6 FileOutputStream (java.io.FileOutputStream)5 URL (java.net.URL)5 OpenClinicaSystemException (org.akaza.openclinica.exception.OpenClinicaSystemException)3 EventLoopGroup (io.netty.channel.EventLoopGroup)2 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)2 SocketChannel (io.netty.channel.socket.SocketChannel)2