X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ffcp%2FFcpInterface.java;h=36e18e65ea4251d8497def0c0a5da4a17d2c59d4;hb=0747ce52deab6ed6e4c3118959cf76827c2ce495;hp=25cf4ae63f34b6c9a9197a7a10bdf485692d1388;hpb=1e9a08c2b73b16dc178437eb8c8025aaa083fcca;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/fcp/FcpInterface.java b/src/main/java/net/pterodactylus/sone/fcp/FcpInterface.java index 25cf4ae..36e18e6 100644 --- a/src/main/java/net/pterodactylus/sone/fcp/FcpInterface.java +++ b/src/main/java/net/pterodactylus/sone/fcp/FcpInterface.java @@ -1,5 +1,5 @@ /* - * Sone - FcpInterface.java - Copyright © 2011–2015 David Roden + * Sone - FcpInterface.java - Copyright © 2011–2016 David Roden * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -153,41 +153,37 @@ public class FcpInterface { */ public void handle(PluginReplySender pluginReplySender, SimpleFieldSet parameters, Bucket data, int accessType) { if (!active.get()) { - try { - sendReply(pluginReplySender, null, new ErrorResponse(400, "FCP Interface deactivated")); - } catch (PluginNotFoundException pnfe1) { - logger.log(Level.FINE, "Could not set error to plugin.", pnfe1); - } + sendErrorReply(pluginReplySender, null, 503, "FCP Interface deactivated"); return; } AbstractSoneCommand command = commands.get(parameters.get("Message")); if ((accessType == FredPluginFCP.ACCESS_FCP_RESTRICTED) && (((fullAccessRequired.get() == FullAccessRequired.WRITING) && command.requiresWriteAccess()) || (fullAccessRequired.get() == FullAccessRequired.ALWAYS))) { - try { - sendReply(pluginReplySender, null, new ErrorResponse(401, "Not authorized")); - } catch (PluginNotFoundException pnfe1) { - logger.log(Level.FINE, "Could not set error to plugin.", pnfe1); - } + sendErrorReply(pluginReplySender, null, 401, "Not authorized"); return; } + if (command == null) { + sendErrorReply(pluginReplySender, null, 404, "Unrecognized Message: " + parameters.get("Message")); + return; + } + String identifier = parameters.get("Identifier"); + if ((identifier == null) || (identifier.length() == 0)) { + sendErrorReply(pluginReplySender, null, 400, "Missing Identifier."); + return; + } + try { + Response response = command.execute(parameters, data, AccessType.values()[accessType]); + sendReply(pluginReplySender, identifier, response); + } catch (Exception e1) { + logger.log(Level.WARNING, "Could not process FCP command “%s”.", command); + sendErrorReply(pluginReplySender, identifier, 500, "Error executing command: " + e1.getMessage()); + } + } + + private void sendErrorReply(PluginReplySender pluginReplySender, String identifier, int errorCode, String message) { try { - if (command == null) { - sendReply(pluginReplySender, null, new ErrorResponse("Unrecognized Message: " + parameters.get("Message"))); - return; - } - String identifier = parameters.get("Identifier"); - if ((identifier == null) || (identifier.length() == 0)) { - sendReply(pluginReplySender, null, new ErrorResponse("Missing Identifier.")); - return; - } - try { - Response response = command.execute(parameters, data, AccessType.values()[accessType]); - sendReply(pluginReplySender, identifier, response); - } catch (Exception e1) { - logger.log(Level.WARNING, "Could not process FCP command “%s”.", command); - sendReply(pluginReplySender, identifier, new ErrorResponse("Error executing command: " + e1.getMessage())); - } + sendReply(pluginReplySender, identifier, new ErrorResponse(errorCode, message)); } catch (PluginNotFoundException pnfe1) { - logger.log(Level.WARNING, "Could not find destination plugin: " + pluginReplySender); + logger.log(Level.FINE, "Could not send error to plugin.", pnfe1); } }