From d69290f3e94d6589bd049693d226a10e9b926c9e Mon Sep 17 00:00:00 2001 From: Inderjeet Singh Date: Sun, 14 Nov 2010 08:32:56 +0000 Subject: [PATCH] moved contents of wsf into greaze-server --- .../wsexample/server/ProcedureDispatcher.java | 4 +- .../gson/wsexample/server/RestDispatcher.java | 12 +-- .../com/google/gson/rest/server/IdMap.java | 79 -------------- .../google/gson/rest/server/MetaDataMap.java | 52 --------- .../google/gson/rest/server/Repository.java | 48 --------- .../gson/rest/server/RepositoryInMemory.java | 95 ----------------- .../gson/rest/server/ResponseBuilderMap.java | 57 ---------- .../gson/rest/server/RestRequestReceiver.java | 96 ----------------- .../gson/rest/server/RestResponseBuilder.java | 68 ------------ .../gson/rest/server/RestResponseSender.java | 75 ------------- .../gson/wsf/inject/CallPathProvider.java | 45 -------- .../procedural/RequestBodySpecProvider.java | 41 ------- .../procedural/RequestSpecProvider.java | 41 ------- .../WebServiceCallServerProvider.java | 57 ---------- .../WebServiceCallSpecProvider.java | 43 -------- .../server/procedural/RequestReceiver.java | 100 ------------------ .../server/procedural/ResponseBuilder.java | 30 ------ .../wsf/server/procedural/ResponseSender.java | 73 ------------- .../WebServiceCallServerBuilder.java | 29 ----- .../main/resources/assembly-descriptor.xml | 21 ---- wsf/src/main/resources/javadoc-descriptor.xml | 18 ---- 21 files changed, 8 insertions(+), 1076 deletions(-) delete mode 100644 wsf/src/main/java/com/google/gson/rest/server/IdMap.java delete mode 100644 wsf/src/main/java/com/google/gson/rest/server/MetaDataMap.java delete mode 100644 wsf/src/main/java/com/google/gson/rest/server/Repository.java delete mode 100644 wsf/src/main/java/com/google/gson/rest/server/RepositoryInMemory.java delete mode 100644 wsf/src/main/java/com/google/gson/rest/server/ResponseBuilderMap.java delete mode 100644 wsf/src/main/java/com/google/gson/rest/server/RestRequestReceiver.java delete mode 100644 wsf/src/main/java/com/google/gson/rest/server/RestResponseBuilder.java delete mode 100644 wsf/src/main/java/com/google/gson/rest/server/RestResponseSender.java delete mode 100644 wsf/src/main/java/com/google/gson/wsf/inject/CallPathProvider.java delete mode 100644 wsf/src/main/java/com/google/gson/wsf/inject/server/procedural/RequestBodySpecProvider.java delete mode 100644 wsf/src/main/java/com/google/gson/wsf/inject/server/procedural/RequestSpecProvider.java delete mode 100755 wsf/src/main/java/com/google/gson/wsf/inject/server/procedural/WebServiceCallServerProvider.java delete mode 100755 wsf/src/main/java/com/google/gson/wsf/inject/server/procedural/WebServiceCallSpecProvider.java delete mode 100644 wsf/src/main/java/com/google/gson/wsf/server/procedural/RequestReceiver.java delete mode 100644 wsf/src/main/java/com/google/gson/wsf/server/procedural/ResponseBuilder.java delete mode 100644 wsf/src/main/java/com/google/gson/wsf/server/procedural/ResponseSender.java delete mode 100644 wsf/src/main/java/com/google/gson/wsf/server/procedural/WebServiceCallServerBuilder.java delete mode 100644 wsf/src/main/resources/assembly-descriptor.xml delete mode 100644 wsf/src/main/resources/javadoc-descriptor.xml diff --git a/wsexample/server/src/main/java/com/google/gson/wsexample/server/ProcedureDispatcher.java b/wsexample/server/src/main/java/com/google/gson/wsexample/server/ProcedureDispatcher.java index 8660fe67..432b1aca 100644 --- a/wsexample/server/src/main/java/com/google/gson/wsexample/server/ProcedureDispatcher.java +++ b/wsexample/server/src/main/java/com/google/gson/wsexample/server/ProcedureDispatcher.java @@ -28,14 +28,14 @@ import com.google.greaze.definition.webservice.ResponseSpec; import com.google.greaze.definition.webservice.WebServiceCallSpec; import com.google.greaze.definition.webservice.WebServiceRequest; import com.google.greaze.definition.webservice.WebServiceResponse; +import com.google.greaze.webservice.server.RequestReceiver; +import com.google.greaze.webservice.server.ResponseSender; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.example.model.Cart; import com.google.gson.example.model.Order; import com.google.gson.example.model.TypedKeys; import com.google.gson.example.service.SampleJsonService; -import com.google.gson.wsf.server.procedural.RequestReceiver; -import com.google.gson.wsf.server.procedural.ResponseSender; /** * A dispatcher for all the procedural calls diff --git a/wsexample/server/src/main/java/com/google/gson/wsexample/server/RestDispatcher.java b/wsexample/server/src/main/java/com/google/gson/wsexample/server/RestDispatcher.java index f3f32648..e20566ca 100644 --- a/wsexample/server/src/main/java/com/google/gson/wsexample/server/RestDispatcher.java +++ b/wsexample/server/src/main/java/com/google/gson/wsexample/server/RestDispatcher.java @@ -26,17 +26,17 @@ import com.google.greaze.definition.rest.RestCallSpec; import com.google.greaze.definition.rest.RestRequest; import com.google.greaze.definition.rest.RestResponse; import com.google.greaze.definition.rest.ValueBasedId; +import com.google.greaze.rest.server.Repository; +import com.google.greaze.rest.server.RepositoryInMemory; +import com.google.greaze.rest.server.ResponseBuilderMap; +import com.google.greaze.rest.server.RestRequestReceiver; +import com.google.greaze.rest.server.RestResponseBuilder; +import com.google.greaze.rest.server.RestResponseSender; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.example.model.Cart; import com.google.gson.example.model.Order; import com.google.gson.example.service.ServicePaths; -import com.google.gson.rest.server.Repository; -import com.google.gson.rest.server.RepositoryInMemory; -import com.google.gson.rest.server.ResponseBuilderMap; -import com.google.gson.rest.server.RestRequestReceiver; -import com.google.gson.rest.server.RestResponseBuilder; -import com.google.gson.rest.server.RestResponseSender; /** * A dispatcher for all the REST requests 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 deleted file mode 100644 index b652c574..00000000 --- a/wsf/src/main/java/com/google/gson/rest/server/IdMap.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (C) 2010 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.google.gson.rest.server; - -import java.lang.reflect.Type; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import java.util.logging.Level; -import java.util.logging.Logger; - -import com.google.greaze.definition.rest.HasId; -import com.google.greaze.definition.rest.ID; -import com.google.greaze.definition.rest.IDFactory; - -/** - * This class provides a type-safe map to access values associated with Ids - * - * @author inder - * - * @param the type of the objects being kept in the map - */ -public class IdMap> { - public static final Logger LOG = Logger.getLogger(IdMap.class.getName()); - public static final long ID_START_VALUE = 1L; - protected final Map map; - private volatile long nextAvailableId; - private final IDFactory idFactory; - - /** - * Use create(Type) instead of constructor - */ - protected IdMap(Class classOfI, Type typeOfId) { - map = new ConcurrentHashMap(); - nextAvailableId = ID_START_VALUE; - this.idFactory = new IDFactory(classOfI, typeOfId); - } - - public T get(I id) { - return map.get(id); - } - - public T put(T obj) { - map.put(obj.getId(), obj); - return obj; - } - - 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(I id) { - return map.containsKey(id); - } - - public synchronized I getNextId() { - long id = nextAvailableId++; - return idFactory.createId(id); - } - - 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 deleted file mode 100644 index 38465661..00000000 --- a/wsf/src/main/java/com/google/gson/rest/server/MetaDataMap.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (C) 2010 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.google.gson.rest.server; - -import java.util.HashMap; -import java.util.Map; - -import com.google.greaze.definition.rest.ID; -import com.google.greaze.definition.rest.MetaData; -import com.google.greaze.definition.rest.RestResource; - -/** - * A map of resources to their MetaData - * - * @author inder - * - * @param the rest resource for whic the metadata is being stored - */ -public class MetaDataMap> { - private final Map> map; - - public MetaDataMap() { - this.map = new HashMap>(); - } - - public MetaData get(I resourceId) { - MetaData metaData = map.get(resourceId); - if (metaData == null) { - metaData = MetaData.create(); - map.put(resourceId, metaData); - } - return metaData; - } - - @Override - public String toString() { - return String.format("%s", map); - } -} 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 deleted file mode 100644 index e19fd659..00000000 --- a/wsf/src/main/java/com/google/gson/rest/server/Repository.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) 2010 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.google.gson.rest.server; - -import com.google.greaze.definition.rest.HasId; -import com.google.greaze.definition.rest.ID; - -/** - * An interface for a repository of rest resources. Meant for abstracting the server-side - * storage of rest resources. - * - * @author inder - * - * @param the type of rest resource - */ -public interface Repository> { - public R get(I resourceId); - - /** - * if resource.getId() == null, inserts the resource after assigning it a new id. - * Otherwise, updates the resource ensuring that it pre-exists. - */ - public R put(R resource); - - public void delete(I resourceId); - - public boolean exists(I resourceId); - - /** - * Ensures that the specified resource has a valid id that will be used when it is saved - */ - public I assignId(R resource); - - 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 deleted file mode 100644 index 259fbce1..00000000 --- a/wsf/src/main/java/com/google/gson/rest/server/RepositoryInMemory.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (C) 2010 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.google.gson.rest.server; - -import com.google.common.base.Preconditions; -import com.google.greaze.definition.rest.ID; -import com.google.greaze.definition.rest.MetaData; -import com.google.greaze.definition.rest.RestResource; - -/** - * An in-memory map of rest resources - * - * @author inder - * - * @param Type variable for the resource - */ -public class RepositoryInMemory> implements Repository { - private static final String METADATA_KEY_IS_FRESHLY_ASSIGNED_ID = "isFreshlyAssignedId"; - - private final IdMap resources; - private final MetaDataMap metaDataMap; - - public RepositoryInMemory(Class classOfI, Class classOfResource) { - this.resources = IdMap.create(classOfI, classOfResource); - this.metaDataMap = new MetaDataMap(); - } - - @Override - public R get(I resourceId) { - return resources.get(resourceId); - } - - public boolean isFreshlyAssignedId(I resourceId) { - MetaData metaData = metaDataMap.get(resourceId); - if (metaData == null) { - return false; - } - return metaData.getBoolean(METADATA_KEY_IS_FRESHLY_ASSIGNED_ID); - } - - @Override - public R put(R resource) { - if (!resource.hasId()) { - // insert semantics - assignId(resource); - } else { - I id = resource.getId(); - if (!isFreshlyAssignedId(id)) { - // update semantics - Preconditions.checkState(resources.exists(resource.getId())); - } - } - resource = resources.put(resource); - metaDataMap.get(resource.getId()).remove(METADATA_KEY_IS_FRESHLY_ASSIGNED_ID); - return resource; - } - - @Override - public void delete(I resourceId) { - resources.delete(resourceId); - } - - @Override - public boolean exists(I resourceId) { - return resources.exists(resourceId); - } - - @Override - public I getNextId() { - return resources.getNextId(); - } - - @Override - public I assignId(R resource) { - if (resource.getId() == null) { - I id = resources.getNextId(); - resource.setId(id); - metaDataMap.get(id).putBoolean(METADATA_KEY_IS_FRESHLY_ASSIGNED_ID, true); - } - return resource.getId(); - } -} diff --git a/wsf/src/main/java/com/google/gson/rest/server/ResponseBuilderMap.java b/wsf/src/main/java/com/google/gson/rest/server/ResponseBuilderMap.java deleted file mode 100644 index 12da8ff9..00000000 --- a/wsf/src/main/java/com/google/gson/rest/server/ResponseBuilderMap.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) 2010 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.google.gson.rest.server; - -import java.lang.reflect.Type; -import java.util.HashMap; -import java.util.Map; - -import com.google.greaze.definition.rest.ID; -import com.google.greaze.definition.rest.RestCallSpec; -import com.google.greaze.definition.rest.RestResource; - -/** - * A map of {@link RestCallSpec}, {@link RestResponseBuilder} to help figure out which - * {@link RestResponseBuilder} to use for a {@link RestCallSpec}. - * - * @author Inderjeet Singh - */ -public final class ResponseBuilderMap { - public static final class Builder { - private final Map> map = - new HashMap>(); - - public > Builder set( - Type resourceType, RestResponseBuilder responseBuilder) { - map.put(resourceType, responseBuilder); - return this; - } - - public ResponseBuilderMap build() { - return new ResponseBuilderMap(map); - } - } - - private final Map> map; - - public ResponseBuilderMap(Map> map) { - this.map = map; - } - - public RestResponseBuilder get(Type resourceType) { - return map.get(resourceType); - } -} 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 deleted file mode 100644 index 8be43849..00000000 --- a/wsf/src/main/java/com/google/gson/rest/server/RestRequestReceiver.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.google.gson.rest.server; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.Reader; -import java.lang.reflect.Type; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; - -import com.google.greaze.definition.HeaderMap; -import com.google.greaze.definition.HeaderMapSpec; -import com.google.greaze.definition.HttpMethod; -import com.google.greaze.definition.WebServiceSystemException; -import com.google.greaze.definition.rest.ID; -import com.google.greaze.definition.rest.RestRequest; -import com.google.greaze.definition.rest.RestRequestSpec; -import com.google.greaze.definition.rest.RestResource; -import com.google.gson.Gson; -import com.google.gson.JsonParseException; - -/** - * Receives and parses a request at the server side on a {@link HttpServletRequest}. - * - * @author inder - */ -public final class RestRequestReceiver> { - - private final Gson gson; - private final RestRequestSpec spec; - - public RestRequestReceiver(Gson gson, RestRequestSpec spec) { - this.gson = gson; - this.spec = spec; - } - - public RestRequest receive(HttpServletRequest request, I resourceId) { - try { - HeaderMap requestParams = buildRequestParams(request); - R requestBody = buildRequestBody(request); - - HttpMethod method = HttpMethod.getMethod(request.getMethod()); - String simulatedMethod = request.getHeader(HttpMethod.SIMULATED_METHOD_HEADER); - if (simulatedMethod != null && !simulatedMethod.equals("")) { - method = HttpMethod.getMethod(simulatedMethod); - } - return new RestRequest(method, requestParams, resourceId, requestBody, spec.getResourceType()); - } catch (IOException e) { - throw new WebServiceSystemException(e); - } catch (JsonParseException e) { - // Not a Web service request - throw new WebServiceSystemException(e); - } - } - - private HeaderMap buildRequestParams(HttpServletRequest request) { - HeaderMapSpec paramsSpec = this.spec.getHeadersSpec(); - HeaderMap.Builder paramsBuilder = new HeaderMap.Builder(paramsSpec); - for (Map.Entry param : paramsSpec.entrySet()) { - String name = param.getKey(); - Type type = param.getValue(); - String header = request.getHeader(name); - if (header == null || header.equals("")) { - // check parameter map for the value - header = request.getParameter(name); - } - if (header != null && !header.equals("")) { - Object value = gson.fromJson(header, type); - paramsBuilder.put(name, value); - } - } - return paramsBuilder.build(); - } - - private R buildRequestBody(HttpServletRequest request) throws IOException { - Reader reader = new BufferedReader(new InputStreamReader(request.getInputStream())); - R requestBody = gson.fromJson(reader, spec.getResourceType()); - return requestBody; - } -} 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 deleted file mode 100644 index ae9bd7d7..00000000 --- a/wsf/src/main/java/com/google/gson/rest/server/RestResponseBuilder.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (C) 2010 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.google.gson.rest.server; - -import com.google.greaze.definition.HttpMethod; -import com.google.greaze.definition.rest.ID; -import com.google.greaze.definition.rest.RestCallSpec; -import com.google.greaze.definition.rest.RestRequest; -import com.google.greaze.definition.rest.RestResource; -import com.google.greaze.definition.rest.RestResponse; - -public class RestResponseBuilder> { - protected final Repository resources; - - public RestResponseBuilder(Repository resources) { - this.resources = resources; - } - - public void buildResponse(RestCallSpec callSpec, RestRequest request, - RestResponse.Builder responseBuilder) { - HttpMethod method = request.getMethod(); - R responseBody = null; - switch (method) { - case GET: - responseBody = get(request.getId()); - break; - case POST: - responseBody = post(request.getBody()); - break; - case DELETE: - delete(request.getId()); - break; - case PUT: - default: - throw new IllegalStateException("Unexpected method: " + method); - } - responseBuilder.setBody(responseBody); - } - - public R get(I resourceId) { - return resources.get(resourceId); - } - - public R post(R resource) { - return resources.put(resource); - } - - public void delete(I resourceId) { - resources.delete(resourceId); - } - - public R put(R resource) { - return resources.put(resource); - } -} 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 deleted file mode 100644 index e34dbd67..00000000 --- a/wsf/src/main/java/com/google/gson/rest/server/RestResponseSender.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.google.gson.rest.server; - -import java.io.IOException; -import java.lang.reflect.Type; -import java.util.Map; -import java.util.logging.Logger; - -import javax.servlet.http.HttpServletResponse; - -import com.google.greaze.definition.ContentBodySpec; -import com.google.greaze.definition.HeaderMap; -import com.google.greaze.definition.HeaderMapSpec; -import com.google.greaze.definition.rest.ID; -import com.google.greaze.definition.rest.RestResource; -import com.google.greaze.definition.rest.RestResponse; -import com.google.gson.Gson; - -/** - * Sends a JSON web service response on {@link HttpServletResponse}. - * - * @author inder - */ -public final class RestResponseSender> { - private static final Logger logger = Logger.getLogger(RestResponseSender.class.getCanonicalName()); - - private Gson gson; - - public RestResponseSender(Gson gson) { - this.gson = gson; - } - - public void send(HttpServletResponse conn, RestResponse response) { - try { - sendHeaders(conn, response.getHeaders()); - sendBody(conn, response.getBody()); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - private void sendHeaders(HttpServletResponse conn, HeaderMap responseParams) { - HeaderMapSpec spec = responseParams.getSpec(); - for (Map.Entry param : responseParams.entrySet()) { - String paramName = param.getKey(); - Object paramValue = param.getValue(); - Type paramType = spec.getTypeFor(paramName); - String json = gson.toJson(paramValue, paramType); - logger.fine("RESPONSE HEADER:{" + paramName + ", " + json + "}"); - conn.addHeader(paramName, json); - } - } - - private void sendBody(HttpServletResponse conn, R responseBody) throws IOException { - conn.setContentType(ContentBodySpec.JSON_CONTENT_TYPE); - conn.setCharacterEncoding(ContentBodySpec.JSON_CHARACTER_ENCODING); - String json = gson.toJson(responseBody); - logger.fine("RESPONSE BODY:" + json); - conn.getWriter().append(json); - } -} diff --git a/wsf/src/main/java/com/google/gson/wsf/inject/CallPathProvider.java b/wsf/src/main/java/com/google/gson/wsf/inject/CallPathProvider.java deleted file mode 100644 index 3e74ee0d..00000000 --- a/wsf/src/main/java/com/google/gson/wsf/inject/CallPathProvider.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.google.gson.wsf.inject; - -import javax.servlet.http.HttpServletRequest; - -import com.google.greaze.definition.CallPath; -import com.google.inject.Inject; -import com.google.inject.Provider; - -/** - * Guice provider for {@link CallPath} for an incoming web service request. - * - * @author inder - */ -public final class CallPathProvider implements Provider { - private final CallPath callPath; - - @Inject - public CallPathProvider(HttpServletRequest request) { - this(request.getPathInfo()); - } - - public CallPathProvider(String pathInfo) { - this.callPath = new CallPath(pathInfo); - } - - @Override - public CallPath get() { - return callPath; - } -} diff --git a/wsf/src/main/java/com/google/gson/wsf/inject/server/procedural/RequestBodySpecProvider.java b/wsf/src/main/java/com/google/gson/wsf/inject/server/procedural/RequestBodySpecProvider.java deleted file mode 100644 index 6bdd987f..00000000 --- a/wsf/src/main/java/com/google/gson/wsf/inject/server/procedural/RequestBodySpecProvider.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.google.gson.wsf.inject.server.procedural; - -import com.google.greaze.definition.webservice.RequestBodySpec; -import com.google.greaze.definition.webservice.RequestSpec; -import com.google.inject.Inject; -import com.google.inject.Provider; - -/** - * Guice provider for the {@link RequestBodySpec} to map to the incoming requests. - * - * @author inder - */ -public final class RequestBodySpecProvider implements Provider { - - private final RequestSpec requestSpec; - - @Inject - public RequestBodySpecProvider(RequestSpec requestSpec) { - this.requestSpec = requestSpec; - } - - @Override - public RequestBodySpec get() { - return requestSpec.getBodySpec(); - } -} diff --git a/wsf/src/main/java/com/google/gson/wsf/inject/server/procedural/RequestSpecProvider.java b/wsf/src/main/java/com/google/gson/wsf/inject/server/procedural/RequestSpecProvider.java deleted file mode 100644 index 495a300e..00000000 --- a/wsf/src/main/java/com/google/gson/wsf/inject/server/procedural/RequestSpecProvider.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.google.gson.wsf.inject.server.procedural; - -import com.google.greaze.definition.webservice.RequestSpec; -import com.google.greaze.definition.webservice.WebServiceCallSpec; -import com.google.inject.Inject; -import com.google.inject.Provider; - -/** - * Guice provider for the {@link RequestSpec} to map to the incoming requests. - * - * @author inder - */ -public final class RequestSpecProvider implements Provider { - - private final WebServiceCallSpec webServiceCallSpec; - - @Inject - public RequestSpecProvider(WebServiceCallSpec webServiceCallSpec) { - this.webServiceCallSpec = webServiceCallSpec; - } - - @Override - public RequestSpec get() { - return webServiceCallSpec.getRequestSpec(); - } -} diff --git a/wsf/src/main/java/com/google/gson/wsf/inject/server/procedural/WebServiceCallServerProvider.java b/wsf/src/main/java/com/google/gson/wsf/inject/server/procedural/WebServiceCallServerProvider.java deleted file mode 100755 index 02eb3df9..00000000 --- a/wsf/src/main/java/com/google/gson/wsf/inject/server/procedural/WebServiceCallServerProvider.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.google.gson.wsf.inject.server.procedural; - -import javax.servlet.http.HttpServletRequest; - -import com.google.greaze.definition.webservice.WebServiceCall; -import com.google.greaze.definition.webservice.WebServiceCallSpec; -import com.google.greaze.definition.webservice.WebServiceRequest; -import com.google.greaze.definition.webservice.WebServiceResponse; -import com.google.gson.Gson; -import com.google.gson.wsf.server.procedural.RequestReceiver; -import com.google.gson.wsf.server.procedural.WebServiceCallServerBuilder; -import com.google.inject.Inject; -import com.google.inject.Provider; - -/** - * Guice provider for {@link WebServiceCall} to be used by a server-side implementation. - * - * @author inder - */ -public final class WebServiceCallServerProvider implements Provider { - private final Gson gson; - private final WebServiceCallSpec callSpec; - private final HttpServletRequest request; - - @Inject - public WebServiceCallServerProvider(Gson gson, HttpServletRequest request, - WebServiceCallSpec callSpec) { - this.callSpec = callSpec; - this.gson = gson; - this.request = request; - } - - @Override - public WebServiceCallServerBuilder get() { - RequestReceiver receiver = new RequestReceiver(gson, callSpec.getRequestSpec()); - WebServiceRequest wsRequest = receiver.receive(request); - - WebServiceResponse.Builder responseBuilder = - new WebServiceResponse.Builder(callSpec.getResponseSpec()); - return new WebServiceCallServerBuilder(callSpec, wsRequest, responseBuilder); - } -} \ No newline at end of file diff --git a/wsf/src/main/java/com/google/gson/wsf/inject/server/procedural/WebServiceCallSpecProvider.java b/wsf/src/main/java/com/google/gson/wsf/inject/server/procedural/WebServiceCallSpecProvider.java deleted file mode 100755 index dbd5bb20..00000000 --- a/wsf/src/main/java/com/google/gson/wsf/inject/server/procedural/WebServiceCallSpecProvider.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.google.gson.wsf.inject.server.procedural; - -import com.google.greaze.definition.CallPath; -import com.google.greaze.definition.webservice.WebServiceCallSpec; -import com.google.greaze.definition.webservice.WebServiceSpec; -import com.google.inject.Inject; -import com.google.inject.Provider; - -/** - * Guice provider for {@link WebServiceCallSpec}. - * - * @author inder - */ -public final class WebServiceCallSpecProvider implements Provider { - private final CallPath callPath; - private final WebServiceSpec webServiceSpec; - - @Inject - WebServiceCallSpecProvider(CallPath callPath, WebServiceSpec webServiceSpec) { - this.callPath = callPath; - this.webServiceSpec = webServiceSpec; - } - - @Override - public WebServiceCallSpec get() { - return webServiceSpec.getCalls().get(callPath); - } -} \ No newline at end of file diff --git a/wsf/src/main/java/com/google/gson/wsf/server/procedural/RequestReceiver.java b/wsf/src/main/java/com/google/gson/wsf/server/procedural/RequestReceiver.java deleted file mode 100644 index 5c24c2b2..00000000 --- a/wsf/src/main/java/com/google/gson/wsf/server/procedural/RequestReceiver.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.google.gson.wsf.server.procedural; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.Reader; -import java.lang.reflect.Type; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; - -import com.google.greaze.definition.HeaderMap; -import com.google.greaze.definition.HeaderMapSpec; -import com.google.greaze.definition.HttpMethod; -import com.google.greaze.definition.WebServiceSystemException; -import com.google.greaze.definition.webservice.RequestBody; -import com.google.greaze.definition.webservice.RequestBodySpec; -import com.google.greaze.definition.webservice.RequestSpec; -import com.google.greaze.definition.webservice.WebServiceRequest; -import com.google.gson.Gson; -import com.google.gson.JsonParseException; - -/** - * Receives and parses a request at the server side on a {@link HttpServletRequest}. - * - * @author inder - */ -public final class RequestReceiver { - - private final Gson gson; - private final RequestSpec spec; - - public RequestReceiver(Gson gson, RequestSpec spec) { - this.gson = gson; - this.spec = spec; - } - - public WebServiceRequest receive(HttpServletRequest request) { - try { - HeaderMap requestParams = buildRequestParams(request); - RequestBody requestBody = buildRequestBody(request); - - HttpMethod method = HttpMethod.getMethod(request.getMethod()); - return new WebServiceRequest(method, requestParams, requestBody); - } catch (IOException e) { - throw new WebServiceSystemException(e); - } catch (JsonParseException e) { - // Not a Web service request - throw new WebServiceSystemException(e); - } - } - - private HeaderMap buildRequestParams(HttpServletRequest request) { - HeaderMapSpec paramsSpec = this.spec.getHeadersSpec(); - HeaderMap.Builder paramsBuilder = new HeaderMap.Builder(paramsSpec); - for (Map.Entry param : paramsSpec.entrySet()) { - String name = param.getKey(); - Type type = param.getValue(); - String header = request.getHeader(name); - if (header == null || header.equals("")) { - // check parameter map for the value - header = request.getParameter(name); - } - if (header != null && !header.equals("")) { - Object value = gson.fromJson(header, type); - paramsBuilder.put(name, value); - } - } - return paramsBuilder.build(); - } - - private RequestBody buildRequestBody(HttpServletRequest request) throws IOException { - RequestBodySpec bodySpec = spec.getBodySpec(); - if (bodySpec.size() == 0) { - return createEmptyRequestBody(bodySpec); - } - Reader reader = new BufferedReader(new InputStreamReader(request.getInputStream())); - RequestBody requestBody = gson.fromJson(reader, RequestBody.class); - return requestBody; - } - - private RequestBody createEmptyRequestBody(RequestBodySpec bodySpec) { - return new RequestBody.Builder(bodySpec).build(); - } -} diff --git a/wsf/src/main/java/com/google/gson/wsf/server/procedural/ResponseBuilder.java b/wsf/src/main/java/com/google/gson/wsf/server/procedural/ResponseBuilder.java deleted file mode 100644 index cb223e6c..00000000 --- a/wsf/src/main/java/com/google/gson/wsf/server/procedural/ResponseBuilder.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (C) 2010 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.google.gson.wsf.server.procedural; - -import com.google.greaze.definition.webservice.WebServiceCallSpec; -import com.google.greaze.definition.webservice.WebServiceRequest; -import com.google.greaze.definition.webservice.WebServiceResponse; - -/** - * An interface describing a class that can build a response - * - * @author inder - */ -public interface ResponseBuilder { - public void buildResponse(WebServiceCallSpec callSpec, WebServiceRequest request, - WebServiceResponse.Builder responseBuilder); -} diff --git a/wsf/src/main/java/com/google/gson/wsf/server/procedural/ResponseSender.java b/wsf/src/main/java/com/google/gson/wsf/server/procedural/ResponseSender.java deleted file mode 100644 index 5e15727a..00000000 --- a/wsf/src/main/java/com/google/gson/wsf/server/procedural/ResponseSender.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.google.gson.wsf.server.procedural; - -import java.io.IOException; -import java.lang.reflect.Type; -import java.util.Map; -import java.util.logging.Logger; - -import javax.servlet.http.HttpServletResponse; - -import com.google.greaze.definition.HeaderMap; -import com.google.greaze.definition.HeaderMapSpec; -import com.google.greaze.definition.webservice.ResponseBody; -import com.google.greaze.definition.webservice.WebServiceResponse; -import com.google.gson.Gson; - -/** - * Sends a JSON web service response on {@link HttpServletResponse}. - * - * @author inder - */ -public final class ResponseSender { - private static final Logger logger = Logger.getLogger(ResponseSender.class.getCanonicalName()); - - private Gson gson; - - public ResponseSender(Gson gson) { - this.gson = gson; - } - - public void send(HttpServletResponse conn, WebServiceResponse response) { - try { - sendHeaders(conn, response.getHeaders()); - sendBody(conn, response.getBody()); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - private void sendHeaders(HttpServletResponse conn, HeaderMap responseParams) { - HeaderMapSpec spec = responseParams.getSpec(); - for (Map.Entry param : responseParams.entrySet()) { - String paramName = param.getKey(); - Object paramValue = param.getValue(); - Type paramType = spec.getTypeFor(paramName); - String json = gson.toJson(paramValue, paramType); - logger.fine("RESPONSE HEADER:{" + paramName + ", " + json + "}"); - conn.addHeader(paramName, json); - } - } - - private void sendBody(HttpServletResponse conn, ResponseBody responseBody) throws IOException { - conn.setContentType(responseBody.getContentType()); - conn.setCharacterEncoding(responseBody.getCharacterEncoding()); - String json = gson.toJson(responseBody); - logger.fine("RESPONSE BODY:" + json); - conn.getWriter().append(json); - } -} diff --git a/wsf/src/main/java/com/google/gson/wsf/server/procedural/WebServiceCallServerBuilder.java b/wsf/src/main/java/com/google/gson/wsf/server/procedural/WebServiceCallServerBuilder.java deleted file mode 100644 index ea3cbdc9..00000000 --- a/wsf/src/main/java/com/google/gson/wsf/server/procedural/WebServiceCallServerBuilder.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (C) 2009 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.google.gson.wsf.server.procedural; - -import com.google.greaze.definition.webservice.WebServiceCallSpec; -import com.google.greaze.definition.webservice.WebServiceRequest; -import com.google.greaze.definition.webservice.WebServiceResponse.Builder; - -public class WebServiceCallServerBuilder { - - public WebServiceCallServerBuilder( - @SuppressWarnings("unused") WebServiceCallSpec callSpec, - @SuppressWarnings("unused") WebServiceRequest wsRequest, - @SuppressWarnings("unused") Builder responseBuilder) { - } -} diff --git a/wsf/src/main/resources/assembly-descriptor.xml b/wsf/src/main/resources/assembly-descriptor.xml deleted file mode 100644 index 600d1536..00000000 --- a/wsf/src/main/resources/assembly-descriptor.xml +++ /dev/null @@ -1,21 +0,0 @@ - - release - - zip - - - - - README* - LICENSE* - - - - target - - - wsf-*.jar - - - - \ No newline at end of file diff --git a/wsf/src/main/resources/javadoc-descriptor.xml b/wsf/src/main/resources/javadoc-descriptor.xml deleted file mode 100644 index 156f64a6..00000000 --- a/wsf/src/main/resources/javadoc-descriptor.xml +++ /dev/null @@ -1,18 +0,0 @@ - - true - - - - - - - - - - - - - - - -