Created
September 9, 2012 11:28
-
-
Save holyjak/3683899 to your computer and use it in GitHub Desktop.
REST service mixing data and representation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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