made sample not fail on runtime exceptions

git-svn-id: http://jclouds.googlecode.com/svn/trunk@1091 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
adrian.f.cole 2009-06-08 01:31:26 +00:00
parent 5cb5a3bb71
commit ecc067e119
2 changed files with 48 additions and 4 deletions

View File

@ -68,17 +68,59 @@ public class JCloudsServlet extends HttpServlet {
@Resource @Resource
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
public static class BucketResult {
private String name;
private String size = "unknown";
private String status = "ok";
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setSize(String size) {
this.size = size;
}
public String getSize() {
return size;
}
public void setStatus(String status) {
this.status = status;
}
public String getStatus() {
return status;
}
}
@Override @Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { throws ServletException, IOException {
try { try {
List<S3Bucket.Metadata> myBucketMetadata = context.getConnection().listOwnedBuckets().get( List<S3Bucket.Metadata> myBucketMetadata = context.getConnection().listOwnedBuckets().get(
25, TimeUnit.SECONDS); 25, TimeUnit.SECONDS);
List<S3Bucket> myBuckets = new ArrayList<S3Bucket>(); List<BucketResult> myBuckets = new ArrayList<BucketResult>();
for (S3Bucket.Metadata metadata : myBucketMetadata) { for (S3Bucket.Metadata metadata : myBucketMetadata) {
S3Bucket bucket = context.getConnection().listBucket(metadata.getName()).get(10, BucketResult result = new BucketResult();
TimeUnit.SECONDS); result.setName(metadata.getName());
myBuckets.add(bucket); try {
S3Bucket bucket = context.getConnection().listBucket(metadata.getName()).get(10,
TimeUnit.SECONDS);
if (bucket == S3Bucket.NOT_FOUND) {
result.setStatus("not found");
} else {
result.setSize(bucket.getSize() + "");
}
} catch (Exception e) {
logger.error(e, "Error listing bucket %1$s", result.getName());
result.setStatus(e.getMessage());
}
myBuckets.add(result);
} }
request.setAttribute("buckets", myBuckets); request.setAttribute("buckets", myBuckets);
request.setAttribute("className", className); request.setAttribute("className", className);
@ -86,6 +128,7 @@ public class JCloudsServlet extends HttpServlet {
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(nextJSP); RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(nextJSP);
dispatcher.forward(request, response); dispatcher.forward(request, response);
} catch (Exception e) { } catch (Exception e) {
logger.error(e, "Error listing buckets");
throw new ServletException(e); throw new ServletException(e);
} }
} }

View File

@ -34,6 +34,7 @@
<display:table name="buckets"> <display:table name="buckets">
<display:column property="name" title="Bucket" /> <display:column property="name" title="Bucket" />
<display:column property="size" title="Size" /> <display:column property="size" title="Size" />
<display:column property="status" title="Status" />
</display:table> </display:table>
</body> </body>
</html> </html>