S3ListAllMyBucketsRequest engineRequest = new S3ListAllMyBucketsRequest();
engineRequest.setAccessKey(UserContext.current().getAccessKey());
engineRequest.setRequestTimestamp(cal);
engineRequest.setSignature("");
S3ListAllMyBucketsResponse engineResponse = ServiceProvider
.getInstance().getS3Engine().handleRequest(engineRequest);
// To allow the all buckets list to be serialized via Axiom classes
ListAllMyBucketsResponse allBuckets = S3SerializableServiceImplementation
.toListAllMyBucketsResponse(engineResponse);
OutputStream outputStream = response.getOutputStream();
response.setStatus(200);
response.setContentType("application/xml");
// The content-type literally should be "application/xml; charset=UTF-8"
// but any compliant JVM supplies utf-8 by default
// MTOMAwareResultStreamWriter resultWriter = new
// MTOMAwareResultStreamWriter ("ListAllMyBucketsResult", outputStream
// );
// resultWriter.startWrite();
// resultWriter.writeout(allBuckets);
// resultWriter.stopWrite();
StringBuffer xml = new StringBuffer();
xml.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
xml.append("<ListAllMyBucketsResult xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\">");
xml.append("<Owner><ID>");
xml.append(engineResponse.getOwner().getID()).append("</ID>");
xml.append("<DisplayName>")
.append(engineResponse.getOwner().getDisplayName())
.append("</DisplayName>");
xml.append("</Owner>").append("<Buckets>");
SimpleDateFormat sdf = new SimpleDateFormat(
"yyyy-MM-dd'T'HH:mm:ss.SSSZ");
for (S3ListAllMyBucketsEntry entry : engineResponse.getBuckets()) {
xml.append("<Bucket>").append("<Name>").append(entry.getName())
.append("</Name>");
xml.append("<CreationDate>")
.append(sdf.format(entry.getCreationDate().getTime()))
.append("</CreationDate>");