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