Search in sources :

Example 1 with HttpRedirect

use of org.kohsuke.stapler.HttpRedirect in project hudson-2.x by hudson.

the class PluginManager method doUploadPlugin.

/**
     * Uploads a plugin.
     */
public HttpResponse doUploadPlugin(StaplerRequest req) throws IOException, ServletException {
    try {
        Hudson.getInstance().checkPermission(Hudson.ADMINISTER);
        ServletFileUpload upload = new ServletFileUpload(new DiskFileItemFactory());
        // Parse the request
        FileItem fileItem = (FileItem) upload.parseRequest(req).get(0);
        String fileName = Util.getFileName(fileItem.getName());
        if ("".equals(fileName))
            return new HttpRedirect("advanced");
        if (!fileName.endsWith(".hpi"))
            throw new Failure(hudson.model.Messages.Hudson_NotAPlugin(fileName));
        fileItem.write(new File(rootDir, fileName));
        fileItem.delete();
        pluginUploaded = true;
        return new HttpRedirect(".");
    } catch (IOException e) {
        throw e;
    } catch (Exception e) {
        // grrr. fileItem.write throws this
        throw new ServletException(e);
    }
}
Also used : ServletException(javax.servlet.ServletException) FileItem(org.apache.commons.fileupload.FileItem) HttpRedirect(org.kohsuke.stapler.HttpRedirect) ServletFileUpload(org.apache.commons.fileupload.servlet.ServletFileUpload) IOException(java.io.IOException) DiskFileItemFactory(org.apache.commons.fileupload.disk.DiskFileItemFactory) File(java.io.File) Failure(hudson.model.Failure) ServletException(javax.servlet.ServletException) CycleDetectedException(hudson.util.CyclicGraphDetector.CycleDetectedException) IOException(java.io.IOException)

Example 2 with HttpRedirect

use of org.kohsuke.stapler.HttpRedirect in project hudson-2.x by hudson.

the class PluginManager method doProxyConfigure.

public HttpResponse doProxyConfigure(@QueryParameter("proxy.server") String server, @QueryParameter("proxy.port") String port, @QueryParameter("proxy.noProxyFor") String noProxyFor, @QueryParameter("proxy.userName") String userName, @QueryParameter("proxy.password") String password, @QueryParameter("proxy.authNeeded") String authNeeded) throws IOException {
    Hudson hudson = Hudson.getInstance();
    hudson.checkPermission(Hudson.ADMINISTER);
    server = Util.fixEmptyAndTrim(server);
    if ((server != null) && !"".equals(server)) {
        // If port is not specified assume it is port 80 (usual default for HTTP port)
        int portNumber = 80;
        if (!"".equals(Util.fixNull(port))) {
            portNumber = Integer.parseInt(Util.fixNull(port));
        }
        boolean proxyAuthNeeded = "on".equals(Util.fixNull(authNeeded));
        if (!proxyAuthNeeded) {
            userName = "";
            password = "";
        }
        hudson.proxy = new ProxyConfiguration(server, portNumber, Util.fixEmptyAndTrim(noProxyFor), Util.fixEmptyAndTrim(userName), Util.fixEmptyAndTrim(password), "on".equals(Util.fixNull(authNeeded)));
        hudson.proxy.save();
    } else {
        hudson.proxy = null;
        ProxyConfiguration.getXmlFile().delete();
    }
    return new HttpRedirect("advanced");
}
Also used : HttpRedirect(org.kohsuke.stapler.HttpRedirect) Hudson(hudson.model.Hudson)

Example 3 with HttpRedirect

use of org.kohsuke.stapler.HttpRedirect in project hudson-2.x by hudson.

the class PluginManager method doUpdateSources.

public HttpResponse doUpdateSources(StaplerRequest req) throws IOException {
    Hudson.getInstance().checkPermission(Hudson.ADMINISTER);
    if (req.hasParameter("remove")) {
        UpdateCenter uc = Hudson.getInstance().getUpdateCenter();
        BulkChange bc = new BulkChange(uc);
        try {
            for (String id : req.getParameterValues("sources")) uc.getSites().remove(uc.getById(id));
        } finally {
            bc.commit();
        }
    } else if (req.hasParameter("add"))
        return new HttpRedirect("addSite");
    return new HttpRedirect("./sites");
}
Also used : HttpRedirect(org.kohsuke.stapler.HttpRedirect) UpdateCenter(hudson.model.UpdateCenter)

Example 4 with HttpRedirect

use of org.kohsuke.stapler.HttpRedirect in project hudson-2.x by hudson.

the class LogRecorderManager method doConfigLogger.

/**
     * Configure the logging level.
     */
public HttpResponse doConfigLogger(@QueryParameter String name, @QueryParameter String level) {
    Hudson.getInstance().checkPermission(Hudson.ADMINISTER);
    Level lv;
    if (level.equals("inherit"))
        lv = null;
    else
        lv = Level.parse(level.toUpperCase(Locale.ENGLISH));
    Logger.getLogger(name).setLevel(lv);
    return new HttpRedirect("levels");
}
Also used : HttpRedirect(org.kohsuke.stapler.HttpRedirect) Level(java.util.logging.Level)

Aggregations

HttpRedirect (org.kohsuke.stapler.HttpRedirect)4 Failure (hudson.model.Failure)1 Hudson (hudson.model.Hudson)1 UpdateCenter (hudson.model.UpdateCenter)1 CycleDetectedException (hudson.util.CyclicGraphDetector.CycleDetectedException)1 File (java.io.File)1 IOException (java.io.IOException)1 Level (java.util.logging.Level)1 ServletException (javax.servlet.ServletException)1 FileItem (org.apache.commons.fileupload.FileItem)1 DiskFileItemFactory (org.apache.commons.fileupload.disk.DiskFileItemFactory)1 ServletFileUpload (org.apache.commons.fileupload.servlet.ServletFileUpload)1