{"action":"created","comment":{"url":"https://api.github.com/repos/Netflix/eureka/pulls/comments/31590135","id":31590135,"diff_hunk":"@@ -0,0 +1,153 @@\n+package com.netflix.discovery.shared;\n+\n+import javax.ws.rs.core.MediaType;\n+import javax.ws.rs.core.Response.Status;\n+\n+import com.netflix.appinfo.InstanceInfo;\n+import com.netflix.appinfo.InstanceInfo.InstanceStatus;\n+import com.sun.jersey.api.client.ClientResponse;\n+import com.sun.jersey.api.client.WebResource;\n+import com.sun.jersey.client.apache4.ApacheHttpClient4;\n+\n+/**\n+ * @author Tomasz Bak\n+ */\n+public abstract class JerseyEurekaHttpClient implements EurekaHttpClient {\n+\n+    protected final String serviceUrl;\n+\n+    protected JerseyEurekaHttpClient(String serviceUrl) {\n+        this.serviceUrl = serviceUrl;\n+    }\n+\n+    protected abstract ApacheHttpClient4 getJerseyApacheClient();\n+\n+    @Override\n+    public HttpResponse<Void> register(InstanceInfo info) {\n+        String urlPath = \"apps/\" + info.getAppName();\n+        ClientResponse response = null;\n+        try {\n+            WebResource webResource = getJerseyApacheClient().resource(serviceUrl).path(urlPath);\n+            addExtraHeaders(webResource);\n+            response = webResource\n+                    .header(\"Accept-Encoding\", \"gzip\")\n+                    .type(MediaType.APPLICATION_JSON_TYPE)\n+                    .accept(MediaType.APPLICATION_JSON)\n+                    .post(ClientResponse.class, info);\n+            return HttpResponse.responseWith(response.getStatus());\n+        } finally {\n+            if (response != null) {\n+                response.close();\n+            }\n+        }\n+    }\n+\n+    @Override\n+    public HttpResponse<Void> cancel(String appName, String id) {\n+        ClientResponse response = null;\n+        try {\n+            String urlPath = \"apps/\" + appName + \"/\" + id;\n+            WebResource webResource = getJerseyApacheClient().resource(serviceUrl).path(urlPath);\n+            addExtraHeaders(webResource);\n+            response = webResource.delete(ClientResponse.class);\n+            return HttpResponse.responseWith(response.getStatus());\n+        } finally {\n+            if (response != null) {\n+                response.close();\n+            }\n+        }\n+    }\n+\n+    @Override\n+    public HttpResponse<InstanceInfo> sendHeartBeat(String appName, String id, InstanceInfo info, InstanceStatus overriddenStatus) {\n+        ClientResponse response = null;\n+        try {\n+            String urlPath = \"apps/\" + appName + \"/\" + id;\n+            WebResource webResource = getJerseyApacheClient().resource(serviceUrl)\n+                    .path(urlPath)\n+                    .queryParam(\"status\", info.getStatus().toString())\n+                    .queryParam(\"lastDirtyTimestamp\", info.getLastDirtyTimestamp().toString());\n+            if (overriddenStatus != null) {\n+                webResource = webResource.queryParam(\"overriddenstatus\", overriddenStatus.name());\n+            }\n+            addExtraHeaders(webResource);\n+            response = webResource.accept(MediaType.APPLICATION_JSON_TYPE).put(ClientResponse.class);\n+            InstanceInfo infoFromPeer = null;","path":"eureka-client/src/main/java/com/netflix/discovery/shared/JerseyEurekaHttpClient.java","position":75,"original_position":75,"commit_id":"4e10b9a6bc26185fc4ee3da664a3b1e0690dbd6b","original_commit_id":"4e10b9a6bc26185fc4ee3da664a3b1e0690dbd6b","user":{"login":"tbak","id":728768,"avatar_url":"https://avatars.githubusercontent.com/u/728768?v=3","gravatar_id":"","url":"https://api.github.com/users/tbak","html_url":"https://github.com/tbak","followers_url":"https://api.github.com/users/tbak/followers","following_url":"https://api.github.com/users/tbak/following{/other_user}","gists_url":"https://api.github.com/users/tbak/gists{/gist_id}","starred_url":"https://api.github.com/users/tbak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tbak/subscriptions","organizations_url":"https://api.github.com/users/tbak/orgs","repos_url":"https://api.github.com/users/tbak/repos","events_url":"https://api.github.com/users/tbak/events{/privacy}","received_events_url":"https://api.github.com/users/tbak/received_events","type":"User","site_admin":false},"body":"Good point. We need to override this implementation in replicating client.\n\nOn Tue, Jun 2, 2015 at 5:42 PM, qiangdavidliu <notifications@github.com>\nwrote:\n\n> In\n> eureka-client/src/main/java/com/netflix/discovery/shared/JerseyEurekaHttpClient.java\n> <https://github.com/Netflix/eureka/pull/529#discussion_r31585722>:\n>\n> > +\n> > +    @Override\n> > +    public HttpResponse<InstanceInfo> sendHeartBeat(String appName, String id, InstanceInfo info, InstanceStatus overriddenStatus) {\n> > +        ClientResponse response = null;\n> > +        try {\n> > +            String urlPath = \"apps/\" + appName + \"/\" + id;\n> > +            WebResource webResource = getJerseyApacheClient().resource(serviceUrl)\n> > +                    .path(urlPath)\n> > +                    .queryParam(\"status\", info.getStatus().toString())\n> > +                    .queryParam(\"lastDirtyTimestamp\", info.getLastDirtyTimestamp().toString());\n> > +            if (overriddenStatus != null) {\n> > +                webResource = webResource.queryParam(\"overriddenstatus\", overriddenStatus.name());\n> > +            }\n> > +            addExtraHeaders(webResource);\n> > +            response = webResource.accept(MediaType.APPLICATION_JSON_TYPE).put(ClientResponse.class);\n> > +            InstanceInfo infoFromPeer = null;\n>\n> Can we move these peer specific code to a server implementation of this\n> class? If we can break these out, it would be nice to refactor\n> DiscoveryClient with this class.\n>\n> —\n> Reply to this email directly or view it on GitHub\n> <https://github.com/Netflix/eureka/pull/529/files#r31585722>.\n>\n","created_at":"2015-06-03T02:39:59Z","updated_at":"2015-06-03T02:39:59Z","html_url":"https://github.com/Netflix/eureka/pull/529#discussion_r31590135","pull_request_url":"https://api.github.com/repos/Netflix/eureka/pulls/529","_links":{"self":{"href":"https://api.github.com/repos/Netflix/eureka/pulls/comments/31590135"},"html":{"href":"https://github.com/Netflix/eureka/pull/529#discussion_r31590135"},"pull_request":{"href":"https://api.github.com/repos/Netflix/eureka/pulls/529"}}},"pull_request":{"url":"https://api.github.com/repos/Netflix/eureka/pulls/529","id":36577310,"html_url":"https://github.com/Netflix/eureka/pull/529","diff_url":"https://github.com/Netflix/eureka/pull/529.diff","patch_url":"https://github.com/Netflix/eureka/pull/529.patch","issue_url":"https://api.github.com/repos/Netflix/eureka/issues/529","number":529,"state":"open","locked":false,"title":"1.x batched replication refactoring","user":{"login":"tbak","id":728768,"avatar_url":"https://avatars.githubusercontent.com/u/728768?v=3","gravatar_id":"","url":"https://api.github.com/users/tbak","html_url":"https://github.com/tbak","followers_url":"https://api.github.com/users/tbak/followers","following_url":"https://api.github.com/users/tbak/following{/other_user}","gists_url":"https://api.github.com/users/tbak/gists{/gist_id}","starred_url":"https://api.github.com/users/tbak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tbak/subscriptions","organizations_url":"https://api.github.com/users/tbak/orgs","repos_url":"https://api.github.com/users/tbak/repos","events_url":"https://api.github.com/users/tbak/events{/privacy}","received_events_url":"https://api.github.com/users/tbak/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-05-31T05:31:47Z","updated_at":"2015-06-03T02:39:59Z","closed_at":null,"merged_at":null,"merge_commit_sha":"308edc47f960e06b45a44c663d53875bb5193138","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Netflix/eureka/pulls/529/commits","review_comments_url":"https://api.github.com/repos/Netflix/eureka/pulls/529/comments","review_comment_url":"https://api.github.com/repos/Netflix/eureka/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Netflix/eureka/issues/529/comments","statuses_url":"https://api.github.com/repos/Netflix/eureka/statuses/4e10b9a6bc26185fc4ee3da664a3b1e0690dbd6b","head":{"label":"tbak:features/replication_batching","ref":"features/replication_batching","sha":"4e10b9a6bc26185fc4ee3da664a3b1e0690dbd6b","user":{"login":"tbak","id":728768,"avatar_url":"https://avatars.githubusercontent.com/u/728768?v=3","gravatar_id":"","url":"https://api.github.com/users/tbak","html_url":"https://github.com/tbak","followers_url":"https://api.github.com/users/tbak/followers","following_url":"https://api.github.com/users/tbak/following{/other_user}","gists_url":"https://api.github.com/users/tbak/gists{/gist_id}","starred_url":"https://api.github.com/users/tbak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tbak/subscriptions","organizations_url":"https://api.github.com/users/tbak/orgs","repos_url":"https://api.github.com/users/tbak/repos","events_url":"https://api.github.com/users/tbak/events{/privacy}","received_events_url":"https://api.github.com/users/tbak/received_events","type":"User","site_admin":false},"repo":{"id":21827017,"name":"eureka","full_name":"tbak/eureka","owner":{"login":"tbak","id":728768,"avatar_url":"https://avatars.githubusercontent.com/u/728768?v=3","gravatar_id":"","url":"https://api.github.com/users/tbak","html_url":"https://github.com/tbak","followers_url":"https://api.github.com/users/tbak/followers","following_url":"https://api.github.com/users/tbak/following{/other_user}","gists_url":"https://api.github.com/users/tbak/gists{/gist_id}","starred_url":"https://api.github.com/users/tbak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tbak/subscriptions","organizations_url":"https://api.github.com/users/tbak/orgs","repos_url":"https://api.github.com/users/tbak/repos","events_url":"https://api.github.com/users/tbak/events{/privacy}","received_events_url":"https://api.github.com/users/tbak/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/tbak/eureka","description":"AWS Service registry for resilient mid-tier load balancing and failover.","fork":true,"url":"https://api.github.com/repos/tbak/eureka","forks_url":"https://api.github.com/repos/tbak/eureka/forks","keys_url":"https://api.github.com/repos/tbak/eureka/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tbak/eureka/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tbak/eureka/teams","hooks_url":"https://api.github.com/repos/tbak/eureka/hooks","issue_events_url":"https://api.github.com/repos/tbak/eureka/issues/events{/number}","events_url":"https://api.github.com/repos/tbak/eureka/events","assignees_url":"https://api.github.com/repos/tbak/eureka/assignees{/user}","branches_url":"https://api.github.com/repos/tbak/eureka/branches{/branch}","tags_url":"https://api.github.com/repos/tbak/eureka/tags","blobs_url":"https://api.github.com/repos/tbak/eureka/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tbak/eureka/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tbak/eureka/git/refs{/sha}","trees_url":"https://api.github.com/repos/tbak/eureka/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tbak/eureka/statuses/{sha}","languages_url":"https://api.github.com/repos/tbak/eureka/languages","stargazers_url":"https://api.github.com/repos/tbak/eureka/stargazers","contributors_url":"https://api.github.com/repos/tbak/eureka/contributors","subscribers_url":"https://api.github.com/repos/tbak/eureka/subscribers","subscription_url":"https://api.github.com/repos/tbak/eureka/subscription","commits_url":"https://api.github.com/repos/tbak/eureka/commits{/sha}","git_commits_url":"https://api.github.com/repos/tbak/eureka/git/commits{/sha}","comments_url":"https://api.github.com/repos/tbak/eureka/comments{/number}","issue_comment_url":"https://api.github.com/repos/tbak/eureka/issues/comments{/number}","contents_url":"https://api.github.com/repos/tbak/eureka/contents/{+path}","compare_url":"https://api.github.com/repos/tbak/eureka/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tbak/eureka/merges","archive_url":"https://api.github.com/repos/tbak/eureka/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tbak/eureka/downloads","issues_url":"https://api.github.com/repos/tbak/eureka/issues{/number}","pulls_url":"https://api.github.com/repos/tbak/eureka/pulls{/number}","milestones_url":"https://api.github.com/repos/tbak/eureka/milestones{/number}","notifications_url":"https://api.github.com/repos/tbak/eureka/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tbak/eureka/labels{/name}","releases_url":"https://api.github.com/repos/tbak/eureka/releases{/id}","created_at":"2014-07-14T16:37:46Z","updated_at":"2015-03-24T21:12:35Z","pushed_at":"2015-06-02T04:51:12Z","git_url":"git://github.com/tbak/eureka.git","ssh_url":"git@github.com:tbak/eureka.git","clone_url":"https://github.com/tbak/eureka.git","svn_url":"https://github.com/tbak/eureka","homepage":"","size":9843,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"Netflix:master","ref":"master","sha":"00a016c8446bad8323c3a7f9a4c5a536623e79b8","user":{"login":"Netflix","id":913567,"avatar_url":"https://avatars.githubusercontent.com/u/913567?v=3","gravatar_id":"","url":"https://api.github.com/users/Netflix","html_url":"https://github.com/Netflix","followers_url":"https://api.github.com/users/Netflix/followers","following_url":"https://api.github.com/users/Netflix/following{/other_user}","gists_url":"https://api.github.com/users/Netflix/gists{/gist_id}","starred_url":"https://api.github.com/users/Netflix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Netflix/subscriptions","organizations_url":"https://api.github.com/users/Netflix/orgs","repos_url":"https://api.github.com/users/Netflix/repos","events_url":"https://api.github.com/users/Netflix/events{/privacy}","received_events_url":"https://api.github.com/users/Netflix/received_events","type":"Organization","site_admin":false},"repo":{"id":5198041,"name":"eureka","full_name":"Netflix/eureka","owner":{"login":"Netflix","id":913567,"avatar_url":"https://avatars.githubusercontent.com/u/913567?v=3","gravatar_id":"","url":"https://api.github.com/users/Netflix","html_url":"https://github.com/Netflix","followers_url":"https://api.github.com/users/Netflix/followers","following_url":"https://api.github.com/users/Netflix/following{/other_user}","gists_url":"https://api.github.com/users/Netflix/gists{/gist_id}","starred_url":"https://api.github.com/users/Netflix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Netflix/subscriptions","organizations_url":"https://api.github.com/users/Netflix/orgs","repos_url":"https://api.github.com/users/Netflix/repos","events_url":"https://api.github.com/users/Netflix/events{/privacy}","received_events_url":"https://api.github.com/users/Netflix/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Netflix/eureka","description":"AWS Service registry for resilient mid-tier load balancing and failover.","fork":false,"url":"https://api.github.com/repos/Netflix/eureka","forks_url":"https://api.github.com/repos/Netflix/eureka/forks","keys_url":"https://api.github.com/repos/Netflix/eureka/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Netflix/eureka/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Netflix/eureka/teams","hooks_url":"https://api.github.com/repos/Netflix/eureka/hooks","issue_events_url":"https://api.github.com/repos/Netflix/eureka/issues/events{/number}","events_url":"https://api.github.com/repos/Netflix/eureka/events","assignees_url":"https://api.github.com/repos/Netflix/eureka/assignees{/user}","branches_url":"https://api.github.com/repos/Netflix/eureka/branches{/branch}","tags_url":"https://api.github.com/repos/Netflix/eureka/tags","blobs_url":"https://api.github.com/repos/Netflix/eureka/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Netflix/eureka/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Netflix/eureka/git/refs{/sha}","trees_url":"https://api.github.com/repos/Netflix/eureka/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Netflix/eureka/statuses/{sha}","languages_url":"https://api.github.com/repos/Netflix/eureka/languages","stargazers_url":"https://api.github.com/repos/Netflix/eureka/stargazers","contributors_url":"https://api.github.com/repos/Netflix/eureka/contributors","subscribers_url":"https://api.github.com/repos/Netflix/eureka/subscribers","subscription_url":"https://api.github.com/repos/Netflix/eureka/subscription","commits_url":"https://api.github.com/repos/Netflix/eureka/commits{/sha}","git_commits_url":"https://api.github.com/repos/Netflix/eureka/git/commits{/sha}","comments_url":"https://api.github.com/repos/Netflix/eureka/comments{/number}","issue_comment_url":"https://api.github.com/repos/Netflix/eureka/issues/comments{/number}","contents_url":"https://api.github.com/repos/Netflix/eureka/contents/{+path}","compare_url":"https://api.github.com/repos/Netflix/eureka/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Netflix/eureka/merges","archive_url":"https://api.github.com/repos/Netflix/eureka/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Netflix/eureka/downloads","issues_url":"https://api.github.com/repos/Netflix/eureka/issues{/number}","pulls_url":"https://api.github.com/repos/Netflix/eureka/pulls{/number}","milestones_url":"https://api.github.com/repos/Netflix/eureka/milestones{/number}","notifications_url":"https://api.github.com/repos/Netflix/eureka/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Netflix/eureka/labels{/name}","releases_url":"https://api.github.com/repos/Netflix/eureka/releases{/id}","created_at":"2012-07-26T22:23:07Z","updated_at":"2015-06-02T21:53:52Z","pushed_at":"2015-06-02T23:59:14Z","git_url":"git://github.com/Netflix/eureka.git","ssh_url":"git@github.com:Netflix/eureka.git","clone_url":"https://github.com/Netflix/eureka.git","svn_url":"https://github.com/Netflix/eureka","homepage":"","size":15445,"stargazers_count":1000,"watchers_count":1000,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":224,"mirror_url":null,"open_issues_count":27,"forks":224,"open_issues":27,"watchers":1000,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Netflix/eureka/pulls/529"},"html":{"href":"https://github.com/Netflix/eureka/pull/529"},"issue":{"href":"https://api.github.com/repos/Netflix/eureka/issues/529"},"comments":{"href":"https://api.github.com/repos/Netflix/eureka/issues/529/comments"},"review_comments":{"href":"https://api.github.com/repos/Netflix/eureka/pulls/529/comments"},"review_comment":{"href":"https://api.github.com/repos/Netflix/eureka/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Netflix/eureka/pulls/529/commits"},"statuses":{"href":"https://api.github.com/repos/Netflix/eureka/statuses/4e10b9a6bc26185fc4ee3da664a3b1e0690dbd6b"}}}}