Skip to content

Instantly share code, notes, and snippets.

@holyjak
Created September 9, 2012 11:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save holyjak/3683899 to your computer and use it in GitHub Desktop.
Save holyjak/3683899 to your computer and use it in GitHub Desktop.
REST service mixing data and representation
public class S3FilesResource {
AmazonS3Client amazonS3Client;
// ...
@Path("/files")
public String listS3Files() {
StringBuilder html = new StringBuilder("<html><body>");
List<S3ObjectSummary> files = this.amazonS3Client.listObjects("myBucket").getObjectSummaries();
for (S3ObjectSummary file : files) {
String filePath = file.getKey();
if (!filePath.endsWith("/")) { // exclude directories
html.append("<a href='/content?fileName=").append(filePath).append("'>").append(filePath)
.append("</a><br>");
}
}
return html.append("</body></html>").toString();
}
@Path("/content")
public String getContent(@QueryParam("fileName") String fileName) {
throw new UnsupportedOperationException("Not implemented yet");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment