Skip to content

Commit eeec3a7

Browse files
committed
ensure that we return 200 instead of 204 for success
1 parent 26cd00b commit eeec3a7

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

clusterhq/queue/src/main/java/us/hxbc/clusterhq/queue/Api.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@
1111
import javax.ws.rs.core.Context;
1212
import javax.ws.rs.core.Response;
1313
import java.io.IOException;
14+
import java.nio.file.Files;
1415
import java.util.HashMap;
1516
import java.util.Map;
1617

1718
import static java.util.Objects.requireNonNull;
1819

20+
@Path("/")
1921
public class Api {
2022
private final java.nio.file.Path dir;
2123
private final long CHUNK_SIZE;
@@ -28,17 +30,20 @@ public class Api {
2830

2931
@Path("/{topic}/{username}")
3032
@POST
31-
public void subscribe(@PathParam("topic") String topic,
33+
public Response subscribe(@PathParam("topic") String topic,
3234
@PathParam("username") String username) throws IOException {
3335
ensureTopic(topic).subscribe(username);
36+
return Response.ok().build();
3437
}
3538

3639
private Queue ensureTopic(@PathParam("topic") String topic) throws IOException {
3740
Queue q;
3841
synchronized (topics) {
3942
q = topics.get(topic);
4043
if (q == null) {
41-
q = new Queue(dir, CHUNK_SIZE);
44+
java.nio.file.Path p = dir.resolve(topic);
45+
Files.createDirectory(p);
46+
q = new Queue(p, CHUNK_SIZE);
4247
topics.put(topic, q);
4348
}
4449
}
@@ -47,26 +52,28 @@ private Queue ensureTopic(@PathParam("topic") String topic) throws IOException {
4752

4853
@Path("/{topic}/{username}")
4954
@DELETE
50-
public void unsubscribe(@PathParam("topic") String topic,
55+
public Response unsubscribe(@PathParam("topic") String topic,
5156
@PathParam("username") String username) throws IOException {
5257
Queue q;
5358
synchronized (topics) {
5459
q = topics.get(topic);
5560
}
5661

5762
if (q == null) {
58-
throw new ClientErrorException(Response.Status.NOT_FOUND);
63+
return Response.status(Response.Status.NOT_FOUND).build();
5964
} else {
6065
q.unsubscribe(username);
66+
return Response.ok().build();
6167
}
6268
}
6369

6470
@Path("/{topic}")
6571
@POST
66-
public void publish(@PathParam("topic") String topic,
72+
public Response publish(@PathParam("topic") String topic,
6773
@Context Request request) throws IOException {
6874
ensureTopic(topic).post(request.getInputStream());
6975
request.getInputStream().close();
76+
return Response.ok().build();
7077
}
7178

7279
@Path("/{topic}/{username}")

clusterhq/queue/src/main/java/us/hxbc/clusterhq/queue/Main.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package us.hxbc.clusterhq.queue;
22

3-
import org.glassfish.grizzly.http.server.HttpServer;
3+
import org.glassfish.jersey.filter.LoggingFilter;
44
import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
55
import org.glassfish.jersey.server.ResourceConfig;
66
import org.slf4j.Logger;
@@ -27,9 +27,11 @@ public static void main(String[] args) {
2727
System.exit(1);
2828
}
2929

30-
HttpServer server;
3130
ResourceConfig rc = new ResourceConfig();
32-
rc.register(new Api(dir, 4096));
31+
rc.registerInstances(new Api(dir, 4096));
32+
if (logger.isDebugEnabled()) {
33+
rc.register(new LoggingFilter(java.util.logging.Logger.getGlobal(), false));
34+
}
3335
GrizzlyHttpServerFactory.createHttpServer(URI.create("http://0.0.0.0:" + port), rc);
3436
}
3537
}

0 commit comments

Comments
 (0)