aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst/org/eclipse/jgit
diff options
context:
space:
mode:
authorChristian Halstrick <christian.halstrick@sap.com>2013-08-04 22:49:47 +0200
committerChristian Halstrick <christian.halstrick@sap.com>2014-02-18 21:04:10 +0100
commit38c4f35d8b911426e007716697b37d746740b788 (patch)
tree8c199a7fc9e2b65135cb388ddec588b212fa79fe /org.eclipse.jgit.test/tst/org/eclipse/jgit
parentf08fde3eebc2689210292d78db785f6ec52dc8ef (diff)
downloadjgit-38c4f35d8b911426e007716697b37d746740b788.tar.gz
jgit-38c4f35d8b911426e007716697b37d746740b788.zip
Introduce an abstraction for HTTP connections
Previously all HTTP communication was done with the help of java.net.HttpUrlConnection. In order to make JGit usable in environments where the direct usage of such connections is not allowed but where the environment provides other means to get network connections an abstraction for connections is introduced. The idea is that new implementations of this interface will be introduced which will not use java.net.HttpUrlConnection but use e.g. org.apache.client.http.HttpClient to provide network connections. One example: certain cloud infrastructures don't allow that components in the cloud communicate directly with HttpUrlConnection. Instead they provide services where a component can ask for a connection (given a symbolic name for the destination) and where the infrastructure returns a preconfigured org.apache.http.client.HttpClient. In order to allow JGit to be running in such environments we need the abstraction introduced in this commit. Change-Id: I3b06629f90a118bd284e55bb3f6465fe7d10463d Signed-off-by: Christian Halstrick <christian.halstrick@sap.com> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit.test/tst/org/eclipse/jgit')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/HttpAuthTest.java24
1 files changed, 12 insertions, 12 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/HttpAuthTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/HttpAuthTest.java
index c142bc23aa..5a64b458fa 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/HttpAuthTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/HttpAuthTest.java
@@ -45,7 +45,6 @@ package org.eclipse.jgit.transport;
import static org.junit.Assert.fail;
import java.io.IOException;
-import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
@@ -53,6 +52,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import org.eclipse.jgit.transport.http.JDKHttpConnection;
import org.junit.Test;
public class HttpAuthTest {
@@ -71,7 +71,7 @@ public class HttpAuthTest {
private static String DIGEST = "Digest";
@Test
- public void testHttpAuthScanResponse() throws MalformedURLException {
+ public void testHttpAuthScanResponse() {
checkResponse(new String[] { basicHeader }, BASIC);
checkResponse(new String[] { digestHeader }, DIGEST);
checkResponse(new String[] { basicHeader, digestHeader }, DIGEST);
@@ -83,10 +83,15 @@ public class HttpAuthTest {
}
private static void checkResponse(String[] headers,
- String expectedAuthMethod) throws MalformedURLException {
+ String expectedAuthMethod) {
- AuthHeadersResponse responce = new AuthHeadersResponse(headers);
- HttpAuthMethod authMethod = HttpAuthMethod.scanResponse(responce);
+ AuthHeadersResponse response = null;
+ try {
+ response = new AuthHeadersResponse(headers);
+ } catch (IOException e) {
+ fail("Couldn't instantiate AuthHeadersResponse: " + e.toString());
+ }
+ HttpAuthMethod authMethod = HttpAuthMethod.scanResponse(response);
if (!expectedAuthMethod.equals(getAuthMethodName(authMethod))) {
fail("Wrong authentication method: expected " + expectedAuthMethod
@@ -98,21 +103,16 @@ public class HttpAuthTest {
return authMethod.getClass().getSimpleName();
}
- private static class AuthHeadersResponse extends HttpURLConnection {
+ private static class AuthHeadersResponse extends JDKHttpConnection {
Map<String, List<String>> headerFields = new HashMap<String, List<String>>();
public AuthHeadersResponse(String[] authHeaders)
- throws MalformedURLException {
+ throws MalformedURLException, IOException {
super(new URL(URL_SAMPLE));
parseHeaders(authHeaders);
}
@Override
- public void disconnect() {
- fail("The disconnect method shouldn't be invoked");
- }
-
- @Override
public boolean usingProxy() {
return false;
}