From 8122deb3648e54030992f09f6b6fd9ba7e3fc585 Mon Sep 17 00:00:00 2001 From: Inderjeet Singh Date: Tue, 20 Jul 2010 00:34:40 +0000 Subject: [PATCH] fixed copyright notice, minor cosmetic changes. --- .../gson/wsexample/server/MainServlet.java | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/wsexample/server/src/main/java/com/google/gson/wsexample/server/MainServlet.java b/wsexample/server/src/main/java/com/google/gson/wsexample/server/MainServlet.java index e72b43d3..98c9a5d7 100644 --- a/wsexample/server/src/main/java/com/google/gson/wsexample/server/MainServlet.java +++ b/wsexample/server/src/main/java/com/google/gson/wsexample/server/MainServlet.java @@ -1,5 +1,18 @@ -// Copyright 2010 Google Inc. All Rights Reserved. - +/* + * 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.wsexample.server; import com.google.gson.Gson; @@ -33,11 +46,9 @@ import javax.servlet.http.HttpServletResponse; public class MainServlet extends HttpServlet { @Override public void service(HttpServletRequest req, HttpServletResponse res) { - // construct specs WebServiceCallSpec spec = SampleJsonService.PLACE_ORDER; RequestSpec requestSpec = spec.getRequestSpec(); ResponseSpec responseSpec = spec.getResponseSpec(); - // construct gson instance Gson gson = new GsonBuilder() .registerTypeAdapter(RequestBody.class, new RequestBodyGsonConverter(requestSpec.getBodySpec())) @@ -46,11 +57,13 @@ public class MainServlet extends HttpServlet { .create(); RequestReceiver requestReceiver = new RequestReceiver(gson, requestSpec); WebServiceRequest webServiceRequest = requestReceiver.receive(req); - RequestBody requestBody = webServiceRequest.getBody(); - Cart cart = requestBody.get(TypedKeys.RequestBody.CART); + + Cart cart = webServiceRequest.getBody().get(TypedKeys.RequestBody.CART); String authToken = webServiceRequest.getHeader(TypedKeys.Request.AUTH_TOKEN); + Order order = placeOrder(cart, authToken); + // Empty headers per the spec HeaderMap responseHeaders = new HeaderMap.Builder(responseSpec.getHeadersSpec()).build(); ResponseBody responseBody = new ResponseBody.Builder(responseSpec.getBodySpec()) .put(TypedKeys.ResponseBody.ORDER, order) @@ -61,6 +74,7 @@ public class MainServlet extends HttpServlet { } private Order placeOrder(Cart cart, String authToken) { + // Create an order, in this case a dummy one. return new Order(cart, "Order123"); } }