1 year ago

#118201

test-img

shubham

Why does java Spring return no such method exception for aws sdk while initializing the awsS3Client

I'm trying to upload dynamic objects into the s3 bucket in my web application. But struggling with no such method error during initializing the AWS3Client. Initially, the input is a multipart image saving it into a local machine and then using it for uploading it into the s3 bucket. During uploading the No such method exception occurs as shown in the first image. Exception snapshot during client initialization

Also, specified the amazon dependency used into pom in the second picture. pom-Amazon_dependency

following is the code used for initiating s3client into the application.

Map<String, String> s3Credentials = ((FSRepositoryServiceImpl) fsRepositoryService).getS3Credentials();
AmazonS3 s3 = AmazonS3ClientBuilder.standard().withRegion(Regions.AP_SOUTH_1).withCredentials(
                new AWSStaticCredentialsProvider(new BasicAWSCredentials(s3Credentials.get("accessKeyId"),
                        s3Credentials.get("secretAccessKey"))))
                .build();

Here are some more details about the issue Pom dependency

<dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.4.3</version>
    </dependency>

    <dependency>
        <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-core-asl</artifactId>
        <version>1.9.13</version>
    </dependency>

    <dependency>
        <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-mapper-asl</artifactId>
        <version>1.9.13</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core -->
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-core</artifactId>
        <version>2.13.1</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk-s3 -->
    <dependency>
        <groupId>com.amazonaws</groupId>
        <artifactId>aws-java-sdk-s3</artifactId>
        <version>1.12.150</version>
    </dependency>

Code to upload object into s3 bucket:

            //Save temporary document in file format for uploading to s3
        Map<String, String> s3ObjectDetails = fsRepositoryService.saveTempDocumentforS3Reference(
                basePatientDocumentsRepoPath, docContents, ext, originalImgFileName);

        //Credentials for aws account
        Map<String, String> s3Credentials = ((FSRepositoryServiceImpl) fsRepositoryService).getS3Credentials();

        AmazonS3 s3 = AmazonS3ClientBuilder.standard().withRegion(Regions.AP_SOUTH_1).withCredentials(
                new AWSStaticCredentialsProvider(new BasicAWSCredentials(s3Credentials.get(<accessKeyId>),
                        s3Credentials.get(<secretAccessKey>))))
                .build();

        //bucket details on the aws cloud
        Map<String, String> bucketDetails = ((FSRepositoryServiceImpl) fsRepositoryService).getBucketDetails(
                /* used this for dynamic key name for bucket */s3ObjectDetails.get(<document Name>));

        String uploadingPath = bucketDetails.get(<filePath>) + "/" + patientId + "/";
        uploadingPath = uploadingPath.replace("//", "/");

        String fileToUpload = s3ObjectDetails.get(<Pathofthedocument>);
        PutObjectRequest objectRequest = new PutObjectRequest(bucketDetails.get(bucket),
                uploadingPath + bucketDetails.get(<key>), <fileToUpload>);

        ObjectMetadata metadata = new ObjectMetadata();
        metadata.setContentType("plain/text");
        metadata.addUserMetadata(<key Name>, bucketDetails.get(key));
        objectRequest.setMetadata(metadata);
        PutObjectResult uploadImagetoS3 = s3.putObject(objectRequest);

Error statement:

02:54,190 INFO : Saving Doc 5f5ab725-0403-4554-b62c-674130c9a8f2-1643628704942 under: /data/ihealwell/patients/ImagePrescription/20808/ Jan 31, 2022 5:07:27 PM org.apache.catalina.core.StandardWrapperValve invoke SEVERE: Servlet.service() for servlet [api-dispatcher] in context with path [/IHW] threw exception [Handler processing failed; nested exception is java.lang.NoSuchMethodError: com.fasterxml.jackson.databind.ObjectMapper.enable([Lcom/fasterxml/jackson/core/JsonParser$Feature;)Lcom/fasterxml/jackson/databind/ObjectMapper;] with root cause java.lang.NoSuchMethodError: com.fasterxml.jackson.databind.ObjectMapper.enable([Lcom/fasterxml/jackson/core/JsonParser$Feature;)Lcom/fasterxml/jackson/databind/ObjectMapper; at com.amazonaws.partitions.PartitionsLoader.(PartitionsLoader.java:54) at com.amazonaws.regions.RegionMetadataFactory.create(RegionMetadataFactory.java:30) at com.amazonaws.regions.RegionUtils.initialize(RegionUtils.java:64) at com.amazonaws.regions.RegionUtils.getRegionMetadata(RegionUtils.java:52) at com.amazonaws.regions.RegionUtils.getRegion(RegionUtils.java:106) at com.amazonaws.client.builder.AwsClientBuilder.getRegionObject(AwsClientBuilder.java:256) at com.amazonaws.client.builder.AwsClientBuilder.withRegion(AwsClientBuilder.java:245) at com.amazonaws.client.builder.AwsClientBuilder.withRegion(AwsClientBuilder.java:232) at com.indohealth.ihealwell.web.rest.controller.PatientResourceController.saveOnS3Resource(PatientResourceController.java:1932) at com.indohealth.ihealwell.web.rest.controller.PatientResourceController.saveDocumentOnGlobalResource(PatientResourceController.java:1891) at com.indohealth.ihealwell.web.rest.controller.DocumentResourceController.updateDocumentbyPatient(DocumentResourceController.java:288) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566)

spring

amazon-web-services

amazon-s3

file-upload

multipartfile

0 Answers

Your Answer

Accepted video resources