LOG.fine("Unexpected error : content type is null " + t.toString());
}
}
// Get BeanConverter for Request payload.
BeanConverter requestConverter = getConverterForRequest(contentType, format);
// Get BeanConverter for Response body.
BeanConverter responseConverter = getConverterForFormat(format);
Reader bodyReader = null;
if (!servletRequest.getMethod().equals("GET") && !servletRequest.getMethod().equals("HEAD")) {
bodyReader = servletRequest.getReader();
}
// Execute the request
@SuppressWarnings("unchecked")
Map<String, String[]> parameterMap = servletRequest.getParameterMap();
Future<?> future = handler.execute(parameterMap, bodyReader, token, requestConverter);
ResponseItem responseItem = getResponseItem(future);
servletResponse.setContentType(responseConverter.getContentType());
if (responseItem.getErrorCode() >= 200 && responseItem.getErrorCode() < 400) {
PrintWriter writer = servletResponse.getWriter();
Object response = responseItem.getResponse();
// TODO: ugliness resulting from not using RestfulItem
if (!(response instanceof DataCollection) && !(response instanceof RestfulCollection)) {
response = ImmutableMap.of("entry", response);
}
// JSONP style callbacks
String callback = (this.isJSONPAllowed && HttpUtil.isJSONP(servletRequest) &&
ContentTypes.OUTPUT_JSON_CONTENT_TYPE.equals(responseConverter.getContentType())) ?
servletRequest.getParameter("callback") : null;
if (callback != null) writer.write(callback + '(');
writer.write(responseConverter.convertToString(response));
if (callback != null) writer.write(");\n");
} else {
sendError(servletResponse, responseItem);
}
}