From 0a134db2f0ea5e7577a5a455e299e85fef1b05fe Mon Sep 17 00:00:00 2001 From: Inderjeet Singh Date: Wed, 20 Jan 2010 13:53:53 +0000 Subject: [PATCH] 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 --- .../gson/wsf/server/ResponseBuilder.java | 30 +++++++++++++++++++ .../gson/wsf/server/ResponseSender.java | 2 ++ 2 files changed, 32 insertions(+) create mode 100644 wsf/src/main/java/com/google/gson/wsf/server/ResponseBuilder.java diff --git a/wsf/src/main/java/com/google/gson/wsf/server/ResponseBuilder.java b/wsf/src/main/java/com/google/gson/wsf/server/ResponseBuilder.java new file mode 100644 index 00000000..89dfd352 --- /dev/null +++ b/wsf/src/main/java/com/google/gson/wsf/server/ResponseBuilder.java @@ -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); +} diff --git a/wsf/src/main/java/com/google/gson/wsf/server/ResponseSender.java b/wsf/src/main/java/com/google/gson/wsf/server/ResponseSender.java index 2cccf9d4..5cd4a7c7 100644 --- a/wsf/src/main/java/com/google/gson/wsf/server/ResponseSender.java +++ b/wsf/src/main/java/com/google/gson/wsf/server/ResponseSender.java @@ -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) {