{"action":"created","comment":{"url":"https://api.github.com/repos/palantir/http-remoting/pulls/comments/52416127","id":52416127,"diff_hunk":"@@ -0,0 +1,93 @@\n+/*\n+ * Copyright 2016 Palantir Technologies, Inc. All rights reserved.\n+ *\n+ * Licensed under the Apache License, Version 2.0 (the \"License\");\n+ * you may not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at\n+ *\n+ *     http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+\n+package feign;\n+\n+import static org.hamcrest.Matchers.is;\n+import static org.junit.Assert.assertEquals;\n+import static org.junit.Assert.assertThat;\n+import static org.mockito.Matchers.any;\n+import static org.mockito.Mockito.mock;\n+import static org.mockito.Mockito.when;\n+\n+import com.google.common.base.Charsets;\n+import com.google.common.base.Optional;\n+import com.google.common.collect.ImmutableMap;\n+import com.palantir.remoting.http.FeignClients;\n+import feign.codec.Decoder;\n+import io.dropwizard.Configuration;\n+import io.dropwizard.testing.junit.DropwizardAppRule;\n+import java.io.IOException;\n+import java.io.InputStream;\n+import java.lang.reflect.Type;\n+import java.util.Collection;\n+import javax.net.ssl.SSLSocketFactory;\n+import org.junit.Before;\n+import org.junit.ClassRule;\n+import org.junit.Test;\n+\n+public final class InputStreamDelegateDecoderTest {\n+    @ClassRule\n+    public static final DropwizardAppRule<Configuration> APP = new DropwizardAppRule<>(TestServer.class,\n+            \"src/test/resources/test-server.yml\");\n+\n+    private TestServer.TestService service;\n+    private Decoder delegate;\n+    private Decoder inputStreamDelegateDecoder;\n+\n+    @Before\n+    public void before() {\n+        delegate = mock(Decoder.class);\n+        inputStreamDelegateDecoder = new InputStreamDelegateDecoder(delegate);\n+\n+        String endpointUri = \"http://localhost:\" + APP.getLocalPort();\n+        service = FeignClients.standard().createProxy(Optional.<SSLSocketFactory>absent(), endpointUri,\n+                TestServer.TestService.class);\n+    }\n+\n+    @Test\n+    public void testDecodesAsInputStream() throws Exception {\n+        String data = \"data\";\n+\n+        Response response =\n+                Response.create(200, \"OK\", ImmutableMap.<String, Collection<String>>of(), data, Charsets.UTF_8);\n+\n+        InputStream decoded = (InputStream) inputStreamDelegateDecoder.decode(response, InputStream.class);\n+\n+        assertThat(new String(Util.toByteArray(decoded), Charsets.UTF_8), is(data));\n+    }\n+\n+    @Test\n+    public void testUsesDelegateWhenReturnTypeNotInputStream() throws Exception {\n+        String returned = \"string\";\n+\n+        when(delegate.decode((Response) any(), (Type) any())).thenReturn(returned);\n+        Response response =\n+                Response.create(200, \"OK\", ImmutableMap.<String, Collection<String>>of(), returned, Charsets.UTF_8);\n+        String decodedObject = (String) inputStreamDelegateDecoder.decode(response, String.class);\n+        assertEquals(returned, decodedObject);\n+    }\n+\n+    @Test\n+    public void testStandardClientsUseInputStreamDelegateDecoder() throws IOException {\n+        String data = \"bytes\";\n+        assertThat(Util.toByteArray(service.writeInputStream(data)), is(bytes(data)));\n+    }\n+","path":"http-clients/src/test/java/feign/InputStreamDelegateDecoderTest.java","position":89,"original_position":89,"commit_id":"326e07d46a1feaff3a61d0f854506e195d9eec4b","original_commit_id":"326e07d46a1feaff3a61d0f854506e195d9eec4b","user":{"login":"uschi2000","id":6528449,"avatar_url":"https://avatars.githubusercontent.com/u/6528449?v=3","gravatar_id":"","url":"https://api.github.com/users/uschi2000","html_url":"https://github.com/uschi2000","followers_url":"https://api.github.com/users/uschi2000/followers","following_url":"https://api.github.com/users/uschi2000/following{/other_user}","gists_url":"https://api.github.com/users/uschi2000/gists{/gist_id}","starred_url":"https://api.github.com/users/uschi2000/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uschi2000/subscriptions","organizations_url":"https://api.github.com/users/uschi2000/orgs","repos_url":"https://api.github.com/users/uschi2000/repos","events_url":"https://api.github.com/users/uschi2000/events{/privacy}","received_events_url":"https://api.github.com/users/uschi2000/received_events","type":"User","site_admin":false},"body":"symmetric to the encoder test: what happens if data is empty or null?","created_at":"2016-02-10T05:26:29Z","updated_at":"2016-02-10T05:26:29Z","html_url":"https://github.com/palantir/http-remoting/pull/41#discussion_r52416127","pull_request_url":"https://api.github.com/repos/palantir/http-remoting/pulls/41","_links":{"self":{"href":"https://api.github.com/repos/palantir/http-remoting/pulls/comments/52416127"},"html":{"href":"https://github.com/palantir/http-remoting/pull/41#discussion_r52416127"},"pull_request":{"href":"https://api.github.com/repos/palantir/http-remoting/pulls/41"}}},"pull_request":{"url":"https://api.github.com/repos/palantir/http-remoting/pulls/41","id":58792356,"html_url":"https://github.com/palantir/http-remoting/pull/41","diff_url":"https://github.com/palantir/http-remoting/pull/41.diff","patch_url":"https://github.com/palantir/http-remoting/pull/41.patch","issue_url":"https://api.github.com/repos/palantir/http-remoting/issues/41","number":41,"state":"closed","locked":false,"title":"Allow endpoints to return InputStreams","user":{"login":"j-baker","id":42533,"avatar_url":"https://avatars.githubusercontent.com/u/42533?v=3","gravatar_id":"","url":"https://api.github.com/users/j-baker","html_url":"https://github.com/j-baker","followers_url":"https://api.github.com/users/j-baker/followers","following_url":"https://api.github.com/users/j-baker/following{/other_user}","gists_url":"https://api.github.com/users/j-baker/gists{/gist_id}","starred_url":"https://api.github.com/users/j-baker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/j-baker/subscriptions","organizations_url":"https://api.github.com/users/j-baker/orgs","repos_url":"https://api.github.com/users/j-baker/repos","events_url":"https://api.github.com/users/j-baker/events{/privacy}","received_events_url":"https://api.github.com/users/j-baker/received_events","type":"User","site_admin":false},"body":"At present, Jackson attempts to decode application/octet-stream bodies,\r\neven though they are not JSON. Instead, decode application/octet-stream\r\nresponses with return type byte[] to a byte array, and\r\napplication/octet-stream requests with body type byte[] as a byte array\r\nalso.","created_at":"2016-02-09T18:58:59Z","updated_at":"2016-02-10T05:26:29Z","closed_at":"2016-02-10T02:34:00Z","merged_at":"2016-02-10T02:34:00Z","merge_commit_sha":"5768183443b2fec1f1122d0e74a5cea1d597139c","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/palantir/http-remoting/pulls/41/commits","review_comments_url":"https://api.github.com/repos/palantir/http-remoting/pulls/41/comments","review_comment_url":"https://api.github.com/repos/palantir/http-remoting/pulls/comments{/number}","comments_url":"https://api.github.com/repos/palantir/http-remoting/issues/41/comments","statuses_url":"https://api.github.com/repos/palantir/http-remoting/statuses/326e07d46a1feaff3a61d0f854506e195d9eec4b","head":{"label":"j-baker:handle_octet_stream","ref":"handle_octet_stream","sha":"326e07d46a1feaff3a61d0f854506e195d9eec4b","user":{"login":"j-baker","id":42533,"avatar_url":"https://avatars.githubusercontent.com/u/42533?v=3","gravatar_id":"","url":"https://api.github.com/users/j-baker","html_url":"https://github.com/j-baker","followers_url":"https://api.github.com/users/j-baker/followers","following_url":"https://api.github.com/users/j-baker/following{/other_user}","gists_url":"https://api.github.com/users/j-baker/gists{/gist_id}","starred_url":"https://api.github.com/users/j-baker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/j-baker/subscriptions","organizations_url":"https://api.github.com/users/j-baker/orgs","repos_url":"https://api.github.com/users/j-baker/repos","events_url":"https://api.github.com/users/j-baker/events{/privacy}","received_events_url":"https://api.github.com/users/j-baker/received_events","type":"User","site_admin":false},"repo":{"id":51390778,"name":"http-remoting","full_name":"j-baker/http-remoting","owner":{"login":"j-baker","id":42533,"avatar_url":"https://avatars.githubusercontent.com/u/42533?v=3","gravatar_id":"","url":"https://api.github.com/users/j-baker","html_url":"https://github.com/j-baker","followers_url":"https://api.github.com/users/j-baker/followers","following_url":"https://api.github.com/users/j-baker/following{/other_user}","gists_url":"https://api.github.com/users/j-baker/gists{/gist_id}","starred_url":"https://api.github.com/users/j-baker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/j-baker/subscriptions","organizations_url":"https://api.github.com/users/j-baker/orgs","repos_url":"https://api.github.com/users/j-baker/repos","events_url":"https://api.github.com/users/j-baker/events{/privacy}","received_events_url":"https://api.github.com/users/j-baker/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/j-baker/http-remoting","description":"a collection of useful utilities for use with HTTP remoting setups that use Feign as a client and Jersey as a server","fork":true,"url":"https://api.github.com/repos/j-baker/http-remoting","forks_url":"https://api.github.com/repos/j-baker/http-remoting/forks","keys_url":"https://api.github.com/repos/j-baker/http-remoting/keys{/key_id}","collaborators_url":"https://api.github.com/repos/j-baker/http-remoting/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/j-baker/http-remoting/teams","hooks_url":"https://api.github.com/repos/j-baker/http-remoting/hooks","issue_events_url":"https://api.github.com/repos/j-baker/http-remoting/issues/events{/number}","events_url":"https://api.github.com/repos/j-baker/http-remoting/events","assignees_url":"https://api.github.com/repos/j-baker/http-remoting/assignees{/user}","branches_url":"https://api.github.com/repos/j-baker/http-remoting/branches{/branch}","tags_url":"https://api.github.com/repos/j-baker/http-remoting/tags","blobs_url":"https://api.github.com/repos/j-baker/http-remoting/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/j-baker/http-remoting/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/j-baker/http-remoting/git/refs{/sha}","trees_url":"https://api.github.com/repos/j-baker/http-remoting/git/trees{/sha}","statuses_url":"https://api.github.com/repos/j-baker/http-remoting/statuses/{sha}","languages_url":"https://api.github.com/repos/j-baker/http-remoting/languages","stargazers_url":"https://api.github.com/repos/j-baker/http-remoting/stargazers","contributors_url":"https://api.github.com/repos/j-baker/http-remoting/contributors","subscribers_url":"https://api.github.com/repos/j-baker/http-remoting/subscribers","subscription_url":"https://api.github.com/repos/j-baker/http-remoting/subscription","commits_url":"https://api.github.com/repos/j-baker/http-remoting/commits{/sha}","git_commits_url":"https://api.github.com/repos/j-baker/http-remoting/git/commits{/sha}","comments_url":"https://api.github.com/repos/j-baker/http-remoting/comments{/number}","issue_comment_url":"https://api.github.com/repos/j-baker/http-remoting/issues/comments{/number}","contents_url":"https://api.github.com/repos/j-baker/http-remoting/contents/{+path}","compare_url":"https://api.github.com/repos/j-baker/http-remoting/compare/{base}...{head}","merges_url":"https://api.github.com/repos/j-baker/http-remoting/merges","archive_url":"https://api.github.com/repos/j-baker/http-remoting/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/j-baker/http-remoting/downloads","issues_url":"https://api.github.com/repos/j-baker/http-remoting/issues{/number}","pulls_url":"https://api.github.com/repos/j-baker/http-remoting/pulls{/number}","milestones_url":"https://api.github.com/repos/j-baker/http-remoting/milestones{/number}","notifications_url":"https://api.github.com/repos/j-baker/http-remoting/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/j-baker/http-remoting/labels{/name}","releases_url":"https://api.github.com/repos/j-baker/http-remoting/releases{/id}","deployments_url":"https://api.github.com/repos/j-baker/http-remoting/deployments","created_at":"2016-02-09T18:57:17Z","updated_at":"2016-02-09T18:57:18Z","pushed_at":"2016-02-10T00:45:54Z","git_url":"git://github.com/j-baker/http-remoting.git","ssh_url":"git@github.com:j-baker/http-remoting.git","clone_url":"https://github.com/j-baker/http-remoting.git","svn_url":"https://github.com/j-baker/http-remoting","homepage":"","size":161,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"develop"}},"base":{"label":"palantir:develop","ref":"develop","sha":"c883b42da3a8ae20bb7f3ade227ff88533656e7a","user":{"login":"palantir","id":303157,"avatar_url":"https://avatars.githubusercontent.com/u/303157?v=3","gravatar_id":"","url":"https://api.github.com/users/palantir","html_url":"https://github.com/palantir","followers_url":"https://api.github.com/users/palantir/followers","following_url":"https://api.github.com/users/palantir/following{/other_user}","gists_url":"https://api.github.com/users/palantir/gists{/gist_id}","starred_url":"https://api.github.com/users/palantir/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/palantir/subscriptions","organizations_url":"https://api.github.com/users/palantir/orgs","repos_url":"https://api.github.com/users/palantir/repos","events_url":"https://api.github.com/users/palantir/events{/privacy}","received_events_url":"https://api.github.com/users/palantir/received_events","type":"Organization","site_admin":false},"repo":{"id":43088077,"name":"http-remoting","full_name":"palantir/http-remoting","owner":{"login":"palantir","id":303157,"avatar_url":"https://avatars.githubusercontent.com/u/303157?v=3","gravatar_id":"","url":"https://api.github.com/users/palantir","html_url":"https://github.com/palantir","followers_url":"https://api.github.com/users/palantir/followers","following_url":"https://api.github.com/users/palantir/following{/other_user}","gists_url":"https://api.github.com/users/palantir/gists{/gist_id}","starred_url":"https://api.github.com/users/palantir/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/palantir/subscriptions","organizations_url":"https://api.github.com/users/palantir/orgs","repos_url":"https://api.github.com/users/palantir/repos","events_url":"https://api.github.com/users/palantir/events{/privacy}","received_events_url":"https://api.github.com/users/palantir/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/palantir/http-remoting","description":"a collection of useful utilities for use with HTTP remoting setups that use Feign as a client and Jersey as a server","fork":false,"url":"https://api.github.com/repos/palantir/http-remoting","forks_url":"https://api.github.com/repos/palantir/http-remoting/forks","keys_url":"https://api.github.com/repos/palantir/http-remoting/keys{/key_id}","collaborators_url":"https://api.github.com/repos/palantir/http-remoting/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/palantir/http-remoting/teams","hooks_url":"https://api.github.com/repos/palantir/http-remoting/hooks","issue_events_url":"https://api.github.com/repos/palantir/http-remoting/issues/events{/number}","events_url":"https://api.github.com/repos/palantir/http-remoting/events","assignees_url":"https://api.github.com/repos/palantir/http-remoting/assignees{/user}","branches_url":"https://api.github.com/repos/palantir/http-remoting/branches{/branch}","tags_url":"https://api.github.com/repos/palantir/http-remoting/tags","blobs_url":"https://api.github.com/repos/palantir/http-remoting/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/palantir/http-remoting/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/palantir/http-remoting/git/refs{/sha}","trees_url":"https://api.github.com/repos/palantir/http-remoting/git/trees{/sha}","statuses_url":"https://api.github.com/repos/palantir/http-remoting/statuses/{sha}","languages_url":"https://api.github.com/repos/palantir/http-remoting/languages","stargazers_url":"https://api.github.com/repos/palantir/http-remoting/stargazers","contributors_url":"https://api.github.com/repos/palantir/http-remoting/contributors","subscribers_url":"https://api.github.com/repos/palantir/http-remoting/subscribers","subscription_url":"https://api.github.com/repos/palantir/http-remoting/subscription","commits_url":"https://api.github.com/repos/palantir/http-remoting/commits{/sha}","git_commits_url":"https://api.github.com/repos/palantir/http-remoting/git/commits{/sha}","comments_url":"https://api.github.com/repos/palantir/http-remoting/comments{/number}","issue_comment_url":"https://api.github.com/repos/palantir/http-remoting/issues/comments{/number}","contents_url":"https://api.github.com/repos/palantir/http-remoting/contents/{+path}","compare_url":"https://api.github.com/repos/palantir/http-remoting/compare/{base}...{head}","merges_url":"https://api.github.com/repos/palantir/http-remoting/merges","archive_url":"https://api.github.com/repos/palantir/http-remoting/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/palantir/http-remoting/downloads","issues_url":"https://api.github.com/repos/palantir/http-remoting/issues{/number}","pulls_url":"https://api.github.com/repos/palantir/http-remoting/pulls{/number}","milestones_url":"https://api.github.com/repos/palantir/http-remoting/milestones{/number}","notifications_url":"https://api.github.com/repos/palantir/http-remoting/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/palantir/http-remoting/labels{/name}","releases_url":"https://api.github.com/repos/palantir/http-remoting/releases{/id}","deployments_url":"https://api.github.com/repos/palantir/http-remoting/deployments","created_at":"2015-09-24T19:24:22Z","updated_at":"2016-02-07T22:25:28Z","pushed_at":"2016-02-10T03:44:42Z","git_url":"git://github.com/palantir/http-remoting.git","ssh_url":"git@github.com:palantir/http-remoting.git","clone_url":"https://github.com/palantir/http-remoting.git","svn_url":"https://github.com/palantir/http-remoting","homepage":"","size":202,"stargazers_count":3,"watchers_count":3,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":9,"mirror_url":null,"open_issues_count":5,"forks":9,"open_issues":5,"watchers":3,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/palantir/http-remoting/pulls/41"},"html":{"href":"https://github.com/palantir/http-remoting/pull/41"},"issue":{"href":"https://api.github.com/repos/palantir/http-remoting/issues/41"},"comments":{"href":"https://api.github.com/repos/palantir/http-remoting/issues/41/comments"},"review_comments":{"href":"https://api.github.com/repos/palantir/http-remoting/pulls/41/comments"},"review_comment":{"href":"https://api.github.com/repos/palantir/http-remoting/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/palantir/http-remoting/pulls/41/commits"},"statuses":{"href":"https://api.github.com/repos/palantir/http-remoting/statuses/326e07d46a1feaff3a61d0f854506e195d9eec4b"}}}}