Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minio Cannot list Objects in a bucket using JAVA SDK Client, getting error Non-XML response from server. Response code: 403 #1631

Closed
harshit149 opened this issue Mar 20, 2025 · 12 comments

Comments

@harshit149
Copy link

I am trying to access objects of a bucket via Minio JAVA SdK Client and I am getting following error
io.minio.errors.InvalidResponseException: Non-XML response from server. Response code: 403, Content-Type: text/xml; charset=utf-8, body:

This is my code snippet
// Lists objects information.
            Iterable<Result<Item>> results = minioClient.listObjects(
                    ListObjectsArgs.builder().bucket("bucket-name").build());
            for(Result<Item> result : results) {
                Item item = result.get();
                System.out.println("Object:"+ item.objectName());
            }

What after debugging I am suspecting is URL is not formed correctly by SDK and there is forward slash miss after bucket name in URL.

@lexakimov
Copy link

lexakimov commented Mar 20, 2025

Hi. I have the same "Non-XML response from server" error. We use our own S3 implementation, the problem is in the content-type header. Our server returns Content-Type: text/xml; charset=utf-8 but the client expects Content-Type: application/xml:
In my case, error happens here:

https://github.com/minio/minio-java/blob/master/api/src/main/java/io/minio/S3Base.java#L693

                String contentType = response.headers().get("content-type");
                if (!method.equals(Method.HEAD)
                    && (contentType == null
                        || !Arrays.asList(contentType.split(";")).contains("application/xml"))) {
                  if (response.code() == 304 && response.body().contentLength() == 0) {
                    completableFuture.completeExceptionally(
                        new ServerException(

BTW https://docs.aws.amazon.com/AmazonS3/latest/API/ErrorResponses.html#RESTErrorResponses says:

Content-Type: application/xml

@harshit149
Copy link
Author

@lexakimov do you know if there is any stable version where this still works?

@balamurugana
Copy link
Member

As per the S3 specification, any failed call should return Error XML. minio-java returns Non-XML response if the server violates the spec. Few things you need to check

  1. Check your server is returning proper Error XML
  2. Check your proxy if you use
  3. Check you are using correct port to connect to S3 server.

@lexakimov
Copy link

@harshit149 no, I've made a workaround for now by handling the InvalidResponseException. The developers of our S3 storage have confirmed that the error is on their side (wrong header), not in client.

@lexakimov
Copy link

lexakimov commented Mar 20, 2025

@balamurugana it returns valid xml, but header Content-Type is wrong (client expects application/xml )

---------START-HTTP---------
GET ***** HTTP/1.1
Host: *****
Accept-Encoding: identity
User-Agent: MinIO (Linux; amd64) minio-java/8.5.17
Content-MD5: 1B2M2Y8AsgTpgAmY7PhCfg==
x-amz-content-sha256: UNSIGNED-PAYLOAD
x-amz-date: 20250320T072856Z
Authorization: ██

HTTP/1.1 404
Date: Thu, 20 Mar 2025 07:28:57 GMT
Content-Length: 135
Content-Type: text/xml; charset=utf-8

<?xml version="1.0" encoding="UTF-8"?>
<Error>
  <Code>NoSuchKey</Code>
  <Message>The specified key does not exist.</Message>
</Error>
----------END-HTTP----------

@harshit149
Copy link
Author

Thank you for detailed response and findings.
@lexakimov how can I fix this at server side?

@gyanicit
Copy link

gyanicit commented Mar 20, 2025

I have issue similar to @harshit149 the actual cause is how the URL is being constructed.

URL Constructed by MinIO Client: https://abc.com/myBucket?list-type=2&prefix=t&max-keys=1000&encoding-type=url&delimiter=/

@balamurugana this URL is invalid for me even I am not able to make call via Postman, but after a small tweek I am able to make call on same url via postman.

tweeked URL: https://abc.com/myBucket/?list-type=2&prefix=t&max-keys=1000&encoding-type=url&delimiter=

For better understanding what I did is added slash after bucket name like this "myBucket/". I am not sure in the MinIO URL if you observe the slash is being added but at the very last just after delimiter like this "delimiter=/"

I have created client and the code to access files inside bucket like below

// 1. Create MinIO Client
            MinioClient minioClient = MinioClient.builder()
                    .endpoint("https://abc.com") // Change to your MinIO server
                    .credentials("accessKey", "secretKey") // Use your credentials
                    .region("us-east-1")
                    .build();


Iterable<Result<Item>> results = minioClient.listObjects(
                    ListObjectsArgs.builder()
                            .bucket("myBucket")
                            .maxKeys(1000)
                            .prefix("t")
                            .recursive(true)
                            .build());
            for (Result<Item> result : results) {
                Item item = result.get();
                System.out.println(item.objectName());
            }

@lexakimov
Copy link

lexakimov commented Mar 20, 2025

@harshit149 in my case it was necessary to catch the "no such key found"

before fix i did it this way:

e is ErrorResponseException && e.errorResponse().code().equals("NoSuchKey")

as temporary workaround i added another condition:

e is InvalidResponseException && (e.message?.contains("NoSuchKey") == true || e.httpTrace().contains("NoSuchKey")

@balamurugana
Copy link
Member

@balamurugana it returns valid xml, but header Content-Type is wrong (client expects application/xml )

---------START-HTTP---------
GET ***** HTTP/1.1
Host: *****
Accept-Encoding: identity
User-Agent: MinIO (Linux; amd64) minio-java/8.5.17
Content-MD5: 1B2M2Y8AsgTpgAmY7PhCfg==
x-amz-content-sha256: UNSIGNED-PAYLOAD
x-amz-date: 20250320T072856Z
Authorization: ██

HTTP/1.1 404
Date: Thu, 20 Mar 2025 07:28:57 GMT
Content-Length: 135
Content-Type: text/xml; charset=utf-8

<?xml version="1.0" encoding="UTF-8"?>
<Error>
  <Code>NoSuchKey</Code>
  <Message>The specified key does not exist.</Message>
</Error>
----------END-HTTP----------

@lexakimov It is server side problem. What object storage service are you using?

@balamurugana
Copy link
Member

I have issue similar to @harshit149 the actual cause is how the URL is being constructed.

URL Constructed by MinIO Client: https://abc.com/myBucket?list-type=2&prefix=t&max-keys=1000&encoding-type=url&delimiter=/

@balamurugana this URL is invalid for me even I am not able to make call via Postman, but after a small tweek I am able to make call on same url via postman.

tweeked URL: https://abc.com/myBucket/?list-type=2&prefix=t&max-keys=1000&encoding-type=url&delimiter=

For better understanding what I did is added slash after bucket name like this "myBucket/". I am not sure in the MinIO URL if you observe the slash is being added but at the very last just after delimiter like this "delimiter=/"

I have created client and the code to access files inside bucket like below

// 1. Create MinIO Client
            MinioClient minioClient = MinioClient.builder()
                    .endpoint("https://abc.com") // Change to your MinIO server
                    .credentials("accessKey", "secretKey") // Use your credentials
                    .region("us-east-1")
                    .build();


Iterable<Result<Item>> results = minioClient.listObjects(
                    ListObjectsArgs.builder()
                            .bucket("myBucket")
                            .maxKeys(1000)
                            .prefix("t")
                            .recursive(true)
                            .build());
            for (Result<Item> result : results) {
                Item item = result.get();
                System.out.println(item.objectName());
            }

@gyanicit This is server side issue. There is no need to add /. What is your server?

@harshit149
Copy link
Author

@balamurugana in my case we are using minio object storage service, how can we fix this?

@balamurugana
Copy link
Member

@balamurugana in my case we are using minio object storage service, how can we fix this?

Share your MinIO server detail

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants