James Moger
2011-10-26 8b76369fb44bfd863b27bcede453d676905f52e5
Properly catch Not Allowed (405) and Unknown Request (501) errors
7 files modified
70 ■■■■■ changed files
src/com/gitblit/GitBlitException.java 15 ●●●●● patch | view | raw | blame | history
src/com/gitblit/client/GitblitClient.java 14 ●●●● patch | view | raw | blame | history
src/com/gitblit/client/GitblitManager.java 7 ●●●●● patch | view | raw | blame | history
src/com/gitblit/client/GitblitPanel.java 1 ●●●● patch | view | raw | blame | history
src/com/gitblit/client/GitblitWorker.java 6 ●●●●● patch | view | raw | blame | history
src/com/gitblit/client/Utils.java 15 ●●●●● patch | view | raw | blame | history
src/com/gitblit/utils/JsonUtils.java 12 ●●●●● patch | view | raw | blame | history
src/com/gitblit/GitBlitException.java
@@ -56,7 +56,20 @@
            super(message);
        }
    }
    /**
     * Exception to indicate that the requested action has been disabled on the
     * Gitblit server.
     */
    public static class NotAllowedException extends GitBlitException {
        private static final long serialVersionUID = 1L;
        public NotAllowedException(String message) {
            super(message);
        }
    }
    /**
     * Exception to indicate that the requested action can not be executed by
     * the server because it does not recognize the request type.
src/com/gitblit/client/GitblitClient.java
@@ -23,7 +23,9 @@
import java.util.Map;
import com.gitblit.GitBlitException.ForbiddenException;
import com.gitblit.GitBlitException.NotAllowedException;
import com.gitblit.GitBlitException.UnauthorizedException;
import com.gitblit.GitBlitException.UnknownRequestException;
import com.gitblit.Keys;
import com.gitblit.models.FederationModel;
import com.gitblit.models.RepositoryModel;
@@ -78,21 +80,25 @@
        try {
            refreshUsers();
            refreshSettings();
            allowManagement = true;
        } catch (UnauthorizedException e) {
        } catch (ForbiddenException e) {
        } catch (NotAllowedException e) {
        } catch (UnknownRequestException e) {
        } catch (IOException e) {
            System.err.println(e.getMessage());
            e.printStackTrace();
        }
        try {
            refreshSettings();
            refreshStatus();
            allowAdministration = true;
        } catch (UnauthorizedException e) {
        } catch (ForbiddenException e) {
        } catch (NotAllowedException e) {
        } catch (UnknownRequestException e) {
        } catch (IOException e) {
            System.err.println(e.getMessage());
            e.printStackTrace();
        }
    }
@@ -141,7 +147,7 @@
        settings = RpcUtils.getSettings(url, account, password);
        return settings;
    }
    public ServerStatus refreshStatus() throws IOException {
        status = RpcUtils.getStatus(url, account, password);
        return status;
src/com/gitblit/client/GitblitManager.java
@@ -65,6 +65,7 @@
import org.eclipse.jgit.util.FS;
import com.gitblit.Constants;
import com.gitblit.GitBlitException.ForbiddenException;
import com.gitblit.utils.StringUtils;
/**
@@ -277,6 +278,12 @@
                    if (cause instanceof ConnectException) {
                        JOptionPane.showMessageDialog(GitblitManager.this, cause.getMessage(),
                                Translation.get("gb.error"), JOptionPane.ERROR_MESSAGE);
                    } else if (cause instanceof ForbiddenException) {
                        JOptionPane
                                .showMessageDialog(
                                        GitblitManager.this,
                                        "This Gitblit server does not allow RPC Management or Administration",
                                        Translation.get("gb.error"), JOptionPane.ERROR_MESSAGE);
                    } else {
                        Utils.showException(GitblitManager.this, t);
                    }
src/com/gitblit/client/GitblitPanel.java
@@ -683,6 +683,7 @@
        dialog.setLocationRelativeTo(GitblitPanel.this);
        dialog.setUsers(null, gitblit.getUsernames(), null);
        dialog.setRepositories(gitblit.getRepositories());
        dialog.setFederationSets(gitblit.getFederationSets(), null);
        dialog.setVisible(true);
        final RepositoryModel newRepository = dialog.getRepository();
        final List<String> permittedUsers = dialog.getPermittedUsers();
src/com/gitblit/client/GitblitWorker.java
@@ -24,7 +24,9 @@
import com.gitblit.Constants.RpcRequest;
import com.gitblit.GitBlitException.ForbiddenException;
import com.gitblit.GitBlitException.NotAllowedException;
import com.gitblit.GitBlitException.UnauthorizedException;
import com.gitblit.GitBlitException.UnknownRequestException;
public abstract class GitblitWorker extends SwingWorker<Boolean, Void> {
@@ -59,6 +61,10 @@
                Utils.explainForbidden(parent, request);
            } else if (t instanceof UnauthorizedException) {
                Utils.explainUnauthorized(parent, request);
            } else if (t instanceof NotAllowedException) {
                Utils.explainNotAllowed(parent, request);
            } else if (t instanceof UnknownRequestException) {
                Utils.explainNotAllowed(parent, request);
            } else {
                Utils.showException(parent, t);
            }
src/com/gitblit/client/Utils.java
@@ -48,9 +48,16 @@
        return table;
    }
    public static void explainNotAllowed(Component c, RpcRequest request) {
        String msg = MessageFormat.format("The Gitblit server does not allow the request \"{0}\".",
                request.name());
        JOptionPane.showMessageDialog(c, msg, "Not Allowed", JOptionPane.ERROR_MESSAGE);
    }
    public static void explainForbidden(Component c, RpcRequest request) {
        String msg = MessageFormat.format(
                "The request \"{0}\" has been forbidden by the Gitblit server.", request.name());
                "The request \"{0}\" has been forbidden for the account by the Gitblit server.",
                request.name());
        JOptionPane.showMessageDialog(c, msg, "Forbidden", JOptionPane.ERROR_MESSAGE);
    }
@@ -60,6 +67,12 @@
        JOptionPane.showMessageDialog(c, msg, "Unauthorized", JOptionPane.ERROR_MESSAGE);
    }
    public static void explainUnknown(Component c, RpcRequest request) {
        String msg = MessageFormat.format(
                "The request \"{0}\" is not recognized by the Gitblit server.", request.name());
        JOptionPane.showMessageDialog(c, msg, "Unknown Request", JOptionPane.ERROR_MESSAGE);
    }
    public static void showException(Component c, Throwable t) {
        StringWriter writer = new StringWriter();
        t.printStackTrace(new PrintWriter(writer));
src/com/gitblit/utils/JsonUtils.java
@@ -46,6 +46,7 @@
import org.eclipse.jgit.util.Base64;
import com.gitblit.GitBlitException.ForbiddenException;
import com.gitblit.GitBlitException.NotAllowedException;
import com.gitblit.GitBlitException.UnauthorizedException;
import com.gitblit.GitBlitException.UnknownRequestException;
import com.gitblit.models.RepositoryModel;
@@ -158,7 +159,7 @@
        }
        return gson().fromJson(json, type);
    }
    /**
     * Reads a gson object from the specified url.
     * 
@@ -216,6 +217,12 @@
            } else if (e.getMessage().indexOf("403") > -1) {
                // requested url is forbidden by the requesting user
                throw new ForbiddenException(url);
            } else if (e.getMessage().indexOf("405") > -1) {
                // requested url is not allowed by the server
                throw new NotAllowedException(url);
            } else if (e.getMessage().indexOf("501") > -1) {
                // requested url is not recognized by the server
                throw new UnknownRequestException(url);
            }
            throw e;
        }
@@ -278,6 +285,9 @@
            } else if (e.getMessage().indexOf("403") > -1) {
                // requested url is forbidden by the requesting user
                throw new ForbiddenException(url);
            } else if (e.getMessage().indexOf("405") > -1) {
                // requested url is not allowed by the server
                throw new NotAllowedException(url);
            } else if (e.getMessage().indexOf("501") > -1) {
                // requested url is not recognized by the server
                throw new UnknownRequestException(url);