From 7e05cde8131a04e418d42c41db37ca4a5e5c6b5e Mon Sep 17 00:00:00 2001 From: Inderjeet Singh Date: Thu, 4 Nov 2010 15:25:43 +0000 Subject: [PATCH] Added ability to specify a different ID than the Id class for a RestResource. --- .../google/gson/rest/client/RestClient.java | 17 +++++----- .../gson/rest/client/RestRequestSender.java | 3 +- .../rest/client/RestResponseReceiver.java | 27 ++++++++-------- .../google/gson/rest/definition/HasId.java | 6 ++-- .../com/google/gson/rest/definition/ID.java | 7 ++++ .../gson/rest/definition/IDFactory.java | 20 ++++++++++++ .../com/google/gson/rest/definition/Id.java | 3 +- .../google/gson/rest/definition/MetaData.java | 16 +++++----- .../google/gson/rest/definition/RestCall.java | 12 +++---- .../gson/rest/definition/RestRequest.java | 8 ++--- .../gson/rest/definition/RestResource.java | 2 +- .../gson/rest/definition/RestResponse.java | 12 +++---- .../com/google/gson/rest/server/IdMap.java | 29 +++++++++-------- .../google/gson/rest/server/MetaDataMap.java | 12 +++---- .../google/gson/rest/server/Repository.java | 14 ++++---- .../gson/rest/server/RepositoryInMemory.java | 32 +++++++++---------- .../gson/rest/server/RestRequestReceiver.java | 7 ++-- .../gson/rest/server/RestResponseBuilder.java | 16 +++++----- .../gson/rest/server/RestResponseSender.java | 5 +-- 19 files changed, 141 insertions(+), 107 deletions(-) create mode 100644 wsdef/src/main/java/com/google/gson/rest/definition/ID.java create mode 100644 wsdef/src/main/java/com/google/gson/rest/definition/IDFactory.java diff --git a/wsclient/src/main/java/com/google/gson/rest/client/RestClient.java b/wsclient/src/main/java/com/google/gson/rest/client/RestClient.java index 3cfde220..16bbc9d1 100644 --- a/wsclient/src/main/java/com/google/gson/rest/client/RestClient.java +++ b/wsclient/src/main/java/com/google/gson/rest/client/RestClient.java @@ -24,6 +24,7 @@ import java.util.logging.Logger; import com.google.gson.Gson; import com.google.gson.GsonBuilder; +import com.google.gson.rest.definition.ID; import com.google.gson.rest.definition.RestCallSpec; import com.google.gson.rest.definition.RestRequest; import com.google.gson.rest.definition.RestResource; @@ -61,14 +62,14 @@ public class RestClient { } } - public > RestResponse getResponse( - RestCallSpec callSpec, RestRequest request) { + public > RestResponse getResponse( + RestCallSpec callSpec, RestRequest request) { Gson gson = new GsonBuilder().setVersion(callSpec.getVersion()).create(); return getResponse(callSpec, request, gson); } - public > RestResponse getResponse( - RestCallSpec callSpec, RestRequest request, Gson gson) { + public > RestResponse getResponse( + RestCallSpec callSpec, RestRequest request, Gson gson) { HttpURLConnection conn = null; try { URL webServiceUrl = getWebServiceUrl(callSpec); @@ -88,8 +89,8 @@ public class RestClient { * Use this method if you want to mange the HTTP Connection yourself. This is useful when you * want to use HTTP pipelining. */ - public > RestResponse getResponse( - RestCallSpec callSpec, RestRequest request, Gson gson, HttpURLConnection conn) { + public > RestResponse getResponse( + RestCallSpec callSpec, RestRequest request, Gson gson, HttpURLConnection conn) { try { if (logger != null) { URL webServiceUrl = getWebServiceUrl(callSpec); @@ -97,8 +98,8 @@ public class RestClient { } RestRequestSender requestSender = new RestRequestSender(gson, logLevel); requestSender.send(conn, request); - RestResponseReceiver responseReceiver = - new RestResponseReceiver(gson, callSpec.getResponseSpec(), logLevel); + RestResponseReceiver responseReceiver = + new RestResponseReceiver(gson, callSpec.getResponseSpec(), logLevel); return responseReceiver.receive(conn); } catch (IllegalArgumentException e) { throw new WebServiceSystemException(e); diff --git a/wsclient/src/main/java/com/google/gson/rest/client/RestRequestSender.java b/wsclient/src/main/java/com/google/gson/rest/client/RestRequestSender.java index 9bf6ba69..c0742bae 100644 --- a/wsclient/src/main/java/com/google/gson/rest/client/RestRequestSender.java +++ b/wsclient/src/main/java/com/google/gson/rest/client/RestRequestSender.java @@ -23,6 +23,7 @@ import java.util.logging.Level; import java.util.logging.Logger; import com.google.gson.Gson; +import com.google.gson.rest.definition.ID; import com.google.gson.rest.definition.RestRequest; import com.google.gson.rest.definition.RestResource; import com.google.gson.webservice.definition.HeaderMap; @@ -50,7 +51,7 @@ public final class RestRequestSender { this.logLevel = logLevel; } - public > void send(HttpURLConnection conn, RestRequest request) { + public > void send(HttpURLConnection conn, RestRequest request) { try { conn.setRequestMethod(request.getHttpMethod().toString()); setHeader(conn, "Content-Type", request.getContentType(), true); diff --git a/wsclient/src/main/java/com/google/gson/rest/client/RestResponseReceiver.java b/wsclient/src/main/java/com/google/gson/rest/client/RestResponseReceiver.java index b5c7c73c..a7f6d01e 100644 --- a/wsclient/src/main/java/com/google/gson/rest/client/RestResponseReceiver.java +++ b/wsclient/src/main/java/com/google/gson/rest/client/RestResponseReceiver.java @@ -15,16 +15,6 @@ */ package com.google.gson.rest.client; -import com.google.gson.Gson; -import com.google.gson.rest.definition.RestResource; -import com.google.gson.rest.definition.RestResponse; -import com.google.gson.rest.definition.RestResponseSpec; -import com.google.gson.webservice.definition.ContentBodySpec; -import com.google.gson.webservice.definition.HeaderMap; -import com.google.gson.webservice.definition.HeaderMapSpec; -import com.google.gson.webservice.definition.WebServiceSystemException; -import com.google.gson.wsclient.internal.utils.ConnectionPreconditions; - import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; @@ -35,12 +25,23 @@ import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; +import com.google.gson.Gson; +import com.google.gson.rest.definition.ID; +import com.google.gson.rest.definition.RestResource; +import com.google.gson.rest.definition.RestResponse; +import com.google.gson.rest.definition.RestResponseSpec; +import com.google.gson.webservice.definition.ContentBodySpec; +import com.google.gson.webservice.definition.HeaderMap; +import com.google.gson.webservice.definition.HeaderMapSpec; +import com.google.gson.webservice.definition.WebServiceSystemException; +import com.google.gson.wsclient.internal.utils.ConnectionPreconditions; + /** * Receives a response coming on an {@link HttpURLConnection}. * * @author inder */ -public final class RestResponseReceiver> { +public final class RestResponseReceiver> { private final Gson gson; private final RestResponseSpec spec; private final Logger logger; @@ -56,14 +57,14 @@ public final class RestResponseReceiver> { this.logLevel = logLevel; } - public RestResponse receive(HttpURLConnection conn) { + public RestResponse receive(HttpURLConnection conn) { try { HeaderMapSpec paramSpec = spec.getHeadersSpec(); Type bodyType = spec.getResourceType(); // read response HeaderMap responseParams = readResponseHeaders(conn, paramSpec); R responseBody = readResponseBody(conn, bodyType); - return new RestResponse(responseParams, responseBody, bodyType); + return new RestResponse(responseParams, responseBody, bodyType); } catch (IOException e) { throw new WebServiceSystemException(e); } diff --git a/wsdef/src/main/java/com/google/gson/rest/definition/HasId.java b/wsdef/src/main/java/com/google/gson/rest/definition/HasId.java index c1118497..39b4831a 100644 --- a/wsdef/src/main/java/com/google/gson/rest/definition/HasId.java +++ b/wsdef/src/main/java/com/google/gson/rest/definition/HasId.java @@ -22,8 +22,8 @@ package com.google.gson.rest.definition; * * @param type of object */ -public interface HasId { - public Id getId(); - public void setId(Id id); +public interface HasId { + public I getId(); + public void setId(I id); public boolean hasId(); } diff --git a/wsdef/src/main/java/com/google/gson/rest/definition/ID.java b/wsdef/src/main/java/com/google/gson/rest/definition/ID.java new file mode 100644 index 00000000..8a730024 --- /dev/null +++ b/wsdef/src/main/java/com/google/gson/rest/definition/ID.java @@ -0,0 +1,7 @@ +package com.google.gson.rest.definition; + +public interface ID { + public static final long INVALID_ID = 0L; + + public long getValue(); +} diff --git a/wsdef/src/main/java/com/google/gson/rest/definition/IDFactory.java b/wsdef/src/main/java/com/google/gson/rest/definition/IDFactory.java new file mode 100644 index 00000000..411c1c79 --- /dev/null +++ b/wsdef/src/main/java/com/google/gson/rest/definition/IDFactory.java @@ -0,0 +1,20 @@ +package com.google.gson.rest.definition; + +import java.lang.reflect.Type; + +public class IDFactory { + private final Class classOfI; + private final Type typeOfId; + + public IDFactory(Class classOfI, Type typeOfId) { + this.classOfI = classOfI; + this.typeOfId = typeOfId; + } + + public I createId(long value) { + if (classOfI.isAssignableFrom(Id.class)) { + return (I)Id.get(value, typeOfId); + } + throw new UnsupportedOperationException(); + } +} diff --git a/wsdef/src/main/java/com/google/gson/rest/definition/Id.java b/wsdef/src/main/java/com/google/gson/rest/definition/Id.java index 0081fe21..0c93ba54 100644 --- a/wsdef/src/main/java/com/google/gson/rest/definition/Id.java +++ b/wsdef/src/main/java/com/google/gson/rest/definition/Id.java @@ -35,7 +35,7 @@ import java.lang.reflect.WildcardType; * * @param type variable for the rest resource */ -public final class Id { +public final class Id implements ID { private static final long NULL_VALUE = -1; private final long value; private final Type typeOfId; @@ -46,6 +46,7 @@ public final class Id { this.typeOfId = typeOfId; } + @Override public long getValue() { return value; } diff --git a/wsdef/src/main/java/com/google/gson/rest/definition/MetaData.java b/wsdef/src/main/java/com/google/gson/rest/definition/MetaData.java index 0a764eb9..f3c7a002 100644 --- a/wsdef/src/main/java/com/google/gson/rest/definition/MetaData.java +++ b/wsdef/src/main/java/com/google/gson/rest/definition/MetaData.java @@ -38,17 +38,17 @@ import com.google.gson.reflect.TypeToken; * * @param The resource */ -public final class MetaData> { +public final class MetaData> { private final Map map; private final transient Map mapTransient; - public static > MetaData create() { - return new MetaData(); + public static > MetaData create() { + return new MetaData(); } @SuppressWarnings({"unchecked", "rawtypes"}) - private static MetaData createTypeUnsafe(Map values) { + private static MetaData createTypeUnsafe(Map values) { return new MetaData(values); } @@ -103,20 +103,20 @@ public final class MetaData> { * Gson Type adapter for {@link MetaData}. The serialized representation on wire is just a * Map */ - public static final class GsonTypeAdapter implements JsonSerializer>, - JsonDeserializer>{ + public static final class GsonTypeAdapter implements JsonSerializer>, + JsonDeserializer>{ private static final Type MAP_TYPE = new TypeToken>(){}.getType(); @Override - public MetaData deserialize(JsonElement json, Type typeOfT, + public MetaData deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { Map map = context.deserialize(json, MAP_TYPE); return MetaData.createTypeUnsafe(map); } @Override - public JsonElement serialize(MetaData src, Type typeOfSrc, + public JsonElement serialize(MetaData src, Type typeOfSrc, JsonSerializationContext context) { return context.serialize(src.map, MAP_TYPE); } diff --git a/wsdef/src/main/java/com/google/gson/rest/definition/RestCall.java b/wsdef/src/main/java/com/google/gson/rest/definition/RestCall.java index ebf6b9d4..717cb4a5 100644 --- a/wsdef/src/main/java/com/google/gson/rest/definition/RestCall.java +++ b/wsdef/src/main/java/com/google/gson/rest/definition/RestCall.java @@ -21,13 +21,13 @@ package com.google.gson.rest.definition; * * @author inder */ -public final class RestCall> { +public final class RestCall> { private final RestCallSpec callSpec; - private final RestRequest request; - private final RestResponse response; + private final RestRequest request; + private final RestResponse response; - public RestCall(RestCallSpec callSpec, RestRequest request, RestResponse response) { + public RestCall(RestCallSpec callSpec, RestRequest request, RestResponse response) { this.callSpec = callSpec; this.request = request; this.response = response; @@ -37,11 +37,11 @@ public final class RestCall> { return callSpec; } - public RestRequest getRequest() { + public RestRequest getRequest() { return request; } - public RestResponse getResponse() { + public RestResponse getResponse() { return response; } } diff --git a/wsdef/src/main/java/com/google/gson/rest/definition/RestRequest.java b/wsdef/src/main/java/com/google/gson/rest/definition/RestRequest.java index e70397dc..eb7f4354 100644 --- a/wsdef/src/main/java/com/google/gson/rest/definition/RestRequest.java +++ b/wsdef/src/main/java/com/google/gson/rest/definition/RestRequest.java @@ -15,19 +15,19 @@ */ package com.google.gson.rest.definition; +import java.lang.reflect.Type; + import com.google.gson.webservice.definition.HeaderMap; import com.google.gson.webservice.definition.HttpMethod; import com.google.gson.webservice.definition.TypedKey; -import java.lang.reflect.Type; - /** * The data associated with a Web service request. This includes HTTP request header parameters * (form and URL parameters), and request body. * * @author inder */ -public final class RestRequest> { +public final class RestRequest> { public static final String JSON_CONTENT_TYPE = "application/json"; private final HttpMethod method; @@ -43,7 +43,7 @@ public final class RestRequest> { this.spec = new RestRequestSpec(requestHeaders.getSpec(), resourceType); } - public Id getId() { + public I getId() { return body.getId(); } diff --git a/wsdef/src/main/java/com/google/gson/rest/definition/RestResource.java b/wsdef/src/main/java/com/google/gson/rest/definition/RestResource.java index ada04905..c486a7ce 100644 --- a/wsdef/src/main/java/com/google/gson/rest/definition/RestResource.java +++ b/wsdef/src/main/java/com/google/gson/rest/definition/RestResource.java @@ -22,5 +22,5 @@ package com.google.gson.rest.definition; * * @param the rest resource type */ -public interface RestResource extends HasId { +public interface RestResource extends HasId { } diff --git a/wsdef/src/main/java/com/google/gson/rest/definition/RestResponse.java b/wsdef/src/main/java/com/google/gson/rest/definition/RestResponse.java index 99c7d12b..de1ed967 100644 --- a/wsdef/src/main/java/com/google/gson/rest/definition/RestResponse.java +++ b/wsdef/src/main/java/com/google/gson/rest/definition/RestResponse.java @@ -26,13 +26,13 @@ import com.google.gson.webservice.definition.TypedKey; * * @author inder */ -public final class RestResponse> { +public final class RestResponse> { private final HeaderMap headers; private final R body; private final RestResponseSpec spec; - public static class Builder> { + public static class Builder> { private final HeaderMap.Builder headers; private RS body; private final RestResponseSpec spec; @@ -42,18 +42,18 @@ public final class RestResponse> { headers = new HeaderMap.Builder(spec.getHeadersSpec()); } - public Builder putHeader(TypedKey paramName, T content) { + public Builder putHeader(TypedKey paramName, T content) { headers.put(paramName.getName(), content, paramName.getClassOfT()); return this; } - public Builder setBody(RS body) { + public Builder setBody(RS body) { this.body = body; return this; } - public RestResponse build() { - return new RestResponse(spec, headers.build(), body); + public RestResponse build() { + return new RestResponse(spec, headers.build(), body); } } diff --git a/wsf/src/main/java/com/google/gson/rest/server/IdMap.java b/wsf/src/main/java/com/google/gson/rest/server/IdMap.java index 1b7a9381..0252a460 100644 --- a/wsf/src/main/java/com/google/gson/rest/server/IdMap.java +++ b/wsf/src/main/java/com/google/gson/rest/server/IdMap.java @@ -22,7 +22,8 @@ import java.util.logging.Level; import java.util.logging.Logger; import com.google.gson.rest.definition.HasId; -import com.google.gson.rest.definition.Id; +import com.google.gson.rest.definition.ID; +import com.google.gson.rest.definition.IDFactory; /** * This class provides a type-safe map to access values associated with Ids @@ -31,22 +32,22 @@ import com.google.gson.rest.definition.Id; * * @param the type of the objects being kept in the map */ -public class IdMap> { +public class IdMap> { public static final Logger LOG = Logger.getLogger(IdMap.class.getName()); - protected final Map, T> map; + protected final Map map; private volatile long nextAvailableId; - private final Type typeOfId; + private final IDFactory idFactory; /** * Use {@link #create(Type)} instead of constructor */ - protected IdMap(Type typeOfId) { - this.typeOfId = typeOfId; - map = new ConcurrentHashMap, T>(); + protected IdMap(Class classOfI, Type typeOfId) { + map = new ConcurrentHashMap(); nextAvailableId = 0; + this.idFactory = new IDFactory(classOfI, typeOfId); } - public T get(Id id) { + public T get(I id) { return map.get(id); } @@ -55,23 +56,23 @@ public class IdMap> { return obj; } - public void delete(Id id) { + public void delete(I id) { T removed = map.remove(id); if (removed == null) { LOG.log(Level.WARNING, "Attempted to delete non-existent id: {0}", id); } } - public boolean exists(Id id) { + public boolean exists(I id) { return map.containsKey(id); } - public synchronized Id getNextId() { + public synchronized I getNextId() { long id = nextAvailableId++; - return Id.get(id, typeOfId); + return idFactory.createId(id); } - public static > IdMap create(Type typeOfId) { - return new IdMap(typeOfId); + public static > IdMap create(Class classOfII, Type typeOfId) { + return new IdMap(classOfII, typeOfId); } } diff --git a/wsf/src/main/java/com/google/gson/rest/server/MetaDataMap.java b/wsf/src/main/java/com/google/gson/rest/server/MetaDataMap.java index 3deadd49..38771a88 100644 --- a/wsf/src/main/java/com/google/gson/rest/server/MetaDataMap.java +++ b/wsf/src/main/java/com/google/gson/rest/server/MetaDataMap.java @@ -18,7 +18,7 @@ package com.google.gson.rest.server; import java.util.HashMap; import java.util.Map; -import com.google.gson.rest.definition.Id; +import com.google.gson.rest.definition.ID; import com.google.gson.rest.definition.MetaData; import com.google.gson.rest.definition.RestResource; @@ -29,15 +29,15 @@ import com.google.gson.rest.definition.RestResource; * * @param the rest resource for whic the metadata is being stored */ -public class MetaDataMap> { - private final Map, MetaData> map; +public class MetaDataMap> { + private final Map> map; public MetaDataMap() { - this.map = new HashMap, MetaData>(); + this.map = new HashMap>(); } - public MetaData get(Id resourceId) { - MetaData metaData = map.get(resourceId); + public MetaData get(I resourceId) { + MetaData metaData = map.get(resourceId); if (metaData == null) { metaData = MetaData.create(); map.put(resourceId, metaData); diff --git a/wsf/src/main/java/com/google/gson/rest/server/Repository.java b/wsf/src/main/java/com/google/gson/rest/server/Repository.java index 1c10b9a3..bec767e1 100644 --- a/wsf/src/main/java/com/google/gson/rest/server/Repository.java +++ b/wsf/src/main/java/com/google/gson/rest/server/Repository.java @@ -16,7 +16,7 @@ package com.google.gson.rest.server; import com.google.gson.rest.definition.HasId; -import com.google.gson.rest.definition.Id; +import com.google.gson.rest.definition.ID; /** * An interface for a repository of rest resources. Meant for abstracting the server-side @@ -26,8 +26,8 @@ import com.google.gson.rest.definition.Id; * * @param the type of rest resource */ -public interface Repository> { - public R get(Id resourceId); +public interface Repository> { + public R get(I resourceId); /** * if resource.getId() == null, inserts the resource after assigning it a new id. @@ -35,14 +35,14 @@ public interface Repository> { */ public R put(R resource); - public void delete(Id resourceId); + public void delete(I resourceId); - public boolean exists(Id resourceId); + public boolean exists(I resourceId); /** * Ensures that the specified resource has a valid id that will be used when it is saved */ - public Id assignId(R resource); + public I assignId(R resource); - public Id getNextId(); + public I getNextId(); } diff --git a/wsf/src/main/java/com/google/gson/rest/server/RepositoryInMemory.java b/wsf/src/main/java/com/google/gson/rest/server/RepositoryInMemory.java index 02612ea4..b512aad1 100644 --- a/wsf/src/main/java/com/google/gson/rest/server/RepositoryInMemory.java +++ b/wsf/src/main/java/com/google/gson/rest/server/RepositoryInMemory.java @@ -16,7 +16,7 @@ package com.google.gson.rest.server; import com.google.common.base.Preconditions; -import com.google.gson.rest.definition.Id; +import com.google.gson.rest.definition.ID; import com.google.gson.rest.definition.MetaData; import com.google.gson.rest.definition.RestResource; @@ -27,24 +27,24 @@ import com.google.gson.rest.definition.RestResource; * * @param Type variable for the resource */ -public class RepositoryInMemory> implements Repository { +public class RepositoryInMemory> implements Repository { private static final String METADATA_KEY_IS_FRESHLY_ASSIGNED_ID = "isFreshlyAssignedId"; - private final IdMap resources; - private final MetaDataMap metaDataMap; + private final IdMap resources; + private final MetaDataMap metaDataMap; - public RepositoryInMemory(Class classOfResource) { - this.resources = IdMap.create(classOfResource); - this.metaDataMap = new MetaDataMap(); + public RepositoryInMemory(Class classOfI, Class classOfResource) { + this.resources = IdMap.create(classOfI, classOfResource); + this.metaDataMap = new MetaDataMap(); } @Override - public R get(Id resourceId) { + public R get(I resourceId) { return resources.get(resourceId); } - public boolean isFreshlyAssignedId(Id resourceId) { - MetaData metaData = metaDataMap.get(resourceId); + public boolean isFreshlyAssignedId(I resourceId) { + MetaData metaData = metaDataMap.get(resourceId); if (metaData == null) { return false; } @@ -57,7 +57,7 @@ public class RepositoryInMemory> implements Repository // insert semantics assignId(resource); } else { - Id id = resource.getId(); + I id = resource.getId(); if (!isFreshlyAssignedId(id)) { // update semantics Preconditions.checkState(resources.exists(resource.getId())); @@ -69,24 +69,24 @@ public class RepositoryInMemory> implements Repository } @Override - public void delete(Id resourceId) { + public void delete(I resourceId) { resources.delete(resourceId); } @Override - public boolean exists(Id resourceId) { + public boolean exists(I resourceId) { return resources.exists(resourceId); } @Override - public Id getNextId() { + public I getNextId() { return resources.getNextId(); } @Override - public Id assignId(R resource) { + public I assignId(R resource) { if (resource.getId() == null) { - Id id = resources.getNextId(); + I id = resources.getNextId(); resource.setId(id); metaDataMap.get(id).putBoolean(METADATA_KEY_IS_FRESHLY_ASSIGNED_ID, true); } diff --git a/wsf/src/main/java/com/google/gson/rest/server/RestRequestReceiver.java b/wsf/src/main/java/com/google/gson/rest/server/RestRequestReceiver.java index 2d08451f..74134ee5 100644 --- a/wsf/src/main/java/com/google/gson/rest/server/RestRequestReceiver.java +++ b/wsf/src/main/java/com/google/gson/rest/server/RestRequestReceiver.java @@ -26,6 +26,7 @@ import javax.servlet.http.HttpServletRequest; import com.google.gson.Gson; import com.google.gson.JsonParseException; +import com.google.gson.rest.definition.ID; import com.google.gson.rest.definition.RestRequest; import com.google.gson.rest.definition.RestRequestSpec; import com.google.gson.rest.definition.RestResource; @@ -39,7 +40,7 @@ import com.google.gson.webservice.definition.WebServiceSystemException; * * @author inder */ -public final class RestRequestReceiver> { +public final class RestRequestReceiver> { private final Gson gson; private final RestRequestSpec spec; @@ -49,13 +50,13 @@ public final class RestRequestReceiver> { this.spec = spec; } - public RestRequest receive(HttpServletRequest request) { + public RestRequest receive(HttpServletRequest request) { try { HeaderMap requestParams = buildRequestParams(request); R requestBody = buildRequestBody(request); HttpMethod method = HttpMethod.getMethod(request.getMethod()); - return new RestRequest(method, requestParams, requestBody, spec.getResourceType()); + return new RestRequest(method, requestParams, requestBody, spec.getResourceType()); } catch (IOException e) { throw new WebServiceSystemException(e); } catch (JsonParseException e) { diff --git a/wsf/src/main/java/com/google/gson/rest/server/RestResponseBuilder.java b/wsf/src/main/java/com/google/gson/rest/server/RestResponseBuilder.java index 1c7dd16a..6536f5c8 100644 --- a/wsf/src/main/java/com/google/gson/rest/server/RestResponseBuilder.java +++ b/wsf/src/main/java/com/google/gson/rest/server/RestResponseBuilder.java @@ -15,22 +15,22 @@ */ package com.google.gson.rest.server; -import com.google.gson.rest.definition.Id; +import com.google.gson.rest.definition.ID; import com.google.gson.rest.definition.RestCallSpec; import com.google.gson.rest.definition.RestRequest; import com.google.gson.rest.definition.RestResource; import com.google.gson.rest.definition.RestResponse; import com.google.gson.webservice.definition.HttpMethod; -public abstract class RestResponseBuilder> { - protected final Repository resources; +public abstract class RestResponseBuilder> { + protected final Repository resources; - public RestResponseBuilder(Repository resources) { + public RestResponseBuilder(Repository resources) { this.resources = resources; } - public void buildResponse(RestCallSpec callSpec, RestRequest request, - RestResponse.Builder responseBuilder) { + public void buildResponse(RestCallSpec callSpec, RestRequest request, + RestResponse.Builder responseBuilder) { HttpMethod method = request.getMethod(); R responseBody = null; switch (method) { @@ -50,7 +50,7 @@ public abstract class RestResponseBuilder> { responseBuilder.setBody(responseBody); } - public R get(Id resourceId) { + public R get(I resourceId) { return resources.get(resourceId); } @@ -58,7 +58,7 @@ public abstract class RestResponseBuilder> { return resources.put(resource); } - public void delete(Id resourceId) { + public void delete(I resourceId) { resources.delete(resourceId); } diff --git a/wsf/src/main/java/com/google/gson/rest/server/RestResponseSender.java b/wsf/src/main/java/com/google/gson/rest/server/RestResponseSender.java index 26fea71f..623dd521 100644 --- a/wsf/src/main/java/com/google/gson/rest/server/RestResponseSender.java +++ b/wsf/src/main/java/com/google/gson/rest/server/RestResponseSender.java @@ -23,6 +23,7 @@ import java.util.logging.Logger; import javax.servlet.http.HttpServletResponse; import com.google.gson.Gson; +import com.google.gson.rest.definition.ID; import com.google.gson.rest.definition.RestResource; import com.google.gson.rest.definition.RestResponse; import com.google.gson.webservice.definition.ContentBodySpec; @@ -34,7 +35,7 @@ import com.google.gson.webservice.definition.HeaderMapSpec; * * @author inder */ -public final class RestResponseSender> { +public final class RestResponseSender> { private static final Logger logger = Logger.getLogger(RestResponseSender.class.getCanonicalName()); private Gson gson; @@ -43,7 +44,7 @@ public final class RestResponseSender> { this.gson = gson; } - public void send(HttpServletResponse conn, RestResponse response) { + public void send(HttpServletResponse conn, RestResponse response) { try { sendHeaders(conn, response.getHeaders()); sendBody(conn, response.getBody());