diff 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
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/internal/remote/HttpConnector.java	Tue Aug 06 13:34:34 2013 +0200
+++ b/src/org/tmatesoft/hg/internal/remote/HttpConnector.java	Tue Aug 06 21:18:33 2013 +0200
@@ -28,6 +28,7 @@
 import java.io.SequenceInputStream;
 import java.net.HttpURLConnection;
 import java.net.MalformedURLException;
+import java.net.URI;
 import java.net.URL;
 import java.net.URLConnection;
 import java.security.cert.CertificateException;
@@ -56,6 +57,7 @@
  * @author TMate Software Ltd.
  */
 public class HttpConnector implements Connector {
+	private URI uri;
 	private URL url;
 	private SSLContext sslContext;
 	private String authInfo;
@@ -64,16 +66,16 @@
 	//
 	private HttpURLConnection conn;
 
-	public void init(URL url, SessionContext sessionContext, Object globalConfig) throws HgRuntimeException {
-		this.url = url;
+	public void init(URI uri, SessionContext sessionContext, Object globalConfig) throws HgRuntimeException {
+		this.uri = uri;
 		sessionCtx = sessionContext;
 		debug = new PropertyMarshal(sessionCtx).getBoolean("hg4j.remote.debug", false);
-		if (url.getUserInfo() != null) {
+		if (uri.getUserInfo() != null) {
 			String ai = null;
 			try {
 				// Hack to get Base64-encoded credentials
 				Preferences tempNode = Preferences.userRoot().node("xxx");
-				tempNode.putByteArray("xxx", url.getUserInfo().getBytes());
+				tempNode.putByteArray("xxx", uri.getUserInfo().getBytes());
 				ai = tempNode.get("xxx", null);
 				tempNode.removeNode();
 			} catch (BackingStoreException ex) {
@@ -87,6 +89,11 @@
 	}
 	
 	public void connect() throws HgRemoteConnectionException, HgRuntimeException {
+		try {
+			url = uri.toURL();
+		} catch (MalformedURLException ex) {
+			throw new HgRemoteConnectionException("Bad URL", ex);
+		}
 		if ("https".equals(url.getProtocol())) {
 			try {
 				sslContext = SSLContext.getInstance("SSL");
@@ -132,13 +139,13 @@
 	}
 	
 	public String getServerLocation() {
-		if (url.getUserInfo() == null) {
-			return url.toExternalForm();
+		if (uri.getUserInfo() == null) {
+			return uri.toString();
 		}
-		if (url.getPort() != -1) {
-			return String.format("%s://%s:%d%s", url.getProtocol(), url.getHost(), url.getPort(), url.getPath());
+		if (uri.getPort() != -1) {
+			return String.format("%s://%s:%d%s", uri.getScheme(), uri.getHost(), uri.getPort(), uri.getPath());
 		} else {
-			return String.format("%s://%s%s", url.getProtocol(), url.getHost(), url.getPath());
+			return String.format("%s://%s%s", uri.getScheme(), uri.getHost(), uri.getPath());
 		}
 	}
 
@@ -294,7 +301,6 @@
 					super.close();
 					if (debug) {
 						dumpResponseHeader(u);
-						dumpResponse();
 					}
 					try {
 						checkResponseOk("Push", CMD_UNBUNDLE);
@@ -395,11 +401,4 @@
 			System.out.printf("%s: %s\n", s, conn.getHeaderField(s));
 		}
 	}
-	
-	private void dumpResponse() throws IOException {
-		if (conn.getContentLength() > 0) {
-			final Object content = conn.getContent();
-			System.out.println(content);
-		}
-	}
 }