diff --git a/api/src/main/java/io/minio/ErrorCode.java b/api/src/main/java/io/minio/ErrorCode.java index 00caa2142..4515136ab 100644 --- a/api/src/main/java/io/minio/ErrorCode.java +++ b/api/src/main/java/io/minio/ErrorCode.java @@ -16,10 +16,18 @@ package io.minio; +import org.simpleframework.xml.convert.Convert; +import org.simpleframework.xml.convert.Converter; +import org.simpleframework.xml.stream.InputNode; +import org.simpleframework.xml.stream.OutputNode; +import org.simpleframework.xml.Root; + /** * Amazon AWS S3 error codes. */ +@Root(name = "ErrorCode") +@Convert(ErrorCode.ErrorCodeConverter.class) public enum ErrorCode { // custom error codes NO_SUCH_OBJECT("NoSuchKey", "Object does not exist"), @@ -143,21 +151,30 @@ public String message() { return this.message; } + /** * Returns ErrorCode of given code string. */ public static ErrorCode fromString(String codeString) { - if (codeString == null) { - return null; - } - for (ErrorCode ec : ErrorCode.values()) { if (codeString.equals(ec.code)) { return ec; } } - // Unknown error code string. Its not a standard Amazon S3 error. - return null; + throw new IllegalArgumentException("unknown error code string '" + codeString + "'"); + } + + + public static class ErrorCodeConverter implements Converter { + @Override + public ErrorCode read(InputNode node) throws Exception { + return ErrorCode.fromString(node.getValue()); + } + + @Override + public void write(OutputNode node, ErrorCode errorCode) throws Exception { + node.setValue(errorCode.code()); + } } } diff --git a/api/src/main/java/io/minio/MinioClient.java b/api/src/main/java/io/minio/MinioClient.java index 109465600..89b576158 100755 --- a/api/src/main/java/io/minio/MinioClient.java +++ b/api/src/main/java/io/minio/MinioClient.java @@ -24,8 +24,8 @@ import com.google.common.collect.Multimap; import com.google.common.collect.Multimaps; import com.google.common.io.ByteStreams; -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import io.minio.errors.BucketPolicyTooLargeException; import io.minio.errors.ErrorResponseException; import io.minio.errors.InsufficientDataException; @@ -36,6 +36,7 @@ import io.minio.errors.InvalidPortException; import io.minio.errors.InvalidResponseException; import io.minio.errors.RegionConflictException; +import io.minio.errors.XmlParserException; import io.minio.http.HeaderParser; import io.minio.http.Method; import io.minio.http.Scheme; @@ -52,20 +53,21 @@ import io.minio.messages.InitiateMultipartUploadResult; import io.minio.messages.InputSerialization; import io.minio.messages.Item; +import io.minio.messages.LegalHold; import io.minio.messages.ListAllMyBucketsResult; import io.minio.messages.ListBucketResult; import io.minio.messages.ListBucketResultV1; import io.minio.messages.ListMultipartUploadsResult; import io.minio.messages.ListPartsResult; +import io.minio.messages.LocationConstraint; +import io.minio.messages.NotificationConfiguration; import io.minio.messages.ObjectLockConfiguration; -import io.minio.messages.ObjectLockLegalHold; -import io.minio.messages.ObjectRetentionConfiguration; import io.minio.messages.OutputSerialization; import io.minio.messages.Part; import io.minio.messages.Prefix; -import io.minio.messages.Upload; -import io.minio.messages.NotificationConfiguration; +import io.minio.messages.Retention; import io.minio.messages.SelectObjectContentRequest; +import io.minio.messages.Upload; import io.minio.notification.NotificationInfo; import io.minio.org.apache.commons.validator.routines.InetAddressValidator; @@ -76,7 +78,6 @@ import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.RandomAccessFile; -import java.io.StringReader; import java.net.URL; import java.nio.charset.StandardCharsets; import java.nio.file.Files; @@ -84,12 +85,14 @@ import java.nio.file.Paths; import java.nio.file.StandardCopyOption; import java.nio.file.StandardOpenOption; + import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import java.security.KeyManagementException; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; import java.time.ZonedDateTime; + import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -118,9 +121,6 @@ import okhttp3.Response; import okhttp3.ResponseBody; import okhttp3.Protocol; -import org.xmlpull.v1.XmlPullParser; -import org.xmlpull.v1.XmlPullParserException; -import org.xmlpull.v1.XmlPullParserFactory; /** *

@@ -170,8 +170,6 @@ public class MinioClient { private static final String US_EAST_1 = "us-east-1"; private static final String UPLOAD_ID = "uploadId"; - private static XmlPullParserFactory xmlPullParserFactory = null; - private static final Set amzHeaders = new HashSet<>(); static { @@ -197,15 +195,6 @@ public class MinioClient { standardHeaders.add("range"); } - static { - try { - xmlPullParserFactory = XmlPullParserFactory.newInstance(); - xmlPullParserFactory.setNamespaceAware(true); - } catch (XmlPullParserException e) { - throw new ExceptionInInitializerError(e); - } - } - private PrintWriter traceStream; // the current client instance's base URL. @@ -1045,7 +1034,7 @@ private HttpResponse execute(Method method, String region, String bucketName, St Map headerMap, Map queryParamMap, Object body, int length) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, InvalidResponseException { return execute(method, region, bucketName, objectName, headerMap, queryParamMap, @@ -1069,7 +1058,7 @@ private HttpResponse execute(Method method, String region, String bucketName, St Map headerMap, Map queryParamMap, Object body, int length, boolean md5Required) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, InvalidResponseException { if (headerMap != null) { @@ -1094,14 +1083,20 @@ private HttpResponse executeReq(Method method, String region, String bucketName, Multimap headerMap, Multimap queryParamMap, Object body, int length, boolean md5Required) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, InvalidResponseException { String contentType = null; if (headerMap != null && headerMap.get("Content-Type") != null) { contentType = String.join(" ", headerMap.get("Content-Type")); } if (body != null && !(body instanceof InputStream || body instanceof RandomAccessFile || body instanceof byte[])) { - byte[] bytes = body.toString().getBytes(StandardCharsets.UTF_8); + byte[] bytes; + if (body instanceof CharSequence) { + bytes = body.toString().getBytes(StandardCharsets.UTF_8); + } else { + bytes = Xml.marshal(body).getBytes(StandardCharsets.UTF_8); + } + body = bytes; length = bytes.length; } @@ -1162,7 +1157,7 @@ private HttpResponse executeReq(Method method, String region, String bucketName, if (!("application/xml".equals(response.headers().get("content-type")))) { throw new InvalidResponseException(); } - errorResponse = new ErrorResponse(new StringReader(errorXml)); + errorResponse = Xml.unmarshal(ErrorResponse.class, errorXml); if (this.traceStream != null) { this.traceStream.println(errorXml); } @@ -1233,7 +1228,7 @@ private HttpResponse executeReq(Method method, String region, String bucketName, */ private void updateRegionCache(String bucketName) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, InvalidResponseException { if (bucketName != null && this.accessKey != null && this.secretKey != null && !BucketRegionCache.INSTANCE.exists(bucketName)) { @@ -1243,31 +1238,15 @@ private void updateRegionCache(String bucketName) HttpResponse response = execute(Method.GET, US_EAST_1, bucketName, null, null, queryParamMap, null, 0); - // existing XmlEntity does not work, so fallback to regular parsing. - XmlPullParser xpp = xmlPullParserFactory.newPullParser(); - String location = null; - - try (ResponseBody body = response.body()) { - xpp.setInput(body.charStream()); - while (xpp.getEventType() != XmlPullParser.END_DOCUMENT) { - if (xpp.getEventType() == XmlPullParser.START_TAG && "LocationConstraint".equals(xpp.getName())) { - xpp.next(); - location = getText(xpp); - break; - } - xpp.next(); - } - } - String region; - if (location == null) { - region = US_EAST_1; - } else { - // eu-west-1 can be sometimes 'EU'. - if ("EU".equals(location)) { - region = "eu-west-1"; + try (ResponseBody body = response.body()) { + LocationConstraint lc = Xml.unmarshal(LocationConstraint.class, body.charStream()); + if (lc.location() == null || lc.location().equals("")) { + region = US_EAST_1; // default region + } else if (lc.location().equals("EU")) { + region = "eu-west-1"; // eu-west-1 can be sometimes 'EU'. } else { - region = location; + region = lc.location(); } } @@ -1281,7 +1260,7 @@ private void updateRegionCache(String bucketName) * resort to the server location API. */ private String getRegion(String bucketName) throws InvalidBucketNameException, NoSuchAlgorithmException, - InsufficientDataException, IOException, InvalidKeyException, XmlPullParserException, + InsufficientDataException, IOException, InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, InvalidResponseException { String region; if (this.region == null || "".equals(this.region)) { @@ -1293,18 +1272,6 @@ private String getRegion(String bucketName) throws InvalidBucketNameException, N return region; } - /** - * Returns text of given XML element. - * - * @throws XmlPullParserException upon parsing response xml - */ - private String getText(XmlPullParser xpp) throws XmlPullParserException { - if (xpp.getEventType() == XmlPullParser.TEXT) { - return xpp.getText(); - } - return null; - } - private void checkReadRequestSse(ServerSideEncryption sse) throws IllegalArgumentException { if (sse == null) { return; @@ -1342,7 +1309,7 @@ private void checkWriteRequestSse(ServerSideEncryption sse) throws IllegalArgume private HttpResponse executeGet(String bucketName, String objectName, Map headerMap, Map queryParamMap) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, InvalidResponseException { return execute(Method.GET, getRegion(bucketName), bucketName, objectName, headerMap, queryParamMap, null, 0); } @@ -1356,7 +1323,7 @@ private HttpResponse executeGet(String bucketName, String objectName, Map headerMap) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, InvalidResponseException { HttpResponse response = execute(Method.HEAD, getRegion(bucketName), bucketName, objectName, headerMap, @@ -1391,7 +1358,7 @@ private HttpResponse executeHead(String bucketName, String objectName, Map queryParamMap) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, InvalidResponseException { HttpResponse response = execute(Method.DELETE, getRegion(bucketName), bucketName, objectName, null, queryParamMap, null, 0); @@ -1412,7 +1379,7 @@ private HttpResponse executeDelete(String bucketName, String objectName, Map headerMap, Map queryParamMap, Object data) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, InvalidResponseException { return execute(Method.POST, getRegion(bucketName), bucketName, objectName, headerMap, queryParamMap, data, 0); @@ -1431,7 +1398,7 @@ private HttpResponse executePost(String bucketName, String objectName, Map headerMap, Map queryParamMap, Object data, boolean md5Required) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, InvalidResponseException { return execute(Method.POST, getRegion(bucketName), bucketName, objectName, headerMap, queryParamMap, data, 0, md5Required); @@ -1469,7 +1436,7 @@ private Map normalizeHeaders(Map headerMap) { private HttpResponse executePut(String bucketName, String objectName, Map headerMap, Map queryParamMap, String region, Object data, int length) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, InvalidResponseException { HttpResponse response = execute(Method.PUT, region, bucketName, objectName, headerMap, queryParamMap, @@ -1492,7 +1459,7 @@ private HttpResponse executePut(String bucketName, String objectName, Map headerMap, Map queryParamMap, String region, Object data, int length, boolean md5Required) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, InvalidResponseException { HttpResponse response = execute(Method.PUT, region, bucketName, objectName, headerMap, queryParamMap, @@ -1514,7 +1481,7 @@ private HttpResponse executePut(String bucketName, String objectName, Map headerMap, Map queryParamMap, Object data, int length) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, InvalidResponseException { return executePut(bucketName, objectName, headerMap, queryParamMap, getRegion(bucketName), data, length, false); } @@ -1533,7 +1500,7 @@ private HttpResponse executePut(String bucketName, String objectName, Map headerMap, Map queryParamMap, Object data, int length, boolean md5Required) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, InvalidResponseException { return executePut(bucketName, objectName, headerMap, queryParamMap, getRegion(bucketName), data, length, md5Required); @@ -1578,7 +1545,7 @@ public void setAppInfo(String name, String version) { * @throws IOException upon connection error * @throws InvalidKeyException * upon an invalid access key or secret key - * @throws XmlPullParserException upon parsing response xml + * @throws XmlParserException upon parsing response xml * @throws ErrorResponseException upon unsuccessful execution * @throws InternalException upon internal library error * @throws InvalidResponseException upon a non-xml response from server @@ -1586,7 +1553,7 @@ public void setAppInfo(String name, String version) { */ public ObjectStat statObject(String bucketName, String objectName) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, InvalidResponseException, IllegalArgumentException { return statObject(bucketName, objectName, null); } @@ -1612,7 +1579,7 @@ public ObjectStat statObject(String bucketName, String objectName) * @throws IOException upon connection error * @throws InvalidKeyException * upon an invalid access key or secret key - * @throws XmlPullParserException upon parsing response xml + * @throws XmlParserException upon parsing response xml * @throws ErrorResponseException upon unsuccessful execution * @throws InternalException upon internal library error * @throws IllegalArgumentException upon invalid value is passed to a method. @@ -1621,7 +1588,7 @@ public ObjectStat statObject(String bucketName, String objectName) */ public ObjectStat statObject(String bucketName, String objectName, ServerSideEncryption sse) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, IllegalArgumentException, InvalidResponseException { checkReadRequestSse(sse); checkBucketName(bucketName); @@ -1660,14 +1627,14 @@ public ObjectStat statObject(String bucketName, String objectName, ServerSideEnc * @throws IOException upon connection error * @throws InvalidKeyException * upon an invalid access key or secret key - * @throws XmlPullParserException upon parsing response xml + * @throws XmlParserException upon parsing response xml * @throws ErrorResponseException upon unsuccessful execution * @throws InternalException upon internal library error * @throws InvalidResponseException upon a non-xml response from server */ public String getObjectUrl(String bucketName, String objectName) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, InvalidResponseException { Request request = createRequest(Method.GET, bucketName, objectName, getRegion(bucketName), null, null, null, null, 0, false); @@ -1701,7 +1668,7 @@ public String getObjectUrl(String bucketName, String objectName) * @throws IOException upon connection error * @throws InvalidKeyException * upon an invalid access key or secret key - * @throws XmlPullParserException upon parsing response xml + * @throws XmlParserException upon parsing response xml * @throws ErrorResponseException upon unsuccessful execution * @throws InternalException upon internal library error * @throws IllegalArgumentException upon invalid value is passed to a method. @@ -1709,7 +1676,7 @@ public String getObjectUrl(String bucketName, String objectName) */ public InputStream getObject(String bucketName, String objectName) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, IllegalArgumentException, InvalidResponseException { return getObject(bucketName, objectName, null, null, null); } @@ -1742,7 +1709,7 @@ public InputStream getObject(String bucketName, String objectName) * @throws IOException upon connection error * @throws InvalidKeyException * upon an invalid access key or secret key - * @throws XmlPullParserException upon parsing response xml + * @throws XmlParserException upon parsing response xml * @throws ErrorResponseException upon unsuccessful execution * @throws InternalException upon internal library error * @throws IllegalArgumentException upon invalid value is passed to a method. @@ -1750,7 +1717,7 @@ public InputStream getObject(String bucketName, String objectName) */ public InputStream getObject(String bucketName, String objectName, ServerSideEncryption sse) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, IllegalArgumentException, InvalidResponseException { return getObject(bucketName, objectName, null, null, sse); } @@ -1783,7 +1750,7 @@ public InputStream getObject(String bucketName, String objectName, ServerSideEnc * @throws IOException upon connection error * @throws InvalidKeyException * upon an invalid access key or secret key - * @throws XmlPullParserException upon parsing response xml + * @throws XmlParserException upon parsing response xml * @throws ErrorResponseException upon unsuccessful execution * @throws InternalException upon internal library error * @throws IllegalArgumentException upon invalid value is passed to a method. @@ -1791,7 +1758,7 @@ public InputStream getObject(String bucketName, String objectName, ServerSideEnc */ public InputStream getObject(String bucketName, String objectName, long offset) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, IllegalArgumentException, InvalidResponseException { return getObject(bucketName, objectName, offset, null, null); } @@ -1825,7 +1792,7 @@ public InputStream getObject(String bucketName, String objectName, long offset) * @throws IOException upon connection error * @throws InvalidKeyException * upon an invalid access key or secret key - * @throws XmlPullParserException upon parsing response xml + * @throws XmlParserException upon parsing response xml * @throws ErrorResponseException upon unsuccessful execution * @throws InternalException upon internal library error * @throws IllegalArgumentException upon invalid value is passed to a method. @@ -1833,7 +1800,7 @@ public InputStream getObject(String bucketName, String objectName, long offset) */ public InputStream getObject(String bucketName, String objectName, long offset, Long length) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, IllegalArgumentException, InvalidResponseException { return getObject(bucketName, objectName, offset, length, null); } @@ -1868,7 +1835,7 @@ public InputStream getObject(String bucketName, String objectName, long offset, * @throws IOException upon connection error * @throws InvalidKeyException * upon an invalid access key or secret key - * @throws XmlPullParserException upon parsing response xml + * @throws XmlParserException upon parsing response xml * @throws ErrorResponseException upon unsuccessful execution * @throws InternalException upon internal library error * @throws IllegalArgumentException upon invalid value is passed to a method. @@ -1877,7 +1844,7 @@ public InputStream getObject(String bucketName, String objectName, long offset, public InputStream getObject(String bucketName, String objectName, Long offset, Long length, ServerSideEncryption sse) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, IllegalArgumentException, InvalidResponseException { if ((bucketName == null) || (bucketName.isEmpty())) { throw new IllegalArgumentException("bucket name cannot be empty"); @@ -1937,7 +1904,7 @@ public InputStream getObject(String bucketName, String objectName, Long offset, * @throws IOException upon connection error * @throws InvalidKeyException * upon an invalid access key or secret key - * @throws XmlPullParserException upon parsing response xml + * @throws XmlParserException upon parsing response xml * @throws ErrorResponseException upon unsuccessful execution * @throws InternalException upon internal library error * @throws IllegalArgumentException upon invalid value is passed to a method. @@ -1945,7 +1912,7 @@ public InputStream getObject(String bucketName, String objectName, Long offset, */ public void getObject(String bucketName, String objectName, String fileName) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, IllegalArgumentException, InvalidResponseException { getObject(bucketName, objectName, null, fileName); } @@ -1971,7 +1938,7 @@ public void getObject(String bucketName, String objectName, String fileName) * @throws IOException upon connection error * @throws InvalidKeyException * upon an invalid access key or secret key - * @throws XmlPullParserException upon parsing response xml + * @throws XmlParserException upon parsing response xml * @throws ErrorResponseException upon unsuccessful execution * @throws InternalException upon internal library error * @throws IllegalArgumentException upon invalid value is passed to a method. @@ -1979,7 +1946,7 @@ public void getObject(String bucketName, String objectName, String fileName) */ public void getObject(String bucketName, String objectName, ServerSideEncryption sse, String fileName) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, IllegalArgumentException, InvalidResponseException { checkReadRequestSse(sse); @@ -2080,7 +2047,7 @@ public void getObject(String bucketName, String objectName, ServerSideEncryption * @throws ErrorResponseException upon unsuccessful execution * @throws InternalException upon internal library error * @throws IOException upon connection error - * @throws XmlPullParserException upon parsing response xml + * @throws XmlParserException upon parsing response xml * @throws IllegalArgumentException upon invalid value is passed to a method. * @throws InvalidResponseException upon a non-xml response from server * @@ -2089,7 +2056,7 @@ public void getObject(String bucketName, String objectName, ServerSideEncryption @Deprecated public void copyObject(String bucketName, String objectName, String destBucketName) throws InvalidKeyException, InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, - ErrorResponseException, InternalException, IOException, XmlPullParserException, + ErrorResponseException, InternalException, IOException, XmlParserException, IllegalArgumentException, InvalidResponseException { copyObject(destBucketName, objectName, null, null, bucketName, objectName, null, null); } @@ -2124,7 +2091,7 @@ public void copyObject(String bucketName, String objectName, String destBucketNa * @throws ErrorResponseException upon unsuccessful execution * @throws InternalException upon internal library error * @throws IOException upon connection error - * @throws XmlPullParserException upon parsing response xml + * @throws XmlParserException upon parsing response xml * @throws IllegalArgumentException upon invalid value is passed to a method. * @throws InvalidResponseException upon a non-xml response from server * @@ -2133,7 +2100,7 @@ public void copyObject(String bucketName, String objectName, String destBucketNa @Deprecated public void copyObject(String bucketName, String objectName, String destBucketName, String destObjectName) throws InvalidKeyException, InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, - ErrorResponseException, InternalException, IOException, XmlPullParserException, + ErrorResponseException, InternalException, IOException, XmlParserException, IllegalArgumentException, InvalidResponseException { if (destObjectName == null) { destObjectName = objectName; @@ -2173,7 +2140,7 @@ public void copyObject(String bucketName, String objectName, String destBucketNa * @throws ErrorResponseException upon unsuccessful execution * @throws InternalException upon internal library error * @throws IOException upon connection error - * @throws XmlPullParserException upon parsing response xml + * @throws XmlParserException upon parsing response xml * @throws IllegalArgumentException upon invalid value is passed to a method. * @throws InvalidResponseException upon a non-xml response from server * @@ -2182,7 +2149,7 @@ public void copyObject(String bucketName, String objectName, String destBucketNa @Deprecated public void copyObject(String bucketName, String objectName, String destBucketName, CopyConditions copyConditions) throws InvalidKeyException, InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, - ErrorResponseException, InternalException, IOException, XmlPullParserException, + ErrorResponseException, InternalException, IOException, XmlParserException, IllegalArgumentException, InvalidResponseException { copyObject(destBucketName, objectName, null, null, bucketName, objectName, null, copyConditions); } @@ -2222,7 +2189,7 @@ public void copyObject(String bucketName, String objectName, String destBucketNa * @throws ErrorResponseException upon unsuccessful execution * @throws InternalException upon internal library error * @throws IOException upon connection error - * @throws XmlPullParserException upon parsing response xml + * @throws XmlParserException upon parsing response xml * @throws IllegalArgumentException upon invalid value is passed to a method. * @throws InvalidResponseException upon a non-xml response from server * @@ -2232,7 +2199,7 @@ public void copyObject(String bucketName, String objectName, String destBucketNa public void copyObject(String bucketName, String objectName, String destBucketName, String destObjectName, CopyConditions copyConditions) throws InvalidKeyException, InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, - ErrorResponseException, InternalException, IOException, XmlPullParserException, + ErrorResponseException, InternalException, IOException, XmlParserException, IllegalArgumentException, InvalidResponseException { if (destObjectName == null) { destObjectName = objectName; @@ -2279,7 +2246,7 @@ public void copyObject(String bucketName, String objectName, String destBucketNa * @throws ErrorResponseException upon unsuccessful execution * @throws InternalException upon internal library error * @throws IOException upon connection error - * @throws XmlPullParserException upon parsing response xml + * @throws XmlParserException upon parsing response xml * @throws IllegalArgumentException upon invalid value is passed to a method. * @throws InvalidResponseException upon a non-xml response from server * @@ -2289,7 +2256,7 @@ public void copyObject(String bucketName, String objectName, String destBucketNa public void copyObject(String bucketName, String objectName, ServerSideEncryption sseSource, String destBucketName, String destObjectName, CopyConditions copyConditions, ServerSideEncryption sseTarget) throws InvalidKeyException, InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, - ErrorResponseException, InternalException, IOException, XmlPullParserException, + ErrorResponseException, InternalException, IOException, XmlParserException, IllegalArgumentException, InvalidResponseException { if (destObjectName == null) { destObjectName = objectName; @@ -2333,7 +2300,7 @@ public void copyObject(String bucketName, String objectName, ServerSideEncryptio * @throws IOException upon connection error * @throws InvalidKeyException * upon an invalid access key or secret key - * @throws XmlPullParserException upon parsing response xml + * @throws XmlParserException upon parsing response xml * @throws ErrorResponseException upon unsuccessful execution * @throws InternalException upon internal library error * @throws IllegalArgumentException upon invalid value is passed to a method. @@ -2346,7 +2313,7 @@ public void copyObject(String bucketName, String objectName, String destBucketNa String destObjectName, CopyConditions copyConditions, Map metadata) throws InvalidKeyException, InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, - ErrorResponseException, InternalException, IOException, XmlPullParserException, + ErrorResponseException, InternalException, IOException, XmlParserException, IllegalArgumentException, InvalidResponseException { if (destObjectName == null) { destObjectName = objectName; @@ -2393,7 +2360,7 @@ public void copyObject(String bucketName, String objectName, String destBucketNa * @throws IOException upon connection error * @throws InvalidKeyException * upon an invalid access key or secret key - * @throws XmlPullParserException upon parsing response xml + * @throws XmlParserException upon parsing response xml * @throws ErrorResponseException upon unsuccessful execution * @throws InternalException upon internal library error * @throws IllegalArgumentException upon invalid value is passed to a method. @@ -2403,7 +2370,7 @@ public void copyObject(String bucketName, String objectName, Map String srcBucketName, String srcObjectName, ServerSideEncryption srcSse, CopyConditions copyConditions) throws InvalidKeyException, InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, - ErrorResponseException, InternalException, IOException, XmlPullParserException, + ErrorResponseException, InternalException, IOException, XmlParserException, IllegalArgumentException, InvalidResponseException { if ((bucketName == null) || (bucketName.isEmpty())) { throw new IllegalArgumentException("bucket name cannot be empty"); @@ -2444,10 +2411,9 @@ public void copyObject(String bucketName, String objectName, Map HttpResponse response = executePut(bucketName, objectName, headerMap, null, "", 0); - // For now ignore the copyObjectResult, just read and parse it. - CopyObjectResult result = new CopyObjectResult(); try (ResponseBody body = response.body()) { - result.parseXml(body.charStream()); + // For now ignore the copyObjectResult, just read and parse it. + Xml.unmarshal(CopyObjectResult.class, body.charStream()); } } @@ -2480,7 +2446,7 @@ public void copyObject(String bucketName, String objectName, Map * @throws IOException upon connection error * @throws InvalidKeyException * upon an invalid access key or secret key - * @throws XmlPullParserException upon parsing response xml + * @throws XmlParserException upon parsing response xml * @throws ErrorResponseException upon unsuccessful execution * @throws InternalException upon internal library error * @throws IllegalArgumentException upon invalid value is passed to a method. @@ -2490,7 +2456,7 @@ public void copyObject(String bucketName, String objectName, Map public void composeObject(String bucketName, String objectName, List sources, Map headerMap, ServerSideEncryption sse) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, IllegalArgumentException, InvalidResponseException { if ((bucketName == null) || (bucketName.isEmpty())) { throw new IllegalArgumentException("bucket name cannot be empty"); @@ -2665,17 +2631,16 @@ public void composeObject(String bucketName, String objectName, List headerMap) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, InvalidResponseException { Map queryParamMap = new HashMap<>(); queryParamMap.put("partNumber", Integer.toString(partNumber)); queryParamMap.put("uploadId", uploadId); HttpResponse response = executePut(bucketName, objectName, headerMap, queryParamMap, "", 0); - CopyPartResult result = new CopyPartResult(); try (ResponseBody body = response.body()) { - result.parseXml(body.charStream()); + CopyPartResult result = Xml.unmarshal(CopyPartResult.class, body.charStream()); + return result.etag(); } - return result.etag(); } @@ -2705,7 +2670,7 @@ private String uploadPartCopy(String bucketName, String objectName, String uploa * @throws IOException upon connection error * @throws InvalidKeyException * upon an invalid access key or secret key - * @throws XmlPullParserException upon parsing response xml + * @throws XmlParserException upon parsing response xml * @throws ErrorResponseException upon unsuccessful execution * @throws InternalException upon internal library error * @throws InvalidExpiresRangeException upon input expires is out of range @@ -2714,7 +2679,7 @@ private String uploadPartCopy(String bucketName, String objectName, String uploa public String getPresignedObjectUrl(Method method, String bucketName, String objectName, Integer expires, Map reqParams) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, InvalidExpiresRangeException, InvalidResponseException { // Validate input. if (expires < 1 || expires > DEFAULT_EXPIRY_TIME) { @@ -2763,7 +2728,7 @@ public String getPresignedObjectUrl(Method method, String bucketName, String obj * @throws IOException upon connection error * @throws InvalidKeyException * upon an invalid access key or secret key - * @throws XmlPullParserException upon parsing response xml + * @throws XmlParserException upon parsing response xml * @throws ErrorResponseException upon unsuccessful execution * @throws InternalException upon internal library error * @throws InvalidExpiresRangeException upon input expires is out of range @@ -2772,7 +2737,7 @@ public String getPresignedObjectUrl(Method method, String bucketName, String obj public String presignedGetObject(String bucketName, String objectName, Integer expires, Map reqParams) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, InvalidExpiresRangeException, InvalidResponseException { return getPresignedObjectUrl(Method.GET, bucketName, objectName, expires, reqParams); } @@ -2798,7 +2763,7 @@ public String presignedGetObject(String bucketName, String objectName, Integer e * @throws IOException upon connection error * @throws InvalidKeyException * upon an invalid access key or secret key - * @throws XmlPullParserException upon parsing response xml + * @throws XmlParserException upon parsing response xml * @throws ErrorResponseException upon unsuccessful execution * @throws InternalException upon internal library error * @throws InvalidExpiresRangeException upon input expires is out of range @@ -2806,7 +2771,7 @@ public String presignedGetObject(String bucketName, String objectName, Integer e */ public String presignedGetObject(String bucketName, String objectName, Integer expires) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, InvalidExpiresRangeException, InvalidResponseException { return presignedGetObject(bucketName, objectName, expires, null); } @@ -2833,7 +2798,7 @@ public String presignedGetObject(String bucketName, String objectName, Integer e * @throws IOException upon connection error * @throws InvalidKeyException * upon an invalid access key or secret key - * @throws XmlPullParserException upon parsing response xml + * @throws XmlParserException upon parsing response xml * @throws ErrorResponseException upon unsuccessful execution * @throws InternalException upon internal library error * @throws InvalidExpiresRangeException upon input expires is out of range @@ -2841,7 +2806,7 @@ public String presignedGetObject(String bucketName, String objectName, Integer e */ public String presignedGetObject(String bucketName, String objectName) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, InvalidExpiresRangeException, InvalidResponseException { return presignedGetObject(bucketName, objectName, DEFAULT_EXPIRY_TIME, null); } @@ -2868,7 +2833,7 @@ public String presignedGetObject(String bucketName, String objectName) * @throws IOException upon connection error * @throws InvalidKeyException * upon an invalid access key or secret key - * @throws XmlPullParserException upon parsing response xml + * @throws XmlParserException upon parsing response xml * @throws ErrorResponseException upon unsuccessful execution * @throws InternalException upon internal library error * @throws InvalidExpiresRangeException upon input expires is out of range @@ -2876,7 +2841,7 @@ public String presignedGetObject(String bucketName, String objectName) */ public String presignedPutObject(String bucketName, String objectName, Integer expires) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, InvalidExpiresRangeException, InvalidResponseException { return getPresignedObjectUrl(Method.PUT, bucketName, objectName, expires, null); } @@ -2903,7 +2868,7 @@ public String presignedPutObject(String bucketName, String objectName, Integer e * @throws IOException upon connection error * @throws InvalidKeyException * upon an invalid access key or secret key - * @throws XmlPullParserException upon parsing response xml + * @throws XmlParserException upon parsing response xml * @throws ErrorResponseException upon unsuccessful execution * @throws InternalException upon internal library error * @throws InvalidExpiresRangeException upon input expires is out of range @@ -2911,7 +2876,7 @@ public String presignedPutObject(String bucketName, String objectName, Integer e */ public String presignedPutObject(String bucketName, String objectName) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, InvalidExpiresRangeException, InvalidResponseException { return presignedPutObject(bucketName, objectName, DEFAULT_EXPIRY_TIME); } @@ -2944,7 +2909,7 @@ public String presignedPutObject(String bucketName, String objectName) * @throws IOException upon connection error * @throws InvalidKeyException * upon an invalid access key or secret key - * @throws XmlPullParserException upon parsing response xml + * @throws XmlParserException upon parsing response xml * @throws ErrorResponseException upon unsuccessful execution * @throws InternalException upon internal library error * @throws IllegalArgumentException upon invalid value is passed to a method. @@ -2953,7 +2918,7 @@ public String presignedPutObject(String bucketName, String objectName) */ public Map presignedPostPolicy(PostPolicy policy) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, IllegalArgumentException, InvalidResponseException { return policy.formData(this.accessKey, this.secretKey, getRegion(policy.bucketName())); } @@ -2976,7 +2941,7 @@ public Map presignedPostPolicy(PostPolicy policy) * @throws IOException upon connection error * @throws InvalidKeyException * upon an invalid access key or secret key - * @throws XmlPullParserException upon parsing response xml + * @throws XmlParserException upon parsing response xml * @throws ErrorResponseException upon unsuccessful execution * @throws InternalException upon internal library error * @throws IllegalArgumentException upon invalid value is passed to a method. @@ -2984,7 +2949,7 @@ public Map presignedPostPolicy(PostPolicy policy) */ public void removeObject(String bucketName, String objectName) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, IllegalArgumentException, InvalidResponseException { if ((bucketName == null) || (bucketName.isEmpty())) { throw new IllegalArgumentException("bucket name cannot be empty"); @@ -2998,12 +2963,12 @@ public void removeObject(String bucketName, String objectName) private List removeObject(String bucketName, List objectList) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, InvalidResponseException { Map queryParamMap = new HashMap<>(); queryParamMap.put("delete", ""); - DeleteRequest request = new DeleteRequest(objectList); + DeleteRequest request = new DeleteRequest(objectList, true); HttpResponse response = executePost(bucketName, null, null, queryParamMap, request, true); String bodyContent = ""; @@ -3021,20 +2986,20 @@ private List removeObject(String bucketName, List obj List errorList = null; - bodyContent = bodyContent.trim(); - // Check if body content is message. - DeleteError error = new DeleteError(new StringReader(bodyContent)); - if (error.code() != null) { - // As it is message, add to error list. - errorList = new LinkedList(); - errorList.add(error); - } else { + try { + if (Xml.validate(DeleteError.class, bodyContent)) { + DeleteError error = Xml.unmarshal(DeleteError.class, bodyContent); + errorList = new LinkedList(); + errorList.add(error); + return errorList; + } + } catch (XmlParserException e) { // As it is not message, parse it as message. - DeleteResult result = new DeleteResult(new StringReader(bodyContent)); - errorList = result.errorList(); + // Ignore this exception } - return errorList; + DeleteResult result = Xml.unmarshal(DeleteResult.class, bodyContent); + return result.errorList(); } @@ -3082,9 +3047,9 @@ private synchronized void populate() { errorList = removeObject(bucketName, objectList); } } catch (InvalidBucketNameException | NoSuchAlgorithmException | InsufficientDataException | IOException - | InvalidKeyException | XmlPullParserException | ErrorResponseException + | InvalidKeyException | XmlParserException | ErrorResponseException | InternalException | InvalidResponseException e) { - this.error = new Result<>(null, e); + this.error = new Result<>(e); } finally { if (errorList != null) { this.errorIterator = errorList.iterator(); @@ -3140,7 +3105,7 @@ public Result next() { } if (this.errorIterator.hasNext()) { - return new Result<>(this.errorIterator.next(), null); + return new Result<>(this.errorIterator.next()); } this.completed = true; @@ -3163,9 +3128,9 @@ public void remove() { * * @return an iterator of Result Items. * - ** @throws XmlPullParserException upon parsing response xml + ** @throws XmlParserException upon parsing response xml */ - public Iterable> listObjects(final String bucketName) throws XmlPullParserException { + public Iterable> listObjects(final String bucketName) throws XmlParserException { return listObjects(bucketName, null); } @@ -3178,10 +3143,10 @@ public Iterable> listObjects(final String bucketName) throws XmlPul * * @return an iterator of Result Items. * - * @throws XmlPullParserException upon parsing response xml + * @throws XmlParserException upon parsing response xml */ public Iterable> listObjects(final String bucketName, final String prefix) - throws XmlPullParserException { + throws XmlParserException { // list all objects recursively return listObjects(bucketName, prefix, true); } @@ -3316,9 +3281,9 @@ private synchronized void populate() { this.listBucketResult = listObjectsV2(bucketName, continuationToken, prefix, delimiter, includeUserMetadata); } catch (InvalidBucketNameException | NoSuchAlgorithmException | InsufficientDataException | IOException - | InvalidKeyException | XmlPullParserException | ErrorResponseException + | InvalidKeyException | XmlParserException | ErrorResponseException | InternalException | InvalidResponseException e) { - this.error = new Result<>(null, e); + this.error = new Result<>(e); } finally { if (this.listBucketResult != null) { this.itemIterator = this.listBucketResult.contents().iterator(); @@ -3383,20 +3348,11 @@ public Result next() { if (this.itemIterator.hasNext()) { Item item = this.itemIterator.next(); - return new Result<>(item, null); + return new Result<>(item); } if (this.prefixIterator.hasNext()) { - Prefix prefix = this.prefixIterator.next(); - Item item; - try { - item = new Item(prefix.prefix(), true); - } catch (XmlPullParserException e) { - // special case: ignore the error as we can't propagate the exception in next() - item = null; - } - - return new Result<>(item, null); + return new Result<>(this.prefixIterator.next().toItem()); } this.completed = true; @@ -3424,7 +3380,7 @@ public void remove() { private ListBucketResult listObjectsV2(String bucketName, String continuationToken, String prefix, String delimiter, boolean includeUserMetadata) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, InvalidResponseException { Map queryParamMap = new HashMap<>(); queryParamMap.put("list-type", "2"); @@ -3451,10 +3407,9 @@ private ListBucketResult listObjectsV2(String bucketName, String continuationTok HttpResponse response = executeGet(bucketName, null, null, queryParamMap); - ListBucketResult result = new ListBucketResult(); - result.parseXml(response.body().charStream()); - response.body().close(); - return result; + try (ResponseBody body = response.body()) { + return Xml.unmarshal(ListBucketResult.class, body.charStream()); + } } @@ -3492,9 +3447,9 @@ private synchronized void populate() { try { this.listBucketResult = listObjectsV1(bucketName, marker, prefix, delimiter); } catch (InvalidBucketNameException | NoSuchAlgorithmException | InsufficientDataException | IOException - | InvalidKeyException | XmlPullParserException | ErrorResponseException + | InvalidKeyException | XmlParserException | ErrorResponseException | InternalException | InvalidResponseException e) { - this.error = new Result<>(null, e); + this.error = new Result<>(e); } finally { if (this.listBucketResult != null) { this.itemIterator = this.listBucketResult.contents().iterator(); @@ -3560,20 +3515,11 @@ public Result next() { if (this.itemIterator.hasNext()) { Item item = this.itemIterator.next(); this.lastObjectName = item.objectName(); - return new Result<>(item, null); + return new Result<>(item); } if (this.prefixIterator.hasNext()) { - Prefix prefix = this.prefixIterator.next(); - Item item; - try { - item = new Item(prefix.prefix(), true); - } catch (XmlPullParserException e) { - // special case: ignore the error as we can't propagate the exception in next() - item = null; - } - - return new Result<>(item, null); + return new Result<>(this.prefixIterator.next().toItem()); } this.completed = true; @@ -3600,7 +3546,7 @@ public void remove() { */ private ListBucketResultV1 listObjectsV1(String bucketName, String marker, String prefix, String delimiter) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, InvalidResponseException { Map queryParamMap = new HashMap<>(); @@ -3622,10 +3568,9 @@ private ListBucketResultV1 listObjectsV1(String bucketName, String marker, Strin HttpResponse response = executeGet(bucketName, null, null, queryParamMap); - ListBucketResultV1 result = new ListBucketResultV1(); - result.parseXml(response.body().charStream()); - response.body().close(); - return result; + try (ResponseBody body = response.body()) { + return Xml.unmarshal(ListBucketResultV1.class, body.charStream()); + } } @@ -3647,20 +3592,20 @@ private ListBucketResultV1 listObjectsV1(String bucketName, String marker, Strin * @throws IOException upon connection error * @throws InvalidKeyException * upon an invalid access key or secret key - * @throws XmlPullParserException upon parsing response xml + * @throws XmlParserException upon parsing response xml * @throws ErrorResponseException upon unsuccessful execution * @throws InternalException upon internal library error * @throws InvalidResponseException upon a non-xml response from server */ public List listBuckets() throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, InvalidResponseException { HttpResponse response = executeGet(null, null, null, null); - ListAllMyBucketsResult result = new ListAllMyBucketsResult(); - result.parseXml(response.body().charStream()); - response.body().close(); - return result.buckets(); + try (ResponseBody body = response.body()) { + ListAllMyBucketsResult result = Xml.unmarshal(ListAllMyBucketsResult.class, body.charStream()); + return result.buckets(); + } } @@ -3686,7 +3631,7 @@ public List listBuckets() * @throws IOException upon connection error * @throws InvalidKeyException * upon an invalid access key or secret key - * @throws XmlPullParserException upon parsing response xml + * @throws XmlParserException upon parsing response xml * @throws ErrorResponseException upon unsuccessful execution * @throws InternalException upon internal library error * @throws InvalidResponseException upon a non-xml response from server @@ -3694,7 +3639,7 @@ public List listBuckets() */ public boolean bucketExists(String bucketName) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, InvalidResponseException { try { executeHead(bucketName, null); @@ -3722,7 +3667,7 @@ public boolean bucketExists(String bucketName) * @throws IOException upon connection error * @throws InvalidKeyException * upon an invalid access key or secret key - * @throws XmlPullParserException upon parsing response xml + * @throws XmlParserException upon parsing response xml * @throws ErrorResponseException upon unsuccessful execution. * @throws ErrorResponseException upon unsuccessful execution * @throws InternalException upon internal library error @@ -3731,7 +3676,7 @@ public boolean bucketExists(String bucketName) */ public void makeBucket(String bucketName) throws InvalidBucketNameException, RegionConflictException, NoSuchAlgorithmException, InsufficientDataException, - IOException, InvalidKeyException, XmlPullParserException, ErrorResponseException, + IOException, InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, InvalidResponseException { this.makeBucket(bucketName, null, false); } @@ -3755,7 +3700,7 @@ public void makeBucket(String bucketName) * @throws IOException upon connection error * @throws InvalidKeyException * upon an invalid access key or secret key - * @throws XmlPullParserException upon parsing response xml + * @throws XmlParserException upon parsing response xml * @throws ErrorResponseException upon unsuccessful execution * @throws InternalException upon internal library error @@ -3764,7 +3709,7 @@ public void makeBucket(String bucketName) */ public void makeBucket(String bucketName, String region) throws InvalidBucketNameException, RegionConflictException, NoSuchAlgorithmException, InsufficientDataException, - IOException, InvalidKeyException, XmlPullParserException, ErrorResponseException, + IOException, InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, InvalidResponseException { this.makeBucket(bucketName, region, false); } @@ -3789,7 +3734,7 @@ public void makeBucket(String bucketName, String region) * @throws IOException upon connection error * @throws InvalidKeyException * upon an invalid access key or secret key - * @throws XmlPullParserException upon parsing response xml + * @throws XmlParserException upon parsing response xml * @throws ErrorResponseException upon unsuccessful execution * @throws InternalException upon internal library error @@ -3798,7 +3743,7 @@ public void makeBucket(String bucketName, String region) */ public void makeBucket(String bucketName, String region, boolean objectLock) throws InvalidBucketNameException, RegionConflictException, NoSuchAlgorithmException, InsufficientDataException, - IOException, InvalidKeyException, XmlPullParserException, ErrorResponseException, + IOException, InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, InvalidResponseException { // If region param is not provided, set it with the one provided by constructor if (region == null) { @@ -3845,7 +3790,7 @@ public void makeBucket(String bucketName, String region, boolean objectLock) * @throws IOException upon connection error * @throws InvalidKeyException * upon an invalid access key or secret key - * @throws XmlPullParserException upon parsing response xml + * @throws XmlParserException upon parsing response xml * @throws ErrorResponseException upon unsuccessful execution * @throws InternalException upon internal library error @@ -3854,7 +3799,7 @@ public void makeBucket(String bucketName, String region, boolean objectLock) */ public void enableVersioning(String bucketName) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, - IOException, InvalidKeyException, XmlPullParserException, ErrorResponseException, + IOException, InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, InvalidResponseException { Map queryParamMap = new HashMap<>(); queryParamMap.put("versioning", ""); @@ -3880,7 +3825,7 @@ public void enableVersioning(String bucketName) * @throws IOException upon connection error * @throws InvalidKeyException * upon an invalid access key or secret key - * @throws XmlPullParserException upon parsing response xml + * @throws XmlParserException upon parsing response xml * @throws ErrorResponseException upon unsuccessful execution * @throws InternalException upon internal library error @@ -3889,7 +3834,7 @@ public void enableVersioning(String bucketName) */ public void disableVersioning(String bucketName) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, - IOException, InvalidKeyException, XmlPullParserException, ErrorResponseException, + IOException, InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, InvalidResponseException { Map queryParamMap = new HashMap<>(); queryParamMap.put("versioning", ""); @@ -3918,14 +3863,14 @@ public void disableVersioning(String bucketName) * @throws IOException upon connection error * @throws InvalidKeyException * upon an invalid access key or secret key - * @throws XmlPullParserException upon parsing response xml + * @throws XmlParserException upon parsing response xml * @throws ErrorResponseException upon unsuccessful execution * @throws InternalException upon internal library error * @throws InvalidResponseException upon a non-xml response from server */ public void setDefaultRetention(String bucketName, ObjectLockConfiguration config) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, InvalidResponseException { Map queryParamMap = new HashMap<>(); queryParamMap.put("object-lock", ""); @@ -3951,27 +3896,23 @@ public void setDefaultRetention(String bucketName, ObjectLockConfiguration confi * @throws IOException upon connection error * @throws InvalidKeyException * upon an invalid access key or secret key - * @throws XmlPullParserException upon parsing response xml + * @throws XmlParserException upon parsing response xml * @throws ErrorResponseException upon unsuccessful execution * @throws InternalException upon internal library error * @throws InvalidResponseException upon a non-xml response from server */ public ObjectLockConfiguration getDefaultRetention(String bucketName) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, InvalidResponseException { Map queryParamMap = new HashMap<>(); queryParamMap.put("object-lock", ""); HttpResponse response = executeGet(bucketName, null, null, queryParamMap); - ObjectLockConfiguration result = new ObjectLockConfiguration(); - try { - result.parseXml(response.body().charStream()); - } finally { - response.body().close(); + try (ResponseBody body = response.body()) { + return Xml.unmarshal(ObjectLockConfiguration.class, body.charStream()); } - return result; } @@ -3996,16 +3937,16 @@ public ObjectLockConfiguration getDefaultRetention(String bucketName) * @throws IOException upon connection error * @throws InvalidKeyException * upon an invalid access key or secret key - * @throws XmlPullParserException upon parsing response xml + * @throws XmlParserException upon parsing response xml * @throws ErrorResponseException upon unsuccessful execution * @throws InternalException upon internal library error * @throws InvalidResponseException upon a non-xml response from server * @throws IllegalArgumentException upon invalid value is passed to a method. */ public void setObjectRetention(String bucketName, String objectName, String versionId, - ObjectRetentionConfiguration config, boolean bypassGovernanceRetention) + Retention config, boolean bypassGovernanceRetention) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, InvalidResponseException, IllegalArgumentException { if (config == null ) { @@ -4035,10 +3976,10 @@ public void setObjectRetention(String bucketName, String objectName, String vers * *

Example:
*
{@code
-   * ObjectRetentionConfiguration objectRetentionConfiguration = minioClient.getObjectRetention("my-bucketname", 
+   * Retention retention = minioClient.getObjectRetention("my-bucketname", 
    * "my-object", "version-Id" );
-   * System.out.println("Mode " + objectRetentionConfiguration.mode()); 
-   * System.out.println("Retanetion Until  " + objectRetentionConfiguration.getRetentionDate()); }
+ * System.out.println("Mode " + retention.mode()); + * System.out.println("Retanetion Until " + retention.retainUntilDate()); } * * @param bucketName Bucket name. * @param objectName Object name. @@ -4052,14 +3993,14 @@ public void setObjectRetention(String bucketName, String objectName, String vers * @throws IOException upon connection error * @throws InvalidKeyException * upon an invalid access key or secret key - * @throws XmlPullParserException upon parsing response xml + * @throws XmlParserException upon parsing response xml * @throws ErrorResponseException upon unsuccessful execution * @throws InternalException upon internal library error * @throws InvalidResponseException upon a non-xml response from server */ - public ObjectRetentionConfiguration getObjectRetention(String bucketName, String objectName, String versionId) + public Retention getObjectRetention(String bucketName, String objectName, String versionId) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, InvalidResponseException { Map queryParamMap = new HashMap<>(); @@ -4072,13 +4013,9 @@ public ObjectRetentionConfiguration getObjectRetention(String bucketName, String } HttpResponse response = executeGet(bucketName, objectName, null, queryParamMap); - ObjectRetentionConfiguration result = new ObjectRetentionConfiguration(); - try { - result.parseXml(response.body().charStream()); - } finally { - response.body().close(); + try (ResponseBody body = response.body()) { + return Xml.unmarshal(Retention.class, body.charStream()); } - return result; } /** @@ -4100,14 +4037,14 @@ public ObjectRetentionConfiguration getObjectRetention(String bucketName, String * @throws IOException upon connection error * @throws InvalidKeyException * upon an invalid access key or secret key - * @throws XmlPullParserException upon parsing response xml + * @throws XmlParserException upon parsing response xml * @throws ErrorResponseException upon unsuccessful execution * @throws InternalException upon internal library error * @throws InvalidResponseException upon a non-xml response from server */ public void enableObjectLegalHold(String bucketName, String objectName, String versionId) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, InvalidResponseException { Map queryParamMap = new HashMap<>(); @@ -4119,9 +4056,9 @@ public void enableObjectLegalHold(String bucketName, String objectName, String v queryParamMap.put("versionId", versionId); } - ObjectLockLegalHold objectLockLegalHold = new ObjectLockLegalHold(true); + LegalHold legalHold = new LegalHold(true); - HttpResponse response = executePut(bucketName, objectName, null, queryParamMap, objectLockLegalHold, 0); + HttpResponse response = executePut(bucketName, objectName, null, queryParamMap, legalHold, 0); response.body().close(); } @@ -4144,14 +4081,14 @@ public void enableObjectLegalHold(String bucketName, String objectName, String v * @throws IOException upon connection error * @throws InvalidKeyException * upon an invalid access key or secret key - * @throws XmlPullParserException upon parsing response xml + * @throws XmlParserException upon parsing response xml * @throws ErrorResponseException upon unsuccessful execution * @throws InternalException upon internal library error * @throws InvalidResponseException upon a non-xml response from server */ public void disableObjectLegalHold(String bucketName, String objectName, String versionId) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, InvalidResponseException { Map queryParamMap = new HashMap<>(); @@ -4163,9 +4100,9 @@ public void disableObjectLegalHold(String bucketName, String objectName, String queryParamMap.put("versionId", versionId); } - ObjectLockLegalHold objectLockLegalHold = new ObjectLockLegalHold(false); + LegalHold legalHold = new LegalHold(false); - HttpResponse response = executePut(bucketName, objectName, null, queryParamMap, objectLockLegalHold, 0); + HttpResponse response = executePut(bucketName, objectName, null, queryParamMap, legalHold, 0); response.body().close(); } @@ -4190,14 +4127,14 @@ public void disableObjectLegalHold(String bucketName, String objectName, String * @throws IOException upon connection error * @throws InvalidKeyException * upon an invalid access key or secret key - * @throws XmlPullParserException upon parsing response xml + * @throws XmlParserException upon parsing response xml * @throws ErrorResponseException upon unsuccessful execution * @throws InternalException upon internal library error * @throws InvalidResponseException upon a non-xml response from server */ public boolean isObjectLegalHoldEnabled(String bucketName, String objectName, String versionId) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, InvalidResponseException { Map queryParamMap = new HashMap<>(); @@ -4210,13 +4147,10 @@ public boolean isObjectLegalHoldEnabled(String bucketName, String objectName, St } HttpResponse response = executeGet(bucketName, objectName, null, queryParamMap); - ObjectLockLegalHold result = new ObjectLockLegalHold(); - try { - result.parseXml(response.body().charStream()); - } finally { - response.body().close(); + try (ResponseBody body = response.body()) { + LegalHold result = Xml.unmarshal(LegalHold.class, body.charStream()); + return result.status(); } - return result.status(); } /** @@ -4239,7 +4173,7 @@ public boolean isObjectLegalHoldEnabled(String bucketName, String objectName, St * @throws IOException upon connection error * @throws InvalidKeyException * upon an invalid access key or secret key - * @throws XmlPullParserException upon parsing response xml + * @throws XmlParserException upon parsing response xml * @throws ErrorResponseException upon unsuccessful execution * @throws InternalException upon internal library error * @throws IllegalArgumentException upon invalid value is passed to a method. @@ -4248,7 +4182,7 @@ public boolean isObjectLegalHoldEnabled(String bucketName, String objectName, St */ public void removeBucket(String bucketName) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, InvalidResponseException { executeDelete(bucketName, null, null); } @@ -4276,7 +4210,7 @@ public void removeBucket(String bucketName) * @throws IOException upon connection error * @throws InvalidKeyException * upon an invalid access key or secret key - * @throws XmlPullParserException upon parsing response xml + * @throws XmlParserException upon parsing response xml * @throws ErrorResponseException upon unsuccessful execution * @throws InternalException upon internal library error * @throws IllegalArgumentException upon invalid value is passed to a method. @@ -4288,7 +4222,7 @@ public void removeBucket(String bucketName) @Deprecated public void putObject(String bucketName, String objectName, String fileName) throws InvalidBucketNameException, NoSuchAlgorithmException, IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, IllegalArgumentException, InsufficientDataException, InvalidResponseException { putObject(bucketName, objectName, fileName, null, null, null, null); } @@ -4317,7 +4251,7 @@ public void putObject(String bucketName, String objectName, String fileName) * @throws IOException upon connection error * @throws InvalidKeyException * upon an invalid access key or secret key - * @throws XmlPullParserException upon parsing response xml + * @throws XmlParserException upon parsing response xml * @throws ErrorResponseException upon unsuccessful execution * @throws InternalException upon internal library error * @throws IllegalArgumentException upon invalid value is passed to a method. @@ -4329,7 +4263,7 @@ public void putObject(String bucketName, String objectName, String fileName) @Deprecated public void putObject(String bucketName, String objectName, String fileName, String contentType) throws InvalidBucketNameException, NoSuchAlgorithmException, IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, IllegalArgumentException, InsufficientDataException, InvalidResponseException { putObject(bucketName, objectName, fileName, null, null, null, contentType ); } @@ -4358,7 +4292,7 @@ public void putObject(String bucketName, String objectName, String fileName, Str * @throws IOException upon connection error * @throws InvalidKeyException * upon an invalid access key or secret key - * @throws XmlPullParserException upon parsing response xml + * @throws XmlParserException upon parsing response xml * @throws ErrorResponseException upon unsuccessful execution * @throws InternalException upon internal library error * @throws IllegalArgumentException upon invalid value is passed to a method. @@ -4370,7 +4304,7 @@ public void putObject(String bucketName, String objectName, String fileName, Str @Deprecated public void putObject(String bucketName, String objectName, String fileName, ServerSideEncryption sse) throws InvalidBucketNameException, NoSuchAlgorithmException, IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, IllegalArgumentException, InsufficientDataException,InvalidResponseException { putObject(bucketName, objectName, fileName, null, null, sse, null); } @@ -4403,7 +4337,7 @@ public void putObject(String bucketName, String objectName, String fileName, Ser * @throws IOException upon connection error * @throws InvalidKeyException * upon an invalid access key or secret key - * @throws XmlPullParserException upon parsing response xml + * @throws XmlParserException upon parsing response xml * @throws ErrorResponseException upon unsuccessful execution * @throws InternalException upon internal library error * @throws IllegalArgumentException upon invalid value is passed to a method. @@ -4415,7 +4349,7 @@ public void putObject(String bucketName, String objectName, String fileName, Ser public void putObject(String bucketName, String objectName, String fileName, Long size, Map headerMap, ServerSideEncryption sse, String contentType) throws InvalidBucketNameException, NoSuchAlgorithmException, IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, IllegalArgumentException, InsufficientDataException, InvalidResponseException { if (fileName == null || "".equals(fileName)) { throw new IllegalArgumentException("empty file name is not allowed"); @@ -4490,7 +4424,7 @@ public void putObject(String bucketName, String objectName, String fileName, Lo * @throws IOException upon connection error * @throws InvalidKeyException * upon an invalid access key or secret key - * @throws XmlPullParserException upon parsing response xml + * @throws XmlParserException upon parsing response xml * @throws ErrorResponseException upon unsuccessful execution * @throws InternalException upon internal library error * @throws IllegalArgumentException upon invalid value is passed to a method. @@ -4502,7 +4436,7 @@ public void putObject(String bucketName, String objectName, String fileName, Lo @Deprecated public void putObject(String bucketName, String objectName, InputStream stream, long size, String contentType) throws InvalidBucketNameException, NoSuchAlgorithmException, IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, IllegalArgumentException, InsufficientDataException, InvalidResponseException { putObject(bucketName, objectName, stream, size, null, null, contentType); } @@ -4558,7 +4492,7 @@ public void putObject(String bucketName, String objectName, InputStream stream, * @throws IOException upon connection error * @throws InvalidKeyException * upon an invalid access key or secret key - * @throws XmlPullParserException upon parsing response xml + * @throws XmlParserException upon parsing response xml * @throws ErrorResponseException upon unsuccessful execution * @throws InternalException upon internal library error * @throws IllegalArgumentException upon invalid value is passed to a method. @@ -4570,7 +4504,7 @@ public void putObject(String bucketName, String objectName, InputStream stream, @Deprecated public void putObject(String bucketName, String objectName, InputStream stream, Map headerMap) throws InvalidBucketNameException, NoSuchAlgorithmException, IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, IllegalArgumentException, InsufficientDataException, InvalidResponseException { if (headerMap == null) { headerMap = new HashMap<>(); @@ -4631,7 +4565,7 @@ public void putObject(String bucketName, String objectName, InputStream stream, * @throws IOException upon connection error * @throws InvalidKeyException * upon an invalid access key or secret key - * @throws XmlPullParserException upon parsing response xml + * @throws XmlParserException upon parsing response xml * @throws ErrorResponseException upon unsuccessful execution * @throws InternalException upon internal library error * @throws IllegalArgumentException upon invalid value is passed to a method. @@ -4644,7 +4578,7 @@ public void putObject(String bucketName, String objectName, InputStream stream, public void putObject(String bucketName, String objectName, InputStream stream, long size, Map headerMap) throws InvalidBucketNameException, NoSuchAlgorithmException, IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, IllegalArgumentException, InsufficientDataException , InvalidResponseException { putObject(bucketName, objectName, stream, size, headerMap, null, null); } @@ -4698,7 +4632,7 @@ public void putObject(String bucketName, String objectName, InputStream stream, * @throws IOException upon connection error * @throws InvalidKeyException * upon an invalid access key or secret key - * @throws XmlPullParserException upon parsing response xml + * @throws XmlParserException upon parsing response xml * @throws ErrorResponseException upon unsuccessful execution * @throws InternalException upon internal library error * @throws IllegalArgumentException upon invalid value is passed to a method. @@ -4711,7 +4645,7 @@ public void putObject(String bucketName, String objectName, InputStream stream, public void putObject(String bucketName, String objectName, InputStream stream, long size, ServerSideEncryption sse) throws InvalidBucketNameException, NoSuchAlgorithmException, IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, IllegalArgumentException, InsufficientDataException, InvalidResponseException { putObject(bucketName, objectName, stream, size, null, sse, null); } @@ -4779,7 +4713,7 @@ public void putObject(String bucketName, String objectName, InputStream stream, * @throws IOException upon connection error * @throws InvalidKeyException * upon an invalid access key or secret key - * @throws XmlPullParserException upon parsing response xml + * @throws XmlParserException upon parsing response xml * @throws ErrorResponseException upon unsuccessful execution * @throws InternalException upon internal library error * @throws IllegalArgumentException upon invalid value is passed to a method. @@ -4792,7 +4726,7 @@ public void putObject(String bucketName, String objectName, InputStream stream, public void putObject(String bucketName, String objectName, InputStream stream, Map headerMap, ServerSideEncryption sse) throws InvalidBucketNameException, NoSuchAlgorithmException, IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, IllegalArgumentException, InsufficientDataException, InvalidResponseException { putObject(bucketName, objectName, stream, null, headerMap, sse, null ); } @@ -4859,7 +4793,7 @@ public void putObject(String bucketName, String objectName, InputStream stream, * @throws IOException upon connection error * @throws InvalidKeyException * upon an invalid access key or secret key - * @throws XmlPullParserException upon parsing response xml + * @throws XmlParserException upon parsing response xml * @throws ErrorResponseException upon unsuccessful execution * @throws InternalException upon internal library error * @throws IllegalArgumentException upon invalid value is passed to a method. @@ -4872,7 +4806,7 @@ public void putObject(String bucketName, String objectName, InputStream stream, public void putObject(String bucketName, String objectName, InputStream stream, long size, Map headerMap, ServerSideEncryption sse) throws InvalidBucketNameException, NoSuchAlgorithmException, IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, IllegalArgumentException, InsufficientDataException, InvalidResponseException { putObject(bucketName, objectName, stream, size, headerMap, sse, null); } @@ -4928,7 +4862,7 @@ public void putObject(String bucketName, String objectName, InputStream stream, * @throws IOException upon connection error * @throws InvalidKeyException * upon an invalid access key or secret key - * @throws XmlPullParserException upon parsing response xml + * @throws XmlParserException upon parsing response xml * @throws ErrorResponseException upon unsuccessful execution * @throws InternalException upon internal library error * @throws IllegalArgumentException upon invalid value is passed to a method. @@ -4939,7 +4873,7 @@ public void putObject(String bucketName, String objectName, InputStream stream, @Deprecated public void putObject(String bucketName, String objectName, InputStream stream, String contentType) throws InvalidBucketNameException, NoSuchAlgorithmException, IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, IllegalArgumentException, InsufficientDataException, InvalidResponseException { putObject(bucketName, objectName, stream, null, null, null, contentType); } @@ -5008,7 +4942,7 @@ public void putObject(String bucketName, String objectName, InputStream stream, * @throws IOException upon connection error * @throws InvalidKeyException * upon an invalid access key or secret key - * @throws XmlPullParserException upon parsing response xml + * @throws XmlParserException upon parsing response xml * @throws ErrorResponseException upon unsuccessful execution * @throws InternalException upon internal library error * @throws IllegalArgumentException upon invalid value is passed to a method. @@ -5020,7 +4954,7 @@ public void putObject(String bucketName, String objectName, InputStream stream, public void putObject(String bucketName, String objectName, InputStream stream, Long size, Map headerMap, ServerSideEncryption sse, String contentType) throws InvalidBucketNameException, NoSuchAlgorithmException, IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, IllegalArgumentException, InsufficientDataException, InvalidResponseException { if (!(stream instanceof BufferedInputStream)) { @@ -5049,7 +4983,7 @@ public void putObject(String bucketName, String objectName, InputStream stream, private void putObject(String bucketName, String objectName, Long size, Object data, Map headerMap, ServerSideEncryption sse, String contentType) throws InvalidBucketNameException, NoSuchAlgorithmException, IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, IllegalArgumentException, InsufficientDataException, InvalidResponseException { boolean unknownSize = false; @@ -5158,7 +5092,7 @@ private void putObject(String bucketName, String objectName, Long size, Object d private String putObject(String bucketName, String objectName, Object data, int length, Map headerMap, String uploadId, int partNumber) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, InvalidResponseException { HttpResponse response = null; @@ -5178,7 +5112,7 @@ private String putObject(String bucketName, String objectName, Object data, int private void putObject(String bucketName, String objectName, PutObjectOptions options, Object data) throws InvalidBucketNameException, NoSuchAlgorithmException, IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, IllegalArgumentException, InsufficientDataException, InvalidResponseException { Map headerMap = new HashMap<>(); @@ -5268,7 +5202,7 @@ private void putObject(String bucketName, String objectName, PutObjectOptions op * @throws IOException upon connection error * @throws InvalidKeyException * upon an invalid access key or secret key - * @throws XmlPullParserException upon parsing response xml + * @throws XmlParserException upon parsing response xml * @throws ErrorResponseException upon unsuccessful execution * @throws InternalException upon internal library error * @throws IllegalArgumentException upon invalid value is passed to a method. @@ -5276,7 +5210,7 @@ private void putObject(String bucketName, String objectName, PutObjectOptions op */ public void putObject(String bucketName, String objectName, String filename, PutObjectOptions options) throws InvalidBucketNameException, NoSuchAlgorithmException, IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, IllegalArgumentException, InsufficientDataException, InvalidResponseException { checkBucketName(bucketName); checkObjectName(objectName); @@ -5336,7 +5270,7 @@ public void putObject(String bucketName, String objectName, String filename, Put * @throws IOException upon connection error * @throws InvalidKeyException * upon an invalid access key or secret key - * @throws XmlPullParserException upon parsing response xml + * @throws XmlParserException upon parsing response xml * @throws ErrorResponseException upon unsuccessful execution * @throws InternalException upon internal library error * @throws IllegalArgumentException upon invalid value is passed to a method. @@ -5344,7 +5278,7 @@ public void putObject(String bucketName, String objectName, String filename, Put */ public void putObject(String bucketName, String objectName, InputStream stream, PutObjectOptions options) throws InvalidBucketNameException, NoSuchAlgorithmException, IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, IllegalArgumentException, InsufficientDataException, InvalidResponseException { checkBucketName(bucketName); checkObjectName(objectName); @@ -5385,7 +5319,7 @@ public void putObject(String bucketName, String objectName, InputStream stream, * @throws IOException upon connection error * @throws InvalidKeyException * upon an invalid access key or secret key - * @throws XmlPullParserException upon parsing response xml + * @throws XmlParserException upon parsing response xml * @throws ErrorResponseException upon unsuccessful execution * @throws InternalException upon internal library error * @throws BucketPolicyTooLargeException upon bucket policy too large in size @@ -5394,7 +5328,7 @@ public void putObject(String bucketName, String objectName, InputStream stream, public String getBucketPolicy(String bucketName) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, InvalidKeyException, - XmlPullParserException, ErrorResponseException, InternalException, BucketPolicyTooLargeException, + XmlParserException, ErrorResponseException, InternalException, BucketPolicyTooLargeException, InvalidResponseException { Map queryParamMap = new HashMap<>(); queryParamMap.put("policy", ""); @@ -5476,7 +5410,7 @@ public String getBucketPolicy(String bucketName) * @throws IOException upon connection error * @throws InvalidKeyException * upon an invalid access key or secret key - * @throws XmlPullParserException upon parsing response xml + * @throws XmlParserException upon parsing response xml * @throws ErrorResponseException upon unsuccessful execution * @throws InternalException upon internal library error * @throws InvalidResponseException upon a non-xml response from server @@ -5484,7 +5418,7 @@ public String getBucketPolicy(String bucketName) public void setBucketPolicy(String bucketName, String policy) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, InvalidKeyException, - XmlPullParserException, ErrorResponseException, InternalException, InvalidResponseException { + XmlParserException, ErrorResponseException, InternalException, InvalidResponseException { Map headerMap = new HashMap<>(); headerMap.put("Content-Type", "application/json"); @@ -5513,7 +5447,7 @@ public void setBucketPolicy(String bucketName, String policy) * InputStream even before reading given length * @throws IOException upon connection error * @throws InvalidKeyException upon an invalid access key or secret key - * @throws XmlPullParserException upon parsing response xml + * @throws XmlParserException upon parsing response xml * @throws ErrorResponseException upon unsuccessful execution * @throws InternalException upon internal library error * @throws IllegalArgumentException upon invalid value is passed to a method. @@ -5522,7 +5456,7 @@ public void setBucketPolicy(String bucketName, String policy) public void setBucketLifeCycle(String bucketName, String lifeCycle) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, InvalidKeyException, - XmlPullParserException, ErrorResponseException, InternalException,IllegalArgumentException, + XmlParserException, ErrorResponseException, InternalException,IllegalArgumentException, InvalidResponseException { if ((lifeCycle == null) || "".equals(lifeCycle)) { throw new IllegalArgumentException("life cycle cannot be empty"); @@ -5549,7 +5483,7 @@ public void setBucketLifeCycle(String bucketName, String lifeCycle) * InputStream even before reading given length * @throws IOException upon connection error * @throws InvalidKeyException upon an invalid access key or secret key - * @throws XmlPullParserException upon parsing response xml + * @throws XmlParserException upon parsing response xml * @throws ErrorResponseException upon unsuccessful execution * @throws InternalException upon internal library error * @throws InvalidResponseException upon a non-xml response from server @@ -5557,7 +5491,7 @@ public void setBucketLifeCycle(String bucketName, String lifeCycle) public void deleteBucketLifeCycle(String bucketName) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, InvalidKeyException, - XmlPullParserException, ErrorResponseException, InternalException, InvalidResponseException { + XmlParserException, ErrorResponseException, InternalException, InvalidResponseException { Map queryParamMap = new HashMap<>(); queryParamMap.put("lifecycle", ""); HttpResponse response = executeDelete(bucketName, "", queryParamMap); @@ -5578,7 +5512,7 @@ public void deleteBucketLifeCycle(String bucketName) * InputStream even before reading given length * @throws IOException upon connection error * @throws InvalidKeyException upon an invalid access key or secret key - * @throws XmlPullParserException upon parsing response xml + * @throws XmlParserException upon parsing response xml * @throws ErrorResponseException upon unsuccessful execution * @throws InternalException upon internal library error * @throws InvalidResponseException upon a non-xml response from server @@ -5587,7 +5521,7 @@ public void deleteBucketLifeCycle(String bucketName) public String getBucketLifeCycle(String bucketName) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, InvalidKeyException, - XmlPullParserException, ErrorResponseException, InternalException, InvalidResponseException { + XmlParserException, ErrorResponseException, InternalException, InvalidResponseException { Map queryParamMap = new HashMap<>(); queryParamMap.put("lifecycle", ""); HttpResponse response = null; @@ -5633,7 +5567,7 @@ public String getBucketLifeCycle(String bucketName) * @throws IOException upon connection error * @throws InvalidKeyException * upon an invalid access key or secret key - * @throws XmlPullParserException upon parsing response xml + * @throws XmlParserException upon parsing response xml * @throws ErrorResponseException upon unsuccessful execution * @throws InternalException upon internal library error * @throws InvalidResponseException upon a non-xml response from server @@ -5642,19 +5576,14 @@ public String getBucketLifeCycle(String bucketName) public NotificationConfiguration getBucketNotification(String bucketName) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, InvalidKeyException, - XmlPullParserException, ErrorResponseException, InternalException, InvalidResponseException { + XmlParserException, ErrorResponseException, InternalException, InvalidResponseException { Map queryParamMap = new HashMap<>(); queryParamMap.put("notification", ""); HttpResponse response = executeGet(bucketName, null, null, queryParamMap); - NotificationConfiguration result = new NotificationConfiguration(); - try { - result.parseXml(response.body().charStream()); - } finally { - response.body().close(); + try (ResponseBody body = response.body()) { + return Xml.unmarshal(NotificationConfiguration.class, body.charStream()); } - - return result; } @@ -5676,7 +5605,7 @@ public NotificationConfiguration getBucketNotification(String bucketName) * @throws IOException upon connection error * @throws InvalidKeyException * upon an invalid access key or secret key - * @throws XmlPullParserException upon parsing response xml + * @throws XmlParserException upon parsing response xml * @throws ErrorResponseException upon unsuccessful execution * @throws InternalException upon internal library error * @throws InvalidResponseException upon a non-xml response from server @@ -5685,7 +5614,7 @@ public NotificationConfiguration getBucketNotification(String bucketName) public void setBucketNotification(String bucketName, NotificationConfiguration notificationConfiguration) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, InvalidKeyException, - XmlPullParserException, ErrorResponseException, InternalException, InvalidResponseException { + XmlParserException, ErrorResponseException, InternalException, InvalidResponseException { Map queryParamMap = new HashMap<>(); queryParamMap.put("notification", ""); HttpResponse response = executePut(bucketName, null, null, queryParamMap, notificationConfiguration.toString(), 0); @@ -5710,7 +5639,7 @@ public void setBucketNotification(String bucketName, NotificationConfiguration n * @throws IOException upon connection error * @throws InvalidKeyException * upon an invalid access key or secret key - * @throws XmlPullParserException upon parsing response xml + * @throws XmlParserException upon parsing response xml * @throws ErrorResponseException upon unsuccessful execution * @throws InternalException upon internal library error * @throws InvalidResponseException upon a non-xml response from server @@ -5718,7 +5647,7 @@ public void setBucketNotification(String bucketName, NotificationConfiguration n public void removeAllBucketNotification(String bucketName) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, InvalidKeyException, - XmlPullParserException, ErrorResponseException, InternalException, InvalidResponseException { + XmlParserException, ErrorResponseException, InternalException, InvalidResponseException { NotificationConfiguration notificationConfiguration = new NotificationConfiguration(); setBucketNotification(bucketName, notificationConfiguration); } @@ -5731,7 +5660,7 @@ public void removeAllBucketNotification(String bucketName) * @return an iterator of Upload. * @see #listIncompleteUploads(String, String, boolean) */ - public Iterable> listIncompleteUploads(String bucketName) throws XmlPullParserException { + public Iterable> listIncompleteUploads(String bucketName) throws XmlParserException { return listIncompleteUploads(bucketName, null, true, true); } @@ -5743,11 +5672,11 @@ public Iterable> listIncompleteUploads(String bucketName) throws * * @return an iterator of Upload. * - * @throws XmlPullParserException upon parsing response xml + * @throws XmlParserException upon parsing response xml * @see #listIncompleteUploads(String, String, boolean) */ public Iterable> listIncompleteUploads(String bucketName, String prefix) - throws XmlPullParserException { + throws XmlParserException { return listIncompleteUploads(bucketName, prefix, true, true); } @@ -5806,9 +5735,9 @@ private synchronized void populate() { this.listMultipartUploadsResult = listIncompleteUploads(bucketName, nextKeyMarker, nextUploadIdMarker, prefix, delimiter, 1000); } catch (InvalidBucketNameException | NoSuchAlgorithmException | InsufficientDataException | IOException - | InvalidKeyException | XmlPullParserException | ErrorResponseException + | InvalidKeyException | XmlParserException | ErrorResponseException | InternalException | InvalidResponseException e) { - this.error = new Result<>(null, e); + this.error = new Result<>(e); } finally { if (this.listMultipartUploadsResult != null) { this.uploadIterator = this.listMultipartUploadsResult.uploads().iterator(); @@ -5820,7 +5749,7 @@ private synchronized void populate() { private synchronized long getAggregatedPartSize(String objectName, String uploadId) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException { long aggregatedPartSize = 0; @@ -5891,7 +5820,7 @@ public Result next() { try { aggregatedPartSize = getAggregatedPartSize(upload.objectName(), upload.uploadId()); } catch (InvalidBucketNameException | NoSuchAlgorithmException | InsufficientDataException | IOException - | InvalidKeyException | XmlPullParserException | ErrorResponseException + | InvalidKeyException | XmlParserException | ErrorResponseException | InternalException e) { // special case: ignore the error as we can't propagate the exception in next() aggregatedPartSize = -1; @@ -5900,7 +5829,7 @@ public Result next() { upload.setAggregatedPartSize(aggregatedPartSize); } - return new Result<>(upload, null); + return new Result<>(upload); } this.completed = true; @@ -5923,7 +5852,7 @@ public void remove() { private ListMultipartUploadsResult listIncompleteUploads(String bucketName, String keyMarker, String uploadIdMarker, String prefix, String delimiter, int maxUploads) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, InvalidResponseException { if (maxUploads < 0 || maxUploads > 1000) { maxUploads = 1000; @@ -5955,10 +5884,9 @@ private ListMultipartUploadsResult listIncompleteUploads(String bucketName, Stri HttpResponse response = executeGet(bucketName, null, null, queryParamMap); - ListMultipartUploadsResult result = new ListMultipartUploadsResult(); - result.parseXml(response.body().charStream()); - response.body().close(); - return result; + try (ResponseBody body = response.body()) { + return Xml.unmarshal(ListMultipartUploadsResult.class, body.charStream()); + } } @@ -5967,7 +5895,7 @@ private ListMultipartUploadsResult listIncompleteUploads(String bucketName, Stri */ private String initMultipartUpload(String bucketName, String objectName, Map headerMap) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException , InvalidResponseException { // set content type if not set already if ((headerMap != null) && (headerMap.get("Content-Type") == null)) { @@ -5979,10 +5907,10 @@ private String initMultipartUpload(String bucketName, String objectName, Map queryParamMap = new HashMap<>(); queryParamMap.put(UPLOAD_ID, uploadId); @@ -6016,9 +5944,13 @@ private void completeMultipart(String bucketName, String objectName, String uplo bodyContent = bodyContent.trim(); if (!bodyContent.isEmpty()) { - ErrorResponse errorResponse = new ErrorResponse(new StringReader(bodyContent)); - if (errorResponse.code() != null) { - throw new ErrorResponseException(errorResponse, response.response()); + try { + if (Xml.validate(ErrorResponse.class, bodyContent)) { + ErrorResponse errorResponse = Xml.unmarshal(ErrorResponse.class, bodyContent); + throw new ErrorResponseException(errorResponse, response.response()); + } + } catch (XmlParserException e) { + // As it is not message, ignore this exception } } } @@ -6047,9 +5979,9 @@ private synchronized void populate() { try { this.listPartsResult = listObjectParts(bucketName, objectName, uploadId, nextPartNumberMarker); } catch (InvalidBucketNameException | NoSuchAlgorithmException | InsufficientDataException | IOException - | InvalidKeyException | XmlPullParserException | ErrorResponseException + | InvalidKeyException | XmlParserException | ErrorResponseException | InternalException | InvalidResponseException e) { - this.error = new Result<>(null, e); + this.error = new Result<>(e); } finally { if (this.listPartsResult != null) { this.partIterator = this.listPartsResult.partList().iterator(); @@ -6107,7 +6039,7 @@ public Result next() { } if (this.partIterator.hasNext()) { - return new Result<>(this.partIterator.next(), null); + return new Result<>(this.partIterator.next()); } this.completed = true; @@ -6130,7 +6062,7 @@ public void remove() { */ private ListPartsResult listObjectParts(String bucketName, String objectName, String uploadId, int partNumberMarker) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, InvalidResponseException { Map queryParamMap = new HashMap<>(); queryParamMap.put(UPLOAD_ID, uploadId); @@ -6140,10 +6072,9 @@ private ListPartsResult listObjectParts(String bucketName, String objectName, St HttpResponse response = executeGet(bucketName, objectName, null, queryParamMap); - ListPartsResult result = new ListPartsResult(); - result.parseXml(response.body().charStream()); - response.body().close(); - return result; + try (ResponseBody body = response.body()) { + return Xml.unmarshal(ListPartsResult.class, body.charStream()); + } } @@ -6152,7 +6083,7 @@ private ListPartsResult listObjectParts(String bucketName, String objectName, St */ private void abortMultipartUpload(String bucketName, String objectName, String uploadId) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, InvalidResponseException { Map queryParamMap = new HashMap<>(); queryParamMap.put(UPLOAD_ID, uploadId); @@ -6178,14 +6109,14 @@ private void abortMultipartUpload(String bucketName, String objectName, String u * @throws IOException upon connection error * @throws InvalidKeyException * upon an invalid access key or secret key - * @throws XmlPullParserException upon parsing response xml + * @throws XmlParserException upon parsing response xml * @throws ErrorResponseException upon unsuccessful execution * @throws InternalException upon internal library error * @throws InvalidResponseException upon a non-xml response from server */ public void removeIncompleteUpload(String bucketName, String objectName) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, InvalidResponseException { for (Result r : listIncompleteUploads(bucketName, objectName, true, false)) { Upload upload = r.get(); @@ -6213,7 +6144,7 @@ public void removeIncompleteUpload(String bucketName, String objectName) * @throws IOException upon connection error * @throws InvalidKeyException * upon an invalid access key or secret key - * @throws XmlPullParserException upon parsing response xml + * @throws XmlParserException upon parsing response xml * @throws ErrorResponseException upon unsuccessful execution * @throws InternalException upon internal library error * @throws InvalidResponseException upon a non-xml response from server @@ -6222,7 +6153,7 @@ public void removeIncompleteUpload(String bucketName, String objectName) public void listenBucketNotification(String bucketName, String prefix, String suffix, String[] events, BucketEventListener eventCallback) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, InvalidResponseException { Multimap queryParamMap = HashMultimap.create(); @@ -6295,7 +6226,7 @@ public CloseableIterator> listenBucketNotification(Stri String suffix, String[] events) throws IOException, InvalidKeyException, NoSuchAlgorithmException, InsufficientDataException, InvalidResponseException, InternalException, InvalidBucketNameException, - XmlPullParserException, ErrorResponseException { + XmlParserException, ErrorResponseException { Multimap queryParamMap = HashMultimap.create(); queryParamMap.put("prefix", prefix); @@ -6370,13 +6301,13 @@ public Result next() { try { notificationInfo = mapper.readValue(notificationString, NotificationInfo.class); - return new Result<>(notificationInfo, null); + return new Result<>(notificationInfo); } catch (JsonParseException e) { - return new Result<>(null, e); + return new Result<>(e); } catch ( JsonMappingException e) { - return new Result<>(null, e); + return new Result<>(e); } catch ( IOException e) { - return new Result<>(null, e); + return new Result<>(e); } finally { notificationString = null; notificationInfo = null; @@ -6408,7 +6339,7 @@ public Result next() { * @throws IOException upon connection error * @throws InvalidKeyException * upon an invalid access key or secret key - * @throws XmlPullParserException upon parsing response xml + * @throws XmlParserException upon parsing response xml * @throws ErrorResponseException upon unsuccessful execution * @throws InternalException upon internal library error * @throws InvalidResponseException upon a non-xml response from server @@ -6419,7 +6350,7 @@ public SelectResponseStream selectObjectContent(String bucketName, String object InputSerialization is, OutputSerialization os, boolean requestProgress, Long scanStartRange, Long scanEndRange, ServerSideEncryption sse) throws InvalidBucketNameException, IllegalArgumentException, NoSuchAlgorithmException, InsufficientDataException, - IOException, InvalidKeyException, XmlPullParserException, ErrorResponseException, + IOException, InvalidKeyException, XmlParserException, ErrorResponseException, InternalException, InvalidResponseException { if ((bucketName == null) || (bucketName.isEmpty())) { throw new IllegalArgumentException("bucket name cannot be empty"); diff --git a/api/src/main/java/io/minio/Result.java b/api/src/main/java/io/minio/Result.java index 82b3a5558..eb6a1ad9f 100644 --- a/api/src/main/java/io/minio/Result.java +++ b/api/src/main/java/io/minio/Result.java @@ -18,16 +18,14 @@ import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonMappingException; -import java.io.IOException; -import java.security.InvalidKeyException; -import java.security.NoSuchAlgorithmException; - -import org.xmlpull.v1.XmlPullParserException; - import io.minio.errors.ErrorResponseException; import io.minio.errors.InsufficientDataException; import io.minio.errors.InternalException; import io.minio.errors.InvalidBucketNameException; +import io.minio.errors.XmlParserException; +import java.io.IOException; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; /** @@ -38,8 +36,14 @@ public class Result { private final Exception ex; - public Result(T type, Exception ex) { + public Result(T type) { this.type = type; + this.ex = null; + } + + + public Result(Exception ex) { + this.type = null; this.ex = ex; } @@ -50,7 +54,7 @@ public Result(T type, Exception ex) { public T get() throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, JsonParseException, JsonMappingException,IOException, - InvalidKeyException, XmlPullParserException, ErrorResponseException, + InvalidKeyException, XmlParserException, ErrorResponseException, InternalException { if (ex == null) { return type; @@ -72,8 +76,8 @@ public T get() throw (InvalidKeyException) ex; } - if (ex instanceof XmlPullParserException) { - throw (XmlPullParserException) ex; + if (ex instanceof XmlParserException) { + throw (XmlParserException) ex; } if (ex instanceof ErrorResponseException) { diff --git a/api/src/main/java/io/minio/SelectResponseStream.java b/api/src/main/java/io/minio/SelectResponseStream.java index d206dc057..95038e622 100644 --- a/api/src/main/java/io/minio/SelectResponseStream.java +++ b/api/src/main/java/io/minio/SelectResponseStream.java @@ -19,6 +19,7 @@ import io.minio.errors.InternalException; import io.minio.errors.MinioException; import io.minio.messages.Stats; +import io.minio.messages.Progress; import java.io.ByteArrayInputStream; import java.io.EOFException; @@ -140,15 +141,13 @@ private boolean populate() ByteArrayInputStream payloadStream = new ByteArrayInputStream(data, headerLength, payloadLength); if (headerMap.get(":event-type").equals("Progress")) { - Stats stats = new Stats("Progress"); - stats.parseXml(new InputStreamReader(payloadStream, StandardCharsets.UTF_8)); + Stats stats = (Stats) Xml.unmarshal(Progress.class, new InputStreamReader(payloadStream, StandardCharsets.UTF_8)); this.stats = stats; return false; } if (headerMap.get(":event-type").equals("Stats")) { - Stats stats = new Stats("Stats"); - stats.parseXml(new InputStreamReader(payloadStream, StandardCharsets.UTF_8)); + Stats stats = Xml.unmarshal(Stats.class, new InputStreamReader(payloadStream, StandardCharsets.UTF_8)); this.stats = stats; return false; } diff --git a/api/src/main/java/io/minio/Xml.java b/api/src/main/java/io/minio/Xml.java new file mode 100644 index 000000000..5efc576f8 --- /dev/null +++ b/api/src/main/java/io/minio/Xml.java @@ -0,0 +1,86 @@ +/* + * MinIO Java SDK for Amazon S3 Compatible Cloud Storage, + * (C) 2020 MinIO, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.minio; + +import io.minio.errors.XmlParserException; +import java.io.Reader; +import java.io.StringReader; +import java.io.StringWriter; +import org.simpleframework.xml.convert.AnnotationStrategy; +import org.simpleframework.xml.core.Persister; +import org.simpleframework.xml.Serializer; + + +public class Xml { + /** + * This marshal method will traverse the provided object checking for field annotations in order + * to compose the XML data. + */ + public static String marshal(Object source) throws XmlParserException { + try { + Serializer serializer = new Persister(new AnnotationStrategy()); + StringWriter writer = new StringWriter(); + serializer.write(source, writer); + return writer.toString(); + } catch (Exception e) { + throw new XmlParserException(e); + } + } + + + /** + * This unmarshal method will read the contents of the XML document from the provided source and + * populate the object with the values deserialized. + */ + public static T unmarshal(Class type, Reader source) throws XmlParserException { + try { + Serializer serializer = new Persister(new AnnotationStrategy()); + return serializer.read(type, source); + } catch (Exception e) { + throw new XmlParserException(e); + } + } + + + /** + * This unmarshal method will read the contents of the XML document from the provided source and + * populate the object with the values deserialized. + */ + public static T unmarshal(Class type, String source) throws XmlParserException { + try { + Serializer serializer = new Persister(new AnnotationStrategy()); + return serializer.read(type, new StringReader(source)); + } catch (Exception e) { + throw new XmlParserException(e); + } + } + + + /** + * This validate method will validate the contents of the XML document against the specified XML + * class schema. + */ + public static boolean validate(Class type, String source) throws XmlParserException { + try { + Serializer serializer = new Persister(new AnnotationStrategy()); + return serializer.validate(type, source); + } catch (Exception e) { + throw new XmlParserException(e); + } + } +} diff --git a/api/src/main/java/io/minio/errors/ErrorResponseException.java b/api/src/main/java/io/minio/errors/ErrorResponseException.java index 53e88aa5d..d33e5ad41 100644 --- a/api/src/main/java/io/minio/errors/ErrorResponseException.java +++ b/api/src/main/java/io/minio/errors/ErrorResponseException.java @@ -55,7 +55,7 @@ public ErrorResponse errorResponse() { public String toString() { Request request = response.request(); return "error occurred\n" - + errorResponse.getString() + "\n" + + errorResponse.toString() + "\n" + "request={" + "method=" + request.method() + ", " + "url=" + request.url() + ", " diff --git a/api/src/main/java/io/minio/errors/XmlParserException.java b/api/src/main/java/io/minio/errors/XmlParserException.java new file mode 100644 index 000000000..1c7fe2d8e --- /dev/null +++ b/api/src/main/java/io/minio/errors/XmlParserException.java @@ -0,0 +1,34 @@ +/* + * MinIO Java SDK for Amazon S3 Compatible Cloud Storage, (C) 2015 MinIO, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.minio.errors; + + +public class XmlParserException extends MinioException { + Exception exception; + + + public XmlParserException(Exception exception) { + super(); + this.exception = exception; + } + + + @Override + public String toString() { + return exception.toString(); + } +} diff --git a/api/src/main/java/io/minio/messages/Bucket.java b/api/src/main/java/io/minio/messages/Bucket.java index 1bf28aaf5..bd46e5dd5 100644 --- a/api/src/main/java/io/minio/messages/Bucket.java +++ b/api/src/main/java/io/minio/messages/Bucket.java @@ -16,26 +16,23 @@ package io.minio.messages; -import com.google.api.client.util.Key; -import io.minio.Time; import java.time.ZonedDateTime; -import org.xmlpull.v1.XmlPullParserException; +import org.simpleframework.xml.Element; +import org.simpleframework.xml.Root; /** - * Helper class to parse Amazon AWS S3 response XML containing bucket information. + * Helper class to denote bucket information for ListAllMyBucketsResult. */ -@SuppressWarnings("SameParameterValue") -public class Bucket extends XmlEntity { - @Key("Name") +@Root(name = "Bucket", strict = false) +public class Bucket { + @Element(name = "Name") private String name; - @Key("CreationDate") - private String creationDate; + @Element(name = "CreationDate") + private ResponseDate creationDate; - public Bucket() throws XmlPullParserException { - super(); - super.name = "Bucket"; + public Bucket() { } @@ -51,6 +48,6 @@ public String name() { * Returns creation date. */ public ZonedDateTime creationDate() { - return ZonedDateTime.parse(creationDate, Time.RESPONSE_DATE_FORMAT); + return creationDate.zonedDateTime(); } } diff --git a/api/src/main/java/io/minio/messages/CloudFunctionConfiguration.java b/api/src/main/java/io/minio/messages/CloudFunctionConfiguration.java index c7320df03..ce6045d0d 100644 --- a/api/src/main/java/io/minio/messages/CloudFunctionConfiguration.java +++ b/api/src/main/java/io/minio/messages/CloudFunctionConfiguration.java @@ -16,47 +16,21 @@ package io.minio.messages; -import java.util.LinkedList; -import java.util.List; - -import org.xmlpull.v1.XmlPullParserException; - -import com.google.api.client.util.Key; +import org.simpleframework.xml.Element; +import org.simpleframework.xml.Root; /** - * Helper class to parse Amazon AWS S3 response XML containing cloud function configuration. + * Helper class to denote CloudFunction configuration of NotificationConfiguration. */ -public class CloudFunctionConfiguration extends XmlEntity { - @Key("Id") - private String id; - @Key("CloudFunction") +@Root(name = "CloudFunctionConfiguration", strict = false) +public class CloudFunctionConfiguration extends NotificationCommonConfiguration { + @Element(name = "CloudFunction") private String cloudFunction; - @Key("Event") - private List events = new LinkedList<>(); - @Key("Filter") - private Filter filter; - public CloudFunctionConfiguration() throws XmlPullParserException { + public CloudFunctionConfiguration() { super(); - super.name = "CloudFunctionConfiguration"; - } - - - /** - * Returns id. - */ - public String id() { - return id; - } - - - /** - * Sets id. - */ - public void setId(String id) { - this.id = id; } @@ -74,36 +48,4 @@ public String cloudFunction() { public void setCloudFunction(String cloudFunction) { this.cloudFunction = cloudFunction; } - - - /** - * Returns events. - */ - public List events() throws IllegalArgumentException { - return EventType.fromStringList(events); - } - - - /** - * Sets event. - */ - public void setEvents(List events) { - this.events = EventType.toStringList(events); - } - - - /** - * Returns filter. - */ - public Filter filter() { - return filter; - } - - - /** - * Sets filter. - */ - public void setFilter(Filter filter) { - this.filter = filter; - } } diff --git a/api/src/main/java/io/minio/messages/CompleteMultipartUpload.java b/api/src/main/java/io/minio/messages/CompleteMultipartUpload.java index 8bbe53769..a684775b4 100644 --- a/api/src/main/java/io/minio/messages/CompleteMultipartUpload.java +++ b/api/src/main/java/io/minio/messages/CompleteMultipartUpload.java @@ -18,46 +18,31 @@ import java.util.Arrays; import java.util.List; - -import org.xmlpull.v1.XmlPullParserException; - -import com.google.api.client.util.Key; +import org.simpleframework.xml.ElementList; +import org.simpleframework.xml.Namespace; +import org.simpleframework.xml.Root; /** - * Helper class to construct complete multipart upload request XML for Amazon AWS S3. + * Denotes complete multipart upload request XML as per + * https://docs.aws.amazon.com/AmazonS3/latest/API/API_CompleteMultipartUpload.html. */ -@SuppressWarnings("unused") -public class CompleteMultipartUpload extends XmlEntity { - @Key("Part") +@Root(name = "CompleteMultipartUpload") +@Namespace(reference = "http://s3.amazonaws.com/doc/2006-03-01/") +@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(value = "URF_UNREAD_FIELD") +public class CompleteMultipartUpload { + @ElementList(name = "Part", inline = true) private List partList; - public CompleteMultipartUpload() throws XmlPullParserException { - this(null); - } - - /** * Constucts a new CompleteMultipartUpload object with given parts. */ - public CompleteMultipartUpload(Part[] parts) throws XmlPullParserException { - super(); - super.name = "CompleteMultipartUpload"; - super.namespaceDictionary.set("", "http://s3.amazonaws.com/doc/2006-03-01/"); - - if (parts == null) { - this.partList = null; - } else { - this.partList = Arrays.asList(parts); + public CompleteMultipartUpload(Part[] parts) throws IllegalArgumentException { + if (parts == null || parts.length == 0) { + throw new IllegalArgumentException("null or empty parts"); } - } - - /** - * Returns List of Parts of mulitpart upload. - */ - public List partList() { - return partList; + this.partList = Arrays.asList(parts); } } diff --git a/api/src/main/java/io/minio/messages/CompressionType.java b/api/src/main/java/io/minio/messages/CompressionType.java index f38258e7a..092d1c787 100644 --- a/api/src/main/java/io/minio/messages/CompressionType.java +++ b/api/src/main/java/io/minio/messages/CompressionType.java @@ -18,7 +18,7 @@ /** - * CSV/JSON object's compression format. + * CSV/JSON object's compression format for select object content. */ public enum CompressionType { NONE, GZIP, BZIP2; diff --git a/api/src/main/java/io/minio/messages/CopyObjectResult.java b/api/src/main/java/io/minio/messages/CopyObjectResult.java index 096c5a060..b67374c79 100644 --- a/api/src/main/java/io/minio/messages/CopyObjectResult.java +++ b/api/src/main/java/io/minio/messages/CopyObjectResult.java @@ -17,38 +17,40 @@ package io.minio.messages; -import com.google.api.client.util.Key; import java.time.ZonedDateTime; -import io.minio.Time; -import org.xmlpull.v1.XmlPullParserException; +import org.simpleframework.xml.Element; +import org.simpleframework.xml.Namespace; +import org.simpleframework.xml.Root; + /** - * Helper class to parse Amazon AWS S3 response XML containing - * object item information. + * Denotes CopyObject response XML as per https://docs.aws.amazon.com/AmazonS3/latest/API/API_CopyObject.html. */ -@SuppressWarnings({ "SameParameterValue", "unused" }) -public class CopyObjectResult extends XmlEntity { - @Key("ETag") +@Root(name = "CopyObjectResult", strict = false) +@Namespace(reference = "http://s3.amazonaws.com/doc/2006-03-01/") +public class CopyObjectResult { + @Element(name = "ETag") private String etag; - @Key("LastModified") - private String lastModified; + @Element(name = "LastModified") + private ResponseDate lastModified; - public CopyObjectResult() throws XmlPullParserException { - super(); - super.name = "CopyObjectResult"; - } - /** - * Returns last modified time of the object. - */ - public ZonedDateTime lastModified() { - return ZonedDateTime.parse(lastModified, Time.RESPONSE_DATE_FORMAT); + public CopyObjectResult() { } + /** * Returns ETag of the object. */ public String etag() { return etag; } + + + /** + * Returns last modified time. + */ + public ZonedDateTime lastModified() { + return lastModified.zonedDateTime(); + } } diff --git a/api/src/main/java/io/minio/messages/CopyPartResult.java b/api/src/main/java/io/minio/messages/CopyPartResult.java index 7f9a8bc5a..dbecdfcfa 100644 --- a/api/src/main/java/io/minio/messages/CopyPartResult.java +++ b/api/src/main/java/io/minio/messages/CopyPartResult.java @@ -17,39 +17,14 @@ package io.minio.messages; -import com.google.api.client.util.Key; -import io.minio.Time; -import java.time.ZonedDateTime; -import org.xmlpull.v1.XmlPullParserException; +import org.simpleframework.xml.Namespace; +import org.simpleframework.xml.Root; + /** - * Helper class to parse Amazon AWS S3 response XML containing - * object item information. + * Denotes UploadPartCopy response XML as per https://docs.aws.amazon.com/AmazonS3/latest/API/API_UploadPartCopy.html. */ -@SuppressWarnings({ "SameParameterValue", "unused" }) -public class CopyPartResult extends XmlEntity { - @Key("ETag") - private String etag; - @Key("LastModified") - private String lastModified; - - public CopyPartResult() throws XmlPullParserException { - super(); - super.name = "CopyPartResult"; - } - - /** - * Returns last modified time of the object. - */ - public ZonedDateTime lastModified() { - return ZonedDateTime.parse(lastModified, Time.RESPONSE_DATE_FORMAT); - } - - /** - * Returns ETag of the object. - */ - public String etag() { - return etag; - } +@Root(name = "CopyPartResult", strict = false) +@Namespace(reference = "http://s3.amazonaws.com/doc/2006-03-01/") +public class CopyPartResult extends CopyObjectResult { } - diff --git a/api/src/main/java/io/minio/messages/CreateBucketConfiguration.java b/api/src/main/java/io/minio/messages/CreateBucketConfiguration.java index 5de08ed97..e8b27a9b1 100644 --- a/api/src/main/java/io/minio/messages/CreateBucketConfiguration.java +++ b/api/src/main/java/io/minio/messages/CreateBucketConfiguration.java @@ -16,36 +16,27 @@ package io.minio.messages; -import org.xmlpull.v1.XmlPullParserException; - -import com.google.api.client.util.Key; +import org.simpleframework.xml.Element; +import org.simpleframework.xml.Namespace; +import org.simpleframework.xml.Root; /** - * Helper class to construct create bucket configuration request XML for Amazon AWS S3. + * Denotes create bucket configuration request XML as per + * https://docs.aws.amazon.com/AmazonS3/latest/API/API_CreateBucket.html. */ -public class CreateBucketConfiguration extends XmlEntity { - @Key("LocationConstraint") +@Root(name = "CreateBucketConfiguration") +@Namespace(reference = "http://s3.amazonaws.com/doc/2006-03-01/") +@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(value = "URF_UNREAD_FIELD") +public class CreateBucketConfiguration { + @Element(name = "LocationConstraint") private String locationConstraint; /** * Constructs a new CreateBucketConfiguration object with given location constraint. */ - public CreateBucketConfiguration(String locationConstraint) throws XmlPullParserException { - super(); - super.name = "CreateBucketConfiguration"; - super.namespaceDictionary.set("", "http://s3.amazonaws.com/doc/2006-03-01/"); - + public CreateBucketConfiguration(String locationConstraint) { this.locationConstraint = locationConstraint; } - - - /** - * Returns location constraint. - */ - @SuppressWarnings("unused") - public String locationConstraint() { - return locationConstraint; - } } diff --git a/api/src/main/java/io/minio/messages/CsvInputSerialization.java b/api/src/main/java/io/minio/messages/CsvInputSerialization.java index eabbf0845..290dba9d9 100644 --- a/api/src/main/java/io/minio/messages/CsvInputSerialization.java +++ b/api/src/main/java/io/minio/messages/CsvInputSerialization.java @@ -16,30 +16,29 @@ package io.minio.messages; -import org.xmlpull.v1.XmlPullParserException; - -import com.google.api.client.util.Key; +import org.simpleframework.xml.Element; +import org.simpleframework.xml.Root; /** - * Helper class to generate Amazon AWS S3 request XML for SelectObjectContentRequest/InputSerialization/CSV - * information. + * Helper class to denote CSV input serialization request XML as per SelectObjectContentRequest. */ +@Root(name = "CSV") @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(value = "URF_UNREAD_FIELD") -public class CsvInputSerialization extends XmlEntity { - @Key("AllowQuotedRecordDelimiter") +public class CsvInputSerialization { + @Element(name = "AllowQuotedRecordDelimiter", required = false) private boolean allowQuotedRecordDelimiter; - @Key("Comments") + @Element(name = "Comments", required = false) private Character comments; - @Key("FieldDelimiter") + @Element(name = "FieldDelimiter", required = false) private Character fieldDelimiter; - @Key("FileHeaderInfo") - private String fileHeaderInfo; - @Key("QuoteCharacter") + @Element(name = "FileHeaderInfo", required = false) + private FileHeaderInfo fileHeaderInfo; + @Element(name = "QuoteCharacter", required = false) private Character quoteCharacter; - @Key("QuoteEscapeCharacter") + @Element(name = "QuoteEscapeCharacter", required = false) private Character quoteEscapeCharacter; - @Key("RecordDelimiter") + @Element(name = "RecordDelimiter", required = false) private Character recordDelimiter; @@ -48,17 +47,11 @@ public class CsvInputSerialization extends XmlEntity { */ public CsvInputSerialization(boolean allowQuotedRecordDelimiter, Character comments, Character fieldDelimiter, FileHeaderInfo fileHeaderInfo, Character quoteCharacter, Character quoteEscapeCharacter, - Character recordDelimiter) - throws XmlPullParserException { - super(); - this.name = "CSV"; - + Character recordDelimiter) { this.allowQuotedRecordDelimiter = allowQuotedRecordDelimiter; this.comments = comments; this.fieldDelimiter = fieldDelimiter; - if (fileHeaderInfo != null) { - this.fileHeaderInfo = fileHeaderInfo.toString(); - } + this.fileHeaderInfo = fileHeaderInfo; this.quoteCharacter = quoteCharacter; this.quoteEscapeCharacter = quoteEscapeCharacter; this.recordDelimiter = recordDelimiter; diff --git a/api/src/main/java/io/minio/messages/CsvOutputSerialization.java b/api/src/main/java/io/minio/messages/CsvOutputSerialization.java index 42ccc7910..5dcc6fce4 100644 --- a/api/src/main/java/io/minio/messages/CsvOutputSerialization.java +++ b/api/src/main/java/io/minio/messages/CsvOutputSerialization.java @@ -16,26 +16,25 @@ package io.minio.messages; -import org.xmlpull.v1.XmlPullParserException; - -import com.google.api.client.util.Key; +import org.simpleframework.xml.Element; +import org.simpleframework.xml.Root; /** - * Helper class to generate Amazon AWS S3 request XML for SelectObjectContentRequest/OutputSerialization/CSV - * information. + * Helper class to denote CSV output serialization request XML as per SelectObjectContentRequest. */ +@Root(name = "CSV") @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(value = "URF_UNREAD_FIELD") -public class CsvOutputSerialization extends XmlEntity { - @Key("FieldDelimiter") +public class CsvOutputSerialization { + @Element(name = "FieldDelimiter", required = false) private Character fieldDelimiter; - @Key("QuoteCharacter") + @Element(name = "QuoteCharacter", required = false) private Character quoteCharacter; - @Key("QuoteEscapeCharacter") + @Element(name = "QuoteEscapeCharacter", required = false) private Character quoteEscapeCharacter; - @Key("QuoteFields") - private String quoteFields; - @Key("RecordDelimiter") + @Element(name = "QuoteFields", required = false) + private QuoteFields quoteFields; + @Element(name = "RecordDelimiter", required = false) private Character recordDelimiter; @@ -43,16 +42,11 @@ public class CsvOutputSerialization extends XmlEntity { * Constructs a new CsvOutputSerialization object. */ public CsvOutputSerialization(Character fieldDelimiter, Character quoteCharacter, Character quoteEscapeCharacter, - QuoteFields quoteFields, Character recordDelimiter) throws XmlPullParserException { - super(); - this.name = "CSV"; - + QuoteFields quoteFields, Character recordDelimiter) { this.fieldDelimiter = fieldDelimiter; this.quoteCharacter = quoteCharacter; this.quoteEscapeCharacter = quoteEscapeCharacter; - if (quoteFields != null) { - this.quoteFields = quoteFields.toString(); - } + this.quoteFields = quoteFields; this.recordDelimiter = recordDelimiter; } } diff --git a/api/src/main/java/io/minio/messages/DefaultRetention.java b/api/src/main/java/io/minio/messages/DefaultRetention.java index eb5ed3b4f..0eca221f3 100644 --- a/api/src/main/java/io/minio/messages/DefaultRetention.java +++ b/api/src/main/java/io/minio/messages/DefaultRetention.java @@ -16,68 +16,39 @@ package io.minio.messages; -import org.xmlpull.v1.XmlPullParserException; - -import com.google.api.client.util.Key; +import org.simpleframework.xml.Element; +import org.simpleframework.xml.ElementUnion; +import org.simpleframework.xml.Root; /** - * Helper class to parse Amazon AWS S3 response XML containing DefaultRetention information. + * Helper class to denote DefaultRetention information for ObjectLockConfiguration. */ -@SuppressWarnings("SameParameterValue") -public class DefaultRetention extends XmlEntity { - @Key("Mode") - private String mode; - @Key("Days") - private Integer days; - @Key("Years") - private Integer years; +@Root(name = "DefaultRetention", strict = false) +public class DefaultRetention { + @Element(name = "Mode", required = false) + private RetentionMode mode; + @ElementUnion({@Element(name = "Days", type = RetentionDurationDays.class, required = false), + @Element(name = "Years", type = RetentionDurationYears.class, required = false)}) + private RetentionDuration duration; - public DefaultRetention() throws XmlPullParserException { - super(); - this.name = "DefaultRetention"; + public DefaultRetention() { } - /** - * Constructs a new DefaultRetention object with given retention. - */ - public DefaultRetention(RetentionMode mode, int duration, DurationUnit unit) throws XmlPullParserException { - this(); - - if (mode != null) { - this.mode = mode.toString(); - } - - if (unit == DurationUnit.DAYS) { - this.days = duration; - } else { - this.years = duration; - } + public DefaultRetention(RetentionMode mode, RetentionDuration duration) { + this.mode = mode; + this.duration = duration; } - /** - * Returns mode. - */ public RetentionMode mode() { - return RetentionMode.fromString(mode); - } - - - /** - * Returns days. - */ - public Integer days() { - return days; + return mode; } - /** - * Returns years. - */ - public Integer years() { - return years; + public RetentionDuration duration() { + return duration; } } diff --git a/api/src/main/java/io/minio/messages/DeleteError.java b/api/src/main/java/io/minio/messages/DeleteError.java index 01cc63369..8d836f9ea 100644 --- a/api/src/main/java/io/minio/messages/DeleteError.java +++ b/api/src/main/java/io/minio/messages/DeleteError.java @@ -16,31 +16,15 @@ package io.minio.messages; -import java.io.IOException; -import java.io.Reader; - -import org.xmlpull.v1.XmlPullParserException; +import org.simpleframework.xml.Namespace; +import org.simpleframework.xml.Root; /** - * Helper class to parse Amazon AWS S3 error response XML. + * Denotes Error response XML as per https://docs.aws.amazon.com/AmazonS3/latest/API/API_DeleteObjects.html. */ -@SuppressWarnings("unused") +@Root(name = "Error", strict = false) +@Namespace(reference = "http://s3.amazonaws.com/doc/2006-03-01/") public class DeleteError extends ErrorResponse { - /** - * Constructs a new ErrorResponse object by reading given reader stream. - */ - public DeleteError() throws XmlPullParserException { - super(); - super.name = "Error"; - } - - - /** - * Constructs a new ErrorResponse object by reading given reader stream. - */ - public DeleteError(Reader reader) throws IOException, XmlPullParserException { - this(); - this.parseXml(reader); - } + private static final long serialVersionUID = 1905162041950251407L; // fix SE_BAD_FIELD } diff --git a/api/src/main/java/io/minio/messages/DeleteObject.java b/api/src/main/java/io/minio/messages/DeleteObject.java index 995c806e0..ead76c90b 100644 --- a/api/src/main/java/io/minio/messages/DeleteObject.java +++ b/api/src/main/java/io/minio/messages/DeleteObject.java @@ -16,35 +16,28 @@ package io.minio.messages; -import org.xmlpull.v1.XmlPullParserException; - -import com.google.api.client.util.Key; +import org.simpleframework.xml.Element; +import org.simpleframework.xml.Root; /** - * Helper class to create Amazon AWS S3 request XML containing object information for Multiple object deletion. + * Helper class to denote Object information for DeleteRequest. */ +@Root(name = "Object") @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(value = "URF_UNREAD_FIELD") -public class DeleteObject extends XmlEntity { - @Key("Key") +public class DeleteObject { + @Element(name = "Key") private String name; - @Key("VersionId") + @Element(name = "VersionId", required = false) private String versionId; - public DeleteObject(String name) throws XmlPullParserException { - this(name, null); + public DeleteObject(String name) { + this.name = name; } - /** - * Constructs new delete object for given name and version ID. - * - */ - public DeleteObject(String name, String versionId) throws XmlPullParserException { - super(); - super.name = "Object"; - + public DeleteObject(String name, String versionId) { this.name = name; this.versionId = versionId; } diff --git a/api/src/main/java/io/minio/messages/DeleteRequest.java b/api/src/main/java/io/minio/messages/DeleteRequest.java index dd652039d..1f7680d4d 100644 --- a/api/src/main/java/io/minio/messages/DeleteRequest.java +++ b/api/src/main/java/io/minio/messages/DeleteRequest.java @@ -17,36 +17,30 @@ package io.minio.messages; import java.util.List; - -import org.xmlpull.v1.XmlPullParserException; - -import com.google.api.client.util.Key; +import org.simpleframework.xml.Element; +import org.simpleframework.xml.ElementList; +import org.simpleframework.xml.Namespace; +import org.simpleframework.xml.Root; /** - * Helper class to create Amazon AWS S3 request XML containing information for Multiple object deletion. + * Denotes delete (multiple) objects request XML as per + * https://docs.aws.amazon.com/AmazonS3/latest/API/API_DeleteObjects.html. */ +@Root(name = "Delete") +@Namespace(reference = "http://s3.amazonaws.com/doc/2006-03-01/") @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(value = "URF_UNREAD_FIELD") -public class DeleteRequest extends XmlEntity { - @Key("Quiet") +public class DeleteRequest { + @Element(name = "Quiet", required = false) private boolean quiet; - @Key("Object") + @ElementList(name = "Object", inline = true) private List objectList; - public DeleteRequest(List objectList) throws XmlPullParserException { - this(objectList, true); - } - - /** * Constructs new delete request for given object list and quiet flag. */ - public DeleteRequest(List objectList, boolean quiet) throws XmlPullParserException { - super(); - super.name = "Delete"; - super.namespaceDictionary.set("", "http://s3.amazonaws.com/doc/2006-03-01/"); - + public DeleteRequest(List objectList, boolean quiet) { this.objectList = objectList; this.quiet = quiet; } diff --git a/api/src/main/java/io/minio/messages/DeleteResult.java b/api/src/main/java/io/minio/messages/DeleteResult.java index b9ebbf8ab..5fd6f3f17 100644 --- a/api/src/main/java/io/minio/messages/DeleteResult.java +++ b/api/src/main/java/io/minio/messages/DeleteResult.java @@ -16,43 +16,52 @@ package io.minio.messages; -import java.io.IOException; -import java.io.Reader; import java.util.LinkedList; import java.util.List; - -import org.xmlpull.v1.XmlPullParserException; - -import com.google.api.client.util.Key; +import org.simpleframework.xml.ElementList; +import org.simpleframework.xml.Namespace; +import org.simpleframework.xml.Root; /** - * Helper class to create Amazon AWS S3 request XML containing information for Multiple object deletion. + * Denotes Delete objects response XML as per https://docs.aws.amazon.com/AmazonS3/latest/API/API_DeleteObjects.html. */ -@SuppressWarnings({"SameParameterValue", "unused"}) -public class DeleteResult extends XmlEntity { - @Key("Deleted") - private List objectList = new LinkedList<>(); - @Key("Error") - private List errorList = new LinkedList<>(); +@Root(name = "DeleteResult", strict = false) +@Namespace(reference = "http://s3.amazonaws.com/doc/2006-03-01/") +public class DeleteResult { + @ElementList(name = "Deleted", inline = true, required = false) + private List objectList; + @ElementList(name = "Error", inline = true, required = false) + private List errorList; /** * Constructs new delete result by parsing content on given reader. */ - public DeleteResult(Reader reader) throws IOException, XmlPullParserException { - super(); - super.name = "DeleteResult"; - this.parseXml(reader); + public DeleteResult() { } + /** + * Returns deleted object list. + */ public List objectList() { + if (objectList == null) { + return new LinkedList<>(); + } + return objectList; } + /** + * Returns delete error list. + */ public List errorList() { + if (errorList == null) { + return new LinkedList<>(); + } + return errorList; } } diff --git a/api/src/main/java/io/minio/messages/DeletedObject.java b/api/src/main/java/io/minio/messages/DeletedObject.java index 4484a403c..986d824cd 100644 --- a/api/src/main/java/io/minio/messages/DeletedObject.java +++ b/api/src/main/java/io/minio/messages/DeletedObject.java @@ -16,29 +16,26 @@ package io.minio.messages; -import org.xmlpull.v1.XmlPullParserException; - -import com.google.api.client.util.Key; +import org.simpleframework.xml.Element; +import org.simpleframework.xml.Root; /** - * Helper class to create Amazon AWS S3 request XML containing information for Multiple object deletion. + * Helper class to denote deleted object for DeleteResult. */ -@SuppressWarnings({"SameParameterValue", "unused"}) -public class DeletedObject extends XmlEntity { - @Key("Key") +@Root(name = "Deleted", strict = false) +public class DeletedObject { + @Element(name = "Key") private String name; - @Key("VersionId") + @Element(name = "VersionId") private String versionId; - @Key("DeleteMarker") + @Element(name = "DeleteMarker") private boolean deleteMarker; - @Key("DeleteMarkerVersionId") + @Element(name = "DeleteMarkerVersionId") private String deleteMarkerVersionId; - public DeletedObject() throws XmlPullParserException { - super(); - super.name = "Deleted"; + public DeletedObject() { } diff --git a/api/src/main/java/io/minio/messages/ErrorResponse.java b/api/src/main/java/io/minio/messages/ErrorResponse.java index 031d29944..461440640 100644 --- a/api/src/main/java/io/minio/messages/ErrorResponse.java +++ b/api/src/main/java/io/minio/messages/ErrorResponse.java @@ -16,52 +16,38 @@ package io.minio.messages; -import java.io.IOException; -import java.io.Reader; - -import org.xmlpull.v1.XmlPullParserException; - -import com.google.api.client.util.Key; -import com.google.api.client.xml.XmlNamespaceDictionary; - import io.minio.ErrorCode; +import java.io.Serializable; +import org.simpleframework.xml.Element; +import org.simpleframework.xml.Namespace; +import org.simpleframework.xml.Root; /** - * Helper class to parse Amazon AWS S3 error response XML. + * Denotes Error response XML of any S3 REST APIs. */ -@SuppressWarnings("unused") -public class ErrorResponse extends XmlEntity { - @Key("Code") - protected String code; - @Key("Message") +@Root(name = "ErrorResponse", strict = false) +@Namespace(reference = "http://s3.amazonaws.com/doc/2006-03-01/") +public class ErrorResponse implements Serializable { + private static final long serialVersionUID = 1905162041950251407L; // fix SE_BAD_FIELD + + @Element(name = "Code") + protected ErrorCode errorCode; + @Element(name = "Message", required = false) protected String message; - @Key("BucketName") + @Element(name = "BucketName", required = false) protected String bucketName; - @Key("Key") + @Element(name = "Key", required = false) protected String objectName; - @Key("Resource") + @Element(name = "Resource", required = false) protected String resource; - @Key("RequestId") + @Element(name = "RequestId", required = false) protected String requestId; - @Key("HostId") + @Element(name = "HostId", required = false) protected String hostId; - protected ErrorCode errorCode; - - public ErrorResponse() throws XmlPullParserException { - super(); - super.name = "ErrorResponse"; - } - - - /** - * Constructs a new ErrorResponse object by reading given reader stream. - */ - public ErrorResponse(Reader reader) throws IOException, XmlPullParserException { - this(); - this.parseXml(reader); + public ErrorResponse() { } @@ -69,11 +55,8 @@ public ErrorResponse(Reader reader) throws IOException, XmlPullParserException { * Constructs a new ErrorResponse object with error code, bucket name, object name, resource, request ID and host ID. */ public ErrorResponse(ErrorCode errorCode, String bucketName, String objectName, String resource, String requestId, - String hostId) throws XmlPullParserException { - this(); + String hostId) { this.errorCode = errorCode; - this.code = errorCode.code(); - this.message = errorCode.message(); this.bucketName = bucketName; this.objectName = objectName; this.resource = resource; @@ -86,26 +69,19 @@ public ErrorResponse(ErrorCode errorCode, String bucketName, String objectName, * Returns error code. */ public ErrorCode errorCode() { - if (this.errorCode == null) { - this.errorCode = ErrorCode.fromString(this.code); - } - return this.errorCode; } - /** - * Returns error code string. - */ - public String code() { - return this.code; - } - /** * Returns error message. */ public String message() { - return this.message; + if (this.message != null) { + return this.message; + } + + return this.errorCode.message(); } @@ -150,28 +126,16 @@ public String resource() { /** - * Fills up this ErrorResponse object's fields by reading/parsing values from given Reader input stream. - */ - @Override - public void parseXml(Reader reader) throws IOException, XmlPullParserException { - XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary(); - namespaceDictionary.set("", ""); - super.parseXml(reader, namespaceDictionary); - } - - - /** - * Returns string with field values. + * Returns string representation of this object. */ - public String getString() { - return "ErrorResponse(" - + "code=" + code + ", " - + "message=" + message + ", " - + "bucketName=" + bucketName + ", " - + "objectName=" + objectName + ", " - + "resource=" + resource + ", " - + "requestId=" + requestId + ", " - + "hostId=" + hostId + public String toString() { + return "ErrorResponse(code = " + errorCode.code() + ", " + + "message = " + message() + ", " + + "bucketName = " + bucketName + ", " + + "objectName = " + objectName + ", " + + "resource = " + resource + ", " + + "requestId = " + requestId + ", " + + "hostId = " + hostId + ")"; } } diff --git a/api/src/main/java/io/minio/messages/EventType.java b/api/src/main/java/io/minio/messages/EventType.java index 8c02744e2..63453742f 100644 --- a/api/src/main/java/io/minio/messages/EventType.java +++ b/api/src/main/java/io/minio/messages/EventType.java @@ -16,13 +16,18 @@ package io.minio.messages; -import java.util.LinkedList; -import java.util.List; +import org.simpleframework.xml.convert.Convert; +import org.simpleframework.xml.convert.Converter; +import org.simpleframework.xml.stream.InputNode; +import org.simpleframework.xml.stream.OutputNode; +import org.simpleframework.xml.Root; /** * Amazon AWS S3 event types for notifications. */ +@Root(name = "Event") +@Convert(EventType.EventTypeConverter.class) public enum EventType { OBJECT_CREATED_ANY("s3:ObjectCreated:*"), OBJECT_CREATED_PUT("s3:ObjectCreated:Put"), @@ -53,40 +58,26 @@ public String toString() { /** * Returns EventType of given string. */ - public static EventType fromString(String eventTypeString) throws IllegalArgumentException { + public static EventType fromString(String eventTypeString) { for (EventType et : EventType.values()) { if (eventTypeString.equals(et.value)) { return et; } } - throw new IllegalArgumentException("unknown event '" + eventTypeString + "'"); } - /** - * Returns List<EventType> of given List<String>. - */ - public static List fromStringList(List eventList) throws IllegalArgumentException { - List eventTypeList = new LinkedList(); - for (String event: eventList) { - eventTypeList.add(EventType.fromString(event)); + public static class EventTypeConverter implements Converter { + @Override + public EventType read(InputNode node) throws Exception { + return EventType.fromString(node.getValue()); } - return eventTypeList; - } - - - /** - * Returns List<String> of given List<EventType>. - */ - public static List toStringList(List eventTypeList) { - List events = new LinkedList(); - for (EventType eventType: eventTypeList) { - events.add(eventType.toString()); + @Override + public void write(OutputNode node, EventType eventType) throws Exception { + node.setValue(eventType.toString()); } - - return events; } } diff --git a/api/src/main/java/io/minio/messages/Filter.java b/api/src/main/java/io/minio/messages/Filter.java index 4819f38e7..1c15c4237 100644 --- a/api/src/main/java/io/minio/messages/Filter.java +++ b/api/src/main/java/io/minio/messages/Filter.java @@ -16,48 +16,56 @@ package io.minio.messages; -import org.xmlpull.v1.XmlPullParserException; - -import com.google.api.client.util.Key; - +import java.util.LinkedList; +import java.util.List; +import org.simpleframework.xml.ElementList; +import org.simpleframework.xml.Root; /** - * Helper class to parse Amazon AWS S3 response XML containing Filter. + * Helper class to denote Filter configuration of CloudFunctionConfiguration, QueueConfiguration or TopicConfiguration. */ -@SuppressWarnings("WeakerAccess") -public class Filter extends XmlEntity { - @Key("S3Key") - private S3Key s3Key = new S3Key(); - +@Root(name = "Filter", strict = false) +public class Filter { + @ElementList(name = "S3Key") + private List filterRuleList; - public Filter() throws XmlPullParserException { - super(); - super.name = "Filter"; + public Filter() { } - /** - * Returns S3 Key. + * Sets filter rule to list. + * As per Amazon AWS S3 server behavior, its not possible to set more than one rule for "prefix" or "suffix". + * However the spec http://docs.aws.amazon.com/AmazonS3/latest/API/RESTBucketPUTnotification.html + * is not clear about this behavior. */ - public S3Key s3Key() { - return s3Key; - } + private void setRule(String name, String value) throws IllegalArgumentException { + if (value.length() > 1024) { + throw new IllegalArgumentException("value '" + value + "' is more than 1024 long"); + } + if (filterRuleList == null) { + filterRuleList = new LinkedList<>(); + } - /** - * Sets S3 Key. - */ - public void setS3Key(S3Key s3Key) { - this.s3Key = s3Key; - } + for (FilterRule rule: filterRuleList) { + // Remove rule.name is same as given name. + if (rule.name().equals(name)) { + filterRuleList.remove(rule); + } + } + filterRuleList.add(new FilterRule(name, value)); + } - public void setPrefixRule(String value) throws IllegalArgumentException, XmlPullParserException { - s3Key.setPrefixRule(value); + public void setPrefixRule(String value) throws IllegalArgumentException { + setRule("prefix", value); } + public void setSuffixRule(String value) throws IllegalArgumentException { + setRule("suffix", value); + } - public void setSuffixRule(String value) throws IllegalArgumentException, XmlPullParserException { - s3Key.setSuffixRule(value); + public List filterRuleList() { + return filterRuleList; } } diff --git a/api/src/main/java/io/minio/messages/FilterRule.java b/api/src/main/java/io/minio/messages/FilterRule.java index 982b96cd3..90b638c77 100644 --- a/api/src/main/java/io/minio/messages/FilterRule.java +++ b/api/src/main/java/io/minio/messages/FilterRule.java @@ -16,26 +16,28 @@ package io.minio.messages; -import org.xmlpull.v1.XmlPullParserException; - -import com.google.api.client.util.Key; +import org.simpleframework.xml.Element; +import org.simpleframework.xml.Root; /** - * Helper class to parse Amazon AWS S3 response XML containing filter rule. + * Helper class to denote FilterRule configuration of CloudFunctionConfiguration, QueueConfiguration or + * TopicConfiguration. */ -public class FilterRule extends XmlEntity { - @Key("Name") +@Root(name = "FilterRule", strict = false) +public class FilterRule { + @Element(name = "Name") private String name; - @Key("Value") + @Element(name = "Value") private String value; - - public FilterRule() throws XmlPullParserException { - super(); - super.name = "FilterRule"; + public FilterRule() { } + public FilterRule(String name, String value) { + this.name = name; + this.value = value; + } /** * Returns filter name. @@ -44,27 +46,10 @@ public String name() { return name; } - - /** - * Sets filter name. - */ - public void setName(String name) { - this.name = name; - } - - /** * Returns filter value. */ public String value() { return value; } - - - /** - * Sets filter value. - */ - public void setValue(String value) { - this.value = value; - } } diff --git a/api/src/main/java/io/minio/messages/Grantee.java b/api/src/main/java/io/minio/messages/Grantee.java deleted file mode 100644 index 8dac7de5b..000000000 --- a/api/src/main/java/io/minio/messages/Grantee.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * MinIO Java SDK for Amazon S3 Compatible Cloud Storage, (C) 2015 MinIO, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.minio.messages; - -import org.xmlpull.v1.XmlPullParserException; - -import com.google.api.client.util.Key; - - -/** - * Helper class to parse Amazon AWS S3 response XML containing Grantee information. - */ -@SuppressWarnings({"SameParameterValue", "unused"}) -public class Grantee extends XmlEntity { - @Key("ID") - private String id; - @Key("DisplayName") - private String displayName; - @Key("EmailAddress") - private String emailAddress; - @Key("Type") - private String type; - @Key("URI") - private String uri; - - - public Grantee() throws XmlPullParserException { - super(); - this.name = "Grantee"; - } - - - /** - * Returns grantee id. - */ - public String id() { - return id; - } - - - /** - * Returns grantee display name. - */ - public String displayName() { - return displayName; - } - - - /** - * Returns grantee email address. - */ - public String emailAddress() { - return emailAddress; - } - - - /** - * Returns grantee type. - */ - public String type() { - return type; - } - - - /** - * Returns grantee URI. - */ - public String uri() { - return uri; - } -} diff --git a/api/src/main/java/io/minio/messages/InitiateMultipartUploadResult.java b/api/src/main/java/io/minio/messages/InitiateMultipartUploadResult.java index a0290769c..8cee5ce22 100644 --- a/api/src/main/java/io/minio/messages/InitiateMultipartUploadResult.java +++ b/api/src/main/java/io/minio/messages/InitiateMultipartUploadResult.java @@ -16,27 +16,27 @@ package io.minio.messages; -import org.xmlpull.v1.XmlPullParserException; - -import com.google.api.client.util.Key; +import org.simpleframework.xml.Element; +import org.simpleframework.xml.Namespace; +import org.simpleframework.xml.Root; /** - * Helper class to parse Amazon AWS S3 response XML containing initiate multipart upload result. + * Denotes CreateMultipartUpload response XML as per + * https://docs.aws.amazon.com/AmazonS3/latest/API/API_CreateMultipartUpload.html. */ -@SuppressWarnings({"SameParameterValue", "unused"}) -public class InitiateMultipartUploadResult extends XmlEntity { - @Key("Bucket") +@Root(name = "InitiateMultipartUploadResult", strict = false) +@Namespace(reference = "http://s3.amazonaws.com/doc/2006-03-01/") +public class InitiateMultipartUploadResult { + @Element(name = "Bucket") private String bucketName; - @Key("Key") + @Element(name = "Key") private String objectName; - @Key("UploadId") + @Element(name = "UploadId") private String uploadId; - public InitiateMultipartUploadResult() throws XmlPullParserException { - super(); - this.name = "InitiateMultipartUploadResult"; + public InitiateMultipartUploadResult() { } diff --git a/api/src/main/java/io/minio/messages/Initiator.java b/api/src/main/java/io/minio/messages/Initiator.java index b653d156d..46e81d5e9 100644 --- a/api/src/main/java/io/minio/messages/Initiator.java +++ b/api/src/main/java/io/minio/messages/Initiator.java @@ -16,25 +16,23 @@ package io.minio.messages; -import org.xmlpull.v1.XmlPullParserException; - -import com.google.api.client.util.Key; +import org.simpleframework.xml.Element; +import org.simpleframework.xml.Root; /** - * Helper class to parse Amazon AWS S3 response XML containing initator information. + * Helper class to denote Initator information of a multipart upload and used in ListMultipartUploadsResult + * and ListPartsResult. */ -@SuppressWarnings("unused") -public class Initiator extends XmlEntity { - @Key("ID") +@Root(name = "Initiator", strict = false) +public class Initiator { + @Element(name = "ID") private String id; - @Key("DisplayName") + @Element(name = "DisplayName") private String displayName; - public Initiator() throws XmlPullParserException { - super(); - this.name = "Initiator"; + public Initiator() { } diff --git a/api/src/main/java/io/minio/messages/InputSerialization.java b/api/src/main/java/io/minio/messages/InputSerialization.java index 205dd1e11..e71347016 100644 --- a/api/src/main/java/io/minio/messages/InputSerialization.java +++ b/api/src/main/java/io/minio/messages/InputSerialization.java @@ -16,68 +16,50 @@ package io.minio.messages; -import org.xmlpull.v1.XmlPullParserException; - -import com.google.api.client.util.Key; +import org.simpleframework.xml.Element; +import org.simpleframework.xml.Root; /** - * Helper class to generate Amazon AWS S3 request XML for SelectObjectContentRequest/InputSerialization information. + * Helper class to denote Input Serialization information of SelectObjectContentRequest. */ +@Root(name = "InputSerialization") @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(value = "URF_UNREAD_FIELD") -public class InputSerialization extends XmlEntity { - @Key("CompressionType") - private String compressionType; - @Key("CSV") +public class InputSerialization { + @Element(name = "CompressionType", required = false) + private CompressionType compressionType; + @Element(name = "CSV", required = false) private CsvInputSerialization csv; - @Key("JSON") + @Element(name = "JSON", required = false) private JsonInputSerialization json; - @Key("Parquet") + @Element(name = "Parquet", required = false) private ParquetInputSerialization parquet; - - public InputSerialization() throws XmlPullParserException { - super(); - this.name = "InputSerialization"; - } - /** * Constructs a new InputSerialization object with CSV. */ - public static InputSerialization csv(CompressionType compressionType, boolean allowQuotedRecordDelimiter, - Character comments, Character fieldDelimiter, FileHeaderInfo fileHeaderInfo, - Character quoteCharacter, Character quoteEscapeCharacter, - Character recordDelimiter) throws XmlPullParserException { - InputSerialization is = new InputSerialization(); - if (compressionType != null) { - is.compressionType = compressionType.toString(); - } - is.csv = new CsvInputSerialization(allowQuotedRecordDelimiter, comments, fieldDelimiter, fileHeaderInfo, - quoteCharacter, quoteEscapeCharacter, recordDelimiter); - return is; + public InputSerialization(CompressionType compressionType, boolean allowQuotedRecordDelimiter, + Character comments, Character fieldDelimiter, FileHeaderInfo fileHeaderInfo, + Character quoteCharacter, Character quoteEscapeCharacter, + Character recordDelimiter) { + this.csv = new CsvInputSerialization(allowQuotedRecordDelimiter, comments, fieldDelimiter, fileHeaderInfo, + quoteCharacter, quoteEscapeCharacter, recordDelimiter); } /** * Constructs a new InputSerialization object with JSON. */ - public static InputSerialization json(CompressionType compressionType, JsonType type) throws XmlPullParserException { - InputSerialization is = new InputSerialization(); - if (compressionType != null) { - is.compressionType = compressionType.toString(); - } - is.json = new JsonInputSerialization(type); - return is; + public InputSerialization(CompressionType compressionType, JsonType type) { + this.json = new JsonInputSerialization(type); } /** * Constructs a new InputSerialization object with Parquet. */ - public static InputSerialization parquet() throws XmlPullParserException { - InputSerialization is = new InputSerialization(); - is.parquet = new ParquetInputSerialization(); - return is; + public InputSerialization() { + this.parquet = new ParquetInputSerialization(); } } diff --git a/api/src/main/java/io/minio/messages/Item.java b/api/src/main/java/io/minio/messages/Item.java index c509ee839..e8ec758c3 100644 --- a/api/src/main/java/io/minio/messages/Item.java +++ b/api/src/main/java/io/minio/messages/Item.java @@ -16,49 +16,45 @@ package io.minio.messages; -import com.google.api.client.util.Key; -import io.minio.Time; import java.time.ZonedDateTime; import java.util.Map; -import org.xmlpull.v1.XmlPullParserException; +import org.simpleframework.xml.Element; +import org.simpleframework.xml.ElementMap; +import org.simpleframework.xml.Root; /** - * Helper class to parse Amazon AWS S3 response XML containing object item information. + * Helper class to denote Object information in ListBucketResult and ListBucketResultV1. */ -@SuppressWarnings({"SameParameterValue", "unused"}) -public class Item extends XmlEntity { - @Key("Key") +@Root(name = "Contents", strict = false) +public class Item { + @Element(name = "Key") private String objectName; - @Key("LastModified") - private String lastModified; - @Key("ETag") + @Element(name = "LastModified") + private ResponseDate lastModified; + @Element(name = "ETag") private String etag; - @Key("Size") + @Element(name = "Size") private long size; - @Key("StorageClass") + @Element(name = "StorageClass") private String storageClass; - @Key("Owner") + @Element(name = "Owner") private Owner owner; - @Key("UserMetadata") + @ElementMap(name = "UserMetadata", required = false) private Map userMetadata; private boolean isDir = false; - public Item() throws XmlPullParserException { - this(null, false); + public Item() { } /** - * Constructs a new Item object with given object name and IsDir flag. + * Constructs a new Item for prefix i.e. directory. */ - public Item(String objectName, boolean isDir) throws XmlPullParserException { - super(); - this.name = "Item"; - - this.objectName = objectName; - this.isDir = isDir; + public Item(String prefix) { + this.objectName = prefix; + this.isDir = true; } @@ -74,7 +70,7 @@ public String objectName() { * Returns last modified time of the object. */ public ZonedDateTime lastModified() { - return ZonedDateTime.parse(lastModified, Time.RESPONSE_DATE_FORMAT); + return lastModified.zonedDateTime(); } @@ -89,7 +85,7 @@ public String etag() { /** * Returns object size. */ - public long objectSize() { + public long size() { return size; } diff --git a/api/src/main/java/io/minio/messages/JsonInputSerialization.java b/api/src/main/java/io/minio/messages/JsonInputSerialization.java index f39dfb8e9..612dc1fc3 100644 --- a/api/src/main/java/io/minio/messages/JsonInputSerialization.java +++ b/api/src/main/java/io/minio/messages/JsonInputSerialization.java @@ -16,30 +16,24 @@ package io.minio.messages; -import org.xmlpull.v1.XmlPullParserException; - -import com.google.api.client.util.Key; +import org.simpleframework.xml.Element; +import org.simpleframework.xml.Root; /** - * Helper class to generate Amazon AWS S3 request XML for SelectObjectContentRequest/InputSerialization/JSON - * information. + * Helper class to denote JSON input serialization request XML as per SelectObjectContentRequest. */ +@Root(name = "JSON") @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(value = "URF_UNREAD_FIELD") -public class JsonInputSerialization extends XmlEntity { - @Key("Type") - private String type; +public class JsonInputSerialization { + @Element(name = "Type", required = false) + private JsonType type; /** * Constructs a new JsonInputSerialization object. */ - public JsonInputSerialization(JsonType type) throws XmlPullParserException { - super(); - this.name = "JSON"; - - if (type != null) { - this.type = type.toString(); - } + public JsonInputSerialization(JsonType type) { + this.type = type; } } diff --git a/api/src/main/java/io/minio/messages/JsonOutputSerialization.java b/api/src/main/java/io/minio/messages/JsonOutputSerialization.java index 940b11abb..739c0415b 100644 --- a/api/src/main/java/io/minio/messages/JsonOutputSerialization.java +++ b/api/src/main/java/io/minio/messages/JsonOutputSerialization.java @@ -16,28 +16,24 @@ package io.minio.messages; -import org.xmlpull.v1.XmlPullParserException; - -import com.google.api.client.util.Key; +import org.simpleframework.xml.Element; +import org.simpleframework.xml.Root; /** - * Helper class to generate Amazon AWS S3 request XML for SelectObjectContentRequest/OutputSerialization/JSON - * information. + * Helper class to denote JSON output serialization request XML as per SelectObjectContentRequest. */ +@Root(name = "JSON") @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(value = "URF_UNREAD_FIELD") -public class JsonOutputSerialization extends XmlEntity { - @Key("RecordDelimiter") +public class JsonOutputSerialization { + @Element(name = "RecordDelimiter", required = false) private Character recordDelimiter; /** * Constructs a new JsonOutputSerialization object. */ - public JsonOutputSerialization(Character recordDelimiter) throws XmlPullParserException { - super(); - this.name = "JSON"; - + public JsonOutputSerialization(Character recordDelimiter) { this.recordDelimiter = recordDelimiter; } } diff --git a/api/src/main/java/io/minio/messages/ObjectLockLegalHold.java b/api/src/main/java/io/minio/messages/LegalHold.java similarity index 60% rename from api/src/main/java/io/minio/messages/ObjectLockLegalHold.java rename to api/src/main/java/io/minio/messages/LegalHold.java index 1070c5ebf..798105ded 100644 --- a/api/src/main/java/io/minio/messages/ObjectLockLegalHold.java +++ b/api/src/main/java/io/minio/messages/LegalHold.java @@ -16,31 +16,31 @@ package io.minio.messages; -import org.xmlpull.v1.XmlPullParserException; -import com.google.api.client.util.Key; +import org.simpleframework.xml.Element; +import org.simpleframework.xml.Namespace; +import org.simpleframework.xml.Root; /** - * Helper class to construct create bucket configuration request XML for Amazon AWS S3. + * Denotes legal hold configuration request/response XML as per + * https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutObjectLegalHold.html and + * https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetObjectLegalHold.html. */ -@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(value = "URF_UNREAD_FIELD") -public class ObjectLockLegalHold extends XmlEntity{ - @Key("Status") +@Root(name = "LegalHold", strict = false) +@Namespace(reference = "http://s3.amazonaws.com/doc/2006-03-01/") +public class LegalHold { + @Element(name = "Status", required = false) private String status; - /** - * Constructs a new ObjectLockLegalHold object . - */ - public ObjectLockLegalHold() throws XmlPullParserException { - super(); - super.name = "LegalHold"; + + public LegalHold() { } + /** - * Constructs a new ObjectLockLegalHold object with given status. + * Constructs a new LegalHold object with given status. */ - public ObjectLockLegalHold(boolean status) throws XmlPullParserException { - this(); + public LegalHold(boolean status) { if (status) { this.status = "ON"; } else { @@ -48,6 +48,7 @@ public ObjectLockLegalHold(boolean status) throws XmlPullParserException { } } + /** * Indicates whether the specified object has a Legal Hold in place or not. */ diff --git a/api/src/main/java/io/minio/messages/ListAllMyBucketsResult.java b/api/src/main/java/io/minio/messages/ListAllMyBucketsResult.java index b2b871f29..dcf6e76e5 100644 --- a/api/src/main/java/io/minio/messages/ListAllMyBucketsResult.java +++ b/api/src/main/java/io/minio/messages/ListAllMyBucketsResult.java @@ -18,32 +18,32 @@ import java.util.LinkedList; import java.util.List; - -import org.xmlpull.v1.XmlPullParserException; - -import com.google.api.client.util.Key; +import org.simpleframework.xml.Element; +import org.simpleframework.xml.ElementList; +import org.simpleframework.xml.Namespace; +import org.simpleframework.xml.Root; /** - * Helper class to parse Amazon AWS S3 response XML containing ListAllMyBucketsResult information. + * Denotes list buckets response XML as per + * https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListBuckets.html. */ -public class ListAllMyBucketsResult extends XmlEntity { - @Key("Owner") +@Root(name = "ListAllMyBucketsResult", strict = false) +@Namespace(reference = "http://s3.amazonaws.com/doc/2006-03-01/") +public class ListAllMyBucketsResult { + @Element(name = "Owner") private Owner owner; - @Key("Buckets") - private Buckets buckets; + @ElementList(name = "Buckets") + private List buckets; - public ListAllMyBucketsResult() throws XmlPullParserException { - super(); - this.name = "ListAllMyBucketsResult"; + public ListAllMyBucketsResult() { } /** * Returns owner. */ - @SuppressWarnings("unused") public Owner owner() { return owner; } @@ -57,6 +57,6 @@ public List buckets() { return new LinkedList<>(); } - return buckets.bucketList(); + return buckets; } } diff --git a/api/src/main/java/io/minio/messages/ListBucketResult.java b/api/src/main/java/io/minio/messages/ListBucketResult.java index 58c96bdf9..370a33339 100644 --- a/api/src/main/java/io/minio/messages/ListBucketResult.java +++ b/api/src/main/java/io/minio/messages/ListBucketResult.java @@ -18,44 +18,44 @@ import java.util.LinkedList; import java.util.List; - -import org.xmlpull.v1.XmlPullParserException; - -import com.google.api.client.util.Key; +import org.simpleframework.xml.Element; +import org.simpleframework.xml.ElementList; +import org.simpleframework.xml.Namespace; +import org.simpleframework.xml.Root; /** - * Helper class to parse Amazon AWS S3 response XML containing ListBucketResult Version 2 information. + * Denotes list objects v2 response XML as per + * https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListObjectsV2.html. */ -@SuppressWarnings({"SameParameterValue", "unused"}) -public class ListBucketResult extends XmlEntity { - @Key("Name") +@Root(name = "ListBucketResult", strict = false) +@Namespace(reference = "http://s3.amazonaws.com/doc/2006-03-01/") +public class ListBucketResult { + @Element(name = "Name") private String name; - @Key("Prefix") + @Element(name = "Prefix", required = false) private String prefix; - @Key("ContinuationToken") + @Element(name = "ContinuationToken", required = false) private String continuationToken; - @Key("NextContinuationToken") + @Element(name = "NextContinuationToken", required = false) private String nextContinuationToken; - @Key("StartAfter") + @Element(name = "StartAfter", required = false) private String startAfter; - @Key("KeyCount") - private String keyCount; - @Key("MaxKeys") + @Element(name = "KeyCount", required = false) + private int keyCount; + @Element(name = "MaxKeys") private int maxKeys; - @Key("Delimiter") + @Element(name = "Delimiter", required = false) private String delimiter; - @Key("IsTruncated") + @Element(name = "IsTruncated", required = false) private boolean isTruncated; - @Key("Contents") + @ElementList(name = "Contents", inline = true, required = false) private List contents; - @Key("CommonPrefixes") + @ElementList(name = "CommonPrefixes", inline = true, required = false) private List commonPrefixes; - public ListBucketResult() throws XmlPullParserException { - super(); - super.name = "ListBucketResult"; + public ListBucketResult() { } @@ -102,7 +102,7 @@ public String startAfter() { /** * Returns key count. */ - public String keyCount() { + public int keyCount() { return keyCount; } @@ -138,6 +138,7 @@ public List contents() { if (contents == null) { return new LinkedList<>(); } + return contents; } @@ -149,6 +150,7 @@ public List commonPrefixes() { if (commonPrefixes == null) { return new LinkedList<>(); } + return commonPrefixes; } } diff --git a/api/src/main/java/io/minio/messages/ListBucketResultV1.java b/api/src/main/java/io/minio/messages/ListBucketResultV1.java index 99f51a9db..c11e0e357 100644 --- a/api/src/main/java/io/minio/messages/ListBucketResultV1.java +++ b/api/src/main/java/io/minio/messages/ListBucketResultV1.java @@ -18,40 +18,40 @@ import java.util.LinkedList; import java.util.List; - -import org.xmlpull.v1.XmlPullParserException; - -import com.google.api.client.util.Key; +import org.simpleframework.xml.Element; +import org.simpleframework.xml.ElementList; +import org.simpleframework.xml.Namespace; +import org.simpleframework.xml.Root; /** - * Helper class to parse Amazon AWS S3 response XML containing ListBucketResult Version 1 information. + * Denotes list objects v1 response XML as per + * https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListObjects.html. */ -@SuppressWarnings({"SameParameterValue", "unused"}) -public class ListBucketResultV1 extends XmlEntity { - @Key("Name") +@Root(name = "ListBucketResult", strict = false) +@Namespace(reference = "http://s3.amazonaws.com/doc/2006-03-01/") +public class ListBucketResultV1 { + @Element(name = "Name") private String name; - @Key("Prefix") + @Element(name = "Prefix", required = false) private String prefix; - @Key("Marker") + @Element(name = "Marker", required = false) private String marker; - @Key("NextMarker") + @Element(name = "NextMarker", required = false) private String nextMarker; - @Key("MaxKeys") + @Element(name = "MaxKeys") private int maxKeys; - @Key("Delimiter") + @Element(name = "Delimiter", required = false) private String delimiter; - @Key("IsTruncated") + @Element(name = "IsTruncated", required = false) private boolean isTruncated; - @Key("Contents") + @ElementList(name = "Contents", inline = true, required = false) private List contents; - @Key("CommonPrefixes") + @ElementList(name = "CommonPrefixes", inline = true, required = false) private List commonPrefixes; - public ListBucketResultV1() throws XmlPullParserException { - super(); - super.name = "ListBucketResult"; + public ListBucketResultV1() { } @@ -118,6 +118,7 @@ public List contents() { if (contents == null) { return new LinkedList<>(); } + return contents; } @@ -129,6 +130,7 @@ public List commonPrefixes() { if (commonPrefixes == null) { return new LinkedList<>(); } + return commonPrefixes; } } diff --git a/api/src/main/java/io/minio/messages/ListMultipartUploadsResult.java b/api/src/main/java/io/minio/messages/ListMultipartUploadsResult.java index 148f1db1d..d12b489fa 100644 --- a/api/src/main/java/io/minio/messages/ListMultipartUploadsResult.java +++ b/api/src/main/java/io/minio/messages/ListMultipartUploadsResult.java @@ -16,40 +16,40 @@ package io.minio.messages; -import java.util.ArrayList; +import java.util.LinkedList; import java.util.List; - -import org.xmlpull.v1.XmlPullParserException; - -import com.google.api.client.util.Key; +import org.simpleframework.xml.Element; +import org.simpleframework.xml.ElementList; +import org.simpleframework.xml.Namespace; +import org.simpleframework.xml.Root; /** - * Helper class to parse Amazon AWS S3 response XML containing ListMultipartUploadResult information. + * Denotes list of multipart uploads response XML as per + * https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListMultipartUploads.html. */ -@SuppressWarnings({"WeakerAccess", "unused"}) -public class ListMultipartUploadsResult extends XmlEntity { - @Key("Upload") - List uploads; - @Key("Bucket") +@Root(name = "ListMultipartUploadsResult", strict = false) +@Namespace(reference = "http://s3.amazonaws.com/doc/2006-03-01/") +public class ListMultipartUploadsResult { + @Element(name = "Bucket") private String bucketName; - @Key("KeyMarker") + @Element(name = "KeyMarker", required = false) private String keyMarker; - @Key("UploadIdMarker") + @Element(name = "UploadIdMarker", required = false) private String uploadIdMarker; - @Key("NextKeyMarker") + @Element(name = "NextKeyMarker", required = false) private String nextKeyMarker; - @Key("NextUploadIdMarker") + @Element(name = "NextUploadIdMarker", required = false) private String nextUploadIdMarker; - @Key("MaxUploads") + @Element(name = "MaxUploads") private int maxUploads; - @Key("IsTruncated") + @Element(name = "IsTruncated", required = false) private boolean isTruncated; + @ElementList(name = "Upload", inline = true, required = false) + List uploads; - public ListMultipartUploadsResult() throws XmlPullParserException { - super(); - super.name = "ListMultipartUploadsResult"; + public ListMultipartUploadsResult() { } @@ -114,8 +114,9 @@ public int maxUploads() { */ public List uploads() { if (uploads == null) { - return new ArrayList<>(); + return new LinkedList<>(); } + return uploads; } } diff --git a/api/src/main/java/io/minio/messages/ListPartsResult.java b/api/src/main/java/io/minio/messages/ListPartsResult.java index 014d81132..9220f2f66 100644 --- a/api/src/main/java/io/minio/messages/ListPartsResult.java +++ b/api/src/main/java/io/minio/messages/ListPartsResult.java @@ -18,42 +18,42 @@ import java.util.LinkedList; import java.util.List; - -import org.xmlpull.v1.XmlPullParserException; - -import com.google.api.client.util.Key; +import org.simpleframework.xml.Element; +import org.simpleframework.xml.ElementList; +import org.simpleframework.xml.Namespace; +import org.simpleframework.xml.Root; /** - * Helper class to parse Amazon AWS S3 response XML containing ListPartsResult information. + * Denotes list of parts of a upload response XML as per + * https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListParts.html. */ -@SuppressWarnings("unused") -public class ListPartsResult extends XmlEntity { - @Key("Bucket") +@Root(name = "ListPartsResult", strict = false) +@Namespace(reference = "http://s3.amazonaws.com/doc/2006-03-01/") +public class ListPartsResult { + @Element(name = "Bucket") private String bucketName; - @Key("Key") + @Element(name = "Key") private String objectName; - @Key("Initiator") + @Element(name = "Initiator") private Initiator initiator; - @Key("Owner") + @Element(name = "Owner") private Owner owner; - @Key("StorageClass") + @Element(name = "StorageClass") private String storageClass; - @Key("PartNumberMarker") + @Element(name = "PartNumberMarker") private int partNumberMarker; - @Key("NextPartNumberMarker") + @Element(name = "NextPartNumberMarker") private int nextPartNumberMarker; - @Key("MaxParts") + @Element(name = "MaxParts") private int maxParts; - @Key("IsTruncated") + @Element(name = "IsTruncated") private boolean isTruncated; - @Key("Part") + @ElementList(name = "Part", inline = true, required = false) private List partList; - public ListPartsResult() throws XmlPullParserException { - super(); - this.name = "ListPartsResult"; + public ListPartsResult() { } diff --git a/api/src/main/java/io/minio/messages/Buckets.java b/api/src/main/java/io/minio/messages/LocationConstraint.java similarity index 53% rename from api/src/main/java/io/minio/messages/Buckets.java rename to api/src/main/java/io/minio/messages/LocationConstraint.java index c5434f212..01793c97d 100644 --- a/api/src/main/java/io/minio/messages/Buckets.java +++ b/api/src/main/java/io/minio/messages/LocationConstraint.java @@ -1,5 +1,5 @@ /* - * MinIO Java SDK for Amazon S3 Compatible Cloud Storage, (C) 2015 MinIO, Inc. + * MinIO Java SDK for Amazon S3 Compatible Cloud Storage, (C) 2020 MinIO, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,33 +16,25 @@ package io.minio.messages; -import java.util.LinkedList; -import java.util.List; - -import org.xmlpull.v1.XmlPullParserException; - -import com.google.api.client.util.Key; +import org.simpleframework.xml.Namespace; +import org.simpleframework.xml.Root; +import org.simpleframework.xml.Text; /** - * Helper class to parse Amazon AWS S3 response XML containing list of bucket information. + * Denotes bucket location response XML as per + * https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetBucketLocation.html. */ -@SuppressWarnings("WeakerAccess") -public class Buckets extends XmlEntity { - @Key("Bucket") - private List bucketList = new LinkedList<>(); +@Root(name = "LocationConstraint", strict = false) +@Namespace(reference = "http://s3.amazonaws.com/doc/2006-03-01/") +public class LocationConstraint { + @Text(required = false) + private String location = ""; - - public Buckets() throws XmlPullParserException { - super(); - super.name = "Buckets"; + public LocationConstraint() { } - - /** - * Returns List of Buckets. - */ - public List bucketList() { - return bucketList; + public String location() { + return location; } } diff --git a/api/src/main/java/io/minio/messages/NotificationCommonConfiguration.java b/api/src/main/java/io/minio/messages/NotificationCommonConfiguration.java new file mode 100644 index 000000000..bffd6bd1b --- /dev/null +++ b/api/src/main/java/io/minio/messages/NotificationCommonConfiguration.java @@ -0,0 +1,106 @@ +/* + * MinIO Java SDK for Amazon S3 Compatible Cloud Storage, (C) 2017 MinIO, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.minio.messages; + +import java.util.List; +import org.simpleframework.xml.Element; +import org.simpleframework.xml.ElementList; + + +/** + * Helper class to denote common fields of CloudFunctionConfiguration, QueueConfiguration and TopicConfiguration. + */ +public class NotificationCommonConfiguration { + @Element(name = "Id") + private String id; + @ElementList(name = "Event", inline = true, required = false) + private List events; + @Element(name = "Filter") + private Filter filter; + + + public NotificationCommonConfiguration() { + } + + + /** + * Returns id. + */ + public String id() { + return id; + } + + + /** + * Sets id. + */ + public void setId(String id) { + this.id = id; + } + + + /** + * Returns events. + */ + public List events() { + return events; + } + + + /** + * Sets event. + */ + public void setEvents(List events) { + this.events = events; + } + + + /** + * sets filter prefix rule. + */ + public void setPrefixRule(String value) throws IllegalArgumentException { + if (filter == null) { + filter = new Filter(); + } + + filter.setPrefixRule(value); + } + + + /** + * sets filter suffix rule. + */ + public void setSuffixRule(String value) throws IllegalArgumentException { + if (filter == null) { + filter = new Filter(); + } + + filter.setSuffixRule(value); + } + + + /** + * returns filter rule list. + */ + public List filterRuleList() { + if (filter != null) { + return filter.filterRuleList(); + } + + return null; + } +} diff --git a/api/src/main/java/io/minio/messages/NotificationConfiguration.java b/api/src/main/java/io/minio/messages/NotificationConfiguration.java index 2ca8b6e77..7f0e57053 100644 --- a/api/src/main/java/io/minio/messages/NotificationConfiguration.java +++ b/api/src/main/java/io/minio/messages/NotificationConfiguration.java @@ -16,32 +16,29 @@ package io.minio.messages; -import java.util.LinkedList; import java.util.List; - -import org.xmlpull.v1.XmlPullParserException; - -import com.google.api.client.util.Key; +import org.simpleframework.xml.ElementList; +import org.simpleframework.xml.Namespace; +import org.simpleframework.xml.Root; /** - * Helper class to parse Amazon AWS S3 response XML containing notification configuration. + * Denotes Notification configuration request/response XML as per + * https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutBucketNotificationConfiguration.html and + * https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetBucketNotificationConfiguration.html. */ -public class NotificationConfiguration extends XmlEntity { - @Key("CloudFunctionConfiguration") - private List cloudFunctionConfigurationList = new LinkedList<>(); - @Key("QueueConfiguration") - private List queueConfigurationList = new LinkedList<>(); - @Key("TopicConfiguration") - private List topicConfigurationList = new LinkedList<>(); - - /** - * Constructs a new notification configuration with default namespace. - */ - public NotificationConfiguration() throws XmlPullParserException { - super(); - super.name = "NotificationConfiguration"; - super.namespaceDictionary.set("", "http://s3.amazonaws.com/doc/2006-03-01/"); +@Root(name = "NotificationConfiguration", strict = false) +@Namespace(reference = "http://s3.amazonaws.com/doc/2006-03-01/") +public class NotificationConfiguration { + @ElementList(name = "CloudFunctionConfiguration", inline = true, required = false) + private List cloudFunctionConfigurationList; + @ElementList(name = "QueueConfiguration", inline = true, required = false) + private List queueConfigurationList; + @ElementList(name = "TopicConfiguration", inline = true, required = false) + private List topicConfigurationList; + + + public NotificationConfiguration() { } diff --git a/api/src/main/java/io/minio/messages/ObjectLockConfiguration.java b/api/src/main/java/io/minio/messages/ObjectLockConfiguration.java index 571f6546f..8bdb4aa08 100644 --- a/api/src/main/java/io/minio/messages/ObjectLockConfiguration.java +++ b/api/src/main/java/io/minio/messages/ObjectLockConfiguration.java @@ -16,74 +16,63 @@ package io.minio.messages; -import org.xmlpull.v1.XmlPullParserException; - -import com.google.api.client.util.Key; +import org.simpleframework.xml.Element; +import org.simpleframework.xml.Namespace; +import org.simpleframework.xml.Root; /** - * Helper class to construct create bucket configuration request XML for Amazon AWS S3. + * Denotes object lock configuration request/response XML as per + * https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutObjectLockConfiguration.html and + * https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetObjectLockConfiguration.html. */ -@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(value = "URF_UNREAD_FIELD") -public class ObjectLockConfiguration extends XmlEntity { - @Key("ObjectLockEnabled") +@Root(name = "ObjectLockConfiguration", strict = false) +@Namespace(reference = "http://s3.amazonaws.com/doc/2006-03-01/") +public class ObjectLockConfiguration { + @Element(name = "ObjectLockEnabled") private String objectLockEnabled = "Enabled"; - @Key("Rule") + @Element(name = "Rule", required = false) private Rule rule; - /** - * Constructs a new ObjectLockConfiguration object. - */ - public ObjectLockConfiguration() throws XmlPullParserException { - super(); - super.name = "ObjectLockConfiguration"; - super.namespaceDictionary.set("", "http://s3.amazonaws.com/doc/2006-03-01/"); + public ObjectLockConfiguration() { } /** * Constructs a new ObjectLockConfiguration object with given retention. */ - public ObjectLockConfiguration(RetentionMode mode, int duration, DurationUnit unit) throws XmlPullParserException { - this(); + public ObjectLockConfiguration(RetentionMode mode, RetentionDuration duration) throws IllegalArgumentException { + if (mode != null && duration != null) { + this.rule = new Rule(mode, duration); + } - this.rule = new Rule(mode, duration, unit); + if (mode != null || duration != null) { + throw new IllegalArgumentException("mode or duration is null"); + } } /** - * Returns mode. + * Returns retention mode. */ public RetentionMode mode() { if (rule == null) { return null; } - + return rule.mode(); } /** - * Returns days. + * Returns retention duration. */ - public Integer days() { + public RetentionDuration duration() { if (rule == null) { return null; } - - return rule.days(); - } - - /** - * Returns years. - */ - public Integer years() { - if (rule == null) { - return null; - } - - return rule.years(); + return rule.duration(); } } diff --git a/api/src/main/java/io/minio/messages/OutputSerialization.java b/api/src/main/java/io/minio/messages/OutputSerialization.java index 7776d0662..178372635 100644 --- a/api/src/main/java/io/minio/messages/OutputSerialization.java +++ b/api/src/main/java/io/minio/messages/OutputSerialization.java @@ -16,47 +16,36 @@ package io.minio.messages; -import org.xmlpull.v1.XmlPullParserException; - -import com.google.api.client.util.Key; +import org.simpleframework.xml.Element; +import org.simpleframework.xml.Root; /** - * Helper class to generate Amazon AWS S3 request XML for SelectObjectContentRequest/OutputSerialization information. + * Helper class to denote Output Serialization information of SelectObjectContentRequest. */ +@Root(name = "OutputSerialization") @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(value = "URF_UNREAD_FIELD") -public class OutputSerialization extends XmlEntity { - @Key("CSV") +public class OutputSerialization { + @Element(name = "CSV", required = false) private CsvOutputSerialization csv; - @Key("JSON") + @Element(name = "JSON", required = false) private JsonOutputSerialization json; - - public OutputSerialization() throws XmlPullParserException { - super(); - this.name = "OutputSerialization"; - } - /** * Constructs a new OutputSerialization object with CSV. */ - public static OutputSerialization csv(Character fieldDelimiter, Character quoteCharacter, - Character quoteEscapeCharacter, QuoteFields quoteFields, - Character recordDelimiter) throws XmlPullParserException { - OutputSerialization os = new OutputSerialization(); - os.csv = new CsvOutputSerialization(fieldDelimiter, quoteCharacter, quoteEscapeCharacter, quoteFields, - recordDelimiter); - return os; + public OutputSerialization(Character fieldDelimiter, Character quoteCharacter, Character quoteEscapeCharacter, + QuoteFields quoteFields, Character recordDelimiter) { + this.csv = new CsvOutputSerialization(fieldDelimiter, quoteCharacter, quoteEscapeCharacter, quoteFields, + recordDelimiter); } /** * Constructs a new OutputSerialization object with JSON. */ - public static OutputSerialization json(Character recordDelimiter) throws XmlPullParserException { - OutputSerialization os = new OutputSerialization(); - os.json = new JsonOutputSerialization(recordDelimiter); - return os; + public OutputSerialization(Character recordDelimiter) { + this.json = new JsonOutputSerialization(recordDelimiter); } } diff --git a/api/src/main/java/io/minio/messages/Owner.java b/api/src/main/java/io/minio/messages/Owner.java index c8b7bf228..b1ebe68b1 100644 --- a/api/src/main/java/io/minio/messages/Owner.java +++ b/api/src/main/java/io/minio/messages/Owner.java @@ -16,25 +16,23 @@ package io.minio.messages; -import org.xmlpull.v1.XmlPullParserException; - -import com.google.api.client.util.Key; +import org.simpleframework.xml.Element; +import org.simpleframework.xml.Root; /** - * Helper class to parse Amazon AWS S3 response XML containing Owner information. + * Helper class to denote owner information for ListAllMyBucketsResult, ListBucketResult, ListBucketResultV1, + * ListMultipartUploadsResult and ListPartsResult. */ -@SuppressWarnings("SameParameterValue") -public class Owner extends XmlEntity { - @Key("ID") +@Root(name = "Owner", strict = false) +public class Owner { + @Element(name = "ID", required = false) private String id; - @Key("DisplayName") + @Element(name = "DisplayName", required = false) private String displayName; - public Owner() throws XmlPullParserException { - super(); - this.name = "Owner"; + public Owner() { } diff --git a/api/src/main/java/io/minio/messages/ParquetInputSerialization.java b/api/src/main/java/io/minio/messages/ParquetInputSerialization.java index caf3b610d..35499169c 100644 --- a/api/src/main/java/io/minio/messages/ParquetInputSerialization.java +++ b/api/src/main/java/io/minio/messages/ParquetInputSerialization.java @@ -16,16 +16,12 @@ package io.minio.messages; -import org.xmlpull.v1.XmlPullParserException; +import org.simpleframework.xml.Root; /** - * Helper class to generate Amazon AWS S3 request XML for SelectObjectContentRequest/InputSerialization/Parquet - * information. + * Helper class to denote Parquet input serialization request XML as per SelectObjectContentRequest. */ -public class ParquetInputSerialization extends XmlEntity { - public ParquetInputSerialization() throws XmlPullParserException { - super(); - this.name = "Parquet"; - } +@Root(name = "Parquet") +public class ParquetInputSerialization { } diff --git a/api/src/main/java/io/minio/messages/Part.java b/api/src/main/java/io/minio/messages/Part.java index 41d674dd8..78b4e8762 100644 --- a/api/src/main/java/io/minio/messages/Part.java +++ b/api/src/main/java/io/minio/messages/Part.java @@ -16,39 +16,36 @@ package io.minio.messages; -import com.google.api.client.util.Key; -import io.minio.Time; import java.time.ZonedDateTime; -import org.xmlpull.v1.XmlPullParserException; +import org.simpleframework.xml.Element; +import org.simpleframework.xml.Root; /** - * Helper class to parse Amazon AWS S3 response XML containing Part information. + * Helper class to denote Part information of a multipart upload and used in CompleteMultipartUpload + * and ListPartsResult. */ -@SuppressWarnings({"WeakerAccess", "unused"}) -public class Part extends XmlEntity { - @Key("PartNumber") +@Root(name = "Part", strict = false) +public class Part { + @Element(name = "PartNumber") private int partNumber; - @Key("ETag") + @Element(name = "ETag") private String etag; - @Key("LastModified") - private String lastModified; - @Key("Size") + @Element(name = "LastModified", required = false) + private ResponseDate lastModified; + @Element(name = "Size", required = false) private Long size; - public Part() throws XmlPullParserException { - this(0, null); + public Part() { } /** * Constructs a new Part object with given part number and ETag. */ - public Part(int partNumber, String etag) throws XmlPullParserException { - super(); - super.name = "Part"; - + public Part(int partNumber, String etag) { + this.partNumber = partNumber; this.etag = etag; } @@ -74,7 +71,7 @@ public String etag() { * Returns last modified time. */ public ZonedDateTime lastModified() { - return ZonedDateTime.parse(lastModified, Time.RESPONSE_DATE_FORMAT); + return lastModified.zonedDateTime(); } diff --git a/api/src/main/java/io/minio/messages/Prefix.java b/api/src/main/java/io/minio/messages/Prefix.java index cc29e229e..0ce5b9060 100644 --- a/api/src/main/java/io/minio/messages/Prefix.java +++ b/api/src/main/java/io/minio/messages/Prefix.java @@ -16,30 +16,24 @@ package io.minio.messages; -import org.xmlpull.v1.XmlPullParserException; - -import com.google.api.client.util.Key; +import org.simpleframework.xml.Element; +import org.simpleframework.xml.Root; /** - * Helper class to parse Amazon AWS S3 response XML containing Prefix information. + * Helper class to denote Prefix information in ListBucketResult and ListBucketResultV1. */ -@SuppressWarnings({"WeakerAccess", "unused"}) -public class Prefix extends XmlEntity { - @Key("Prefix") +@Root(name = "CommonPrefixes", strict = false) +public class Prefix { + @Element(name = "Prefix") private String prefix; - public Prefix() throws XmlPullParserException { - super(); - super.name = "Prefix"; + public Prefix() { } - /** - * Returns prefix. - */ - public String prefix() { - return prefix; + public Item toItem() { + return new Item(prefix); } } diff --git a/api/src/main/java/io/minio/messages/Progress.java b/api/src/main/java/io/minio/messages/Progress.java new file mode 100644 index 000000000..35f090df9 --- /dev/null +++ b/api/src/main/java/io/minio/messages/Progress.java @@ -0,0 +1,29 @@ +/* + * MinIO Java SDK for Amazon S3 Compatible Cloud Storage, (C) 2020 MinIO, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.minio.messages; + +import org.simpleframework.xml.Namespace; +import org.simpleframework.xml.Root; + + +/** + * Helper class to denote Progress information of S3 select response message. + */ +@Root(name = "Progress", strict = false) +@Namespace(reference = "http://s3.amazonaws.com/doc/2006-03-01/") +public class Progress extends Stats { +} diff --git a/api/src/main/java/io/minio/messages/QueueConfiguration.java b/api/src/main/java/io/minio/messages/QueueConfiguration.java index 654b2891f..35eb37988 100644 --- a/api/src/main/java/io/minio/messages/QueueConfiguration.java +++ b/api/src/main/java/io/minio/messages/QueueConfiguration.java @@ -16,47 +16,21 @@ package io.minio.messages; -import java.util.LinkedList; -import java.util.List; - -import org.xmlpull.v1.XmlPullParserException; - -import com.google.api.client.util.Key; +import org.simpleframework.xml.Element; +import org.simpleframework.xml.Root; /** - * Helper class to parse Amazon AWS S3 response XML containing queue configuration. + * Helper class to denote Queue configuration of NotificationConfiguration. */ -public class QueueConfiguration extends XmlEntity { - @Key("Id") - private String id; - @Key("Queue") +@Root(name = "QueueConfiguration", strict = false) +public class QueueConfiguration extends NotificationCommonConfiguration { + @Element(name = "Queue") private String queue; - @Key("Event") - private List events = new LinkedList<>(); - @Key("Filter") - private Filter filter; - public QueueConfiguration() throws XmlPullParserException { + public QueueConfiguration() { super(); - super.name = "QueueConfiguration"; - } - - - /** - * Returns id. - */ - public String id() { - return id; - } - - - /** - * Sets id. - */ - public void setId(String id) { - this.id = id; } @@ -74,38 +48,4 @@ public String queue() { public void setQueue(String queue) { this.queue = queue; } - - - /** - * Returns events. - */ - public List events() throws IllegalArgumentException { - return EventType.fromStringList(events); - } - - - /** - * Sets event. - */ - public void setEvents(List events) { - this.events = EventType.toStringList(events); - } - - - - /** - * Sets filter. - */ - public void setFilter(Filter filter) { - this.filter = filter; - } - - /** - * Returns filter. - */ - public Filter filter() { - return filter; - } - - } diff --git a/api/src/main/java/io/minio/messages/RequestProgress.java b/api/src/main/java/io/minio/messages/RequestProgress.java index 839df6f43..b9959ad5f 100644 --- a/api/src/main/java/io/minio/messages/RequestProgress.java +++ b/api/src/main/java/io/minio/messages/RequestProgress.java @@ -16,27 +16,23 @@ package io.minio.messages; -import org.xmlpull.v1.XmlPullParserException; - -import com.google.api.client.util.Key; +import org.simpleframework.xml.Element; +import org.simpleframework.xml.Root; /** - * Helper class to generate Amazon AWS S3 request XML for SelectObjectContentRequest/RequestProgress information. + * Helper class to denote progress request in select object content request XML for SelectObjectContentRequest. */ +@Root(name = "RequestProgress", strict = false) @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(value = "URF_UNREAD_FIELD") -public class RequestProgress extends XmlEntity { - @Key("Enabled") - private boolean enabled; +public class RequestProgress { + @Element(name = "Enabled") + private boolean enabled = true; /** * Constructs a new RequestProgress object. */ - public RequestProgress() throws XmlPullParserException { - super(); - super.name = "ScanRange"; - - this.enabled = true; + public RequestProgress() { } } diff --git a/api/src/main/java/io/minio/messages/ResponseDate.java b/api/src/main/java/io/minio/messages/ResponseDate.java new file mode 100644 index 000000000..a5e96c2ee --- /dev/null +++ b/api/src/main/java/io/minio/messages/ResponseDate.java @@ -0,0 +1,54 @@ +/* + * MinIO Java SDK for Amazon S3 Compatible Cloud Storage, (C) 2015 MinIO, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.minio.messages; + +import io.minio.Time; +import java.time.ZonedDateTime; +import org.simpleframework.xml.convert.Convert; +import org.simpleframework.xml.convert.Converter; +import org.simpleframework.xml.stream.InputNode; +import org.simpleframework.xml.stream.OutputNode; +import org.simpleframework.xml.Root; + +@Root +@Convert(ResponseDate.ResponseDateConverter.class) +public class ResponseDate { + private ZonedDateTime zonedDateTime; + + public ResponseDate() { + } + + public ResponseDate(ZonedDateTime zonedDateTime) { + this.zonedDateTime = zonedDateTime; + } + + public ZonedDateTime zonedDateTime() { + return zonedDateTime; + } + + public static class ResponseDateConverter implements Converter { + @Override + public ResponseDate read(InputNode node) throws Exception { + return new ResponseDate(ZonedDateTime.parse(node.getValue(), Time.RESPONSE_DATE_FORMAT)); + } + + @Override + public void write(OutputNode node, ResponseDate amzDate) throws Exception { + node.setValue(amzDate.zonedDateTime().format(Time.RESPONSE_DATE_FORMAT)); + } + } +} diff --git a/api/src/main/java/io/minio/messages/ObjectRetentionConfiguration.java b/api/src/main/java/io/minio/messages/Retention.java similarity index 50% rename from api/src/main/java/io/minio/messages/ObjectRetentionConfiguration.java rename to api/src/main/java/io/minio/messages/Retention.java index b683d699c..83cc8391e 100644 --- a/api/src/main/java/io/minio/messages/ObjectRetentionConfiguration.java +++ b/api/src/main/java/io/minio/messages/Retention.java @@ -16,37 +16,35 @@ package io.minio.messages; -import com.google.api.client.util.Key; -import io.minio.Time; import java.time.ZonedDateTime; -import org.xmlpull.v1.XmlPullParserException; +import org.simpleframework.xml.Element; +import org.simpleframework.xml.Namespace; +import org.simpleframework.xml.Root; + /** - * Helper class to parse Amazon AWS S3 response XML containing ObjectLockRetention information. + * Denotes retention configuration request/response XML as per + * https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutObjectRetention.html and + * https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetObjectRetention.html. */ -@SuppressWarnings("SameParameterValue") -public class ObjectRetentionConfiguration extends XmlEntity { - @Key("Mode") - private String mode; - @Key("RetainUntilDate") - private String retainUntilDate; +@Root(name = "Retention", strict = false) +@Namespace(reference = "http://s3.amazonaws.com/doc/2006-03-01/") +public class Retention { + @Element(name = "Mode", required = false) + private RetentionMode mode; + @Element(name = "RetainUntilDate", required = false) + private ResponseDate retainUntilDate; - /** - * Constructs a new ObjectRetentionConfiguration object. - */ - public ObjectRetentionConfiguration() throws XmlPullParserException { - super(); - super.name = "Retention"; + + public Retention() { } + /** - * Constructs a new ObjectRetentionConfiguration object with given retention + * Constructs a new Retention object with given retention * until date and mode. */ - public ObjectRetentionConfiguration(RetentionMode mode, ZonedDateTime retainUntilDate) - throws XmlPullParserException, IllegalArgumentException { - this(); - + public Retention(RetentionMode mode, ZonedDateTime retainUntilDate) { if (mode == null) { throw new IllegalArgumentException("null mode is not allowed"); } @@ -55,21 +53,27 @@ public ObjectRetentionConfiguration(RetentionMode mode, ZonedDateTime retainUnt throw new IllegalArgumentException("null retainUntilDate is not allowed"); } - this.mode = mode.toString(); - this.retainUntilDate = retainUntilDate.format(Time.EXPIRATION_DATE_FORMAT); + this.mode = mode; + this.retainUntilDate = new ResponseDate(retainUntilDate); } + /** * Returns mode. */ public RetentionMode mode() { - return this.mode == null ? null : RetentionMode.fromString(this.mode); + return this.mode; } + /** * Returns retain until date. */ public ZonedDateTime retainUntilDate() { - return retainUntilDate == null ? null : ZonedDateTime.parse(retainUntilDate, Time.EXPIRATION_DATE_FORMAT); + if (retainUntilDate != null) { + return retainUntilDate.zonedDateTime(); + } + + return null; } } diff --git a/api/src/main/java/io/minio/messages/RetentionDuration.java b/api/src/main/java/io/minio/messages/RetentionDuration.java new file mode 100644 index 000000000..969e98838 --- /dev/null +++ b/api/src/main/java/io/minio/messages/RetentionDuration.java @@ -0,0 +1,24 @@ +/* + * MinIO Java SDK for Amazon S3 Compatible Cloud Storage, (C) 2020 MinIO, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.minio.messages; + + +public interface RetentionDuration { + public RetentionDurationUnit unit(); + + public int duration(); +} diff --git a/api/src/main/java/io/minio/messages/Grant.java b/api/src/main/java/io/minio/messages/RetentionDurationDays.java similarity index 51% rename from api/src/main/java/io/minio/messages/Grant.java rename to api/src/main/java/io/minio/messages/RetentionDurationDays.java index 499670770..91142a1c2 100644 --- a/api/src/main/java/io/minio/messages/Grant.java +++ b/api/src/main/java/io/minio/messages/RetentionDurationDays.java @@ -1,5 +1,5 @@ /* - * MinIO Java SDK for Amazon S3 Compatible Cloud Storage, (C) 2015 MinIO, Inc. + * MinIO Java SDK for Amazon S3 Compatible Cloud Storage, (C) 2020 MinIO, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,40 +16,27 @@ package io.minio.messages; -import org.xmlpull.v1.XmlPullParserException; +import org.simpleframework.xml.Root; +import org.simpleframework.xml.Text; -import com.google.api.client.util.Key; - -/** - * Helper class to parse Amazon AWS S3 response XML containing Grant information. - */ -@SuppressWarnings({"SameParameterValue", "unused"}) -public class Grant extends XmlEntity { - @Key("Grantee") - private Grantee grantee; - @Key("Permission") - private String permission; +@Root(name = "Days") +public class RetentionDurationDays implements RetentionDuration { + @Text(required = false) + private Integer days; - public Grant() throws XmlPullParserException { - super(); - this.name = "Grant"; + public RetentionDurationDays(int days) { + this.days = Integer.valueOf(days); } - /** - * Returns Grantee. - */ - public Grantee grantee() { - return grantee; + public RetentionDurationUnit unit() { + return RetentionDurationUnit.DAYS; } - /** - * Returns permission. - */ - public String permission() { - return permission; + public int duration() { + return days; } } diff --git a/api/src/main/java/io/minio/messages/DurationUnit.java b/api/src/main/java/io/minio/messages/RetentionDurationUnit.java similarity index 86% rename from api/src/main/java/io/minio/messages/DurationUnit.java rename to api/src/main/java/io/minio/messages/RetentionDurationUnit.java index 86ef680f2..8713431cd 100644 --- a/api/src/main/java/io/minio/messages/DurationUnit.java +++ b/api/src/main/java/io/minio/messages/RetentionDurationUnit.java @@ -1,5 +1,5 @@ /* - * MinIO Java SDK for Amazon S3 Compatible Cloud Storage, (C) 2019 MinIO, Inc. + * MinIO Java SDK for Amazon S3 Compatible Cloud Storage, (C) 2020 MinIO, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,8 +18,8 @@ /** - * DurationUnit of default retention configuration. + * Duration unit of default retention configuration. */ -public enum DurationUnit { +public enum RetentionDurationUnit { DAYS, YEARS; } diff --git a/api/src/main/java/io/minio/messages/RetentionDurationYears.java b/api/src/main/java/io/minio/messages/RetentionDurationYears.java new file mode 100644 index 000000000..0a4b500b4 --- /dev/null +++ b/api/src/main/java/io/minio/messages/RetentionDurationYears.java @@ -0,0 +1,42 @@ +/* + * MinIO Java SDK for Amazon S3 Compatible Cloud Storage, (C) 2020 MinIO, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.minio.messages; + +import org.simpleframework.xml.Root; +import org.simpleframework.xml.Text; + + +@Root(name = "Years") +public class RetentionDurationYears implements RetentionDuration { + @Text(required = false) + private Integer years; + + + public RetentionDurationYears(int years) { + this.years = Integer.valueOf(years); + } + + + public RetentionDurationUnit unit() { + return RetentionDurationUnit.YEARS; + } + + + public int duration() { + return years; + } +} diff --git a/api/src/main/java/io/minio/messages/RetentionMode.java b/api/src/main/java/io/minio/messages/RetentionMode.java index 535e6f3df..dc88c27d3 100644 --- a/api/src/main/java/io/minio/messages/RetentionMode.java +++ b/api/src/main/java/io/minio/messages/RetentionMode.java @@ -22,24 +22,4 @@ */ public enum RetentionMode { GOVERNANCE, COMPLIANCE; - - /** - * Returns ErrorCode of given code string. - */ - public static RetentionMode fromString(String modeString) { - if (modeString == null) { - return null; - } - - if (modeString.equals(RetentionMode.GOVERNANCE.toString())) { - return RetentionMode.GOVERNANCE; - } - - if (modeString.equals(RetentionMode.COMPLIANCE.toString())) { - return RetentionMode.COMPLIANCE; - } - - // Unknown mode string. - return null; - } } diff --git a/api/src/main/java/io/minio/messages/Rule.java b/api/src/main/java/io/minio/messages/Rule.java index 3e3598ca1..c312f98f9 100644 --- a/api/src/main/java/io/minio/messages/Rule.java +++ b/api/src/main/java/io/minio/messages/Rule.java @@ -16,56 +16,53 @@ package io.minio.messages; -import org.xmlpull.v1.XmlPullParserException; - -import com.google.api.client.util.Key; +import org.simpleframework.xml.Element; +import org.simpleframework.xml.Root; /** - * Helper class to parse Amazon AWS S3 response XML containing Rule information. + * Helper class to denote Rule information for ObjectLockConfiguration. */ -@SuppressWarnings("SameParameterValue") -public class Rule extends XmlEntity { - @Key("DefaultRetention") +@Root(name = "Rule", strict = false) +public class Rule { + @Element(name = "DefaultRetention", required = false) private DefaultRetention defaultRetention; - public Rule() throws XmlPullParserException { - super(); - this.name = "Rule"; + public Rule() { } /** * Constructs a new Rule object with given retention. */ - public Rule(RetentionMode mode, int duration, DurationUnit unit) throws XmlPullParserException { - this(); - - this.defaultRetention = new DefaultRetention(mode, duration, unit); + public Rule(RetentionMode mode, RetentionDuration duration) { + if (mode != null && duration != null) { + this.defaultRetention = new DefaultRetention(mode, duration); + } } /** - * Returns mode. + * Returns retention mode. */ public RetentionMode mode() { + if (defaultRetention == null) { + return null; + } + return defaultRetention.mode(); } /** - * Returns days. + * Returns retention duration. */ - public Integer days() { - return defaultRetention.days(); - } + public RetentionDuration duration() { + if (defaultRetention == null) { + return null; + } - - /** - * Returns years. - */ - public Integer years() { - return defaultRetention.years(); + return defaultRetention.duration(); } } diff --git a/api/src/main/java/io/minio/messages/S3Key.java b/api/src/main/java/io/minio/messages/S3Key.java deleted file mode 100644 index 47ad07ebc..000000000 --- a/api/src/main/java/io/minio/messages/S3Key.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * MinIO Java SDK for Amazon S3 Compatible Cloud Storage, (C) 2017 MinIO, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.minio.messages; - -import java.util.LinkedList; -import java.util.List; - -import org.xmlpull.v1.XmlPullParserException; - -import com.google.api.client.util.Key; - - -/** - * Helper class to parse Amazon AWS S3 response XML containing S3Key. - */ -@SuppressWarnings("WeakerAccess") -public class S3Key extends XmlEntity { - @Key("FilterRule") - private List filterRuleList = new LinkedList<>(); - - - public S3Key() throws XmlPullParserException { - super(); - super.name = "S3Key"; - } - - - /** - * Returns filter rule list. - */ - public List filterRuleList() { - return filterRuleList; - } - - - /** - * Sets filter rule to list. - * As per Amazon AWS S3 server behavior, its not possible to set more than one rule for "prefix" or "suffix". - * However the spec http://docs.aws.amazon.com/AmazonS3/latest/API/RESTBucketPUTnotification.html - * is not clear about this behavior. - */ - private void setRule(String name, String value) throws IllegalArgumentException, XmlPullParserException { - if (value.length() > 1024) { - throw new IllegalArgumentException("value '" + value + "' is more than 1024 long"); - } - - for (FilterRule rule: filterRuleList) { - // Remove rule.name is same as given name. - if (rule.name().equals(name)) { - filterRuleList.remove(rule); - } - } - - FilterRule newRule = new FilterRule(); - newRule.setName(name); - newRule.setValue(value); - filterRuleList.add(newRule); - } - - - public void setPrefixRule(String value) throws IllegalArgumentException, XmlPullParserException { - setRule("prefix", value); - } - - - public void setSuffixRule(String value) throws IllegalArgumentException, XmlPullParserException { - setRule("suffix", value); - } -} diff --git a/api/src/main/java/io/minio/messages/ScanRange.java b/api/src/main/java/io/minio/messages/ScanRange.java index 8a513c689..5dfe02073 100644 --- a/api/src/main/java/io/minio/messages/ScanRange.java +++ b/api/src/main/java/io/minio/messages/ScanRange.java @@ -16,28 +16,26 @@ package io.minio.messages; -import org.xmlpull.v1.XmlPullParserException; - -import com.google.api.client.util.Key; +import org.simpleframework.xml.Element; +import org.simpleframework.xml.Root; /** - * Helper class to generate Amazon AWS S3 request XML for SelectObjectContentRequest/ScanRange information. + * Helper class to denote scan range in select object content request XML for SelectObjectContentRequest. */ +@Root(name = "ScanRange") @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(value = "URF_UNREAD_FIELD") -public class ScanRange extends XmlEntity { - @Key("Start") +public class ScanRange { + @Element(name = "Start", required = false) private Long start; - @Key("End") + @Element(name = "End", required = false) private Long end; + /** * Constructs new ScanRange object for given start and end. */ - public ScanRange(Long start, Long end) throws XmlPullParserException { - super(); - super.name = "ScanRange"; - + public ScanRange(Long start, Long end) { this.start = start; this.end = end; } diff --git a/api/src/main/java/io/minio/messages/SelectObjectContentRequest.java b/api/src/main/java/io/minio/messages/SelectObjectContentRequest.java index dbff99564..5a89abebf 100644 --- a/api/src/main/java/io/minio/messages/SelectObjectContentRequest.java +++ b/api/src/main/java/io/minio/messages/SelectObjectContentRequest.java @@ -16,27 +16,30 @@ package io.minio.messages; -import org.xmlpull.v1.XmlPullParserException; - -import com.google.api.client.util.Key; +import org.simpleframework.xml.Element; +import org.simpleframework.xml.Namespace; +import org.simpleframework.xml.Root; /** - * Helper class to generate Amazon AWS S3 request XML for SelectObjectContentRequest information. + * Denotes select object content request XML as per + * https://docs.aws.amazon.com/AmazonS3/latest/API/API_SelectObjectContent.html. */ +@Root(name = "SelectObjectContentRequest") +@Namespace(reference = "http://s3.amazonaws.com/doc/2006-03-01/") @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(value = "URF_UNREAD_FIELD") -public class SelectObjectContentRequest extends XmlEntity { - @Key("Expression") +public class SelectObjectContentRequest { + @Element(name = "Expression") private String expression; - @Key("ExpressionType") - private String expressionType; - @Key("RequestProgress") + @Element(name = "ExpressionType") + private String expressionType = "SQL"; + @Element(name = "RequestProgress", required = false) private RequestProgress requestProgress; - @Key("InputSerialization") + @Element(name = "InputSerialization") private InputSerialization inputSerialization; - @Key("OutputSerialization") + @Element(name = "OutputSerialization") private OutputSerialization outputSerialization; - @Key("ScanRange") + @Element(name = "ScanRange", required = false) private ScanRange scanRange; @@ -44,14 +47,8 @@ public class SelectObjectContentRequest extends XmlEntity { * Constructs new SelectObjectContentRequest object for given parameters. */ public SelectObjectContentRequest(String expression, boolean requestProgress, InputSerialization is, - OutputSerialization os, Long scanStartRange, Long scanEndRange) - throws XmlPullParserException { - super(); - this.name = "SelectObjectContentRequest"; - super.namespaceDictionary.set("", "http://s3.amazonaws.com/doc/2006-03-01/"); - + OutputSerialization os, Long scanStartRange, Long scanEndRange) { this.expression = expression; - this.expressionType = "SQL"; if (requestProgress) { this.requestProgress = new RequestProgress(); } diff --git a/api/src/main/java/io/minio/messages/Stats.java b/api/src/main/java/io/minio/messages/Stats.java index ccb619d46..d310a1585 100644 --- a/api/src/main/java/io/minio/messages/Stats.java +++ b/api/src/main/java/io/minio/messages/Stats.java @@ -16,42 +16,29 @@ package io.minio.messages; -import java.io.IOException; -import java.io.Reader; +import org.simpleframework.xml.Element; +import org.simpleframework.xml.Namespace; +import org.simpleframework.xml.Root; -import org.xmlpull.v1.XmlPullParserException; - -import com.google.api.client.util.Key; -import com.google.api.client.xml.XmlNamespaceDictionary; /** - * Helper class to parse Stats/Progress message in S3 select response message. + * Helper class to denote Stats information of S3 select response message. */ -public class Stats extends XmlEntity { - @Key("BytesScanned") +@Root(name = "Stats", strict = false) +@Namespace(reference = "http://s3.amazonaws.com/doc/2006-03-01/") +public class Stats { + @Element(name = "BytesScanned") private long bytesScanned = -1; - @Key("BytesProcessed") + @Element(name = "BytesProcessed") private long bytesProcessed = -1; - @Key("BytesReturned") + @Element(name = "BytesReturned") private long bytesReturned = -1; - /** - * Constructs a new Stats object. - */ - public Stats(String name) throws XmlPullParserException { - super(); - super.name = name; - } /** - * Fills up this Stats object's fields by reading/parsing values from given Reader input stream. + * Constructs a new Stats object. */ - @Override - public void parseXml(Reader reader) throws IOException, XmlPullParserException { - XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary(); - namespaceDictionary.set("s3", "http://s3.amazonaws.com/doc/2006-03-01/"); - namespaceDictionary.set("", ""); - super.parseXml(reader, namespaceDictionary); + public Stats() { } @@ -62,6 +49,7 @@ public long bytesScanned() { return this.bytesScanned; } + /** * Returns bytes processed. */ @@ -69,6 +57,7 @@ public long bytesProcessed() { return this.bytesProcessed; } + /** * Returns bytes returned. */ diff --git a/api/src/main/java/io/minio/messages/TopicConfiguration.java b/api/src/main/java/io/minio/messages/TopicConfiguration.java index f5af4d115..0ebb16389 100644 --- a/api/src/main/java/io/minio/messages/TopicConfiguration.java +++ b/api/src/main/java/io/minio/messages/TopicConfiguration.java @@ -16,40 +16,21 @@ package io.minio.messages; -import java.util.LinkedList; -import java.util.List; - -import org.xmlpull.v1.XmlPullParserException; - -import com.google.api.client.util.Key; +import org.simpleframework.xml.Element; +import org.simpleframework.xml.Root; /** - * Helper class to parse Amazon AWS S3 response XML containing topic configuration. + * Helper class to denote Topic configuration of NotificationConfiguration. */ -@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(value = "URF_UNREAD_FIELD") -public class TopicConfiguration extends XmlEntity { - @Key("Id") - private String id; - @Key("Topic") +@Root(name = "TopicConfiguration", strict = false) +public class TopicConfiguration extends NotificationCommonConfiguration { + @Element(name = "Topic") private String topic; - @Key("Event") - private List events = new LinkedList<>(); - @Key("Filter") - private Filter filter; - public TopicConfiguration() throws XmlPullParserException { + public TopicConfiguration() { super(); - super.name = "TopicConfiguration"; - } - - - /** - * Sets ID. This is used only in functional test. - */ - public void setId(String id) { - this.id = id; } @@ -67,36 +48,4 @@ public String topic() { public void setTopic(String topic) { this.topic = topic; } - - - /** - * Returns events. - */ - public List events() throws IllegalArgumentException { - return EventType.fromStringList(events); - } - - - /** - * Sets event. - */ - public void setEvents(List events) { - this.events = EventType.toStringList(events); - } - - - /** - * Returns filter. - */ - public Filter filter() { - return filter; - } - - - /** - * Sets filter. - */ - public void setFilter(Filter filter) { - this.filter = filter; - } } diff --git a/api/src/main/java/io/minio/messages/Upload.java b/api/src/main/java/io/minio/messages/Upload.java index 76e834f5b..a412f75f5 100644 --- a/api/src/main/java/io/minio/messages/Upload.java +++ b/api/src/main/java/io/minio/messages/Upload.java @@ -16,35 +16,34 @@ package io.minio.messages; -import com.google.api.client.util.Key; -import io.minio.Time; import java.time.ZonedDateTime; -import org.xmlpull.v1.XmlPullParserException; +import org.simpleframework.xml.Element; +import org.simpleframework.xml.Namespace; +import org.simpleframework.xml.Root; /** - * Helper class to parse Amazon AWS S3 response XML containing Upload information. + * Helper class to denote Upload information of a multipart upload and used in ListMultipartUploadsResult. */ -@SuppressWarnings("unused") -public class Upload extends XmlEntity { - @Key("Key") +@Root(name = "Upload", strict = false) +@Namespace(reference = "http://s3.amazonaws.com/doc/2006-03-01/") +public class Upload { + @Element(name = "Key") private String objectName; - @Key("UploadId") + @Element(name = "UploadId") private String uploadId; - @Key("Initiator") + @Element(name = "Initiator") private Initiator initiator; - @Key("Owner") + @Element(name = "Owner") private Owner owner; - @Key("StorageClass") + @Element(name = "StorageClass") private String storageClass; - @Key("Initiated") - private String initiated; + @Element(name = "Initiated") + private ResponseDate initiated; private long aggregatedPartSize; - public Upload() throws XmlPullParserException { - super(); - super.name = "Upload"; + public Upload() { } @@ -92,7 +91,7 @@ public String storageClass() { * Returns initated time. */ public ZonedDateTime initiated() { - return ZonedDateTime.parse(initiated, Time.RESPONSE_DATE_FORMAT); + return initiated.zonedDateTime(); } diff --git a/api/src/main/java/io/minio/messages/XmlEntity.java b/api/src/main/java/io/minio/messages/XmlEntity.java deleted file mode 100644 index 0c5c15f1e..000000000 --- a/api/src/main/java/io/minio/messages/XmlEntity.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * MinIO Java SDK for Amazon S3 Compatible Cloud Storage, (C) 2015 MinIO, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.minio.messages; - -import java.io.IOException; -import java.io.Reader; - -import org.xmlpull.v1.XmlPullParser; -import org.xmlpull.v1.XmlPullParserException; - -import com.google.api.client.xml.GenericXml; -import com.google.api.client.xml.Xml; -import com.google.api.client.xml.XmlNamespaceDictionary; - - -/** - * XML parser interface class extended from GenericXML. - */ -public abstract class XmlEntity extends GenericXml { - private XmlPullParser xmlPullParser; - private XmlNamespaceDictionary defaultNamespaceDictionary; - - - /** - * Constructs a new XmlEntity class. - */ - public XmlEntity() throws XmlPullParserException { - super.namespaceDictionary = new XmlNamespaceDictionary(); - super.namespaceDictionary.set("s3", "http://s3.amazonaws.com/doc/2006-03-01/"); - super.namespaceDictionary.set("", ""); - - this.xmlPullParser = Xml.createParser(); - this.defaultNamespaceDictionary = new XmlNamespaceDictionary(); - } - - - /** - * Constructs a new XmlEntity class by parsing content from given reader input stream. - */ - public XmlEntity(Reader reader) throws IOException, XmlPullParserException { - this(); - this.parseXml(reader); - } - - - /** - * Parses content from given reader input stream. - */ - public void parseXml(Reader reader) throws IOException, XmlPullParserException { - this.xmlPullParser.setInput(reader); - Xml.parseElement(this.xmlPullParser, this, this.defaultNamespaceDictionary, null); - } - - - /** - * Parses content from given reader input stream and namespace dictionary. - */ - protected void parseXml(Reader reader, XmlNamespaceDictionary namespaceDictionary) - throws IOException, XmlPullParserException { - this.xmlPullParser.setInput(reader); - Xml.parseElement(this.xmlPullParser, this, namespaceDictionary, null); - } -} diff --git a/api/src/test/java/io/minio/MinioClientTest.java b/api/src/test/java/io/minio/MinioClientTest.java index 33f882e29..08d055d38 100644 --- a/api/src/test/java/io/minio/MinioClientTest.java +++ b/api/src/test/java/io/minio/MinioClientTest.java @@ -380,7 +380,7 @@ public void testListObjects() Item item = objectsInBucket.next().get(); assertEquals("key", item.objectName()); - assertEquals(11, item.objectSize()); + assertEquals(11, item.size()); assertEquals("STANDARD", item.storageClass()); assertEquals("2015-05-05T02:21:15.716Z", item.lastModified().format(Time.RESPONSE_DATE_FORMAT)); diff --git a/build.gradle b/build.gradle index 9ba95607f..21b0e69fd 100644 --- a/build.gradle +++ b/build.gradle @@ -52,7 +52,7 @@ subprojects { } dependencies { - compile "com.google.http-client:google-http-client-xml:1.24.1" + compile "org.simpleframework:simple-xml:2.7.1" compile "com.google.guava:guava:25.1-jre" compile "com.squareup.okhttp3:okhttp:3.13.1" compile "com.squareup.okio:okio:1.17.2" diff --git a/examples/PutObjectProgressBar.java b/examples/PutObjectProgressBar.java index 78d19dd4d..9119dddfa 100644 --- a/examples/PutObjectProgressBar.java +++ b/examples/PutObjectProgressBar.java @@ -22,8 +22,6 @@ import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; -import org.xmlpull.v1.XmlPullParserException; - import io.minio.MinioClient; import io.minio.errors.ErrorResponseException; import io.minio.errors.InsufficientDataException; @@ -32,6 +30,7 @@ import io.minio.errors.InvalidBucketNameException; import io.minio.errors.InvalidEndpointException; import io.minio.errors.InvalidPortException; +import io.minio.errors.XmlParserException; import me.tongfei.progressbar.ProgressBarStyle; @@ -42,7 +41,7 @@ public class PutObjectProgressBar { public static void main(String[] args) throws InvalidKeyException, NoSuchAlgorithmException, InvalidEndpointException, InvalidPortException, InvalidBucketNameException, InsufficientDataException, ErrorResponseException, InternalException, - IllegalArgumentException, IOException, XmlPullParserException, InvalidResponseException { + IllegalArgumentException, IOException, XmlParserException, InvalidResponseException { /* play.min.io for test and development. */ MinioClient minioClient = new MinioClient("https://play.min.io", "Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG"); diff --git a/examples/PutObjectUiProgressBar.java b/examples/PutObjectUiProgressBar.java index ae1c1139d..d09a879fd 100644 --- a/examples/PutObjectUiProgressBar.java +++ b/examples/PutObjectUiProgressBar.java @@ -29,8 +29,6 @@ import javax.swing.ProgressMonitorInputStream; import javax.swing.SwingWorker; -import org.xmlpull.v1.XmlPullParserException; - import io.minio.MinioClient; import io.minio.errors.ErrorResponseException; import io.minio.errors.InsufficientDataException; @@ -39,6 +37,7 @@ import io.minio.errors.InvalidEndpointException; import io.minio.errors.InvalidPortException; import io.minio.errors.InvalidResponseException; +import io.minio.errors.XmlParserException; public class PutObjectUiProgressBar extends JFrame { @@ -72,7 +71,7 @@ public void go() { * as well. This function is involed when user clicks on the UI */ private void uploadFile(String fileName) throws IOException, NoSuchAlgorithmException, InvalidKeyException, - XmlPullParserException, InvalidEndpointException, InvalidPortException, + XmlParserException, InvalidEndpointException, InvalidPortException, InvalidBucketNameException, InsufficientDataException, ErrorResponseException, InternalException, IllegalArgumentException, InvalidResponseException { diff --git a/examples/SelectObjectContent.java b/examples/SelectObjectContent.java index d0598a412..08d74ad20 100644 --- a/examples/SelectObjectContent.java +++ b/examples/SelectObjectContent.java @@ -57,9 +57,9 @@ public static void main(String[] args) minioClient.putObject("my-bucketname", "my-objectName", bais, Long.valueOf(data.length), null, null, null); String sqlExpression = "select * from S3Object"; - InputSerialization is = InputSerialization.csv(null, false, null, null, FileHeaderInfo.USE, + InputSerialization is = new InputSerialization(null, false, null, null, FileHeaderInfo.USE, null, null, null); - OutputSerialization os = OutputSerialization.csv(null, null, null, QuoteFields.ASNEEDED, null); + OutputSerialization os = new OutputSerialization(null, null, null, QuoteFields.ASNEEDED, null); SelectResponseStream stream = minioClient.selectObjectContent("my-bucketname", "my-objectName", sqlExpression, is, os, true, null, null, null); diff --git a/examples/SetBucketNotification.java b/examples/SetBucketNotification.java index 9ba264b65..9b71a4171 100644 --- a/examples/SetBucketNotification.java +++ b/examples/SetBucketNotification.java @@ -28,7 +28,6 @@ import io.minio.messages.NotificationConfiguration; import io.minio.messages.QueueConfiguration; import io.minio.messages.EventType; -import io.minio.messages.Filter; import io.minio.errors.MinioException; @@ -58,11 +57,8 @@ public static void main(String[] args) eventList.add(EventType.OBJECT_CREATED_PUT); eventList.add(EventType.OBJECT_CREATED_COPY); queueConfiguration.setEvents(eventList); - - Filter filter = new Filter(); - filter.setPrefixRule("images"); - filter.setSuffixRule("pg"); - queueConfiguration.setFilter(filter); + queueConfiguration.setPrefixRule("images"); + queueConfiguration.setSuffixRule("pg"); queueConfigurationList.add(queueConfiguration); notificationConfiguration.setQueueConfigurationList(queueConfigurationList); diff --git a/examples/SetGetBucketObjectLockConfig.java b/examples/SetGetBucketObjectLockConfig.java index 8f98c426c..4a3476627 100644 --- a/examples/SetGetBucketObjectLockConfig.java +++ b/examples/SetGetBucketObjectLockConfig.java @@ -21,22 +21,21 @@ import org.xmlpull.v1.XmlPullParserException; import io.minio.MinioClient; -import io.minio.messages.DurationUnit; +import io.minio.messages.RetentionDurationDays; import io.minio.messages.ObjectLockConfiguration; import io.minio.messages.RetentionMode; import io.minio.errors.MinioException; public class SetGetBucketObjectLockConfig { /** - * MinioClient.makeBucket() example. + * Set/Get Bucket Object Lock configuration example. */ public static void main(String[] args) throws IOException, NoSuchAlgorithmException, InvalidKeyException, XmlPullParserException { try { - /* Amazon S3: */ MinioClient s3Client = new MinioClient("https://s3.amazonaws.com", "YOUR-ACCESSKEYID", - "YOUR-SECRETACCESSKEY"); + "YOUR-SECRETACCESSKEY"); // Create bucket if it doesn't exist. boolean found = s3Client.bucketExists("my-bucketname"); @@ -48,19 +47,19 @@ public static void main(String[] args) System.out.println("my-bucketname is created successfully with object lock functionality enabled."); } - // Declaring config with Retention mode as Compliance and - // duration as 100 days - ObjectLockConfiguration config = new ObjectLockConfiguration(RetentionMode.COMPLIANCE,100 , DurationUnit.DAYS); + // Declaring config with Retention mode as Compliance and duration as 100 days + ObjectLockConfiguration config = new ObjectLockConfiguration(RetentionMode.COMPLIANCE, + new RetentionDurationDays(100)); // Set object lock configuration - s3Client.setDefaultRetention("my-bucketname" , config); + s3Client.setDefaultRetention("my-bucketname", config); // Get object lock configuration ObjectLockConfiguration bucketConfig = s3Client.getDefaultRetention("my-bucketname"); - System.out.println(" Lock Configuration : " + bucketConfig); - - + System.out.println("Default retention configuration of bucket"); + System.out.println("Mode: " + bucketConfig.mode()); + System.out.println("Duration: " + bucketConfig.duration()); } catch (MinioException e) { System.out.println("Error occurred: " + e); } diff --git a/examples/SetGetObjectLockRetentionConfig.java b/examples/SetGetObjectLockRetentionConfig.java index f53e2212a..3f2b9ee67 100644 --- a/examples/SetGetObjectLockRetentionConfig.java +++ b/examples/SetGetObjectLockRetentionConfig.java @@ -24,7 +24,7 @@ import io.minio.errors.InvalidPortException; import io.minio.errors.MinioException; import io.minio.errors.RegionConflictException; -import io.minio.messages.ObjectRetentionConfiguration; +import io.minio.messages.Retention; import io.minio.messages.RetentionMode; import java.io.ByteArrayInputStream; @@ -47,7 +47,6 @@ public static void main(String[] args) InvalidPortException, InvalidEndpointException, RegionConflictException, IllegalArgumentException { try { - /* play.min.io for test and development. */ MinioClient minioClient = new MinioClient("https://play.min.io", "Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG"); @@ -62,7 +61,6 @@ public static void main(String[] args) System.out.println("my-bucketname is created successfully with object lock functionality enabled."); } - StringBuilder builder = new StringBuilder(); for (int i = 0; i < 100; i++) { builder.append("Sphinx of black quartz, judge my vow: Used by Adobe InDesign to display font samples. "); @@ -76,27 +74,23 @@ public static void main(String[] args) // Create object 'my-objectname' in 'my-bucketname' with content from the input stream. minioClient.putObject("my-bucketname", "my-objectname", bais, Long.valueOf(bais.available()), null, null, - "application/octet-stream"); + "application/octet-stream"); bais.close(); System.out.println("my-objectname is uploaded successfully"); - - // Declaring config with Retention mode as Compliance and - // retain until MAY 2021 + // Declaring config with Retention mode as Compliance and + // retain until one year to current date. ZonedDateTime retentionUntil = ZonedDateTime.now().plusYears(1); - ObjectRetentionConfiguration config = - new ObjectRetentionConfiguration(RetentionMode.COMPLIANCE, retentionUntil); + Retention config = new Retention(RetentionMode.COMPLIANCE, retentionUntil); // Set object lock configuration minioClient.setObjectRetention("my-bucketname" , "my-objectname", "" , config, true ); // Get object lock retention - ObjectRetentionConfiguration objectRetentionConfiguration = minioClient.getObjectRetention("my-bucketname" , - "my-objectname", "" ); + Retention retention = minioClient.getObjectRetention("my-bucketname", "my-objectname", ""); - System.out.println(" Mode : " + objectRetentionConfiguration.mode()); - System.out.println(" Retainuntil Date : " + objectRetentionConfiguration.retainUntilDate()); - + System.out.println("Mode: " + retention.mode()); + System.out.println("Retainuntil Date: " + retention.retainUntilDate()); } catch (MinioException e) { System.out.println("Error occurred: " + e); } diff --git a/functional/FunctionalTest.java b/functional/FunctionalTest.java index 8d7b7ba7e..58df6ace6 100644 --- a/functional/FunctionalTest.java +++ b/functional/FunctionalTest.java @@ -715,7 +715,7 @@ public static void putObject_test12() throws Exception { try (final InputStream is = new ContentInputStream(1 * KB)) { client.putObject(bucketName, objectName, is, Long.valueOf(1 * KB), headerMap, null, null); } catch (ErrorResponseException e) { - if (!e.errorResponse().code().equals("InvalidStorageClass")) { + if (e.errorResponse().errorCode() != ErrorCode.INVALID_STORAGE_CLASS) { throw e; } } @@ -1623,7 +1623,7 @@ public static void listIncompleteUploads_test1() throws Exception { try (final InputStream is = new ContentInputStream(6 * MB)) { client.putObject(bucketName, objectName, is, Long.valueOf( 9 * MB), null, null, nullContentType); } catch (ErrorResponseException e) { - if (!e.errorResponse().code().equals("IncompleteBody")) { + if (e.errorResponse().errorCode() != ErrorCode.INCOMPLETE_BODY) { throw e; } } catch (java.net.ProtocolException e) { @@ -1661,7 +1661,7 @@ public static void listIncompleteUploads_test2() throws Exception { try (final InputStream is = new ContentInputStream(6 * MB)) { client.putObject(bucketName, objectName, is, Long.valueOf( 9 * MB), null, null, nullContentType); } catch (ErrorResponseException e) { - if (!e.errorResponse().code().equals("IncompleteBody")) { + if (e.errorResponse().errorCode() != ErrorCode.INCOMPLETE_BODY) { throw e; } } catch (java.net.ProtocolException e) { @@ -1701,7 +1701,7 @@ public static void listIncompleteUploads_test3() throws Exception { try (final InputStream is = new ContentInputStream(6 * MB)) { client.putObject(bucketName, objectName, is, Long.valueOf( 9 * MB), null, null, nullContentType); } catch (ErrorResponseException e) { - if (!e.errorResponse().code().equals("IncompleteBody")) { + if (e.errorResponse().errorCode() != ErrorCode.INCOMPLETE_BODY) { throw e; } } catch (java.net.ProtocolException e) { @@ -1741,7 +1741,7 @@ public static void removeIncompleteUploads_test() throws Exception { try (final InputStream is = new ContentInputStream(6 * MB)) { client.putObject(bucketName, objectName, is, Long.valueOf( 9 * MB), null, null, nullContentType); } catch (ErrorResponseException e) { - if (!e.errorResponse().code().equals("IncompleteBody")) { + if (e.errorResponse().errorCode() != ErrorCode.INCOMPLETE_BODY) { throw e; } } catch (java.net.ProtocolException e) { @@ -2073,7 +2073,7 @@ public static void copyObject_test2() throws Exception { try { client.copyObject(destBucketName, objectName, null, null, bucketName, null, null, invalidETag); } catch (ErrorResponseException e) { - if (!e.errorResponse().code().equals("PreconditionFailed")) { + if (e.errorResponse().errorCode() != ErrorCode.PRECONDITION_FAILED) { throw e; } } @@ -2206,7 +2206,7 @@ public static void copyObject_test5() throws Exception { } catch (ErrorResponseException e) { // File should not be copied as ETag set in copyConditions matches object's // ETag. - if (!e.errorResponse().code().equals("PreconditionFailed")) { + if (e.errorResponse().errorCode() != ErrorCode.PRECONDITION_FAILED) { throw e; } } @@ -2295,7 +2295,7 @@ public static void copyObject_test7() throws Exception { } catch (ErrorResponseException e) { // File should not be copied as object was modified after date set in // copyConditions. - if (!e.errorResponse().code().equals("PreconditionFailed")) { + if (e.errorResponse().errorCode() != ErrorCode.PRECONDITION_FAILED) { throw e; } } @@ -3073,11 +3073,8 @@ public static void setBucketNotification_test1() throws Exception { eventList.add(EventType.OBJECT_CREATED_PUT); eventList.add(EventType.OBJECT_CREATED_COPY); topicConfiguration.setEvents(eventList); - - Filter filter = new Filter(); - filter.setPrefixRule("images"); - filter.setSuffixRule("pg"); - topicConfiguration.setFilter(filter); + topicConfiguration.setPrefixRule("images"); + topicConfiguration.setSuffixRule("pg"); topicConfigurationList.add(topicConfiguration); notificationConfiguration.setTopicConfigurationList(topicConfigurationList); @@ -3186,11 +3183,8 @@ public static void removeAllBucketNotification_test1() throws Exception { eventList.add(EventType.OBJECT_CREATED_PUT); eventList.add(EventType.OBJECT_CREATED_COPY); topicConfiguration.setEvents(eventList); - - Filter filter = new Filter(); - filter.setPrefixRule("images"); - filter.setSuffixRule("pg"); - topicConfiguration.setFilter(filter); + topicConfiguration.setPrefixRule("images"); + topicConfiguration.setSuffixRule("pg"); topicConfigurationList.add(topicConfiguration); notificationConfiguration.setTopicConfigurationList(topicConfigurationList); @@ -3348,12 +3342,12 @@ public static void selectObjectContent_test1() throws Exception { client.putObject(bucketName, objectName, bais, Long.valueOf(data.length), null, null, null); String sqlExpression = "select * from S3Object"; - InputSerialization is = InputSerialization.csv(null, false, null, null, FileHeaderInfo.USE, + InputSerialization is = new InputSerialization(null, false, null, null, FileHeaderInfo.USE, null, null, null); - OutputSerialization os = OutputSerialization.csv(null, null, null, QuoteFields.ASNEEDED, null); + OutputSerialization os = new OutputSerialization(null, null, null, QuoteFields.ASNEEDED, null); responseStream = client.selectObjectContent(bucketName, objectName, sqlExpression, - is, os, true, null, null, null); + is, os, true, null, null, null); String result = new String(readAllBytes(responseStream), StandardCharsets.UTF_8); if (!result.equals(expectedResult)) {