Package org.eclipse.jgit.transport.http

Examples of org.eclipse.jgit.transport.http.HttpConnection


    @Override
    FileStream open(final String path) throws IOException {
      final URL base = httpObjectsUrl;
      final URL u = new URL(base, path);
      final HttpConnection c = httpOpen(u);
      switch (HttpSupport.response(c)) {
      case HttpConnection.HTTP_OK:
        final InputStream in = openInputStream(c);
        final int len = c.getContentLength();
        return new FileStream(in, len);
      case HttpConnection.HTTP_NOT_FOUND:
        throw new FileNotFoundException(u.toString());
      default:
        throw new IOException(u.toString() + ": " //$NON-NLS-1$
            + HttpSupport.response(c) + " " //$NON-NLS-1$
            + c.getResponseMessage());
      }
    }
View Full Code Here


  @Override
  public FetchConnection openFetch() throws TransportException,
      NotSupportedException {
    final String service = SVC_UPLOAD_PACK;
    try {
      final HttpConnection c = connect(service);
      final InputStream in = openInputStream(c);
      try {
        if (isSmartHttp(c, service)) {
          readSmartHeaders(in, service);
          return new SmartHttpFetchConnection(in);
View Full Code Here

    if (!refs.containsKey(Constants.HEAD)) {
      // If HEAD was not published in the info/refs file (it usually
      // is not there) download HEAD by itself as a loose file and do
      // the resolution by hand.
      //
      HttpConnection conn = httpOpen(new URL(baseUrl, Constants.HEAD));
      int status = HttpSupport.response(conn);
      switch (status) {
      case HttpConnection.HTTP_OK: {
        br = toBufferedReader(openInputStream(conn));
        try {
          String line = br.readLine();
          if (line != null && line.startsWith(RefDirectory.SYMREF)) {
            String target = line.substring(RefDirectory.SYMREF.length());
            Ref r = refs.get(target);
            if (r == null)
              r = new ObjectIdRef.Unpeeled(Ref.Storage.NEW, target, null);
            r = new SymbolicRef(Constants.HEAD, r);
            refs.put(r.getName(), r);
          } else if (line != null && ObjectId.isId(line)) {
            Ref r = new ObjectIdRef.Unpeeled(Ref.Storage.NETWORK,
                Constants.HEAD, ObjectId.fromString(line));
            refs.put(r.getName(), r);
          }
        } finally {
          br.close();
        }
        break;
      }

      case HttpConnection.HTTP_NOT_FOUND:
        break;

      default:
        throw new TransportException(uri, MessageFormat.format(
            JGitText.get().cannotReadHEAD, Integer.valueOf(status),
            conn.getResponseMessage()));
      }
    }

    WalkFetchConnection wfc = new WalkFetchConnection(this, d);
    wfc.available(refs);
View Full Code Here

  @Override
  public PushConnection openPush() throws NotSupportedException,
      TransportException {
    final String service = SVC_RECEIVE_PACK;
    try {
      final HttpConnection c = connect(service);
      final InputStream in = openInputStream(c);
      try {
        if (isSmartHttp(c, service)) {
          readSmartHeaders(in, service);
          return new SmartHttpPushConnection(in);
View Full Code Here

    }

    try {
      int authAttempts = 1;
      for (;;) {
        final HttpConnection 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 HttpConnection.HTTP_OK:
          // Check if HttpConnection did some authentication in the
          // background (e.g Kerberos/SPNEGO).
          // That may not work for streaming requests and jgit
          // explicit authentication would be required
          if (authMethod.getType() == HttpAuthMethod.Type.NONE
              && conn.getHeaderField(HDR_WWW_AUTHENTICATE) != null)
            authMethod = HttpAuthMethod.scanResponse(conn);
          return conn;

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

        case HttpConnection.HTTP_UNAUTHORIZED:
          authMethod = HttpAuthMethod.scanResponse(conn);
          if (authMethod.getType() == HttpAuthMethod.Type.NONE)
            throw new TransportException(uri, MessageFormat.format(
                JGitText.get().authenticationNotSupported, uri));
          CredentialsProvider credentialsProvider = getCredentialsProvider();
          if (credentialsProvider == null)
            throw new TransportException(uri,
                JGitText.get().noCredentialsProvider);
          if (authAttempts > 1)
            credentialsProvider.reset(uri);
          if (3 < authAttempts
              || !authMethod.authorize(uri, credentialsProvider)) {
            throw new TransportException(uri,
                JGitText.get().notAuthorized);
          }
          authAttempts++;
          continue;

        case HttpConnection.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;
View Full Code Here

   * @since 3.3
   */
  protected HttpConnection httpOpen(String method, URL u)
      throws IOException {
    final Proxy proxy = HttpSupport.proxyFor(proxySelector, u);
    HttpConnection conn = connectionFactory.create(u, proxy);

    if (!http.sslVerify && "https".equals(u.getProtocol())) { //$NON-NLS-1$
      disableSslVerify(conn);
    }

    conn.setRequestMethod(method);
    conn.setUseCaches(false);
    conn.setRequestProperty(HDR_ACCEPT_ENCODING, ENCODING_GZIP);
    conn.setRequestProperty(HDR_PRAGMA, "no-cache"); //$NON-NLS-1$
    conn.setRequestProperty(HDR_USER_AGENT, userAgent);
    int timeOut = getTimeout();
    if (timeOut != -1) {
      int effTimeOut = timeOut * 1000;
      conn.setConnectTimeout(effTimeOut);
      conn.setReadTimeout(effTimeOut);
    }
    if (this.headers != null && !this.headers.isEmpty()) {
      for (Map.Entry<String, String> entry : this.headers.entrySet())
        conn.setRequestProperty(entry.getKey(), entry.getValue());
    }
    authMethod.configureRequest(conn);
    return conn;
  }
View Full Code Here

TOP

Related Classes of org.eclipse.jgit.transport.http.HttpConnection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.