Second attempt to fix #459
This commit is contained in:
parent
012090b719
commit
61d6f1ba8d
|
@ -22,6 +22,7 @@ package ca.uhn.fhir.rest.server;
|
|||
import static org.apache.commons.lang3.StringUtils.isBlank;
|
||||
import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.Writer;
|
||||
|
@ -651,13 +652,15 @@ public class RestfulServer extends HttpServlet implements IRestfulServer<Servlet
|
|||
* This is basically the end of processing for a successful request, since the
|
||||
* method binding replies to the client and closes the response.
|
||||
*/
|
||||
resourceMethod.invokeServer(this, requestDetails);
|
||||
Closeable outputStreamOrWriter = (Closeable) resourceMethod.invokeServer(this, requestDetails);
|
||||
|
||||
for (int i = getInterceptors().size() - 1; i >= 0; i--) {
|
||||
IServerInterceptor next = getInterceptors().get(i);
|
||||
next.processingCompletedNormally(requestDetails);
|
||||
}
|
||||
|
||||
outputStreamOrWriter.close();
|
||||
|
||||
} catch (NotModifiedException e) {
|
||||
|
||||
for (int i = getInterceptors().size() - 1; i >= 0; i--) {
|
||||
|
@ -1141,24 +1144,19 @@ public class RestfulServer extends HttpServlet implements IRestfulServer<Servlet
|
|||
if (allowPrefer) {
|
||||
addContentLocationHeaders(theRequest, servletResponse, response, resourceName);
|
||||
}
|
||||
Writer writer;
|
||||
if (outcome != null) {
|
||||
ResponseEncoding encoding = RestfulServerUtils.determineResponseEncodingWithDefault(theRequest);
|
||||
servletResponse.setContentType(encoding.getResourceContentType());
|
||||
Writer writer = servletResponse.getWriter();
|
||||
writer = servletResponse.getWriter();
|
||||
IParser parser = encoding.getEncoding().newParser(getFhirContext());
|
||||
parser.setPrettyPrint(RestfulServerUtils.prettyPrintResponse(this, theRequest));
|
||||
try {
|
||||
outcome.execute(parser, writer);
|
||||
} finally {
|
||||
writer.close();
|
||||
}
|
||||
outcome.execute(parser, writer);
|
||||
} else {
|
||||
servletResponse.setContentType(Constants.CT_TEXT_WITH_UTF8);
|
||||
Writer writer = servletResponse.getWriter();
|
||||
writer.close();
|
||||
writer = servletResponse.getWriter();
|
||||
}
|
||||
// getMethod().in
|
||||
return null;
|
||||
return writer;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -21,6 +21,7 @@ package ca.uhn.fhir.rest.server.interceptor;
|
|||
*/
|
||||
import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
@ -51,7 +52,8 @@ public class ExceptionHandlingInterceptor extends InterceptorAdapter {
|
|||
|
||||
@Override
|
||||
public boolean handleException(RequestDetails theRequestDetails, BaseServerResponseException theException, HttpServletRequest theRequest, HttpServletResponse theResponse) throws ServletException, IOException {
|
||||
handleException(theRequestDetails, theException);
|
||||
Closeable writer = (Closeable) handleException(theRequestDetails, theException);
|
||||
writer.close();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -50,12 +50,12 @@ public class ServletRestfulResponse extends RestfulResponse<ServletRequestDetail
|
|||
theHttpResponse.setStatus(stausCode);
|
||||
theHttpResponse.setContentType(contentType);
|
||||
if (bin.getContent() == null || bin.getContent().length == 0) {
|
||||
return null;
|
||||
return theHttpResponse.getOutputStream();
|
||||
} else {
|
||||
theHttpResponse.setContentLength(bin.getContent().length);
|
||||
ServletOutputStream oos = theHttpResponse.getOutputStream();
|
||||
oos.write(bin.getContent());
|
||||
return null;
|
||||
return oos;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -83,8 +83,8 @@ public class ServletRestfulResponse extends RestfulResponse<ServletRequestDetail
|
|||
}
|
||||
|
||||
@Override
|
||||
public final Object sendWriterResponse(int status, String contentType, String charset, Writer writer) throws IOException {
|
||||
return null;
|
||||
public final Object sendWriterResponse(int theStatus, String theContentType, String theCharset, Writer theWriter) throws IOException {
|
||||
return theWriter;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue