added ability to specify a Gson instance for use in getting a response.

This commit is contained in:
Inderjeet Singh 2010-02-03 05:07:52 +00:00
parent f300cf35a2
commit 9c8e8bd77e

View File

@ -61,16 +61,20 @@ public final class WebServiceClient {
}
public WebServiceResponse getResponse(WebServiceCallSpec callSpec, WebServiceRequest request) {
Gson gson = new GsonBuilder().registerTypeAdapter(ResponseBody.class,
new ResponseBodyGsonConverter(callSpec.getResponseSpec().getBodySpec()))
.create();
return getResponse(callSpec, request, gson);
}
public WebServiceResponse getResponse(
WebServiceCallSpec callSpec, WebServiceRequest request, Gson gson) {
try {
URL webServiceUrl = getWebServiceUrl(callSpec);
if (logger != null) {
logger.log(logLevel, "Opening connection to " + webServiceUrl);
}
HttpURLConnection conn = (HttpURLConnection) webServiceUrl.openConnection();
Gson gson = new GsonBuilder()
.registerTypeAdapter(ResponseBody.class,
new ResponseBodyGsonConverter(callSpec.getResponseSpec().getBodySpec()))
.create();
RequestSender requestSender = new RequestSender(gson, logLevel);
requestSender.send(conn, request);
ResponseReceiver responseReceiver =