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

View File

@@ -7,6 +7,8 @@ import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
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.FeedCategory;
@@ -134,7 +136,7 @@ public class EntriesREST extends AbstractREST {
@Path("mark")
@GET
public void mark(@QueryParam("type") Type type,
public Response mark(@QueryParam("type") Type type,
@QueryParam("id") String id, @QueryParam("read") boolean read) {
Preconditions.checkNotNull(type);
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) {

View File

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