Store the insert URI in the information used for inserting.
[Sone.git] / src / main / java / net / pterodactylus / sone / fcp / FcpInterface.java
index 02d84cc..2c7355d 100644 (file)
@@ -39,6 +39,7 @@ import freenet.pluginmanager.PluginReplySender;
 import freenet.support.SimpleFieldSet;
 import freenet.support.api.Bucket;
 
+import com.google.common.annotations.VisibleForTesting;
 /**
  * Implementation of an FCP interface for other clients or plugins to
  * communicate with Sone.
@@ -106,6 +107,11 @@ public class FcpInterface {
        // ACCESSORS
        //
 
+       @VisibleForTesting
+       void addCommand(String name, AbstractSoneCommand command) {
+               commands.put(name, command);
+       }
+
        /**
         * Sets whether the FCP interface should handle requests. If {@code active}
         * is {@code false}, all requests are answered with an error.
@@ -147,24 +153,16 @@ public class FcpInterface {
         *            {@link FredPluginFCP#ACCESS_FCP_RESTRICTED}
         */
        public void handle(PluginReplySender pluginReplySender, SimpleFieldSet parameters, Bucket data, int accessType) {
-               if (!active) {
-                       try {
+               try {
+                       if (!active) {
                                sendReply(pluginReplySender, null, new ErrorResponse(400, "FCP Interface deactivated"));
-                       } catch (PluginNotFoundException pnfe1) {
-                               logger.log(Level.FINE, "Could not set error to plugin.", pnfe1);
+                               return;
                        }
-                       return;
-               }
-               AbstractSoneCommand command = commands.get(parameters.get("Message"));
-               if ((accessType == FredPluginFCP.ACCESS_FCP_RESTRICTED) && (((fullAccessRequired == FullAccessRequired.WRITING) && command.requiresWriteAccess()) || (fullAccessRequired == FullAccessRequired.ALWAYS))) {
-                       try {
+                       AbstractSoneCommand command = commands.get(parameters.get("Message"));
+                       if ((accessType == FredPluginFCP.ACCESS_FCP_RESTRICTED) && (((fullAccessRequired == FullAccessRequired.WRITING) && command.requiresWriteAccess()) || (fullAccessRequired == FullAccessRequired.ALWAYS))) {
                                sendReply(pluginReplySender, null, new ErrorResponse(401, "Not authorized"));
-                       } catch (PluginNotFoundException pnfe1) {
-                               logger.log(Level.FINE, "Could not set error to plugin.", pnfe1);
+                               return;
                        }
-                       return;
-               }
-               try {
                        if (command == null) {
                                sendReply(pluginReplySender, null, new ErrorResponse("Unrecognized Message: " + parameters.get("Message")));
                                return;