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

Handle redirect http status code #1056

Merged

Conversation

balamurugana
Copy link
Member

@balamurugana balamurugana commented Sep 9, 2020

No description provided.

@sinhaashish
Copy link
Contributor

Ran

import io.minio.BucketExistsArgs;
import io.minio.MinioClient;
import io.minio.errors.MinioException;
import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
public class BucketExists {
  /** MinioClient.bucketExists() example. */
  public static void main(String[] args)
    throws IOException, NoSuchAlgorithmException, InvalidKeyException {
    try {
      /* Amazon S3: */
      MinioClient minioClient =
        MinioClient.builder()
          .endpoint("https://s3.amazonaws.com")
          .credentials("***", "***")
          .region("us-east-2")
          .build();
      // Check whether 'my-bucketname' exist or not.
      minioClient.traceOn(System.out);
      boolean found =
        minioClient.bucketExists(BucketExistsArgs.builder().bucket("kannappan300").build());
      if (found) {
        System.out.println("my-bucketname exists");
      } else {
        System.out.println("my-bucketname does not exist");
      }
    } catch (MinioException e) {
      System.out.println("Error occurred: " + e);
    }
  }
}

Got

/usr/lib/jvm/jdk1.8.0_212/bin/java -javaagent:/opt/idea-IC-191.6183.87/lib/idea_rt.jar=33769:/opt/idea-IC-191.6183.87/bin -Dfile.encoding=UTF-8 -classpath /usr/lib/jvm/jdk1.8.0_212/jre/lib/charsets.jar:/usr/lib/jvm/jdk1.8.0_212/jre/lib/deploy.jar:/usr/lib/jvm/jdk1.8.0_212/jre/lib/ext/cldrdata.jar:/usr/lib/jvm/jdk1.8.0_212/jre/lib/ext/dnsns.jar:/usr/lib/jvm/jdk1.8.0_212/jre/lib/ext/jaccess.jar:/usr/lib/jvm/jdk1.8.0_212/jre/lib/ext/jfxrt.jar:/usr/lib/jvm/jdk1.8.0_212/jre/lib/ext/localedata.jar:/usr/lib/jvm/jdk1.8.0_212/jre/lib/ext/nashorn.jar:/usr/lib/jvm/jdk1.8.0_212/jre/lib/ext/sunec.jar:/usr/lib/jvm/jdk1.8.0_212/jre/lib/ext/sunjce_provider.jar:/usr/lib/jvm/jdk1.8.0_212/jre/lib/ext/sunpkcs11.jar:/usr/lib/jvm/jdk1.8.0_212/jre/lib/ext/zipfs.jar:/usr/lib/jvm/jdk1.8.0_212/jre/lib/javaws.jar:/usr/lib/jvm/jdk1.8.0_212/jre/lib/jce.jar:/usr/lib/jvm/jdk1.8.0_212/jre/lib/jfr.jar:/usr/lib/jvm/jdk1.8.0_212/jre/lib/jfxswt.jar:/usr/lib/jvm/jdk1.8.0_212/jre/lib/jsse.jar:/usr/lib/jvm/jdk1.8.0_212/jre/lib/management-agent.jar:/usr/lib/jvm/jdk1.8.0_212/jre/lib/plugin.jar:/usr/lib/jvm/jdk1.8.0_212/jre/lib/resources.jar:/usr/lib/jvm/jdk1.8.0_212/jre/lib/rt.jar:/home/ashish/code/go/src/github.com/minio/minio-java/api/build/libs/minio-7.1.3-DEV-all.jar:/home/ashish/client/target/classes BucketExists
---------START-HTTP---------
HEAD / HTTP/1.1
Host: kannappan300.s3.us-east-2.amazonaws.com
Accept-Encoding: identity
User-Agent: MinIO (amd64; amd64) minio-java/7.1.3-DEV
x-amz-content-sha256: UNSIGNED-PAYLOAD
x-amz-date: 20200914T101855Z
Authorization: AWS4-HMAC-SHA256 Credential=*REDACTED*/20200914/us-east-2/s3/aws4_request, SignedHeaders=accept-encoding;host;x-amz-content-sha256;x-amz-date, Signature=*REDACTED*

HTTP/1.1 301
x-amz-bucket-region: us-east-1
x-amz-request-id: E9FD0D607B0C02A8
x-amz-id-2: IWP8XQsVaZlSjr3RCWug34fM4SlKPYu/OHdh0X4Tczy5Hm84UFiigJHkib/pgOmbHsk26KI2x40=
Content-Type: application/xml
Transfer-Encoding: chunked
Date: Mon, 14 Sep 2020 10:18:56 GMT
Server: AmazonS3

----------END-HTTP----------
Error occurred: error occurred
ErrorResponse(code = PermanentRedirect, message = Moved Permanently. Use region us-east-1, bucketName = kannappan300, objectName = null, resource = /, requestId = E9FD0D607B0C02A8, hostId = IWP8XQsVaZlSjr3RCWug34fM4SlKPYu/OHdh0X4Tczy5Hm84UFiigJHkib/pgOmbHsk26KI2x40=)
request={method=HEAD, url=https://kannappan300.s3.us-east-2.amazonaws.com/, headers=Host: kannappan300.s3.us-east-2.amazonaws.com
Accept-Encoding: identity
User-Agent: MinIO (amd64; amd64) minio-java/7.1.3-DEV
x-amz-content-sha256: UNSIGNED-PAYLOAD
x-amz-date: 20200914T101855Z
Authorization: AWS4-HMAC-SHA256 Credential=*REDACTED*/20200914/us-east-2/s3/aws4_request, SignedHeaders=accept-encoding;host;x-amz-content-sha256;x-amz-date, Signature=*REDACTED*
}
response={code=301, headers=x-amz-bucket-region: us-east-1
x-amz-request-id: E9FD0D607B0C02A8
x-amz-id-2: IWP8XQsVaZlSjr3RCWug34fM4SlKPYu/OHdh0X4Tczy5Hm84UFiigJHkib/pgOmbHsk26KI2x40=
Content-Type: application/xml
Transfer-Encoding: chunked
Date: Mon, 14 Sep 2020 10:18:56 GMT
Server: AmazonS3
}

Copy link
Contributor

@sinhaashish sinhaashish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested & LGTM

Copy link
Contributor

@kannappanr kannappanr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

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

Successfully merging this pull request may close these issues.

3 participants