Collections.sort(sortedPosts, Post.TIME_COMPARATOR);
if (sortedPosts.size() < startPost) {
- return new Response(encodePosts(Collections.<Post> emptyList(), "Posts.", false));
+ return new Response("PostFeed", encodePosts(Collections.<Post> emptyList(), "Posts.", false));
}
- return new Response(encodePosts(sortedPosts.subList(startPost, (maxPosts == -1) ? sortedPosts.size() : Math.min(startPost + maxPosts, sortedPosts.size())), "Posts.", true));
+ return new Response("PostFeed", encodePosts(sortedPosts.subList(startPost, (maxPosts == -1) ? sortedPosts.size() : Math.min(startPost + maxPosts, sortedPosts.size())), "Posts.", true));
}
}
int maxPosts = getInt(parameters, "MaxPosts", -1);
List<Post> posts = sone.getPosts();
if (posts.size() < startPost) {
- return new Response(encodePosts(Collections.<Post> emptyList(), "Posts.", false));
+ return new Response("Posts", encodePosts(Collections.<Post> emptyList(), "Posts.", false));
}
- return new Response(encodePosts(sone.getPosts().subList(startPost, (maxPosts == -1) ? posts.size() : Math.min(startPost + maxPosts, posts.size())), "Posts.", true));
+ return new Response("Posts", encodePosts(sone.getPosts().subList(startPost, (maxPosts == -1) ? posts.size() : Math.min(startPost + maxPosts, posts.size())), "Posts.", true));
}
}
*/
public static class Response {
+ /** The message name of the reponse. */
+ private final String messageName;
+
/** The reply parameters. */
private final SimpleFieldSet replyParameters;
/**
* Creates a new reply with the given parameters.
*
+ * @param messageName
+ * The message name
* @param replyParameters
* The reply parameters
*/
- public Response(SimpleFieldSet replyParameters) {
- this(replyParameters, null, null);
+ public Response(String messageName, SimpleFieldSet replyParameters) {
+ this(messageName, replyParameters, null, null);
}
/**
* Creates a new reply with the given parameters.
*
+ * @param messageName
+ * The message name
* @param replyParameters
* The reply parameters
* @param data
* The data of the reply (may be {@code null})
*/
- public Response(SimpleFieldSet replyParameters, byte[] data) {
- this(replyParameters, data, null);
+ public Response(String messageName, SimpleFieldSet replyParameters, byte[] data) {
+ this(messageName, replyParameters, data, null);
}
/**
* Creates a new reply with the given parameters.
*
+ * @param messageName
+ * The message name
* @param replyParameters
* The reply parameters
* @param bucket
* The bucket of the reply (may be {@code null})
*/
- public Response(SimpleFieldSet replyParameters, Bucket bucket) {
- this(replyParameters, null, bucket);
+ public Response(String messageName, SimpleFieldSet replyParameters, Bucket bucket) {
+ this(messageName, replyParameters, null, bucket);
}
/**
* Creates a new reply with the given parameters.
*
+ * @param messageName
+ * The message name
* @param replyParameters
* The reply parameters
* @param data
* @param bucket
* The bucket of the reply (may be {@code null})
*/
- private Response(SimpleFieldSet replyParameters, byte[] data, Bucket bucket) {
+ private Response(String messageName, SimpleFieldSet replyParameters, byte[] data, Bucket bucket) {
+ this.messageName = messageName;
this.replyParameters = replyParameters;
this.data = data;
this.bucket = bucket;
* @return The reply parameters
*/
public SimpleFieldSet getReplyParameters() {
- return replyParameters;
+ return new SimpleFieldSetBuilder(replyParameters).put("Message", messageName).get();
}
/**
* The error message
*/
public ErrorResponse(String message) {
- super(new SimpleFieldSetBuilder().put("ErrorMessage", message).get());
+ super("Error", new SimpleFieldSetBuilder().put("ErrorMessage", message).get());
}
/**
* The error message
*/
public ErrorResponse(int code, String message) {
- super(new SimpleFieldSetBuilder().put("ErrorMessage", message).put("ErrorCode", code).get());
+ super("Error", new SimpleFieldSetBuilder().put("ErrorMessage", message).put("ErrorCode", code).get());
}
}