protected ApiMetadata createApiMetadata() {
return null;
}
protected Injector createInjector(Function<HttpRequest, HttpResponse> fn, Module module, Properties props) {
ContextBuilder builder = null;
if (provider != null)
try {
builder = ContextBuilder.newBuilder(provider).credentials(identity, credential);
} catch (NoSuchElementException e) {
Logger
.getAnonymousLogger()
.warning(
"provider ["
+ provider
+ "] is not setup as META-INF/services/org.jclouds.apis.ApiMetadata or META-INF/services/org.jclouds.providers.ProviderMetadata");
}
if (builder == null) {
ProviderMetadata pm = createProviderMetadata();
ApiMetadata am = (pm != null) ? pm.getApiMetadata() : checkNotNull(createApiMetadata(),
"either createApiMetadata or createProviderMetadata must be overridden");
builder = pm != null ? ContextBuilder.newBuilder(pm) : ContextBuilder.newBuilder(am);
}
ApiMetadata am = builder.getApiMetadata();
if (am instanceof HttpApiMetadata) {
this.api = HttpApiMetadata.class.cast(am).getApi();
} else if (am instanceof org.jclouds.rest.RestApiMetadata) {
this.api = org.jclouds.rest.RestApiMetadata.class.cast(am).getApi();
} else {
throw new UnsupportedOperationException("unsupported base type: " + am);
}
// isolate tests from eachother, as default credentialStore is static
return builder.credentials(identity, credential).modules(
ImmutableSet.of(new ExpectModule(fn), new NullLoggingModule(), new CredentialStoreModule(new CopyInputStreamInputSupplierMap(
new ConcurrentHashMap<String, InputSupplier<InputStream>>())), module)).overrides(props)
.buildInjector();
}