Search in sources :

Example 1 with StorageClient

use of com.workoss.boot.storage.client.StorageClient in project boot by workoss.

the class StorageServiceFilter method sign.

private void sign(String clientKey, String key, String mimeType, String successActionStatus, HttpServletResponse response) {
    try {
        StorageClient storageClient = null;
        if (StringUtils.isBlank(clientKey)) {
            storageClient = storageTemplate.client();
        } else {
            storageClient = storageTemplate.client(clientKey);
        }
        StorageSignature storageSignature = storageClient.generateWebUploadSign(key, mimeType, successActionStatus);
        writeResponse(response, 200, objectMapper.writeValueAsString(storageSignature));
    } catch (Exception e) {
        String resp = "{\"errcode\":\"-1\",\"errmsg\":\"" + (e.getMessage() != null ? e.getMessage() : "Storage error") + "\"}";
        writeResponse(response, 500, resp);
    }
}
Also used : StorageClient(com.workoss.boot.storage.client.StorageClient) StorageSignature(com.workoss.boot.storage.model.StorageSignature) IOException(java.io.IOException)

Example 2 with StorageClient

use of com.workoss.boot.storage.client.StorageClient in project boot by workoss.

the class BaseStorageTemplate method loadStorageClient.

Map<StorageType, StorageClient> loadStorageClient() {
    ServiceLoader<StorageClient> serviceLoader = ServiceLoader.load(StorageClient.class, this.getClass().getClassLoader());
    Iterator<StorageClient> storageClientIterator = serviceLoader.iterator();
    Map<StorageType, StorageClient> storageClientMap = new HashMap<>(16);
    while (storageClientIterator.hasNext()) {
        StorageClient storageClient = storageClientIterator.next();
        storageClientMap.put(storageClient.type(), storageClient);
    }
    return storageClientMap;
}
Also used : StorageType(com.workoss.boot.storage.model.StorageType) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) StorageClient(com.workoss.boot.storage.client.StorageClient)

Example 3 with StorageClient

use of com.workoss.boot.storage.client.StorageClient in project boot by workoss.

the class BaseStorageTemplate method afterPropertiesSet.

public void afterPropertiesSet() throws Exception {
    Map<StorageType, StorageClient> storageClientMap = loadStorageClient();
    Map<StorageType, Integer> initNumMap = new HashMap<StorageType, Integer>(4);
    if (multiStorageClientConfig != null && multiStorageClientConfig.isEnabled()) {
        log.info("【storage】multiStorageClientConfig init start");
        Optional.ofNullable(multiStorageClientConfig.getClientConfigs()).orElse(new HashMap<>(16)).entrySet().stream().filter(storageClientConfigEntry -> storageClientMap.containsKey(storageClientConfigEntry.getValue().getStorageType())).forEach(storageClientConfigEntry -> {
            Integer num = initNumMap.get(storageClientConfigEntry.getValue().getStorageType());
            if (num == null) {
                addStorageClient(storageClientMap.get(storageClientConfigEntry.getValue().getStorageType()), storageClientConfigEntry.getKey(), storageClientConfigEntry.getValue());
            } else {
                addStorageClient(loadStorageClient().get(storageClientConfigEntry.getValue().getStorageType()), storageClientConfigEntry.getKey(), storageClientConfigEntry.getValue());
            }
            initNumMap.put(storageClientConfigEntry.getValue().getStorageType(), num == null ? 1 : num + 1);
        });
    }
    StorageClientConfig storageClientConfig = multiStorageClientConfig.getDefaultClient();
    if (storageClientConfig != null) {
        Map<StorageType, StorageClient> defaultClientMap = storageClientMap;
        if (initNumMap.containsKey(storageClientConfig.getStorageType())) {
            defaultClientMap = loadStorageClient();
        }
        addStorageClient(defaultClientMap.get(storageClientConfig.getStorageType()), "default", storageClientConfig);
    }
    initNumMap.clear();
}
Also used : StorageType(com.workoss.boot.storage.model.StorageType) java.util(java.util) Logger(org.slf4j.Logger) NonNull(com.workoss.boot.annotation.lang.NonNull) MultiStorageClientConfig(com.workoss.boot.storage.config.MultiStorageClientConfig) StorageClient(com.workoss.boot.storage.client.StorageClient) StorageClientConfig(com.workoss.boot.storage.config.StorageClientConfig) LoggerFactory(org.slf4j.LoggerFactory) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) StorageException(com.workoss.boot.storage.exception.StorageException) StringUtils(com.workoss.boot.util.StringUtils) StorageClientNotFoundException(com.workoss.boot.storage.exception.StorageClientNotFoundException) StorageType(com.workoss.boot.storage.model.StorageType) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) StorageClient(com.workoss.boot.storage.client.StorageClient) MultiStorageClientConfig(com.workoss.boot.storage.config.MultiStorageClientConfig) StorageClientConfig(com.workoss.boot.storage.config.StorageClientConfig)

Aggregations

StorageClient (com.workoss.boot.storage.client.StorageClient)3 StorageType (com.workoss.boot.storage.model.StorageType)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 NonNull (com.workoss.boot.annotation.lang.NonNull)1 MultiStorageClientConfig (com.workoss.boot.storage.config.MultiStorageClientConfig)1 StorageClientConfig (com.workoss.boot.storage.config.StorageClientConfig)1 StorageClientNotFoundException (com.workoss.boot.storage.exception.StorageClientNotFoundException)1 StorageException (com.workoss.boot.storage.exception.StorageException)1 StorageSignature (com.workoss.boot.storage.model.StorageSignature)1 StringUtils (com.workoss.boot.util.StringUtils)1 IOException (java.io.IOException)1 java.util (java.util)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1