Skip to content

Commit

Permalink
fix: send request XML object instead of Object.toString() to execute() (
Browse files Browse the repository at this point in the history
#883)

Fixes #881
  • Loading branch information
balamurugana authored Mar 29, 2020
1 parent b160f1e commit 8004523
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
26 changes: 15 additions & 11 deletions api/src/main/java/io/minio/MinioClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
*/
@SuppressWarnings({"SameParameterValue", "WeakerAccess"})
public class MinioClient {
private static final byte[] EMPTY_BODY = new byte[] {};
private static final Logger LOGGER = Logger.getLogger(MinioClient.class.getName());
// default network I/O timeout is 15 minutes
private static final long DEFAULT_CONNECTION_TIMEOUT = 15 * 60;
Expand Down Expand Up @@ -1037,6 +1038,10 @@ private Response execute(
traceRequestBody = true;
}

if (body == null && (method == Method.PUT || method == Method.POST)) {
body = EMPTY_BODY;
}

HttpUrl url = buildUrl(method, bucketName, objectName, region, queryParamMap);
Request request = createRequest(url, method, headerMap, body, length);

Expand All @@ -1060,7 +1065,6 @@ private Response execute(
.replaceAll("Credential=([^/]+)", "Credential=*REDACTED*");
this.traceStream.println(headers);
if (traceRequestBody) {
this.traceStream.println();
this.traceStream.println(new String((byte[]) body, StandardCharsets.UTF_8));
}
}
Expand Down Expand Up @@ -3296,20 +3300,20 @@ public void makeBucket(String bucketName, String region, boolean objectLock)
if (region == null) {
region = this.region;
}

// If constructor already sets a region, check if it is equal to region param if provided
if (this.region != null && !this.region.equals(region)) {
throw new RegionConflictException(
"passed region conflicts with the one previously specified");
}
String configString;
if (region == null || US_EAST_1.equals(region)) {
// for 'us-east-1', location constraint is not required. for more info
// http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region

if (region == null) {
region = US_EAST_1;
configString = "";
} else {
CreateBucketConfiguration config = new CreateBucketConfiguration(region);
configString = config.toString();
}

CreateBucketConfiguration config = null;
if (!region.equals(US_EAST_1)) {
config = new CreateBucketConfiguration(region);
}

Map<String, String> headerMap = null;
Expand All @@ -3318,7 +3322,7 @@ public void makeBucket(String bucketName, String region, boolean objectLock)
headerMap.put("x-amz-bucket-object-lock-enabled", "true");
}

Response response = executePut(bucketName, null, region, headerMap, null, configString, 0);
Response response = executePut(bucketName, null, region, headerMap, null, config, 0);
response.body().close();
}

Expand Down Expand Up @@ -4217,7 +4221,7 @@ public void setBucketNotification(
Map<String, String> queryParamMap = new HashMap<>();
queryParamMap.put("notification", "");
Response response =
executePut(bucketName, null, null, queryParamMap, notificationConfiguration.toString(), 0);
executePut(bucketName, null, null, queryParamMap, notificationConfiguration, 0);
response.body().close();
}

Expand Down
3 changes: 2 additions & 1 deletion api/src/main/java/io/minio/Xml.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.simpleframework.xml.Serializer;
import org.simpleframework.xml.convert.AnnotationStrategy;
import org.simpleframework.xml.core.Persister;
import org.simpleframework.xml.stream.Format;

/** XML marshaller and unmarshaller. */
public class Xml {
Expand All @@ -33,7 +34,7 @@ public class Xml {
*/
public static String marshal(Object source) throws XmlParserException {
try {
Serializer serializer = new Persister(new AnnotationStrategy());
Serializer serializer = new Persister(new AnnotationStrategy(), new Format(0));
StringWriter writer = new StringWriter();
serializer.write(source, writer);
return writer.toString();
Expand Down

0 comments on commit 8004523

Please sign in to comment.