GitHub PullRequestReviewCommentEvent at 2014-09-11 20:53:33
Repository: s3test
Actor: michaeltandy
Payload: {"action":"created","comment":{"url":"https://api.github.com/repos/michaeltandy/s3test/pulls/comments/17448071","id":17448071,"diff_hunk":"@@ -0,0 +1,59 @@\n+package uk.me.mjt.s3test.xml;\n+\n+import javax.xml.parsers.DocumentBuilder;\n+import javax.xml.parsers.DocumentBuilderFactory;\n+import javax.xml.parsers.ParserConfigurationException;\n+import javax.xml.transform.Transformer;\n+import javax.xml.transform.TransformerException;\n+import javax.xml.transform.TransformerFactory;\n+import javax.xml.transform.dom.DOMSource;\n+import javax.xml.transform.stream.StreamResult;\n+import java.io.StringWriter;\n+import java.nio.charset.StandardCharsets;\n+\n+import org.w3c.dom.Document;\n+import org.w3c.dom.Element;\n+\n+public abstract class XmlDocument {\n+\n+    protected final Document document;\n+\n+    public XmlDocument() {\n+        try {\n+            document = createNewDocument();\n+        } catch (ParserConfigurationException e) {\n+            throw new ExceptionInInitializerError(e);\n+        }\n+    }\n+\n+    public abstract void build();\n+\n+    private Document createNewDocument() throws ParserConfigurationException {\n+        DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();\n+        DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();\n+        return documentBuilder.newDocument();\n+    }\n+\n+    public Element createElementWithText(String name, String text) {\n+        Element element = document.createElement(name);\n+        element.appendChild(document.createTextNode(text));\n+        return element;\n+    }\n+\n+    public byte[] toUtf8Bytes() {\n+        return toString().getBytes(StandardCharsets.UTF_8);\n+    }\n+\n+    @Override\n+    public String toString() {\n+        try {\n+            TransformerFactory transformerFactory = TransformerFactory.newInstance();\n+            Transformer transformer = transformerFactory.newTransformer();\n+            StringWriter writer = new StringWriter();\n+            transformer.transform(new DOMSource(document), new StreamResult(writer));\n+            return writer.getBuffer().toString();","path":"src/main/java/uk/me/mjt/s3test/xml/XmlDocument.java","position":54,"original_position":54,"commit_id":"323e8796abd95f9d5f27bd9a3d3068a5bc7e3438","original_commit_id":"323e8796abd95f9d5f27bd9a3d3068a5bc7e3438","user":{"login":"michaeltandy","id":2449410,"avatar_url":"https://avatars.githubusercontent.com/u/2449410?v=2","gravatar_id":"7167d2302007163407c44fdbb67e7358","url":"https://api.github.com/users/michaeltandy","html_url":"https://github.com/michaeltandy","followers_url":"https://api.github.com/users/michaeltandy/followers","following_url":"https://api.github.com/users/michaeltandy/following{/other_user}","gists_url":"https://api.github.com/users/michaeltandy/gists{/gist_id}","starred_url":"https://api.github.com/users/michaeltandy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/michaeltandy/subscriptions","organizations_url":"https://api.github.com/users/michaeltandy/orgs","repos_url":"https://api.github.com/users/michaeltandy/repos","events_url":"https://api.github.com/users/michaeltandy/events{/privacy}","received_events_url":"https://api.github.com/users/michaeltandy/received_events","type":"User","site_admin":false},"body":"I hate this shitty API so much. I know it's the best one on offer without using an external library, but I still hate it.","created_at":"2014-09-11T20:53:33Z","updated_at":"2014-09-11T20:53:33Z","html_url":"https://github.com/michaeltandy/s3test/pull/2#discussion_r17448071","pull_request_url":"https://api.github.com/repos/michaeltandy/s3test/pulls/2","_links":{"self":{"href":"https://api.github.com/repos/michaeltandy/s3test/pulls/comments/17448071"},"html":{"href":"https://github.com/michaeltandy/s3test/pull/2#discussion_r17448071"},"pull_request":{"href":"https://api.github.com/repos/michaeltandy/s3test/pulls/2"}}},"pull_request":{"url":"https://api.github.com/repos/michaeltandy/s3test/pulls/2","id":21112687,"html_url":"https://github.com/michaeltandy/s3test/pull/2","diff_url":"https://github.com/michaeltandy/s3test/pull/2.diff","patch_url":"https://github.com/michaeltandy/s3test/pull/2.patch","issue_url":"https://api.github.com/repos/michaeltandy/s3test/issues/2","number":2,"state":"open","locked":false,"title":"XML Library Usage","user":{"login":"matthewhubble","id":7779758,"avatar_url":"https://avatars.githubusercontent.com/u/7779758?v=2","gravatar_id":"1c9123872806a3daaa42e6b7eddb5c1d","url":"https://api.github.com/users/matthewhubble","html_url":"https://github.com/matthewhubble","followers_url":"https://api.github.com/users/matthewhubble/followers","following_url":"https://api.github.com/users/matthewhubble/following{/other_user}","gists_url":"https://api.github.com/users/matthewhubble/gists{/gist_id}","starred_url":"https://api.github.com/users/matthewhubble/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matthewhubble/subscriptions","organizations_url":"https://api.github.com/users/matthewhubble/orgs","repos_url":"https://api.github.com/users/matthewhubble/repos","events_url":"https://api.github.com/users/matthewhubble/events{/privacy}","received_events_url":"https://api.github.com/users/matthewhubble/received_events","type":"User","site_admin":false},"body":"Instead of creating XML responses by concatenating strings,XML is instead built using the `javax.xml` library. Created an `XmlDocument` class that handles creating documents and serialising them to strings, along with some helper functions. The following classes extend `XmlDocument` to do something specific:\r\n - `ErrorResponseXmlDocument`\r\n - `ListBucketsXmlDocument`\r\n - `ListObjectsXmlDocument`\r\n\r\nAs well as that I re-factored a few things:\r\n - Made a `Server` base class that `S3Server` extends, which separates out non S3 specific stuff (such as binding to a random port, getting query parameters, reading request data, adding headers etc), so that `S3Server` only contains code that directly relates to S3\r\n - Standardised indenting\r\n - Improved valid bucket names test by actually trying to create buckets, rather than calling a `protected` function on `S3Server`\r\n - Removing author type comments from files\r\n - Improved some variable names\r\n - Other general tidying up","created_at":"2014-09-11T19:51:11Z","updated_at":"2014-09-11T20:53:33Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f3efd357b188afbf2fb174ebfdd549c3b1336591","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/michaeltandy/s3test/pulls/2/commits","review_comments_url":"https://api.github.com/repos/michaeltandy/s3test/pulls/2/comments","review_comment_url":"https://api.github.com/repos/michaeltandy/s3test/pulls/comments/{number}","comments_url":"https://api.github.com/repos/michaeltandy/s3test/issues/2/comments","statuses_url":"https://api.github.com/repos/michaeltandy/s3test/statuses/323e8796abd95f9d5f27bd9a3d3068a5bc7e3438","head":{"label":"matthewhubble:xml-library","ref":"xml-library","sha":"323e8796abd95f9d5f27bd9a3d3068a5bc7e3438","user":{"login":"matthewhubble","id":7779758,"avatar_url":"https://avatars.githubusercontent.com/u/7779758?v=2","gravatar_id":"1c9123872806a3daaa42e6b7eddb5c1d","url":"https://api.github.com/users/matthewhubble","html_url":"https://github.com/matthewhubble","followers_url":"https://api.github.com/users/matthewhubble/followers","following_url":"https://api.github.com/users/matthewhubble/following{/other_user}","gists_url":"https://api.github.com/users/matthewhubble/gists{/gist_id}","starred_url":"https://api.github.com/users/matthewhubble/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matthewhubble/subscriptions","organizations_url":"https://api.github.com/users/matthewhubble/orgs","repos_url":"https://api.github.com/users/matthewhubble/repos","events_url":"https://api.github.com/users/matthewhubble/events{/privacy}","received_events_url":"https://api.github.com/users/matthewhubble/received_events","type":"User","site_admin":false},"repo":{"id":23617488,"name":"s3test","full_name":"matthewhubble/s3test","owner":{"login":"matthewhubble","id":7779758,"avatar_url":"https://avatars.githubusercontent.com/u/7779758?v=2","gravatar_id":"1c9123872806a3daaa42e6b7eddb5c1d","url":"https://api.github.com/users/matthewhubble","html_url":"https://github.com/matthewhubble","followers_url":"https://api.github.com/users/matthewhubble/followers","following_url":"https://api.github.com/users/matthewhubble/following{/other_user}","gists_url":"https://api.github.com/users/matthewhubble/gists{/gist_id}","starred_url":"https://api.github.com/users/matthewhubble/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matthewhubble/subscriptions","organizations_url":"https://api.github.com/users/matthewhubble/orgs","repos_url":"https://api.github.com/users/matthewhubble/repos","events_url":"https://api.github.com/users/matthewhubble/events{/privacy}","received_events_url":"https://api.github.com/users/matthewhubble/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/matthewhubble/s3test","description":"In memory S3 emulation, such as for unit testing.","fork":true,"url":"https://api.github.com/repos/matthewhubble/s3test","forks_url":"https://api.github.com/repos/matthewhubble/s3test/forks","keys_url":"https://api.github.com/repos/matthewhubble/s3test/keys{/key_id}","collaborators_url":"https://api.github.com/repos/matthewhubble/s3test/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/matthewhubble/s3test/teams","hooks_url":"https://api.github.com/repos/matthewhubble/s3test/hooks","issue_events_url":"https://api.github.com/repos/matthewhubble/s3test/issues/events{/number}","events_url":"https://api.github.com/repos/matthewhubble/s3test/events","assignees_url":"https://api.github.com/repos/matthewhubble/s3test/assignees{/user}","branches_url":"https://api.github.com/repos/matthewhubble/s3test/branches{/branch}","tags_url":"https://api.github.com/repos/matthewhubble/s3test/tags","blobs_url":"https://api.github.com/repos/matthewhubble/s3test/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/matthewhubble/s3test/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/matthewhubble/s3test/git/refs{/sha}","trees_url":"https://api.github.com/repos/matthewhubble/s3test/git/trees{/sha}","statuses_url":"https://api.github.com/repos/matthewhubble/s3test/statuses/{sha}","languages_url":"https://api.github.com/repos/matthewhubble/s3test/languages","stargazers_url":"https://api.github.com/repos/matthewhubble/s3test/stargazers","contributors_url":"https://api.github.com/repos/matthewhubble/s3test/contributors","subscribers_url":"https://api.github.com/repos/matthewhubble/s3test/subscribers","subscription_url":"https://api.github.com/repos/matthewhubble/s3test/subscription","commits_url":"https://api.github.com/repos/matthewhubble/s3test/commits{/sha}","git_commits_url":"https://api.github.com/repos/matthewhubble/s3test/git/commits{/sha}","comments_url":"https://api.github.com/repos/matthewhubble/s3test/comments{/number}","issue_comment_url":"https://api.github.com/repos/matthewhubble/s3test/issues/comments/{number}","contents_url":"https://api.github.com/repos/matthewhubble/s3test/contents/{+path}","compare_url":"https://api.github.com/repos/matthewhubble/s3test/compare/{base}...{head}","merges_url":"https://api.github.com/repos/matthewhubble/s3test/merges","archive_url":"https://api.github.com/repos/matthewhubble/s3test/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/matthewhubble/s3test/downloads","issues_url":"https://api.github.com/repos/matthewhubble/s3test/issues{/number}","pulls_url":"https://api.github.com/repos/matthewhubble/s3test/pulls{/number}","milestones_url":"https://api.github.com/repos/matthewhubble/s3test/milestones{/number}","notifications_url":"https://api.github.com/repos/matthewhubble/s3test/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/matthewhubble/s3test/labels{/name}","releases_url":"https://api.github.com/repos/matthewhubble/s3test/releases{/id}","created_at":"2014-09-03T11:19:46Z","updated_at":"2014-09-06T21:21:58Z","pushed_at":"2014-09-11T19:29:33Z","git_url":"git://github.com/matthewhubble/s3test.git","ssh_url":"git@github.com:matthewhubble/s3test.git","clone_url":"https://github.com/matthewhubble/s3test.git","svn_url":"https://github.com/matthewhubble/s3test","homepage":"","size":171,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"michaeltandy:master","ref":"master","sha":"4497524f33a6831bd9779511752dd90f453f137f","user":{"login":"michaeltandy","id":2449410,"avatar_url":"https://avatars.githubusercontent.com/u/2449410?v=2","gravatar_id":"7167d2302007163407c44fdbb67e7358","url":"https://api.github.com/users/michaeltandy","html_url":"https://github.com/michaeltandy","followers_url":"https://api.github.com/users/michaeltandy/followers","following_url":"https://api.github.com/users/michaeltandy/following{/other_user}","gists_url":"https://api.github.com/users/michaeltandy/gists{/gist_id}","starred_url":"https://api.github.com/users/michaeltandy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/michaeltandy/subscriptions","organizations_url":"https://api.github.com/users/michaeltandy/orgs","repos_url":"https://api.github.com/users/michaeltandy/repos","events_url":"https://api.github.com/users/michaeltandy/events{/privacy}","received_events_url":"https://api.github.com/users/michaeltandy/received_events","type":"User","site_admin":false},"repo":{"id":22932893,"name":"s3test","full_name":"michaeltandy/s3test","owner":{"login":"michaeltandy","id":2449410,"avatar_url":"https://avatars.githubusercontent.com/u/2449410?v=2","gravatar_id":"7167d2302007163407c44fdbb67e7358","url":"https://api.github.com/users/michaeltandy","html_url":"https://github.com/michaeltandy","followers_url":"https://api.github.com/users/michaeltandy/followers","following_url":"https://api.github.com/users/michaeltandy/following{/other_user}","gists_url":"https://api.github.com/users/michaeltandy/gists{/gist_id}","starred_url":"https://api.github.com/users/michaeltandy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/michaeltandy/subscriptions","organizations_url":"https://api.github.com/users/michaeltandy/orgs","repos_url":"https://api.github.com/users/michaeltandy/repos","events_url":"https://api.github.com/users/michaeltandy/events{/privacy}","received_events_url":"https://api.github.com/users/michaeltandy/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/michaeltandy/s3test","description":"In memory S3 emulation, such as for unit testing.","fork":false,"url":"https://api.github.com/repos/michaeltandy/s3test","forks_url":"https://api.github.com/repos/michaeltandy/s3test/forks","keys_url":"https://api.github.com/repos/michaeltandy/s3test/keys{/key_id}","collaborators_url":"https://api.github.com/repos/michaeltandy/s3test/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/michaeltandy/s3test/teams","hooks_url":"https://api.github.com/repos/michaeltandy/s3test/hooks","issue_events_url":"https://api.github.com/repos/michaeltandy/s3test/issues/events{/number}","events_url":"https://api.github.com/repos/michaeltandy/s3test/events","assignees_url":"https://api.github.com/repos/michaeltandy/s3test/assignees{/user}","branches_url":"https://api.github.com/repos/michaeltandy/s3test/branches{/branch}","tags_url":"https://api.github.com/repos/michaeltandy/s3test/tags","blobs_url":"https://api.github.com/repos/michaeltandy/s3test/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/michaeltandy/s3test/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/michaeltandy/s3test/git/refs{/sha}","trees_url":"https://api.github.com/repos/michaeltandy/s3test/git/trees{/sha}","statuses_url":"https://api.github.com/repos/michaeltandy/s3test/statuses/{sha}","languages_url":"https://api.github.com/repos/michaeltandy/s3test/languages","stargazers_url":"https://api.github.com/repos/michaeltandy/s3test/stargazers","contributors_url":"https://api.github.com/repos/michaeltandy/s3test/contributors","subscribers_url":"https://api.github.com/repos/michaeltandy/s3test/subscribers","subscription_url":"https://api.github.com/repos/michaeltandy/s3test/subscription","commits_url":"https://api.github.com/repos/michaeltandy/s3test/commits{/sha}","git_commits_url":"https://api.github.com/repos/michaeltandy/s3test/git/commits{/sha}","comments_url":"https://api.github.com/repos/michaeltandy/s3test/comments{/number}","issue_comment_url":"https://api.github.com/repos/michaeltandy/s3test/issues/comments/{number}","contents_url":"https://api.github.com/repos/michaeltandy/s3test/contents/{+path}","compare_url":"https://api.github.com/repos/michaeltandy/s3test/compare/{base}...{head}","merges_url":"https://api.github.com/repos/michaeltandy/s3test/merges","archive_url":"https://api.github.com/repos/michaeltandy/s3test/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/michaeltandy/s3test/downloads","issues_url":"https://api.github.com/repos/michaeltandy/s3test/issues{/number}","pulls_url":"https://api.github.com/repos/michaeltandy/s3test/pulls{/number}","milestones_url":"https://api.github.com/repos/michaeltandy/s3test/milestones{/number}","notifications_url":"https://api.github.com/repos/michaeltandy/s3test/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/michaeltandy/s3test/labels{/name}","releases_url":"https://api.github.com/repos/michaeltandy/s3test/releases{/id}","created_at":"2014-08-13T22:09:10Z","updated_at":"2014-09-03T11:19:13Z","pushed_at":"2014-09-03T23:08:29Z","git_url":"git://github.com/michaeltandy/s3test.git","ssh_url":"git@github.com:michaeltandy/s3test.git","clone_url":"https://github.com/michaeltandy/s3test.git","svn_url":"https://github.com/michaeltandy/s3test","homepage":"","size":186,"stargazers_count":1,"watchers_count":1,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"forks_count":1,"mirror_url":null,"open_issues_count":1,"forks":1,"open_issues":1,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/michaeltandy/s3test/pulls/2"},"html":{"href":"https://github.com/michaeltandy/s3test/pull/2"},"issue":{"href":"https://api.github.com/repos/michaeltandy/s3test/issues/2"},"comments":{"href":"https://api.github.com/repos/michaeltandy/s3test/issues/2/comments"},"review_comments":{"href":"https://api.github.com/repos/michaeltandy/s3test/pulls/2/comments"},"review_comment":{"href":"https://api.github.com/repos/michaeltandy/s3test/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/michaeltandy/s3test/pulls/2/commits"},"statuses":{"href":"https://api.github.com/repos/michaeltandy/s3test/statuses/323e8796abd95f9d5f27bd9a3d3068a5bc7e3438"}}}}