package net.pterodactylus.sone.freenet.fcp;
+import net.pterodactylus.sone.freenet.SimpleFieldSetBuilder;
import freenet.support.SimpleFieldSet;
import freenet.support.api.Bucket;
* @param accessType
* The access type
* @return A reply to send back to the plugin
+ * @throws FcpException
+ * if an error processing the parameters occurs
*/
- public Reply execute(SimpleFieldSet parameters, Bucket data, AccessType accessType);
+ public Response execute(SimpleFieldSet parameters, Bucket data, AccessType accessType) throws FcpException;
/**
* The access type of the request.
*
* @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
*/
- public static class Reply {
+ public static class Response {
/** The reply parameters. */
private final SimpleFieldSet replyParameters;
* @param replyParameters
* The reply parameters
*/
- public Reply(SimpleFieldSet replyParameters) {
+ public Response(SimpleFieldSet replyParameters) {
this(replyParameters, null, null);
}
* @param data
* The data of the reply (may be {@code null})
*/
- public Reply(SimpleFieldSet replyParameters, byte[] data) {
+ public Response(SimpleFieldSet replyParameters, byte[] data) {
this(replyParameters, data, null);
}
* @param bucket
* The bucket of the reply (may be {@code null})
*/
- public Reply(SimpleFieldSet replyParameters, Bucket bucket) {
+ public Response(SimpleFieldSet replyParameters, Bucket bucket) {
this(replyParameters, null, bucket);
}
* @param bucket
* The bucket of the reply (may be {@code null})
*/
- private Reply(SimpleFieldSet replyParameters, byte[] data, Bucket bucket) {
+ private Response(SimpleFieldSet replyParameters, byte[] data, Bucket bucket) {
this.replyParameters = replyParameters;
this.data = data;
this.bucket = bucket;
}
+ /**
+ * Response implementation that can return an error message and an optional
+ * error code.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+ public class ErrorResponse extends Response {
+
+ /**
+ * Creates a new error response with the given message.
+ *
+ * @param message
+ * The error message
+ */
+ public ErrorResponse(String message) {
+ super(new SimpleFieldSetBuilder().put("ErrorMessage", message).get());
+ }
+
+ /**
+ * Creates a new error response with the given code and message.
+ *
+ * @param code
+ * The error code
+ * @param message
+ * The error message
+ */
+ public ErrorResponse(int code, String message) {
+ super(new SimpleFieldSetBuilder().put("ErrorMessage", message).put("ErrorCode", code).get());
+ }
+
+ }
+
}