@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; } }
@Override protected void runImpl() throws IOException, Failure { if (!projectControl.canRunUploadPack()) { throw new Failure(1, "fatal: upload-pack not permitted on this server"); } final UploadPack up = new UploadPack(repo); if (!projectControl.allRefsAreVisible()) { up.setAdvertiseRefsHook( new VisibleRefFilter(tagCache, changeCache, repo, projectControl, db.get(), true)); } up.setPackConfig(config.getPackConfig()); up.setTimeout(config.getTimeout()); List<PreUploadHook> allPreUploadHooks = Lists.newArrayList(preUploadHooks); allPreUploadHooks.add( uploadValidatorsFactory.create(project, repo, session.getRemoteAddressAsString())); up.setPreUploadHook(PreUploadHookChain.newChain(allPreUploadHooks)); try { up.upload(in, out, err); } catch (UploadValidationException e) { // UploadValidationException is used by the UploadValidators to // stop the uploadPack. We do not want this exception to go beyond this // point otherwise it would print a stacktrace in the logs and return an // internal server error to the client. if (!e.isOutput()) { up.sendMessage(e.getMessage()); } } }
/** * 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(); }