]> source.dussan.org Git - gitblit.git/commitdiff
Properly catch Not Allowed (405) and Unknown Request (501) errors
authorJames Moger <james.moger@gitblit.com>
Wed, 26 Oct 2011 21:12:50 +0000 (17:12 -0400)
committerJames Moger <james.moger@gitblit.com>
Wed, 26 Oct 2011 21:12:50 +0000 (17:12 -0400)
src/com/gitblit/GitBlitException.java
src/com/gitblit/client/GitblitClient.java
src/com/gitblit/client/GitblitManager.java
src/com/gitblit/client/GitblitPanel.java
src/com/gitblit/client/GitblitWorker.java
src/com/gitblit/client/Utils.java
src/com/gitblit/utils/JsonUtils.java

index 1111463f31333dd98048c41462af34fc23556772..360f9f0af3071b0a4c4e5a322afecea65eb09c74 100644 (file)
@@ -56,7 +56,20 @@ public class GitBlitException extends IOException {
                        super(message);\r
                }\r
        }\r
-       \r
+\r
+       /**\r
+        * Exception to indicate that the requested action has been disabled on the\r
+        * Gitblit server.\r
+        */\r
+       public static class NotAllowedException extends GitBlitException {\r
+\r
+               private static final long serialVersionUID = 1L;\r
+\r
+               public NotAllowedException(String message) {\r
+                       super(message);\r
+               }\r
+       }\r
+\r
        /**\r
         * Exception to indicate that the requested action can not be executed by\r
         * the server because it does not recognize the request type.\r
index 761283eb29df5da37ea8fcb424fe27c8c24ded3d..9f4dd3e69edc24fee621e7f2af9db31771bceafa 100644 (file)
@@ -23,7 +23,9 @@ import java.util.List;
 import java.util.Map;\r
 \r
 import com.gitblit.GitBlitException.ForbiddenException;\r
+import com.gitblit.GitBlitException.NotAllowedException;\r
 import com.gitblit.GitBlitException.UnauthorizedException;\r
+import com.gitblit.GitBlitException.UnknownRequestException;\r
 import com.gitblit.Keys;\r
 import com.gitblit.models.FederationModel;\r
 import com.gitblit.models.RepositoryModel;\r
@@ -78,21 +80,25 @@ public class GitblitClient implements Serializable {
 \r
                try {\r
                        refreshUsers();\r
+                       refreshSettings();\r
                        allowManagement = true;\r
                } catch (UnauthorizedException e) {\r
                } catch (ForbiddenException e) {\r
+               } catch (NotAllowedException e) {\r
+               } catch (UnknownRequestException e) {\r
                } catch (IOException e) {\r
-                       System.err.println(e.getMessage());\r
+                       e.printStackTrace();\r
                }\r
 \r
                try {\r
-                       refreshSettings();\r
                        refreshStatus();\r
                        allowAdministration = true;\r
                } catch (UnauthorizedException e) {\r
                } catch (ForbiddenException e) {\r
+               } catch (NotAllowedException e) {\r
+               } catch (UnknownRequestException e) {\r
                } catch (IOException e) {\r
-                       System.err.println(e.getMessage());\r
+                       e.printStackTrace();\r
                }\r
 \r
        }\r
@@ -141,7 +147,7 @@ public class GitblitClient implements Serializable {
                settings = RpcUtils.getSettings(url, account, password);\r
                return settings;\r
        }\r
-       \r
+\r
        public ServerStatus refreshStatus() throws IOException {\r
                status = RpcUtils.getStatus(url, account, password);\r
                return status;\r
index d902c590112c444b50fbc4f544e22df481aed408..524c213ecea5a14b971fe032ee25e91a29799e81 100644 (file)
@@ -65,6 +65,7 @@ import org.eclipse.jgit.util.Base64;
 import org.eclipse.jgit.util.FS;\r
 \r
 import com.gitblit.Constants;\r
+import com.gitblit.GitBlitException.ForbiddenException;\r
 import com.gitblit.utils.StringUtils;\r
 \r
 /**\r
@@ -277,6 +278,12 @@ public class GitblitManager extends JFrame implements RegistrationsDialog.Regist
                                        if (cause instanceof ConnectException) {\r
                                                JOptionPane.showMessageDialog(GitblitManager.this, cause.getMessage(),\r
                                                                Translation.get("gb.error"), JOptionPane.ERROR_MESSAGE);\r
+                                       } else if (cause instanceof ForbiddenException) {\r
+                                               JOptionPane\r
+                                                               .showMessageDialog(\r
+                                                                               GitblitManager.this,\r
+                                                                               "This Gitblit server does not allow RPC Management or Administration",\r
+                                                                               Translation.get("gb.error"), JOptionPane.ERROR_MESSAGE);\r
                                        } else {\r
                                                Utils.showException(GitblitManager.this, t);\r
                                        }\r
index 1a24f71b6b5c6af5885dd80d44e0d18619f4711a..9eb896bcd43e19632a46dd74ac3c5f661198cf53 100644 (file)
@@ -683,6 +683,7 @@ public class GitblitPanel extends JPanel implements CloseTabListener {
                dialog.setLocationRelativeTo(GitblitPanel.this);\r
                dialog.setUsers(null, gitblit.getUsernames(), null);\r
                dialog.setRepositories(gitblit.getRepositories());\r
+               dialog.setFederationSets(gitblit.getFederationSets(), null);\r
                dialog.setVisible(true);\r
                final RepositoryModel newRepository = dialog.getRepository();\r
                final List<String> permittedUsers = dialog.getPermittedUsers();\r
index 45baf03d8fe474a4e91797bec5d507c6d45c44b4..5926a77be3a21adfc6a60a7eae97f747b04361b4 100644 (file)
@@ -24,7 +24,9 @@ import javax.swing.SwingWorker;
 \r
 import com.gitblit.Constants.RpcRequest;\r
 import com.gitblit.GitBlitException.ForbiddenException;\r
+import com.gitblit.GitBlitException.NotAllowedException;\r
 import com.gitblit.GitBlitException.UnauthorizedException;\r
+import com.gitblit.GitBlitException.UnknownRequestException;\r
 \r
 public abstract class GitblitWorker extends SwingWorker<Boolean, Void> {\r
 \r
@@ -59,6 +61,10 @@ public abstract class GitblitWorker extends SwingWorker<Boolean, Void> {
                                Utils.explainForbidden(parent, request);\r
                        } else if (t instanceof UnauthorizedException) {\r
                                Utils.explainUnauthorized(parent, request);\r
+                       } else if (t instanceof NotAllowedException) {\r
+                               Utils.explainNotAllowed(parent, request);\r
+                       } else if (t instanceof UnknownRequestException) {\r
+                               Utils.explainNotAllowed(parent, request);\r
                        } else {\r
                                Utils.showException(parent, t);\r
                        }\r
index ae81e7ff4da075af649c477f7b7e9cf3484afbbb..786eb9f29e11a52f10b2fd6c9ce789547c4f8fc2 100644 (file)
@@ -48,9 +48,16 @@ public class Utils {
                return table;\r
        }\r
 \r
+       public static void explainNotAllowed(Component c, RpcRequest request) {\r
+               String msg = MessageFormat.format("The Gitblit server does not allow the request \"{0}\".",\r
+                               request.name());\r
+               JOptionPane.showMessageDialog(c, msg, "Not Allowed", JOptionPane.ERROR_MESSAGE);\r
+       }\r
+\r
        public static void explainForbidden(Component c, RpcRequest request) {\r
                String msg = MessageFormat.format(\r
-                               "The request \"{0}\" has been forbidden by the Gitblit server.", request.name());\r
+                               "The request \"{0}\" has been forbidden for the account by the Gitblit server.",\r
+                               request.name());\r
                JOptionPane.showMessageDialog(c, msg, "Forbidden", JOptionPane.ERROR_MESSAGE);\r
        }\r
 \r
@@ -60,6 +67,12 @@ public class Utils {
                JOptionPane.showMessageDialog(c, msg, "Unauthorized", JOptionPane.ERROR_MESSAGE);\r
        }\r
 \r
+       public static void explainUnknown(Component c, RpcRequest request) {\r
+               String msg = MessageFormat.format(\r
+                               "The request \"{0}\" is not recognized by the Gitblit server.", request.name());\r
+               JOptionPane.showMessageDialog(c, msg, "Unknown Request", JOptionPane.ERROR_MESSAGE);\r
+       }\r
+\r
        public static void showException(Component c, Throwable t) {\r
                StringWriter writer = new StringWriter();\r
                t.printStackTrace(new PrintWriter(writer));\r
index 0c78df95df0076c6afc9c43a5f8dd85576974fa9..5b53bf46d146a3c24624e2689f8873d9181b7fc6 100644 (file)
@@ -46,6 +46,7 @@ import javax.net.ssl.X509TrustManager;
 import org.eclipse.jgit.util.Base64;\r
 \r
 import com.gitblit.GitBlitException.ForbiddenException;\r
+import com.gitblit.GitBlitException.NotAllowedException;\r
 import com.gitblit.GitBlitException.UnauthorizedException;\r
 import com.gitblit.GitBlitException.UnknownRequestException;\r
 import com.gitblit.models.RepositoryModel;\r
@@ -158,7 +159,7 @@ public class JsonUtils {
                }\r
                return gson().fromJson(json, type);\r
        }\r
-       \r
+\r
        /**\r
         * Reads a gson object from the specified url.\r
         * \r
@@ -216,6 +217,12 @@ public class JsonUtils {
                        } else if (e.getMessage().indexOf("403") > -1) {\r
                                // requested url is forbidden by the requesting user\r
                                throw new ForbiddenException(url);\r
+                       } else if (e.getMessage().indexOf("405") > -1) {\r
+                               // requested url is not allowed by the server\r
+                               throw new NotAllowedException(url);\r
+                       } else if (e.getMessage().indexOf("501") > -1) {\r
+                               // requested url is not recognized by the server\r
+                               throw new UnknownRequestException(url);\r
                        }\r
                        throw e;\r
                }\r
@@ -278,6 +285,9 @@ public class JsonUtils {
                        } else if (e.getMessage().indexOf("403") > -1) {\r
                                // requested url is forbidden by the requesting user\r
                                throw new ForbiddenException(url);\r
+                       } else if (e.getMessage().indexOf("405") > -1) {\r
+                               // requested url is not allowed by the server\r
+                               throw new NotAllowedException(url);\r
                        } else if (e.getMessage().indexOf("501") > -1) {\r
                                // requested url is not recognized by the server\r
                                throw new UnknownRequestException(url);\r