Mercurial > jhg
annotate src/org/tmatesoft/hg/internal/remote/HttpConnector.java @ 698:822f3a83ff57
in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Tue, 06 Aug 2013 21:18:33 +0200 |
parents | 24f4efedc9d5 |
children | a483b2b68a2e |
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; |
698
822f3a83ff57
in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
697
diff
changeset
|
31 import java.net.URI; |
687
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.URL; |
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.net.URLConnection; |
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.CertificateException; |
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.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
|
36 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
|
37 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
|
38 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
|
39 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
|
40 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
|
41 |
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.HttpsURLConnection; |
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.SSLContext; |
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.TrustManager; |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
45 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
|
46 |
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.HgRemoteConnectionException; |
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.Nodeid; |
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.core.SessionContext; |
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.internal.PropertyMarshal; |
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.HgRemoteRepository.Range; |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
52 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
|
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 * |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
56 * @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
|
57 * @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
|
58 */ |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
59 public class HttpConnector implements Connector { |
698
822f3a83ff57
in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
697
diff
changeset
|
60 private URI uri; |
687
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
61 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
|
62 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
|
63 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
|
64 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
|
65 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
|
66 // |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
67 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
|
68 |
698
822f3a83ff57
in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
697
diff
changeset
|
69 public void init(URI uri, SessionContext sessionContext, Object globalConfig) throws HgRuntimeException { |
822f3a83ff57
in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
697
diff
changeset
|
70 this.uri = uri; |
687
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
71 sessionCtx = sessionContext; |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
72 debug = new PropertyMarshal(sessionCtx).getBoolean("hg4j.remote.debug", false); |
698
822f3a83ff57
in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
697
diff
changeset
|
73 if (uri.getUserInfo() != null) { |
687
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
74 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
|
75 try { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
76 // 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
|
77 Preferences tempNode = Preferences.userRoot().node("xxx"); |
698
822f3a83ff57
in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
697
diff
changeset
|
78 tempNode.putByteArray("xxx", uri.getUserInfo().getBytes()); |
687
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
79 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
|
80 tempNode.removeNode(); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
81 } 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
|
82 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
|
83 // IGNORE |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
84 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
85 authInfo = ai; |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
86 } else { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
87 authInfo = null; |
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 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
90 |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
91 public void connect() throws HgRemoteConnectionException, HgRuntimeException { |
698
822f3a83ff57
in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
697
diff
changeset
|
92 try { |
822f3a83ff57
in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
697
diff
changeset
|
93 url = uri.toURL(); |
822f3a83ff57
in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
697
diff
changeset
|
94 } catch (MalformedURLException ex) { |
822f3a83ff57
in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
697
diff
changeset
|
95 throw new HgRemoteConnectionException("Bad URL", ex); |
822f3a83ff57
in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
697
diff
changeset
|
96 } |
687
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
97 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
|
98 try { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
99 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
|
100 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
|
101 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
|
102 if (debug) { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
103 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
|
104 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
105 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
106 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
|
107 if (debug) { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
108 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
|
109 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
110 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
111 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
|
112 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
|
113 } |
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 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
|
116 } 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
|
117 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
|
118 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
119 } else { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
120 sslContext = null; |
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 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
123 |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
124 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
|
125 // 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
|
126 |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
127 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
128 |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
129 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
|
130 // 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
|
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 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
|
135 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
|
136 conn.disconnect(); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
137 conn = null; |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
138 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
139 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
140 |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
141 public String getServerLocation() { |
698
822f3a83ff57
in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
697
diff
changeset
|
142 if (uri.getUserInfo() == null) { |
822f3a83ff57
in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
697
diff
changeset
|
143 return uri.toString(); |
687
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
144 } |
698
822f3a83ff57
in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
697
diff
changeset
|
145 if (uri.getPort() != -1) { |
822f3a83ff57
in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
697
diff
changeset
|
146 return String.format("%s://%s:%d%s", uri.getScheme(), uri.getHost(), uri.getPort(), uri.getPath()); |
687
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
147 } else { |
698
822f3a83ff57
in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
697
diff
changeset
|
148 return String.format("%s://%s%s", uri.getScheme(), uri.getHost(), uri.getPath()); |
687
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
149 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
150 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
151 |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
152 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
|
153 // 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
|
154 try { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
155 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
|
156 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
|
157 c.connect(); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
158 if (debug) { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
159 dumpResponseHeader(u); |
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 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
|
162 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
|
163 c.disconnect(); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
164 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
|
165 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
|
166 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
|
167 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
168 // 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
|
169 // 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
|
170 // 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
|
171 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
|
172 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
|
173 c.connect(); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
174 if (debug) { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
175 dumpResponseHeader(u); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
176 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
177 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
|
178 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
|
179 c.disconnect(); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
180 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
|
181 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
|
182 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
183 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
|
184 } 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
|
185 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
|
186 } 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
|
187 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
|
188 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
189 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
190 |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
191 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
|
192 try { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
193 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
|
194 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
|
195 conn.connect(); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
196 if (debug) { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
197 dumpResponseHeader(u); |
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 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
|
200 } 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
|
201 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
|
202 } 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
|
203 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
|
204 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
205 } |
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 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
|
208 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
|
209 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
|
210 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
|
211 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
|
212 sb.append('+'); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
213 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
214 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
|
215 // 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
|
216 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
|
217 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
218 try { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
219 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
|
220 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
|
221 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
|
222 if (usePOST) { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
223 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
|
224 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
|
225 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
|
226 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
|
227 conn.connect(); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
228 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
|
229 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
|
230 os.flush(); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
231 os.close(); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
232 } else { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
233 conn.connect(); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
234 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
235 if (debug) { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
236 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
|
237 dumpResponseHeader(u); |
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 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
|
240 } 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
|
241 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
|
242 } 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
|
243 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
|
244 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
245 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
246 |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
247 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
|
248 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
|
249 try { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
250 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
|
251 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
|
252 conn.connect(); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
253 if (debug) { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
254 dumpResponseHeader(u); |
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 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
|
257 } 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
|
258 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
|
259 } 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
|
260 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
|
261 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
262 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
263 |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
264 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
|
265 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
|
266 try { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
267 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
|
268 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
|
269 conn.connect(); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
270 if (debug) { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
271 dumpResponseHeader(u); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
272 } |
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
|
273 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
|
274 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
|
275 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
|
276 } 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
|
277 // 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
|
278 // 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
|
279 // 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
|
280 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
|
281 } 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
|
282 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
|
283 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
284 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
285 |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
286 // |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
287 // 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
|
288 // 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
|
289 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
|
290 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
|
291 try { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
292 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
|
293 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
|
294 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
|
295 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
|
296 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
|
297 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
|
298 conn.connect(); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
299 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
|
300 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
|
301 super.close(); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
302 if (debug) { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
303 dumpResponseHeader(u); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
304 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
305 try { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
306 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
|
307 } 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
|
308 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
|
309 // 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
|
310 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
|
311 throw e; |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
312 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
313 } |
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 } 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
|
316 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
|
317 } 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
|
318 // 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
|
319 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
|
320 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
321 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
322 |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
323 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
|
324 try { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
325 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
|
326 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
|
327 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
|
328 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
|
329 conn.connect(); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
330 if (debug) { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
331 dumpResponseHeader(u); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
332 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
333 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
|
334 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
|
335 } 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
|
336 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
|
337 } 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
|
338 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
|
339 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
340 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
341 |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
342 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
|
343 try { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
344 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
|
345 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
|
346 conn.connect(); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
347 if (debug) { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
348 dumpResponseHeader(u); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
349 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
350 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
|
351 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
|
352 } 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
|
353 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
|
354 } 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
|
355 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
|
356 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
357 } |
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 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
|
360 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
|
361 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
|
362 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
|
363 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
|
364 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
365 } |
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 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
|
368 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
|
369 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
|
370 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
|
371 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
|
372 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
373 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
|
374 ((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
|
375 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
376 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
|
377 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
378 |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
379 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
|
380 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
|
381 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
|
382 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
383 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
|
384 sb.append('='); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
385 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
|
386 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
|
387 sb.append('+'); |
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 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
|
390 // 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
|
391 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
|
392 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
393 return sb; |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
394 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
395 |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
396 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
|
397 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
|
398 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
|
399 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
|
400 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
|
401 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
|
402 } |
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 } |