return responses when no value is expected

This commit is contained in:
Athou
2013-03-26 21:41:05 +01:00
parent 8db4662dc6
commit 0a8a9f5678
3 changed files with 26 additions and 28 deletions

View File

@@ -1,7 +1,6 @@
package com.commafeed.frontend.rest; package com.commafeed.frontend.rest;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
@@ -68,20 +67,16 @@ public class JSONMessageBodyReaderWriter implements MessageBodyWriter<Object>,
WebApplicationException { WebApplicationException {
httpHeaders.putSingle(HttpHeaders.CONTENT_TYPE, mediaType.toString() httpHeaders.putSingle(HttpHeaders.CONTENT_TYPE, mediaType.toString()
+ ";charset=UTF-8"); + ";charset=UTF-8");
OutputStreamWriter writer = new OutputStreamWriter( OutputStreamWriter writer = new OutputStreamWriter(entityStream, UTF_8);
new BufferedOutputStream(entityStream), UTF_8);
try { Type jsonType;
Type jsonType; if (type.equals(genericType)) {
if (type.equals(genericType)) { jsonType = type;
jsonType = type; } else {
} else { jsonType = genericType;
jsonType = genericType;
}
getGson().toJson(t, jsonType, writer);
} finally {
writer.close();
} }
getGson().toJson(t, jsonType, writer);
writer.flush();
} }
@Override @Override
@@ -91,17 +86,13 @@ public class JSONMessageBodyReaderWriter implements MessageBodyWriter<Object>,
throws IOException, WebApplicationException { throws IOException, WebApplicationException {
InputStreamReader reader = new InputStreamReader( InputStreamReader reader = new InputStreamReader(
new BufferedInputStream(entityStream), UTF_8); new BufferedInputStream(entityStream), UTF_8);
try { Type jsonType;
Type jsonType; if (type.equals(genericType)) {
if (type.equals(genericType)) { jsonType = type;
jsonType = type; } else {
} else { jsonType = genericType;
jsonType = genericType;
}
return getGson().fromJson(reader, jsonType);
} finally {
reader.close();
} }
return getGson().fromJson(reader, jsonType);
} }
private Gson getGson() { private Gson getGson() {

View File

@@ -7,6 +7,8 @@ import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET; import javax.ws.rs.GET;
import javax.ws.rs.Path; import javax.ws.rs.Path;
import javax.ws.rs.QueryParam; import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import com.commafeed.backend.model.Feed; import com.commafeed.backend.model.Feed;
import com.commafeed.backend.model.FeedCategory; import com.commafeed.backend.model.FeedCategory;
@@ -134,7 +136,7 @@ public class EntriesREST extends AbstractREST {
@Path("mark") @Path("mark")
@GET @GET
public void mark(@QueryParam("type") Type type, public Response mark(@QueryParam("type") Type type,
@QueryParam("id") String id, @QueryParam("read") boolean read) { @QueryParam("id") String id, @QueryParam("read") boolean read) {
Preconditions.checkNotNull(type); Preconditions.checkNotNull(type);
Preconditions.checkNotNull(id); Preconditions.checkNotNull(id);
@@ -154,6 +156,7 @@ public class EntriesREST extends AbstractREST {
} }
} }
} }
return Response.ok(Status.OK).build();
} }
private void markEntry(FeedEntry entry, boolean read) { private void markEntry(FeedEntry entry, boolean read) {

View File

@@ -8,6 +8,8 @@ import javax.ws.rs.POST;
import javax.ws.rs.Path; import javax.ws.rs.Path;
import javax.ws.rs.QueryParam; import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import org.apache.commons.fileupload.FileItem; import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileItemFactory; import org.apache.commons.fileupload.FileItemFactory;
@@ -29,7 +31,7 @@ public class SubscriptionsREST extends AbstractREST {
@POST @POST
@Path("subscribe") @Path("subscribe")
public void subscribe(SubscriptionRequest req) { public Response subscribe(SubscriptionRequest req) {
Preconditions.checkNotNull(req); Preconditions.checkNotNull(req);
Preconditions.checkNotNull(req.getTitle()); Preconditions.checkNotNull(req.getTitle());
Preconditions.checkNotNull(req.getUrl()); Preconditions.checkNotNull(req.getUrl());
@@ -48,20 +50,21 @@ public class SubscriptionsREST extends AbstractREST {
sub.setTitle(req.getTitle()); sub.setTitle(req.getTitle());
sub.setUser(getUser()); sub.setUser(getUser());
feedSubscriptionService.save(sub); feedSubscriptionService.save(sub);
return Response.ok(Status.OK).build();
} }
@GET @GET
@Path("unsubscribe") @Path("unsubscribe")
public void unsubscribe(@QueryParam("id") Long subscriptionId) { public Response unsubscribe(@QueryParam("id") Long subscriptionId) {
feedSubscriptionService.deleteById(subscriptionId); feedSubscriptionService.deleteById(subscriptionId);
return Response.ok(Status.OK).build();
} }
@POST @POST
@Path("import") @Path("import")
@Consumes(MediaType.MULTIPART_FORM_DATA) @Consumes(MediaType.MULTIPART_FORM_DATA)
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void importOpml() { public Response importOpml() {
try { try {
FileItemFactory factory = new DiskFileItemFactory(1000000, null); FileItemFactory factory = new DiskFileItemFactory(1000000, null);
ServletFileUpload upload = new ServletFileUpload(factory); ServletFileUpload upload = new ServletFileUpload(factory);
@@ -76,6 +79,7 @@ public class SubscriptionsREST extends AbstractREST {
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e.getMessage(), e); throw new RuntimeException(e.getMessage(), e);
} }
return Response.ok(Status.OK).build();
} }
@GET @GET