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:
parent
e5c89f1ebc
commit
0a134db2f0
@ -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);
|
||||||
|
}
|
@ -26,6 +26,7 @@ import com.google.gson.Gson;
|
|||||||
import com.google.gson.webservice.definition.HeaderMap;
|
import com.google.gson.webservice.definition.HeaderMap;
|
||||||
import com.google.gson.webservice.definition.HeaderMapSpec;
|
import com.google.gson.webservice.definition.HeaderMapSpec;
|
||||||
import com.google.gson.webservice.definition.ResponseBody;
|
import com.google.gson.webservice.definition.ResponseBody;
|
||||||
|
import com.google.gson.webservice.definition.ResponseBodySpec;
|
||||||
import com.google.gson.webservice.definition.WebServiceResponse;
|
import com.google.gson.webservice.definition.WebServiceResponse;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -44,6 +45,7 @@ public final class ResponseSender {
|
|||||||
|
|
||||||
public void send(HttpServletResponse conn, WebServiceResponse response) {
|
public void send(HttpServletResponse conn, WebServiceResponse response) {
|
||||||
try {
|
try {
|
||||||
|
conn.setContentType(ResponseBodySpec.JSON_CONTENT_TYPE);
|
||||||
sendHeaders(conn, response.getHeaders());
|
sendHeaders(conn, response.getHeaders());
|
||||||
sendBody(conn, response.getBody());
|
sendBody(conn, response.getBody());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
Loading…
Reference in New Issue
Block a user