Example usage for org.eclipse.jgit.errors NoRemoteRepositoryException NoRemoteRepositoryException

List of usage examples for org.eclipse.jgit.errors NoRemoteRepositoryException NoRemoteRepositoryException

Introduction

In this page you can find the example usage for org.eclipse.jgit.errors NoRemoteRepositoryException NoRemoteRepositoryException.

Prototype

public NoRemoteRepositoryException(URIish uri, String s) 

Source Link

Document

Constructs an exception indicating a repository does not exist.

Usage

From source file:it.com.atlassian.labs.speakeasy.util.jgit.FixedTransportHttp.java

License:Eclipse Distribution License

private HttpURLConnection connect(final String service) throws TransportException, NotSupportedException {
    final URL u;
    try {//from   w  ww.  j  ava  2 s  .  c om
        final StringBuilder b = new StringBuilder();
        b.append(baseUrl);

        if (b.charAt(b.length() - 1) != '/')
            b.append('/');
        b.append(Constants.INFO_REFS);

        if (useSmartHttp) {
            b.append(b.indexOf("?") < 0 ? '?' : '&'); //$NON-NLS-1$
            b.append("service="); //$NON-NLS-1$
            b.append(service);
        }

        u = new URL(b.toString());
    } catch (MalformedURLException e) {
        throw new NotSupportedException(MessageFormat.format(JGitText.get().invalidURL, uri), e);
    }

    try {
        int authAttempts = 1;
        for (;;) {
            final HttpURLConnection conn = httpOpen(u);
            if (useSmartHttp) {
                String exp = "application/x-" + service + "-advertisement"; //$NON-NLS-1$ //$NON-NLS-2$
                conn.setRequestProperty(HDR_ACCEPT, exp + ", */*"); //$NON-NLS-1$
            } else {
                conn.setRequestProperty(HDR_ACCEPT, "*/*"); //$NON-NLS-1$
            }
            final int status = HttpSupport.response(conn);
            switch (status) {
            case HttpURLConnection.HTTP_OK:
                return conn;

            case HttpURLConnection.HTTP_NOT_FOUND:
                throw new NoRemoteRepositoryException(uri, MessageFormat.format(JGitText.get().uriNotFound, u));

            case HttpURLConnection.HTTP_UNAUTHORIZED:
                authMethod = HttpAuthMethod.scanResponse(conn);
                if (authMethod == HttpAuthMethod.NONE)
                    throw new TransportException(uri,
                            MessageFormat.format(JGitText.get().authenticationNotSupported, uri));
                if (1 < authAttempts || !authMethod.authorize(uri, getCredentialsProvider())) {
                    throw new TransportException(uri, JGitText.get().notAuthorized);
                }
                authAttempts++;
                continue;

            case HttpURLConnection.HTTP_FORBIDDEN:
                throw new TransportException(uri,
                        MessageFormat.format(JGitText.get().serviceNotPermitted, service));

            default:
                String err = status + " " + conn.getResponseMessage(); //$NON-NLS-1$
                throw new TransportException(uri, err);
            }
        }
    } catch (NotSupportedException e) {
        throw e;
    } catch (TransportException e) {
        throw e;
    } catch (IOException e) {
        throw new TransportException(uri, MessageFormat.format(JGitText.get().cannotOpenService, service), e);
    }
}