Browse Source

Add response message, if any, on HTTP status 404

Try to give as much information as possible. The connection's
response message might contain additional hints as to why the
connection could not be established.

Bug: 536541
Change-Id: I7230e4e0be9417be8cedeb8aaab35186fcbf00a5
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
stable-5.1
Thomas Wolf 6 years ago
parent
commit
55ebb83c98
  1. 8
      org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/HttpClientTests.java
  2. 2
      org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties
  3. 2
      org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java
  4. 21
      org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java

8
org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/HttpClientTests.java

@ -175,7 +175,9 @@ public class HttpClientTests extends HttpTestCase {
} catch (NoRemoteRepositoryException err) { } catch (NoRemoteRepositoryException err) {
String exp = uri + ": " + uri String exp = uri + ": " + uri
+ "/info/refs?service=git-upload-pack not found"; + "/info/refs?service=git-upload-pack not found";
assertEquals(exp, err.getMessage()); assertNotNull(err.getMessage());
assertTrue("Unexpected error message",
err.getMessage().startsWith(exp));
} }
} }
} }
@ -191,7 +193,9 @@ public class HttpClientTests extends HttpTestCase {
} catch (NoRemoteRepositoryException err) { } catch (NoRemoteRepositoryException err) {
String exp = uri + ": " + uri String exp = uri + ": " + uri
+ "/info/refs?service=git-upload-pack not found"; + "/info/refs?service=git-upload-pack not found";
assertEquals(exp, err.getMessage()); assertNotNull(err.getMessage());
assertTrue("Unexpected error message",
err.getMessage().startsWith(exp));
} }
} }
} }

2
org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties

@ -755,8 +755,8 @@ updatingRefFailed=Updating the ref {0} to {1} failed. ReturnCode from RefUpdate.
upstreamBranchName=branch ''{0}'' of {1} upstreamBranchName=branch ''{0}'' of {1}
uriNotConfigured=Submodule URI not configured uriNotConfigured=Submodule URI not configured
uriNotFound={0} not found uriNotFound={0} not found
uriNotFoundWithMessage={0} not found: {1}
URINotSupported=URI not supported: {0} URINotSupported=URI not supported: {0}
URLNotFound={0} not found
userConfigFileInvalid=User config file {0} invalid {1} userConfigFileInvalid=User config file {0} invalid {1}
walkFailure=Walk failure. walkFailure=Walk failure.
wantNotValid=want {0} not valid wantNotValid=want {0} not valid

2
org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java

@ -816,8 +816,8 @@ public class JGitText extends TranslationBundle {
/***/ public String upstreamBranchName; /***/ public String upstreamBranchName;
/***/ public String uriNotConfigured; /***/ public String uriNotConfigured;
/***/ public String uriNotFound; /***/ public String uriNotFound;
/***/ public String uriNotFoundWithMessage;
/***/ public String URINotSupported; /***/ public String URINotSupported;
/***/ public String URLNotFound;
/***/ public String userConfigFileInvalid; /***/ public String userConfigFileInvalid;
/***/ public String walkFailure; /***/ public String walkFailure;
/***/ public String wantNotValid; /***/ public String wantNotValid;

21
org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java

@ -483,6 +483,18 @@ public class TransportHttp extends HttpTransport implements WalkTransport,
this.headers = headers; this.headers = headers;
} }
private NoRemoteRepositoryException createNotFoundException(URIish u,
URL url, String msg) {
String text;
if (msg != null && !msg.isEmpty()) {
text = MessageFormat.format(JGitText.get().uriNotFoundWithMessage,
url, msg);
} else {
text = MessageFormat.format(JGitText.get().uriNotFound, url);
}
return new NoRemoteRepositoryException(u, text);
}
private HttpConnection connect(String service) private HttpConnection connect(String service)
throws TransportException, NotSupportedException { throws TransportException, NotSupportedException {
URL u = getServiceURL(service); URL u = getServiceURL(service);
@ -511,8 +523,8 @@ public class TransportHttp extends HttpTransport implements WalkTransport,
return conn; return conn;
case HttpConnection.HTTP_NOT_FOUND: case HttpConnection.HTTP_NOT_FOUND:
throw new NoRemoteRepositoryException(uri, throw createNotFoundException(uri, u,
MessageFormat.format(JGitText.get().uriNotFound, u)); conn.getResponseMessage());
case HttpConnection.HTTP_UNAUTHORIZED: case HttpConnection.HTTP_UNAUTHORIZED:
authMethod = HttpAuthMethod.scanResponse(conn, ignoreTypes); authMethod = HttpAuthMethod.scanResponse(conn, ignoreTypes);
@ -1180,9 +1192,8 @@ public class TransportHttp extends HttpTransport implements WalkTransport,
return; return;
case HttpConnection.HTTP_NOT_FOUND: case HttpConnection.HTTP_NOT_FOUND:
throw new NoRemoteRepositoryException(uri, throw createNotFoundException(uri, conn.getURL(),
MessageFormat.format(JGitText.get().uriNotFound, conn.getResponseMessage());
conn.getURL()));
case HttpConnection.HTTP_FORBIDDEN: case HttpConnection.HTTP_FORBIDDEN:
throw new TransportException(uri, throw new TransportException(uri,

Loading…
Cancel
Save