@Override public StructuredOutput beginResult() { return beginOutput("result"); }
@Override public StructuredOutput beginResult(String name) { return beginOutput(name); }
/** * Handles POST /bucket/id?uploads * * @param ctx the context describing the current request * @param bucket the bucket containing the object to upload * @param id name of the object to upload */ private void startMultipartUpload(WebContext ctx, Bucket bucket, String id) { Response response = ctx.respondWith(); Map<String, String> properties = Maps.newTreeMap(); for (String name : ctx.getRequest().headers().names()) { String nameLower = name.toLowerCase(); if (nameLower.startsWith("x-amz-meta-") || "content-md5".equals(nameLower) || "content-type".equals( nameLower) || "x-amz-acl".equals(nameLower)) { properties.put(name, ctx.getHeader(name)); response.addHeader(name, ctx.getHeader(name)); } } response.setHeader(HTTP_HEADER_NAME_CONTENT_TYPE, CONTENT_TYPE_XML); String uploadId = String.valueOf(uploadIdCounter.inc()); multipartUploads.add(uploadId); getUploadDir(uploadId).mkdirs(); XMLStructuredOutput out = response.xml(); out.beginOutput("InitiateMultipartUploadResult"); out.property(RESPONSE_BUCKET, bucket.getName()); out.property("Key", id); out.property("UploadId", uploadId); out.endOutput(); }
/** * Returns a list of at most the provided number of stored objects * * @param output the xml structured output the list of objects should be written to * @param limit controls the maximum number of objects returned * @param marker the key to start with when listing objects in a bucket * @param prefix limits the response to keys that begin with the specified prefix */ public void outputObjects(XMLStructuredOutput output, int limit, @Nullable String marker, @Nullable String prefix) { ListFileTreeVisitor visitor = new ListFileTreeVisitor(output, limit, marker, prefix); output.beginOutput("ListBucketResult", Attribute.set("xmlns", "http://s3.amazonaws.com/doc/2006-03-01/")); output.property("Name", getName()); output.property("MaxKeys", limit); output.property("Marker", marker); output.property("Prefix", prefix); try { Files.walkFileTree(file.toPath(), visitor); } catch (IOException e) { Exceptions.handle(e); } output.property("IsTruncated", limit > 0 && visitor.getCount() > limit); output.endOutput(); }
out.beginOutput("CompleteMultipartUploadResult"); out.property("Location", ""); out.property(RESPONSE_BUCKET, bucket.getName());
structuredOutput.beginOutput("CopyObjectResult"); structuredOutput.beginObject("LastModified"); structuredOutput.text(RFC822_INSTANT.format(object.getLastModifiedInstant()));
out.beginOutput("ListPartsResult"); out.property(RESPONSE_BUCKET, bucket.getName()); out.property("Key", id);
/** * GET a list of all buckets * * @param ctx the context describing the current request */ private void listBuckets(WebContext ctx) { HttpMethod method = ctx.getRequest().method(); if (GET == method) { List<Bucket> buckets = storage.getBuckets(); Response response = ctx.respondWith(); response.setHeader(HTTP_HEADER_NAME_CONTENT_TYPE, CONTENT_TYPE_XML); XMLStructuredOutput out = response.xml(); out.beginOutput("ListAllMyBucketsResult", Attribute.set("xmlns", "http://s3.amazonaws.com/doc/2006-03-01/")); out.property("hint", "Goto: " + ctx.getBaseURL() + "/ui to visit the admin UI"); outputOwnerInfo(out, "Owner"); out.beginObject("Buckets"); for (Bucket bucket : buckets) { out.beginObject(RESPONSE_BUCKET); out.property("Name", bucket.getName()); out.property("CreationDate", RFC822_INSTANT.format(Instant.ofEpochMilli(bucket.getFile().lastModified()))); out.endObject(); } out.endObject(); out.endOutput(); } else { throw new IllegalArgumentException(ctx.getRequest().method().name()); } }