Example usage for org.eclipse.jgit.transport UploadPack setTimeout

List of usage examples for org.eclipse.jgit.transport UploadPack setTimeout

Introduction

In this page you can find the example usage for org.eclipse.jgit.transport UploadPack setTimeout.

Prototype

public void setTimeout(int seconds) 

Source Link

Document

Set the timeout before willing to abort an IO call.

Usage

From source file:com.gitblit.git.GitblitUploadPackFactory.java

License:Apache License

@Override
public UploadPack create(X req, Repository db)
        throws ServiceNotEnabledException, ServiceNotAuthorizedException {

    int timeout = 0;

    if (req instanceof GitDaemonClient) {
        // git daemon request is always anonymous
        GitDaemonClient client = (GitDaemonClient) req;
        // set timeout from Git daemon
        timeout = client.getDaemon().getTimeout();
    }//from   www  .  java2 s .c  o m

    UploadPack up = new UploadPack(db);
    up.setTimeout(timeout);

    return up;
}

From source file:com.google.gerrit.sshd.commands.Upload.java

License:Apache License

@Override
protected void runImpl() throws IOException, Failure {
    if (!projectControl.canRunUploadPack()) {
        throw new Failure(1, "fatal: upload-pack not permitted on this server");
    }//w w w  .j  av  a  2  s.  c  om

    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());
        }
    }
}

From source file:net.antoniy.gidder.beta.ssh.Upload.java

License:Apache License

@Override
protected void runImpl() throws IOException {
    if (!hasPermission()) {
        err.write(MSG_REPOSITORY_PERMISSIONS.getBytes());
        err.flush();//from   w w w.  j av a  2 s .  c  o m
        onExit(CODE_OK, MSG_REPOSITORY_PERMISSIONS);
        return;
    }

    Config config = new Config();
    //      int timeout = Integer.parseInt(config.getString("transfer", null,
    //            "timeout"));
    int timeout = 10;

    PackConfig packConfig = new PackConfig();
    packConfig.setDeltaCompress(false);
    packConfig.setThreads(1);
    packConfig.fromConfig(config);

    final UploadPack up = new UploadPack(repo);
    up.setPackConfig(packConfig);
    up.setTimeout(timeout);
    up.upload(in, out, err);
}

From source file:net.community.chest.gitcloud.facade.backend.git.BackendUploadPackFactory.java

License:Apache License

@Override
public UploadPack create(final C request, Repository db)
        throws ServiceNotEnabledException, ServiceNotAuthorizedException {
    final File dir = db.getDirectory();
    final String logPrefix;
    if (request instanceof HttpServletRequest) {
        HttpServletRequest req = (HttpServletRequest) request;
        logPrefix = "create(" + req.getMethod() + ")[" + req.getRequestURI() + "][" + req.getQueryString()
                + "]";
    } else {//ww w  .j ava 2  s  .  c o  m
        logPrefix = "create(" + dir.getAbsolutePath() + ")";
    }
    if (logger.isDebugEnabled()) {
        logger.debug(logPrefix + ": " + dir.getAbsolutePath());
    }

    UploadPack up = new UploadPack(db) {
        @Override
        @SuppressWarnings("synthetic-access")
        public void upload(InputStream input, OutputStream output, OutputStream messages) throws IOException {
            InputStream effIn = input;
            OutputStream effOut = output, effMessages = messages;
            if (logger.isTraceEnabled()) {
                LineLevelAppender inputAppender = new LineLevelAppender() {
                    @Override
                    public void writeLineData(CharSequence lineData) throws IOException {
                        logger.trace(logPrefix + " upload(C): " + lineData);
                    }

                    @Override
                    public boolean isWriteEnabled() {
                        return true;
                    }
                };
                effIn = new TeeInputStream(effIn, new HexDumpOutputStream(inputAppender), true);

                LineLevelAppender outputAppender = new LineLevelAppender() {
                    @Override
                    public void writeLineData(CharSequence lineData) throws IOException {
                        logger.trace(logPrefix + " upload(S): " + lineData);
                    }

                    @Override
                    public boolean isWriteEnabled() {
                        return true;
                    }
                };
                effOut = new TeeOutputStream(effOut, new HexDumpOutputStream(outputAppender));

                if (effMessages != null) {
                    LineLevelAppender messagesAppender = new LineLevelAppender() {
                        @Override
                        public void writeLineData(CharSequence lineData) throws IOException {
                            logger.trace(logPrefix + " upload(M): " + lineData);
                        }

                        @Override
                        public boolean isWriteEnabled() {
                            return true;
                        }
                    };
                    // TODO review the decision to use an AsciiLineOutputStream here
                    effMessages = new TeeOutputStream(effMessages, new AsciiLineOutputStream(messagesAppender));
                }
            }

            super.upload(effIn, effOut, effMessages);
        }

        @Override
        @SuppressWarnings("synthetic-access")
        public void sendAdvertisedRefs(RefAdvertiser adv) throws IOException, ServiceMayNotContinueException {
            RefAdvertiser effAdv = adv;
            if (logger.isTraceEnabled() && (adv instanceof PacketLineOutRefAdvertiser)) {
                PacketLineOut pckOut = (PacketLineOut) ReflectionUtils.getField(pckOutField, adv);
                effAdv = new PacketLineOutRefAdvertiser(pckOut) {
                    private final PacketLineOut pckLog = new PacketLineOut( // TODO review the decision to use an AsciiLineOutputStream here
                            new AsciiLineOutputStream(new LineLevelAppender() {
                                @Override
                                public void writeLineData(CharSequence lineData) throws IOException {
                                    logger.trace(logPrefix + " S: " + lineData);
                                }

                                @Override
                                public boolean isWriteEnabled() {
                                    return true;
                                }
                            }));

                    @Override
                    protected void writeOne(CharSequence line) throws IOException {
                        String s = line.toString();
                        super.writeOne(s);
                        pckLog.writeString(s);
                    }

                    @Override
                    protected void end() throws IOException {
                        super.end();
                        pckLog.end();
                    }
                };
            }

            super.sendAdvertisedRefs(effAdv);
        }
    };
    up.setTimeout(uploadTimeoutValue);
    return up;
}