fixed copyright notice, minor cosmetic changes.

This commit is contained in:
Inderjeet Singh 2010-07-20 00:34:40 +00:00
parent 425a59043d
commit 8122deb364

View File

@ -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");
}
}