{"action":"created","comment":{"url":"https://api.github.com/repos/jenkinsci/remoting/pulls/comments/23530799","id":23530799,"diff_hunk":"@@ -234,54 +229,41 @@ public void run() {\n                     return;\n                 }\n \n-                Socket s = connect(port);\n-\n                 events.status(\"Handshaking\");\n-\n-                DataOutputStream dos = new DataOutputStream(s.getOutputStream());\n-                BufferedInputStream in = new BufferedInputStream(s.getInputStream());\n-\n-                dos.writeUTF(\"Protocol:JNLP2-connect\");\n-                Properties props = new Properties();\n-                props.put(\"Secret-Key\", secretKey);\n-                props.put(\"Node-Name\", slaveName);\n-                if (cookie!=null)\n-                    props.put(\"Cookie\", cookie);\n-                ByteArrayOutputStream o = new ByteArrayOutputStream();\n-                props.store(o, null);\n-                dos.writeUTF(o.toString(\"UTF-8\"));\n-\n-                String greeting = readLine(in);\n-                if (greeting.startsWith(\"Unknown protocol\")) {\n-                    LOGGER.info(\"The server didn't understand the v2 handshake. Falling back to v1 handshake\");\n-                    s.close();\n-                    s = connect(port);\n-                    in = new BufferedInputStream(s.getInputStream());\n-                    dos = new DataOutputStream(s.getOutputStream());\n-\n-                    dos.writeUTF(\"Protocol:JNLP-connect\");\n-                    dos.writeUTF(secretKey);\n-                    dos.writeUTF(slaveName);\n-\n-                    greeting = readLine(in); // why, oh why didn't I use DataOutputStream when writing to the network?\n-                    if (!greeting.equals(GREETING_SUCCESS)) {\n-                        onConnectionRejected(greeting);\n-                        continue;\n-                    }\n-                } else {\n-                    if (greeting.equals(GREETING_SUCCESS)) {\n-                        Properties responses = readResponseHeaders(in);\n-                        cookie = responses.getProperty(\"Cookie\");\n-                    } else {\n-                        onConnectionRejected(greeting);\n-                        continue;\n+                Socket jnlpSocket = connect(port);\n+                DataOutputStream outputStream = new DataOutputStream(jnlpSocket.getOutputStream());\n+                BufferedInputStream inputStream = new BufferedInputStream(jnlpSocket.getInputStream());\n+                String response = \"\";\n+\n+                // Try available protocols.\n+                for (JnlpProtocol protocol : protocols) {\n+                    events.status(\"Trying protocol: \" + protocol.getName());\n+                    response = protocol.performHandshake(outputStream, inputStream);\n+\n+                    // On success do not try other protocols.\n+                    if (response.equals(GREETING_SUCCESS)) {\n+                        break;\n                     }\n+\n+                    // On failure log the response and form a new connection.\n+                    events.status(\"Server didn't understand the protocol: \" + response);\n+                    jnlpSocket.close();\n+                    Thread.sleep(500);","path":"src/main/java/hudson/remoting/Engine.java","position":131,"original_position":131,"commit_id":"9a427e0614c7fea4a7d77cd7a4ded90ff2023c9b","original_commit_id":"9a427e0614c7fea4a7d77cd7a4ded90ff2023c9b","user":{"login":"jglick","id":154109,"avatar_url":"https://avatars.githubusercontent.com/u/154109?v=3","gravatar_id":"","url":"https://api.github.com/users/jglick","html_url":"https://github.com/jglick","followers_url":"https://api.github.com/users/jglick/followers","following_url":"https://api.github.com/users/jglick/following{/other_user}","gists_url":"https://api.github.com/users/jglick/gists{/gist_id}","starred_url":"https://api.github.com/users/jglick/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jglick/subscriptions","organizations_url":"https://api.github.com/users/jglick/orgs","repos_url":"https://api.github.com/users/jglick/repos","events_url":"https://api.github.com/users/jglick/events{/privacy}","received_events_url":"https://api.github.com/users/jglick/received_events","type":"User","site_admin":false},"body":"Why? This does not seem to have been in the original code.","created_at":"2015-01-26T13:49:49Z","updated_at":"2015-01-26T13:49:49Z","html_url":"https://github.com/jenkinsci/remoting/pull/28#discussion_r23530799","pull_request_url":"https://api.github.com/repos/jenkinsci/remoting/pulls/28","_links":{"self":{"href":"https://api.github.com/repos/jenkinsci/remoting/pulls/comments/23530799"},"html":{"href":"https://github.com/jenkinsci/remoting/pull/28#discussion_r23530799"},"pull_request":{"href":"https://api.github.com/repos/jenkinsci/remoting/pulls/28"}}},"pull_request":{"url":"https://api.github.com/repos/jenkinsci/remoting/pulls/28","id":27977506,"html_url":"https://github.com/jenkinsci/remoting/pull/28","diff_url":"https://github.com/jenkinsci/remoting/pull/28.diff","patch_url":"https://github.com/jenkinsci/remoting/pull/28.patch","issue_url":"https://api.github.com/repos/jenkinsci/remoting/issues/28","number":28,"state":"open","locked":false,"title":"[JENKINS-26580] Refactor slave JNLP engine to make it easier to add more...","user":{"login":"akshayabd","id":120980,"avatar_url":"https://avatars.githubusercontent.com/u/120980?v=3","gravatar_id":"","url":"https://api.github.com/users/akshayabd","html_url":"https://github.com/akshayabd","followers_url":"https://api.github.com/users/akshayabd/followers","following_url":"https://api.github.com/users/akshayabd/following{/other_user}","gists_url":"https://api.github.com/users/akshayabd/gists{/gist_id}","starred_url":"https://api.github.com/users/akshayabd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akshayabd/subscriptions","organizations_url":"https://api.github.com/users/akshayabd/orgs","repos_url":"https://api.github.com/users/akshayabd/repos","events_url":"https://api.github.com/users/akshayabd/events{/privacy}","received_events_url":"https://api.github.com/users/akshayabd/received_events","type":"User","site_admin":false},"body":"... protocols in the future. The engine will now call a factory that returns a list of protocols to try in order. Developers can implement new protocols in separate classes and add them to the factory to be used. Added tests for existing protocols. I noticed the Engine class doesn't have a corresponding Test class. It would be nice to add one, but I think it needs more refactoring before it would be realistic to add tests for it.","created_at":"2015-01-24T15:02:13Z","updated_at":"2015-01-26T13:49:49Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a75654703ef1df1d458d493ab49380d8af530d2e","assignee":{"login":"kohsuke","id":50003,"avatar_url":"https://avatars.githubusercontent.com/u/50003?v=3","gravatar_id":"","url":"https://api.github.com/users/kohsuke","html_url":"https://github.com/kohsuke","followers_url":"https://api.github.com/users/kohsuke/followers","following_url":"https://api.github.com/users/kohsuke/following{/other_user}","gists_url":"https://api.github.com/users/kohsuke/gists{/gist_id}","starred_url":"https://api.github.com/users/kohsuke/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kohsuke/subscriptions","organizations_url":"https://api.github.com/users/kohsuke/orgs","repos_url":"https://api.github.com/users/kohsuke/repos","events_url":"https://api.github.com/users/kohsuke/events{/privacy}","received_events_url":"https://api.github.com/users/kohsuke/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/jenkinsci/remoting/pulls/28/commits","review_comments_url":"https://api.github.com/repos/jenkinsci/remoting/pulls/28/comments","review_comment_url":"https://api.github.com/repos/jenkinsci/remoting/pulls/comments/{number}","comments_url":"https://api.github.com/repos/jenkinsci/remoting/issues/28/comments","statuses_url":"https://api.github.com/repos/jenkinsci/remoting/statuses/9a427e0614c7fea4a7d77cd7a4ded90ff2023c9b","head":{"label":"akshayabd:JENKINS-26580","ref":"JENKINS-26580","sha":"9a427e0614c7fea4a7d77cd7a4ded90ff2023c9b","user":{"login":"akshayabd","id":120980,"avatar_url":"https://avatars.githubusercontent.com/u/120980?v=3","gravatar_id":"","url":"https://api.github.com/users/akshayabd","html_url":"https://github.com/akshayabd","followers_url":"https://api.github.com/users/akshayabd/followers","following_url":"https://api.github.com/users/akshayabd/following{/other_user}","gists_url":"https://api.github.com/users/akshayabd/gists{/gist_id}","starred_url":"https://api.github.com/users/akshayabd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akshayabd/subscriptions","organizations_url":"https://api.github.com/users/akshayabd/orgs","repos_url":"https://api.github.com/users/akshayabd/repos","events_url":"https://api.github.com/users/akshayabd/events{/privacy}","received_events_url":"https://api.github.com/users/akshayabd/received_events","type":"User","site_admin":false},"repo":{"id":29780066,"name":"remoting","full_name":"akshayabd/remoting","owner":{"login":"akshayabd","id":120980,"avatar_url":"https://avatars.githubusercontent.com/u/120980?v=3","gravatar_id":"","url":"https://api.github.com/users/akshayabd","html_url":"https://github.com/akshayabd","followers_url":"https://api.github.com/users/akshayabd/followers","following_url":"https://api.github.com/users/akshayabd/following{/other_user}","gists_url":"https://api.github.com/users/akshayabd/gists{/gist_id}","starred_url":"https://api.github.com/users/akshayabd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akshayabd/subscriptions","organizations_url":"https://api.github.com/users/akshayabd/orgs","repos_url":"https://api.github.com/users/akshayabd/repos","events_url":"https://api.github.com/users/akshayabd/events{/privacy}","received_events_url":"https://api.github.com/users/akshayabd/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/akshayabd/remoting","description":"Jenkins remoting module","fork":true,"url":"https://api.github.com/repos/akshayabd/remoting","forks_url":"https://api.github.com/repos/akshayabd/remoting/forks","keys_url":"https://api.github.com/repos/akshayabd/remoting/keys{/key_id}","collaborators_url":"https://api.github.com/repos/akshayabd/remoting/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/akshayabd/remoting/teams","hooks_url":"https://api.github.com/repos/akshayabd/remoting/hooks","issue_events_url":"https://api.github.com/repos/akshayabd/remoting/issues/events{/number}","events_url":"https://api.github.com/repos/akshayabd/remoting/events","assignees_url":"https://api.github.com/repos/akshayabd/remoting/assignees{/user}","branches_url":"https://api.github.com/repos/akshayabd/remoting/branches{/branch}","tags_url":"https://api.github.com/repos/akshayabd/remoting/tags","blobs_url":"https://api.github.com/repos/akshayabd/remoting/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/akshayabd/remoting/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/akshayabd/remoting/git/refs{/sha}","trees_url":"https://api.github.com/repos/akshayabd/remoting/git/trees{/sha}","statuses_url":"https://api.github.com/repos/akshayabd/remoting/statuses/{sha}","languages_url":"https://api.github.com/repos/akshayabd/remoting/languages","stargazers_url":"https://api.github.com/repos/akshayabd/remoting/stargazers","contributors_url":"https://api.github.com/repos/akshayabd/remoting/contributors","subscribers_url":"https://api.github.com/repos/akshayabd/remoting/subscribers","subscription_url":"https://api.github.com/repos/akshayabd/remoting/subscription","commits_url":"https://api.github.com/repos/akshayabd/remoting/commits{/sha}","git_commits_url":"https://api.github.com/repos/akshayabd/remoting/git/commits{/sha}","comments_url":"https://api.github.com/repos/akshayabd/remoting/comments{/number}","issue_comment_url":"https://api.github.com/repos/akshayabd/remoting/issues/comments/{number}","contents_url":"https://api.github.com/repos/akshayabd/remoting/contents/{+path}","compare_url":"https://api.github.com/repos/akshayabd/remoting/compare/{base}...{head}","merges_url":"https://api.github.com/repos/akshayabd/remoting/merges","archive_url":"https://api.github.com/repos/akshayabd/remoting/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/akshayabd/remoting/downloads","issues_url":"https://api.github.com/repos/akshayabd/remoting/issues{/number}","pulls_url":"https://api.github.com/repos/akshayabd/remoting/pulls{/number}","milestones_url":"https://api.github.com/repos/akshayabd/remoting/milestones{/number}","notifications_url":"https://api.github.com/repos/akshayabd/remoting/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/akshayabd/remoting/labels{/name}","releases_url":"https://api.github.com/repos/akshayabd/remoting/releases{/id}","created_at":"2015-01-24T15:00:47Z","updated_at":"2015-01-24T15:00:48Z","pushed_at":"2015-01-25T07:19:56Z","git_url":"git://github.com/akshayabd/remoting.git","ssh_url":"git@github.com:akshayabd/remoting.git","clone_url":"https://github.com/akshayabd/remoting.git","svn_url":"https://github.com/akshayabd/remoting","homepage":"http://jenkins-ci.org/","size":2161,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"jenkinsci:master","ref":"master","sha":"e62cef4143e81741a243697b463f3434bc6deb68","user":{"login":"jenkinsci","id":107424,"avatar_url":"https://avatars.githubusercontent.com/u/107424?v=3","gravatar_id":"","url":"https://api.github.com/users/jenkinsci","html_url":"https://github.com/jenkinsci","followers_url":"https://api.github.com/users/jenkinsci/followers","following_url":"https://api.github.com/users/jenkinsci/following{/other_user}","gists_url":"https://api.github.com/users/jenkinsci/gists{/gist_id}","starred_url":"https://api.github.com/users/jenkinsci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jenkinsci/subscriptions","organizations_url":"https://api.github.com/users/jenkinsci/orgs","repos_url":"https://api.github.com/users/jenkinsci/repos","events_url":"https://api.github.com/users/jenkinsci/events{/privacy}","received_events_url":"https://api.github.com/users/jenkinsci/received_events","type":"Organization","site_admin":false},"repo":{"id":2040168,"name":"remoting","full_name":"jenkinsci/remoting","owner":{"login":"jenkinsci","id":107424,"avatar_url":"https://avatars.githubusercontent.com/u/107424?v=3","gravatar_id":"","url":"https://api.github.com/users/jenkinsci","html_url":"https://github.com/jenkinsci","followers_url":"https://api.github.com/users/jenkinsci/followers","following_url":"https://api.github.com/users/jenkinsci/following{/other_user}","gists_url":"https://api.github.com/users/jenkinsci/gists{/gist_id}","starred_url":"https://api.github.com/users/jenkinsci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jenkinsci/subscriptions","organizations_url":"https://api.github.com/users/jenkinsci/orgs","repos_url":"https://api.github.com/users/jenkinsci/repos","events_url":"https://api.github.com/users/jenkinsci/events{/privacy}","received_events_url":"https://api.github.com/users/jenkinsci/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/jenkinsci/remoting","description":"Jenkins remoting module","fork":false,"url":"https://api.github.com/repos/jenkinsci/remoting","forks_url":"https://api.github.com/repos/jenkinsci/remoting/forks","keys_url":"https://api.github.com/repos/jenkinsci/remoting/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jenkinsci/remoting/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jenkinsci/remoting/teams","hooks_url":"https://api.github.com/repos/jenkinsci/remoting/hooks","issue_events_url":"https://api.github.com/repos/jenkinsci/remoting/issues/events{/number}","events_url":"https://api.github.com/repos/jenkinsci/remoting/events","assignees_url":"https://api.github.com/repos/jenkinsci/remoting/assignees{/user}","branches_url":"https://api.github.com/repos/jenkinsci/remoting/branches{/branch}","tags_url":"https://api.github.com/repos/jenkinsci/remoting/tags","blobs_url":"https://api.github.com/repos/jenkinsci/remoting/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jenkinsci/remoting/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jenkinsci/remoting/git/refs{/sha}","trees_url":"https://api.github.com/repos/jenkinsci/remoting/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jenkinsci/remoting/statuses/{sha}","languages_url":"https://api.github.com/repos/jenkinsci/remoting/languages","stargazers_url":"https://api.github.com/repos/jenkinsci/remoting/stargazers","contributors_url":"https://api.github.com/repos/jenkinsci/remoting/contributors","subscribers_url":"https://api.github.com/repos/jenkinsci/remoting/subscribers","subscription_url":"https://api.github.com/repos/jenkinsci/remoting/subscription","commits_url":"https://api.github.com/repos/jenkinsci/remoting/commits{/sha}","git_commits_url":"https://api.github.com/repos/jenkinsci/remoting/git/commits{/sha}","comments_url":"https://api.github.com/repos/jenkinsci/remoting/comments{/number}","issue_comment_url":"https://api.github.com/repos/jenkinsci/remoting/issues/comments/{number}","contents_url":"https://api.github.com/repos/jenkinsci/remoting/contents/{+path}","compare_url":"https://api.github.com/repos/jenkinsci/remoting/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jenkinsci/remoting/merges","archive_url":"https://api.github.com/repos/jenkinsci/remoting/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jenkinsci/remoting/downloads","issues_url":"https://api.github.com/repos/jenkinsci/remoting/issues{/number}","pulls_url":"https://api.github.com/repos/jenkinsci/remoting/pulls{/number}","milestones_url":"https://api.github.com/repos/jenkinsci/remoting/milestones{/number}","notifications_url":"https://api.github.com/repos/jenkinsci/remoting/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jenkinsci/remoting/labels{/name}","releases_url":"https://api.github.com/repos/jenkinsci/remoting/releases{/id}","created_at":"2011-07-13T05:06:16Z","updated_at":"2014-12-20T00:33:57Z","pushed_at":"2014-12-20T00:33:57Z","git_url":"git://github.com/jenkinsci/remoting.git","ssh_url":"git@github.com:jenkinsci/remoting.git","clone_url":"https://github.com/jenkinsci/remoting.git","svn_url":"https://github.com/jenkinsci/remoting","homepage":"http://jenkins-ci.org/","size":3067,"stargazers_count":25,"watchers_count":25,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":39,"mirror_url":null,"open_issues_count":4,"forks":39,"open_issues":4,"watchers":25,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/jenkinsci/remoting/pulls/28"},"html":{"href":"https://github.com/jenkinsci/remoting/pull/28"},"issue":{"href":"https://api.github.com/repos/jenkinsci/remoting/issues/28"},"comments":{"href":"https://api.github.com/repos/jenkinsci/remoting/issues/28/comments"},"review_comments":{"href":"https://api.github.com/repos/jenkinsci/remoting/pulls/28/comments"},"review_comment":{"href":"https://api.github.com/repos/jenkinsci/remoting/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/jenkinsci/remoting/pulls/28/commits"},"statuses":{"href":"https://api.github.com/repos/jenkinsci/remoting/statuses/9a427e0614c7fea4a7d77cd7a4ded90ff2023c9b"}}}}