Example #1
0
  /**
   * Git advertise 요청을 처리한다.
   *
   * <p>when: {@link controllers.GitApp#service(String, String, String, boolean)}에서 사용한다.
   *
   * @param project
   * @param service
   * @param response
   * @return
   * @throws IOException
   * @see <a
   *     href="https://www.kernel.org/pub/software/scm/git/docs/git-upload-pack.html">git-upload-pack</a>
   * @see <a
   *     href="https://www.kernel.org/pub/software/scm/git/docs/git-receive-pack.html">git-receive-pack</a>
   */
  public static byte[] gitAdvertise(Project project, String service, Response response)
      throws IOException {
    response.setContentType("application/x-" + service + "-advertisement");

    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    PacketLineOut packetLineOut = new PacketLineOut(byteArrayOutputStream);
    packetLineOut.writeString("# service=" + service + "\n");
    packetLineOut.end();
    PacketLineOutRefAdvertiser packetLineOutRefAdvertiser =
        new PacketLineOutRefAdvertiser(packetLineOut);

    Repository repository = createGitRepository(project);

    if (service.equals("git-upload-pack")) {
      UploadPack uploadPack = new UploadPack(repository);
      uploadPack.setBiDirectionalPipe(false);
      uploadPack.sendAdvertisedRefs(packetLineOutRefAdvertiser);
    } else if (service.equals("git-receive-pack")) {
      ReceivePack receivePack = new ReceivePack(repository);
      receivePack.sendAdvertisedRefs(packetLineOutRefAdvertiser);
    }

    byteArrayOutputStream.close();

    return byteArrayOutputStream.toByteArray();
  }
Example #2
0
  @Override
  public void doPost(final HttpServletRequest req, final HttpServletResponse rsp)
      throws IOException {
    if (!REQ_TYPE.equals(req.getContentType())) {
      rsp.sendError(SC_UNSUPPORTED_MEDIA_TYPE);
      return;
    }

    final Repository db = getRepository(req);
    try {
      final UploadPack up = uploadPackFactory.create(req, db);
      up.setBiDirectionalPipe(false);
      rsp.setContentType(RSP_TYPE);

      final SmartOutputStream out = new SmartOutputStream(req, rsp);
      up.upload(getInputStream(req), out, null);
      out.close();

    } catch (ServiceNotAuthorizedException e) {
      rsp.reset();
      rsp.sendError(SC_UNAUTHORIZED);
      return;

    } catch (ServiceNotEnabledException e) {
      rsp.reset();
      rsp.sendError(SC_FORBIDDEN);
      return;

    } catch (IOException e) {
      getServletContext().log("Internal error during upload-pack", e);
      rsp.reset();
      rsp.sendError(SC_INTERNAL_SERVER_ERROR);
      return;
    }
  }
Example #3
0
  /**
   * GIT RPC 요청을 처리합니다.
   *
   * <p>when: {@link controllers.GitApp#service(String, String, String, boolean)}에서 사용한다.
   *
   * @param project
   * @param service
   * @param request
   * @param response
   * @return
   * @throws IOException
   * @see <a
   *     href="https://www.kernel.org/pub/software/scm/git/docs/git-upload-pack.html">git-upload-pack</a>
   * @see <a
   *     href="https://www.kernel.org/pub/software/scm/git/docs/git-receive-pack.html">git-receive-pack</a>
   */
  public static byte[] gitRpc(Project project, String service, Request request, Response response)
      throws IOException {
    response.setContentType("application/x-" + service + "-result");
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();

    // FIXME 스트림으로..
    RawBuffer raw = request.body().asRaw();
    byte[] buf = raw.asBytes();
    InputStream in;

    // If the content size is bigger than memoryThreshold,
    // which is defined as 100 * 1024 in play.api.mvc.BodyParsers trait,
    // the content is stored as a file.
    if (buf != null) {
      in = new ByteArrayInputStream(buf);
    } else {
      in = new FileInputStream(raw.asFile());
    }

    Repository repository = createGitRepository(project);

    if (service.equals("git-upload-pack")) {
      UploadPack uploadPack = new UploadPack(repository);
      uploadPack.setBiDirectionalPipe(false);
      uploadPack.upload(in, byteArrayOutputStream, null);
    } else if (service.equals("git-receive-pack")) {
      ReceivePack receivePack = new ReceivePack(repository);
      receivePack.setBiDirectionalPipe(false);
      receivePack.receive(in, byteArrayOutputStream, null);
    }

    // receivePack.setEchoCommandFailures(true);//git버전에 따라서 불린값 설정필요.
    byteArrayOutputStream.close();

    return byteArrayOutputStream.toByteArray();
  }