Skip to Main Content

General Cloud Infrastructure

Announcement

For appeals, questions and feedback, please email oracle-forums_moderators_us@oracle.com

Error Uploading to OCI Object Storage - org.glassfish.hk2.api.UnsatisfiedDependencyException:

Suneet PathakFeb 7 2024

We are attempting to move from AWS to OCI. We are using Spring boot. I was able to upload files to AWS S3 without any issues. However, moving to OCI Object Storage I am encountering the following error. Would appreciate any help on this.

I used this example. https://medium.com/@rashidrizvi/how-to-upload-files-to-oci-object-storage-using-java-spring-boot-1941235f53b8

org.glassfish.hk2.api.MultiException: A MultiException has 1 exceptions.  They are:
1. org.glassfish.hk2.api.UnsatisfiedDependencyException: There was no object available for injection at SystemInjecteeImpl(requiredType=int,parent=DaemonClientAsyncExecutorProvider,qualifiers={@javax.inject.Named("ClientAsyncThreadPoolSize")},position=0,optional=false,self=false,unqualified=null,2072183845)

    at org.jvnet.hk2.internal.ThreeThirtyResolver.resolve(ThreeThirtyResolver.java:51)
    at org.jvnet.hk2.internal.Utilities.justCreate(Utilities.java:1055)
    at org.jvnet.hk2.internal.ServiceLocatorImpl.create(ServiceLocatorImpl.java:968)
    at org.jvnet.hk2.internal.ServiceLocatorImpl.createAndInitialize(ServiceLocatorImpl.java:1072)
    at org.jvnet.hk2.internal.ServiceLocatorImpl.createAndInitialize(ServiceLocatorImpl.java:1064)
    at org.glassfish.jersey.inject.hk2.AbstractHk2InjectionManager.createAndInitialize(AbstractHk2InjectionManager.java:189)
    at org.glassfish.jersey.inject.hk2.ImmediateHk2InjectionManager.createAndInitialize(ImmediateHk2InjectionManager.java:30)
    at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
    at java.base/java.util.HashMap$KeySpliterator.forEachRemaining(HashMap.java:1689)
    at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
    at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
    at java.base/java.util.stream.StreamSpliterators$WrappingSpliterator.forEachRemaining(StreamSpliterators.java:310)
    at java.base/java.util.stream.Streams$ConcatSpliterator.forEachRemaining(Streams.java:734)
    at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
    at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
    at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
    at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682)
    at org.glassfish.jersey.process.internal.AbstractExecutorProvidersConfigurator.registerExecutors(AbstractExecutorProvidersConfigurator.java:65)
    at org.glassfish.jersey.client.ClientExecutorProvidersConfigurator.init(ClientExecutorProvidersConfigurator.java:139)
    at org.glassfish.jersey.client.ClientConfig$State.initRuntime(ClientConfig.java:452)
    at org.glassfish.jersey.internal.util.collection.Values$LazyValueImpl.get(Values.java:317)
    at org.glassfish.jersey.client.ClientConfig.getRuntime(ClientConfig.java:814)
    at org.glassfish.jersey.client.ClientRequest.getConfiguration(ClientRequest.java:263)
    at org.glassfish.jersey.client.JerseyInvocation.validateHttpMethodAndEntity(JerseyInvocation.java:121)
    at org.glassfish.jersey.client.JerseyInvocation.<init>(JerseyInvocation.java:90)
    at org.glassfish.jersey.client.JerseyInvocation.<init>(JerseyInvocation.java:86)
    at org.glassfish.jersey.client.JerseyInvocation.<init>(JerseyInvocation.java:77)
    at org.glassfish.jersey.client.JerseyInvocation$AsyncInvoker.method(JerseyInvocation.java:578)
    at org.glassfish.jersey.client.JerseyCompletionStageRxInvoker.method(JerseyCompletionStageRxInvoker.java:31)
    at com.oracle.bmc.http.client.jersey.JerseyHttpRequest.execute(JerseyHttpRequest.java:239)
    at com.oracle.bmc.http.internal.ClientCall.callAsyncImpl(ClientCall.java:959)
    at com.oracle.bmc.http.internal.ClientCall.callAsyncTokenRefresh(ClientCall.java:902)
    at com.oracle.bmc.retrier.BmcGenericRetrier.doFunctionCall(BmcGenericRetrier.java:175)
    at com.oracle.bmc.retrier.BmcGenericRetrier.doFunctionCallAsync(BmcGenericRetrier.java:181)
    at com.oracle.bmc.retrier.BmcGenericRetrier.lambda$executeAsync$3(BmcGenericRetrier.java:119)
    at com.oracle.bmc.waiter.GenericWaiter.executeAsync(GenericWaiter.java:109)
    at com.oracle.bmc.waiter.GenericWaiter.executeAsync(GenericWaiter.java:98)
    at com.oracle.bmc.retrier.BmcGenericRetrier.executeAsync(BmcGenericRetrier.java:112)
    at com.oracle.bmc.http.internal.ClientCall.callAsyncWithRetrier(ClientCall.java:892)
    at com.oracle.bmc.http.internal.ClientCall.callAsync0(ClientCall.java:839)
    at com.oracle.bmc.http.internal.ClientCall.callSync(ClientCall.java:1032)
    at com.oracle.bmc.objectstorage.ObjectStorageClient.putObject(ObjectStorageClient.java:1745)



My OsClientConfiguration class looks like this:


@Configuration
public class OsClientConfiguration {
    // Path to OCI ociconfig file
    String configurationFilePath = "ociconfig";
    String profile = "DEFAULT";

    public ObjectStorage getObjectStorage() throws IOException{
        //load ociconfig file

        final ConfigFileReader.ConfigFile configFile = ConfigFileReader.parse(configurationFilePath, profile);

        final ConfigFileAuthenticationDetailsProvider provider =
                new ConfigFileAuthenticationDetailsProvider(configFile);

        //build and return client
        return ObjectStorageClient.builder()
                .build(provider);
    }
}

My service class looks like this:



@Autowired
    private OsClientConfiguration configuration;
    @Override
    public void upload(String path,`your text`
                       String fileName,
                       Optional<Map<String, String>> optionalMetaData,
                       InputStream inputStream) throws Exception {

        PutObjectRequest putObjectRequest =
                PutObjectRequest.builder()
                        .namespaceName(namespaceName)
                        .bucketName(path)
                        .objectName(fileName)
                        .contentType(optionalMetaData.get().get("Content-Type"))
                        .contentLength(Long.valueOf(optionalMetaData.get().get("Content-Length")))
                        .putObjectBody(inputStream)
                        .build();

        try {
                configuration.getObjectStorage().putObject(putObjectRequest);
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }finally{
            try {
                configuration.getObjectStorage().close();
                inputStream.close();
            } catch (Exception e) {
                throw new IllegalStateException("Upload. Failed to close OCI Object Storage Connection", e);
            }
        }
    }

My Dependencies are here

implementation 'com.oracle.oci.sdk:oci-java-sdk-addons-resteasy- client-configurator:3.1.0'
implementation 'com.oracle.oci.sdk:oci-java-sdk- objectstorage:3.1.0'
implementation 'com.oracle.oci.sdk:oci-java-sdk-bom:3.1.0'
implementation 'com.oracle.oci.sdk:oci-java-sdk-common- httpclient-jersey:3.1.0'
Comments
Post Details
Added on Feb 7 2024
1 comment
78 views