Mercurial > jhg
comparison cmdline/org/tmatesoft/hg/console/Remote.java @ 177:e10225daface
Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Sat, 02 Apr 2011 23:05:28 +0200 |
parents | 2c3e96674e2a |
children | 62665d8f0686 |
comparison
equal
deleted
inserted
replaced
176:a8df7162ec75 | 177:e10225daface |
---|---|
18 | 18 |
19 import java.io.File; | 19 import java.io.File; |
20 import java.io.FileOutputStream; | 20 import java.io.FileOutputStream; |
21 import java.io.IOException; | 21 import java.io.IOException; |
22 import java.io.InputStream; | 22 import java.io.InputStream; |
23 import java.io.OutputStream; | |
24 import java.net.HttpURLConnection; | |
23 import java.net.URL; | 25 import java.net.URL; |
24 import java.security.cert.CertificateException; | 26 import java.security.cert.CertificateException; |
25 import java.security.cert.X509Certificate; | 27 import java.security.cert.X509Certificate; |
26 import java.util.List; | 28 import java.util.List; |
27 import java.util.Map; | 29 import java.util.Map; |
91 public static void main(String[] args) throws Exception { | 93 public static void main(String[] args) throws Exception { |
92 ConfigFile cfg = new Internals().newConfigFile(); | 94 ConfigFile cfg = new Internals().newConfigFile(); |
93 cfg.addLocation(new File(System.getProperty("user.home"), ".hgrc")); | 95 cfg.addLocation(new File(System.getProperty("user.home"), ".hgrc")); |
94 String svnkitServer = cfg.getSection("paths").get("svnkit"); | 96 String svnkitServer = cfg.getSection("paths").get("svnkit"); |
95 // URL url = new URL(svnkitServer + "?cmd=branches&nodes=30bd389788464287cee22ccff54c330a4b715de5"); | 97 // URL url = new URL(svnkitServer + "?cmd=branches&nodes=30bd389788464287cee22ccff54c330a4b715de5"); |
96 URL url = new URL(svnkitServer + "?cmd=between&pairs=71ddbf8603e8e09d54ac9c5fe4bb5ae824589f1d-8c8e3f372fa1fbfcf92b004b6f2ada2dbaf60028"); | 98 URL url = new URL(svnkitServer + "?cmd=between"); |
97 // URL url = new URL(svnkitServer + "?cmd=changegroup&roots=" + Nodeid.NULL.toString()); | 99 // URL url = new URL(svnkitServer + "?cmd=changegroup&roots=" + Nodeid.NULL.toString()); |
98 // URL url = new URL("http://localhost:8000/" + "?cmd=stream_out"); | 100 // URL url = new URL("http://localhost:8000/" + "?cmd=between"); |
99 // URL url = new URL(svnkitServer + "?cmd=stream_out"); | 101 // URL url = new URL(svnkitServer + "?cmd=stream_out"); |
100 | 102 |
101 SSLContext sslContext = SSLContext.getInstance("SSL"); | 103 SSLContext sslContext = SSLContext.getInstance("SSL"); |
102 class TrustEveryone implements X509TrustManager { | 104 class TrustEveryone implements X509TrustManager { |
103 public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { | 105 public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { |
116 String authInfo = tempNode.get("xxx", null); | 118 String authInfo = tempNode.get("xxx", null); |
117 tempNode.removeNode(); | 119 tempNode.removeNode(); |
118 // | 120 // |
119 sslContext.init(null, new TrustManager[] { new TrustEveryone() }, null); | 121 sslContext.init(null, new TrustManager[] { new TrustEveryone() }, null); |
120 HttpsURLConnection urlConnection = (HttpsURLConnection) url.openConnection(); | 122 HttpsURLConnection urlConnection = (HttpsURLConnection) url.openConnection(); |
121 urlConnection.addRequestProperty("User-Agent", "jhg/0.1.0"); | 123 // HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); |
122 urlConnection.addRequestProperty("Accept", "application/mercurial-0.1"); | 124 urlConnection.setRequestProperty("User-Agent", "jhg/0.1.0"); |
123 urlConnection.addRequestProperty("Authorization", "Basic " + authInfo); | 125 urlConnection.setRequestProperty("Accept", "application/mercurial-0.1"); |
126 urlConnection.setRequestProperty("Authorization", "Basic " + authInfo); | |
124 urlConnection.setSSLSocketFactory(sslContext.getSocketFactory()); | 127 urlConnection.setSSLSocketFactory(sslContext.getSocketFactory()); |
125 urlConnection.connect(); | 128 byte[] body = "pairs=30bd389788464287cee22ccff54c330a4b715de5-dbd663faec1f0175619cf7668bddc6350548b8d6".getBytes(); |
129 urlConnection.setRequestMethod("POST"); | |
130 urlConnection.setRequestProperty("Content-Length", String.valueOf(body.length)); | |
131 urlConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); | |
132 urlConnection.setDoOutput(true); | |
133 urlConnection.setDoInput(true); | |
134 // urlConnection.connect(); | |
135 OutputStream os = urlConnection.getOutputStream(); | |
136 os.write(body); | |
137 os.flush(); | |
138 os.close(); | |
126 System.out.println("Query:" + url.getQuery()); | 139 System.out.println("Query:" + url.getQuery()); |
127 System.out.println("Response headers:"); | 140 System.out.println("Response headers:"); |
128 final Map<String, List<String>> headerFields = urlConnection.getHeaderFields(); | 141 final Map<String, List<String>> headerFields = urlConnection.getHeaderFields(); |
129 for (String s : headerFields.keySet()) { | 142 for (String s : headerFields.keySet()) { |
130 System.out.printf("%s: %s\n", s, urlConnection.getHeaderField(s)); | 143 System.out.printf("%s: %s\n", s, urlConnection.getHeaderField(s)); |