Example usage for org.eclipse.jgit.lib Constants INFO_REFS

List of usage examples for org.eclipse.jgit.lib Constants INFO_REFS

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib Constants INFO_REFS.

Prototype

String INFO_REFS

To view the source code for org.eclipse.jgit.lib Constants INFO_REFS.

Click Source Link

Document

Info refs folder

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  a  va2  s.  c o  m
        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);
    }
}

From source file:org.webcat.core.git.http.GitRequestHandler.java

License:Open Source License

/**
 * Initializes a new GitRequestHandler.//from  w  w  w .j a  va2  s.c  o  m
 */
public GitRequestHandler() {
    // Enable Smart HTTP receive and upload.

    serve("*/git-receive-pack").with(new ReceivePackRequestHandler());
    serve("*/git-upload-pack").with(new UploadPackRequestHandler());

    // Filter accesses to the Git info/refs file through our advertisers
    // so that clients will use Smart HTTP functionality.

    serve("*/" + Constants.INFO_REFS).through(new UploadPackRequestHandler.InfoRefs())
            .through(new ReceivePackRequestHandler.InfoRefs()).with(new InfoRefsRequestHandler());

    // Finally, serve any request that doesn't match the above with a
    // standard Web-DAV response.

    serve("*").with(new GitWebRequestHandler());
}