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

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

Introduction

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

Prototype

public NotSupportedException(String s, Throwable why) 

Source Link

Document

Construct a NotSupportedException for some issue JGit cannot yet handle.

Usage

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

License:Eclipse Distribution License

FixedTransportHttp(final Repository local, final URIish uri) throws NotSupportedException {
    super(local, uri);
    try {/* ww w .j av a  2s .c  o m*/
        String uriString = uri.toString();
        if (!uriString.endsWith("/")) //$NON-NLS-1$
            uriString += "/"; //$NON-NLS-1$
        baseUrl = new URL(uriString);
        objectsUrl = new URL(baseUrl, "objects/"); //$NON-NLS-1$
    } catch (MalformedURLException e) {
        throw new NotSupportedException(MessageFormat.format(JGitText.get().invalidURL, uri), e);
    }
    http = local.getConfig().get(HTTP_KEY);
    proxySelector = ProxySelector.getDefault();
}

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 ww  w . j  a  va2 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);
    }
}