Skip to content

Commit 57d6852

Browse files
change creation of BlobStoreContext
1 parent 518e5e9 commit 57d6852

File tree

1 file changed

+24
-17
lines changed

1 file changed

+24
-17
lines changed

multiapps-controller-web/src/main/java/org/cloudfoundry/multiapps/controller/web/configuration/bean/factory/ObjectStoreFileStorageFactoryBean.java

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
package org.cloudfoundry.multiapps.controller.web.configuration.bean.factory;
22

3+
import java.text.MessageFormat;
4+
import java.util.Collections;
5+
import java.util.HashMap;
6+
import java.util.List;
7+
import java.util.Map;
8+
39
import io.pivotal.cfenv.core.CfService;
410
import org.apache.commons.lang3.StringUtils;
511
import org.cloudfoundry.multiapps.controller.core.util.UriUtil;
@@ -15,12 +21,6 @@
1521
import org.springframework.beans.factory.FactoryBean;
1622
import org.springframework.beans.factory.InitializingBean;
1723

18-
import java.text.MessageFormat;
19-
import java.util.Collections;
20-
import java.util.HashMap;
21-
import java.util.List;
22-
import java.util.Map;
23-
2424
public class ObjectStoreFileStorageFactoryBean implements FactoryBean<ObjectStoreFileStorage>, InitializingBean {
2525

2626
private static final Logger LOGGER = LoggerFactory.getLogger(ObjectStoreFileStorageFactoryBean.class);
@@ -44,26 +44,25 @@ private ObjectStoreFileStorage createObjectStoreFileStorage() {
4444
if (providersServiceInfo.isEmpty()) {
4545
return null;
4646
}
47+
4748
Map<String, Exception> exceptions = new HashMap<>();
49+
4850
for (ObjectStoreServiceInfo objectStoreServiceInfo : providersServiceInfo) {
49-
BlobStoreContext context = getBlobStoreContext(objectStoreServiceInfo);
50-
if (context == null) {
51-
exceptions.put(objectStoreServiceInfo.getProvider(),
52-
new IllegalArgumentException(Messages.MISSING_PROPERTIES_FOR_CREATING_THE_SPECIFIC_PROVIDER));
53-
continue;
54-
}
55-
ObjectStoreFileStorage fileStorage = createFileStorage(objectStoreServiceInfo, context);
5651
try {
52+
BlobStoreContext context = getBlobStoreContext(objectStoreServiceInfo);
53+
ObjectStoreFileStorage fileStorage = createFileStorage(objectStoreServiceInfo, context);
5754
fileStorage.testConnection();
5855
LOGGER.info(MessageFormat.format(Messages.OBJECT_STORE_WITH_PROVIDER_0_CREATED, objectStoreServiceInfo.getProvider()));
5956
return fileStorage;
6057
} catch (Exception e) {
6158
exceptions.put(objectStoreServiceInfo.getProvider(), e);
6259
}
6360
}
61+
6462
exceptions.forEach(
65-
(provider, exception) -> LOGGER.error(MessageFormat.format(Messages.CANNOT_CREATE_OBJECT_STORE_CLIENT_WITH_PROVIDER_0, provider),
66-
exception));
63+
(provider, exception) -> LOGGER.error(
64+
MessageFormat.format(Messages.CANNOT_CREATE_OBJECT_STORE_CLIENT_WITH_PROVIDER_0, provider),
65+
exception));
6766
throw new IllegalStateException(Messages.NO_VALID_OBJECT_STORE_CONFIGURATION_FOUND);
6867
}
6968

@@ -77,15 +76,23 @@ private List<ObjectStoreServiceInfo> getProvidersServiceInfo() {
7776

7877
private BlobStoreContext getBlobStoreContext(ObjectStoreServiceInfo serviceInfo) {
7978
ContextBuilder contextBuilder = ContextBuilder.newBuilder(serviceInfo.getProvider());
79+
8080
if (serviceInfo.getCredentialsSupplier() != null) {
8181
contextBuilder.credentialsSupplier(serviceInfo.getCredentialsSupplier());
8282
} else if (serviceInfo.getIdentity() != null && serviceInfo.getCredential() != null) {
8383
contextBuilder.credentials(serviceInfo.getIdentity(), serviceInfo.getCredential());
8484
} else {
85-
return null;
85+
throw new IllegalArgumentException(Messages.MISSING_PROPERTIES_FOR_CREATING_THE_SPECIFIC_PROVIDER);
8686
}
87+
8788
resolveContextEndpoint(serviceInfo, contextBuilder);
88-
return contextBuilder.buildView(BlobStoreContext.class);
89+
90+
try {
91+
return contextBuilder.buildView(BlobStoreContext.class);
92+
} catch (NullPointerException nullPointerException) {
93+
throw new IllegalArgumentException("JClouds failed to build BlobStoreContext. Possible missing credentials.",
94+
nullPointerException);
95+
}
8996
}
9097

9198
private void resolveContextEndpoint(ObjectStoreServiceInfo serviceInfo, ContextBuilder contextBuilder) {

0 commit comments

Comments
 (0)