Added a new interface ResponseBuilder that is implemented by handlers to build a response of a specific type.

ResponseSender now sets the content-type of the stream to application/json
This commit is contained in:
Inderjeet Singh 2010-01-20 13:53:53 +00:00
parent e5c89f1ebc
commit 0a134db2f0
2 changed files with 32 additions and 0 deletions

View File

@ -0,0 +1,30 @@
/*
* 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;
import com.google.gson.webservice.definition.WebServiceCallSpec;
import com.google.gson.webservice.definition.WebServiceRequest;
import com.google.gson.webservice.definition.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);
}

View File

@ -26,6 +26,7 @@ import com.google.gson.Gson;
import com.google.gson.webservice.definition.HeaderMap;
import com.google.gson.webservice.definition.HeaderMapSpec;
import com.google.gson.webservice.definition.ResponseBody;
import com.google.gson.webservice.definition.ResponseBodySpec;
import com.google.gson.webservice.definition.WebServiceResponse;
/**
@ -44,6 +45,7 @@ public final class ResponseSender {
public void send(HttpServletResponse conn, WebServiceResponse response) {
try {
conn.setContentType(ResponseBodySpec.JSON_CONTENT_TYPE);
sendHeaders(conn, response.getHeaders());
sendBody(conn, response.getBody());
} catch (IOException e) {