Mercurial > hg4j
annotate src/org/tmatesoft/hg/internal/remote/HttpConnector.java @ 697:24f4efedc9d5
Respect the fact ssh and http protocols use different compression approach to sent changegroup data
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Tue, 06 Aug 2013 13:34:34 +0200 |
parents | 9859fcea475d |
children | 822f3a83ff57 |
rev | line source |
---|---|
687
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
1 /* |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
2 * Copyright (c) 2013 TMate Software Ltd |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
3 * |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
4 * This program is free software; you can redistribute it and/or modify |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
6 * the Free Software Foundation; version 2 of the License. |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
7 * |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
8 * This program is distributed in the hope that it will be useful, |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
11 * GNU General Public License for more details. |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
12 * |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
13 * For information on how to redistribute this software under |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
14 * the terms of a license other than GNU General Public License |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
15 * contact TMate Software at support@hg4j.com |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
16 */ |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
17 package org.tmatesoft.hg.internal.remote; |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
18 |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
19 import static org.tmatesoft.hg.util.LogFacility.Severity.Info; |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
20 |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
21 import java.io.BufferedReader; |
697
24f4efedc9d5
Respect the fact ssh and http protocols use different compression approach to sent changegroup data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
687
diff
changeset
|
22 import java.io.ByteArrayInputStream; |
687
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
23 import java.io.FilterOutputStream; |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
24 import java.io.IOException; |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
25 import java.io.InputStream; |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
26 import java.io.InputStreamReader; |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
27 import java.io.OutputStream; |
697
24f4efedc9d5
Respect the fact ssh and http protocols use different compression approach to sent changegroup data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
687
diff
changeset
|
28 import java.io.SequenceInputStream; |
687
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
29 import java.net.HttpURLConnection; |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
30 import java.net.MalformedURLException; |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
31 import java.net.URL; |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
32 import java.net.URLConnection; |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
33 import java.security.cert.CertificateException; |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
34 import java.security.cert.X509Certificate; |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
35 import java.util.Collection; |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
36 import java.util.List; |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
37 import java.util.Map; |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
38 import java.util.prefs.BackingStoreException; |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
39 import java.util.prefs.Preferences; |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
40 |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
41 import javax.net.ssl.HttpsURLConnection; |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
42 import javax.net.ssl.SSLContext; |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
43 import javax.net.ssl.TrustManager; |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
44 import javax.net.ssl.X509TrustManager; |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
45 |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
46 import org.tmatesoft.hg.core.HgRemoteConnectionException; |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
47 import org.tmatesoft.hg.core.Nodeid; |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
48 import org.tmatesoft.hg.core.SessionContext; |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
49 import org.tmatesoft.hg.internal.PropertyMarshal; |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
50 import org.tmatesoft.hg.repo.HgRemoteRepository.Range; |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
51 import org.tmatesoft.hg.repo.HgRuntimeException; |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
52 |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
53 /** |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
54 * |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
55 * @author Artem Tikhomirov |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
56 * @author TMate Software Ltd. |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
57 */ |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
58 public class HttpConnector implements Connector { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
59 private URL url; |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
60 private SSLContext sslContext; |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
61 private String authInfo; |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
62 private boolean debug; |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
63 private SessionContext sessionCtx; |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
64 // |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
65 private HttpURLConnection conn; |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
66 |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
67 public void init(URL url, SessionContext sessionContext, Object globalConfig) throws HgRuntimeException { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
68 this.url = url; |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
69 sessionCtx = sessionContext; |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
70 debug = new PropertyMarshal(sessionCtx).getBoolean("hg4j.remote.debug", false); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
71 if (url.getUserInfo() != null) { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
72 String ai = null; |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
73 try { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
74 // Hack to get Base64-encoded credentials |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
75 Preferences tempNode = Preferences.userRoot().node("xxx"); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
76 tempNode.putByteArray("xxx", url.getUserInfo().getBytes()); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
77 ai = tempNode.get("xxx", null); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
78 tempNode.removeNode(); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
79 } catch (BackingStoreException ex) { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
80 sessionContext.getLog().dump(getClass(), Info, ex, null); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
81 // IGNORE |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
82 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
83 authInfo = ai; |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
84 } else { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
85 authInfo = null; |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
86 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
87 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
88 |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
89 public void connect() throws HgRemoteConnectionException, HgRuntimeException { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
90 if ("https".equals(url.getProtocol())) { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
91 try { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
92 sslContext = SSLContext.getInstance("SSL"); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
93 class TrustEveryone implements X509TrustManager { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
94 public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
95 if (debug) { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
96 System.out.println("checkClientTrusted:" + authType); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
97 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
98 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
99 public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
100 if (debug) { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
101 System.out.println("checkServerTrusted:" + authType); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
102 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
103 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
104 public X509Certificate[] getAcceptedIssuers() { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
105 return new X509Certificate[0]; |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
106 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
107 }; |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
108 sslContext.init(null, new TrustManager[] { new TrustEveryone() }, null); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
109 } catch (Exception ex) { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
110 throw new HgRemoteConnectionException("Can't initialize secure connection", ex); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
111 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
112 } else { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
113 sslContext = null; |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
114 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
115 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
116 |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
117 public void disconnect() throws HgRemoteConnectionException, HgRuntimeException { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
118 // TODO Auto-generated method stub |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
119 |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
120 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
121 |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
122 public void sessionBegin() throws HgRemoteConnectionException, HgRuntimeException { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
123 // TODO Auto-generated method stub |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
124 |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
125 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
126 |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
127 public void sessionEnd() throws HgRemoteConnectionException, HgRuntimeException { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
128 if (conn != null) { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
129 conn.disconnect(); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
130 conn = null; |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
131 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
132 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
133 |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
134 public String getServerLocation() { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
135 if (url.getUserInfo() == null) { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
136 return url.toExternalForm(); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
137 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
138 if (url.getPort() != -1) { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
139 return String.format("%s://%s:%d%s", url.getProtocol(), url.getHost(), url.getPort(), url.getPath()); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
140 } else { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
141 return String.format("%s://%s%s", url.getProtocol(), url.getHost(), url.getPath()); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
142 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
143 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
144 |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
145 public String getCapabilities() throws HgRemoteConnectionException { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
146 // say hello to server, check response |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
147 try { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
148 URL u = new URL(url, url.getPath() + "?cmd=hello"); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
149 HttpURLConnection c = setupConnection(u.openConnection()); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
150 c.connect(); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
151 if (debug) { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
152 dumpResponseHeader(u); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
153 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
154 BufferedReader r = new BufferedReader(new InputStreamReader(c.getInputStream(), "US-ASCII")); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
155 String line = r.readLine(); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
156 c.disconnect(); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
157 final String capsPrefix = CMD_CAPABILITIES + ':'; |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
158 if (line != null && line.startsWith(capsPrefix)) { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
159 return line.substring(capsPrefix.length()).trim(); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
160 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
161 // for whatever reason, some servers do not respond to hello command (e.g. svnkit) |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
162 // but respond to 'capabilities' instead. Try it. |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
163 // TODO [post-1.0] tests needed |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
164 u = new URL(url, url.getPath() + "?cmd=capabilities"); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
165 c = setupConnection(u.openConnection()); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
166 c.connect(); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
167 if (debug) { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
168 dumpResponseHeader(u); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
169 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
170 r = new BufferedReader(new InputStreamReader(c.getInputStream(), "US-ASCII")); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
171 line = r.readLine(); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
172 c.disconnect(); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
173 if (line != null && line.startsWith(capsPrefix)) { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
174 return line.substring(capsPrefix.length()).trim(); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
175 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
176 return new String(); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
177 } catch (MalformedURLException ex) { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
178 throw new HgRemoteConnectionException("Bad URL", ex).setRemoteCommand(CMD_HELLO).setServerInfo(getServerLocation()); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
179 } catch (IOException ex) { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
180 throw new HgRemoteConnectionException("Communication failure", ex).setRemoteCommand(CMD_HELLO).setServerInfo(getServerLocation()); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
181 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
182 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
183 |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
184 public InputStream heads() throws HgRemoteConnectionException, HgRuntimeException { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
185 try { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
186 URL u = new URL(url, url.getPath() + "?cmd=heads"); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
187 conn = setupConnection(u.openConnection()); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
188 conn.connect(); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
189 if (debug) { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
190 dumpResponseHeader(u); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
191 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
192 return conn.getInputStream(); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
193 } catch (MalformedURLException ex) { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
194 throw new HgRemoteConnectionException("Bad URL", ex).setRemoteCommand(CMD_HEADS).setServerInfo(getServerLocation()); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
195 } catch (IOException ex) { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
196 throw new HgRemoteConnectionException("Communication failure", ex).setRemoteCommand(CMD_HEADS).setServerInfo(getServerLocation()); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
197 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
198 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
199 |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
200 public InputStream between(Collection<Range> ranges) throws HgRemoteConnectionException, HgRuntimeException { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
201 StringBuilder sb = new StringBuilder(20 + ranges.size() * 82); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
202 sb.append("pairs="); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
203 for (Range r : ranges) { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
204 r.append(sb); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
205 sb.append('+'); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
206 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
207 if (sb.charAt(sb.length() - 1) == '+') { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
208 // strip last space |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
209 sb.setLength(sb.length() - 1); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
210 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
211 try { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
212 boolean usePOST = ranges.size() > 3; |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
213 URL u = new URL(url, url.getPath() + "?cmd=between" + (usePOST ? "" : '&' + sb.toString())); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
214 conn = setupConnection(u.openConnection()); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
215 if (usePOST) { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
216 conn.setRequestMethod("POST"); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
217 conn.setRequestProperty("Content-Length", String.valueOf(sb.length()/*nodeids are ASCII, bytes == characters */)); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
218 conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
219 conn.setDoOutput(true); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
220 conn.connect(); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
221 OutputStream os = conn.getOutputStream(); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
222 os.write(sb.toString().getBytes()); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
223 os.flush(); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
224 os.close(); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
225 } else { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
226 conn.connect(); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
227 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
228 if (debug) { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
229 System.out.printf("%d ranges, method:%s \n", ranges.size(), conn.getRequestMethod()); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
230 dumpResponseHeader(u); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
231 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
232 return conn.getInputStream(); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
233 } catch (MalformedURLException ex) { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
234 throw new HgRemoteConnectionException("Bad URL", ex).setRemoteCommand(CMD_BETWEEN).setServerInfo(getServerLocation()); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
235 } catch (IOException ex) { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
236 throw new HgRemoteConnectionException("Communication failure", ex).setRemoteCommand(CMD_BETWEEN).setServerInfo(getServerLocation()); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
237 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
238 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
239 |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
240 public InputStream branches(List<Nodeid> nodes) throws HgRemoteConnectionException, HgRuntimeException { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
241 StringBuilder sb = appendNodeidListArgument("nodes", nodes, null); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
242 try { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
243 URL u = new URL(url, url.getPath() + "?cmd=branches&" + sb.toString()); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
244 conn = setupConnection(u.openConnection()); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
245 conn.connect(); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
246 if (debug) { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
247 dumpResponseHeader(u); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
248 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
249 return conn.getInputStream(); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
250 } catch (MalformedURLException ex) { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
251 throw new HgRemoteConnectionException("Bad URL", ex).setRemoteCommand(CMD_BRANCHES).setServerInfo(getServerLocation()); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
252 } catch (IOException ex) { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
253 throw new HgRemoteConnectionException("Communication failure", ex).setRemoteCommand(CMD_BRANCHES).setServerInfo(getServerLocation()); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
254 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
255 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
256 |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
257 public InputStream changegroup(List<Nodeid> roots) throws HgRemoteConnectionException, HgRuntimeException { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
258 StringBuilder sb = appendNodeidListArgument("roots", roots, null); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
259 try { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
260 URL u = new URL(url, url.getPath() + "?cmd=changegroup&" + sb.toString()); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
261 conn = setupConnection(u.openConnection()); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
262 conn.connect(); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
263 if (debug) { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
264 dumpResponseHeader(u); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
265 } |
697
24f4efedc9d5
Respect the fact ssh and http protocols use different compression approach to sent changegroup data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
687
diff
changeset
|
266 InputStream cg = conn.getInputStream(); |
24f4efedc9d5
Respect the fact ssh and http protocols use different compression approach to sent changegroup data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
687
diff
changeset
|
267 InputStream prefix = new ByteArrayInputStream("HG10GZ".getBytes()); // didn't see any other that zip |
24f4efedc9d5
Respect the fact ssh and http protocols use different compression approach to sent changegroup data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
687
diff
changeset
|
268 return new SequenceInputStream(prefix, cg); |
24f4efedc9d5
Respect the fact ssh and http protocols use different compression approach to sent changegroup data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
687
diff
changeset
|
269 } catch (MalformedURLException ex) { |
24f4efedc9d5
Respect the fact ssh and http protocols use different compression approach to sent changegroup data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
687
diff
changeset
|
270 // although there's little user can do about this issue (URLs are constructed by our code) |
24f4efedc9d5
Respect the fact ssh and http protocols use different compression approach to sent changegroup data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
687
diff
changeset
|
271 // it's still better to throw it as checked exception than RT because url is likely malformed due to parameters |
24f4efedc9d5
Respect the fact ssh and http protocols use different compression approach to sent changegroup data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
687
diff
changeset
|
272 // and this may help user to understand the cause (and e.g. change them) |
687
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
273 throw new HgRemoteConnectionException("Bad URL", ex).setRemoteCommand("changegroup").setServerInfo(getServerLocation()); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
274 } catch (IOException ex) { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
275 throw new HgRemoteConnectionException("Communication failure", ex).setRemoteCommand("changegroup").setServerInfo(getServerLocation()); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
276 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
277 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
278 |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
279 // |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
280 // FIXME consider HttpURLConnection#setChunkedStreamingMode() as described at |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
281 // http://stackoverflow.com/questions/2793150/how-to-use-java-net-urlconnection-to-fire-and-handle-http-requests |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
282 public OutputStream unbundle(long outputLen, List<Nodeid> remoteHeads) throws HgRemoteConnectionException, HgRuntimeException { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
283 StringBuilder sb = appendNodeidListArgument(CMD_HEADS, remoteHeads, null); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
284 try { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
285 final URL u = new URL(url, url.getPath() + "?cmd=unbundle&" + sb.toString()); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
286 conn = setupConnection(u.openConnection()); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
287 conn.setRequestMethod("POST"); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
288 conn.setDoOutput(true); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
289 conn.setRequestProperty("Content-Type", "application/mercurial-0.1"); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
290 conn.setRequestProperty("Content-Length", String.valueOf(outputLen)); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
291 conn.connect(); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
292 return new FilterOutputStream(conn.getOutputStream()) { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
293 public void close() throws IOException { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
294 super.close(); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
295 if (debug) { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
296 dumpResponseHeader(u); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
297 dumpResponse(); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
298 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
299 try { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
300 checkResponseOk("Push", CMD_UNBUNDLE); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
301 } catch (HgRemoteConnectionException ex) { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
302 IOException e = new IOException(ex.getMessage()); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
303 // not e.initCause(ex); as HgRemoteConnectionException is just a message holder |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
304 e.setStackTrace(ex.getStackTrace()); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
305 throw e; |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
306 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
307 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
308 }; |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
309 } catch (MalformedURLException ex) { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
310 throw new HgRemoteConnectionException("Bad URL", ex).setRemoteCommand(CMD_UNBUNDLE).setServerInfo(getServerLocation()); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
311 } catch (IOException ex) { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
312 // FIXME consume c.getErrorStream as http://docs.oracle.com/javase/6/docs/technotes/guides/net/http-keepalive.html suggests |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
313 throw new HgRemoteConnectionException("Communication failure", ex).setRemoteCommand(CMD_UNBUNDLE).setServerInfo(getServerLocation()); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
314 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
315 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
316 |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
317 public InputStream pushkey(String opName, String namespace, String key, String oldValue, String newValue) throws HgRemoteConnectionException, HgRuntimeException { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
318 try { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
319 final String p = String.format("%s?cmd=pushkey&namespace=%s&key=%s&old=%s&new=%s", url.getPath(), namespace, key, oldValue, newValue); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
320 URL u = new URL(url, p); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
321 conn = setupConnection(u.openConnection()); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
322 conn.setRequestMethod("POST"); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
323 conn.connect(); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
324 if (debug) { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
325 dumpResponseHeader(u); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
326 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
327 checkResponseOk(opName, "pushkey"); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
328 return conn.getInputStream(); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
329 } catch (MalformedURLException ex) { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
330 throw new HgRemoteConnectionException("Bad URL", ex).setRemoteCommand("pushkey").setServerInfo(getServerLocation()); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
331 } catch (IOException ex) { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
332 throw new HgRemoteConnectionException("Communication failure", ex).setRemoteCommand("pushkey").setServerInfo(getServerLocation()); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
333 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
334 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
335 |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
336 public InputStream listkeys(String namespace, String actionName) throws HgRemoteConnectionException, HgRuntimeException { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
337 try { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
338 URL u = new URL(url, url.getPath() + "?cmd=listkeys&namespace=" + namespace); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
339 conn = setupConnection(u.openConnection()); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
340 conn.connect(); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
341 if (debug) { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
342 dumpResponseHeader(u); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
343 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
344 checkResponseOk(actionName, "listkeys"); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
345 return conn.getInputStream(); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
346 } catch (MalformedURLException ex) { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
347 throw new HgRemoteConnectionException("Bad URL", ex).setRemoteCommand(CMD_LISTKEYS).setServerInfo(getServerLocation()); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
348 } catch (IOException ex) { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
349 throw new HgRemoteConnectionException("Communication failure", ex).setRemoteCommand(CMD_LISTKEYS).setServerInfo(getServerLocation()); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
350 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
351 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
352 |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
353 private void checkResponseOk(String opName, String remoteCmd) throws HgRemoteConnectionException, IOException { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
354 if (conn.getResponseCode() != 200) { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
355 String m = conn.getResponseMessage() == null ? "unknown reason" : conn.getResponseMessage(); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
356 String em = String.format("%s failed: %s (HTTP error:%d)", opName, m, conn.getResponseCode()); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
357 throw new HgRemoteConnectionException(em).setRemoteCommand(remoteCmd).setServerInfo(getServerLocation()); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
358 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
359 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
360 |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
361 private HttpURLConnection setupConnection(URLConnection urlConnection) { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
362 urlConnection.setRequestProperty("User-Agent", "hg4j/1.0.0"); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
363 urlConnection.addRequestProperty("Accept", "application/mercurial-0.1"); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
364 if (authInfo != null) { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
365 urlConnection.addRequestProperty("Authorization", "Basic " + authInfo); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
366 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
367 if (sslContext != null) { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
368 ((HttpsURLConnection) urlConnection).setSSLSocketFactory(sslContext.getSocketFactory()); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
369 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
370 return (HttpURLConnection) urlConnection; |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
371 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
372 |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
373 private StringBuilder appendNodeidListArgument(String key, List<Nodeid> values, StringBuilder sb) { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
374 if (sb == null) { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
375 sb = new StringBuilder(20 + values.size() * 41); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
376 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
377 sb.append(key); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
378 sb.append('='); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
379 for (Nodeid n : values) { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
380 sb.append(n.toString()); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
381 sb.append('+'); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
382 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
383 if (sb.charAt(sb.length() - 1) == '+') { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
384 // strip last space |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
385 sb.setLength(sb.length() - 1); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
386 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
387 return sb; |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
388 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
389 |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
390 private void dumpResponseHeader(URL u) { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
391 System.out.printf("Query (%d bytes):%s\n", u.getQuery().length(), u.getQuery()); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
392 System.out.println("Response headers:"); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
393 final Map<String, List<String>> headerFields = conn.getHeaderFields(); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
394 for (String s : headerFields.keySet()) { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
395 System.out.printf("%s: %s\n", s, conn.getHeaderField(s)); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
396 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
397 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
398 |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
399 private void dumpResponse() throws IOException { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
400 if (conn.getContentLength() > 0) { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
401 final Object content = conn.getContent(); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
402 System.out.println(content); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
403 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
404 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
405 } |