use of org.eclipse.scout.rt.ui.html.res.IBinaryResourceConsumer in project scout.rt by eclipse.
the class UploadRequestHandler method handleUploadFileRequest.
protected void handleUploadFileRequest(IUiSession uiSession, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, String targetAdapterId) throws IOException, FileUploadException {
// If client sent ACK#, cleanup response history accordingly
uiSession.confirmResponseProcessed(getAckSequenceNo(httpServletRequest));
IBinaryResourceConsumer binaryResourceConsumer = resolveJsonAdapter(uiSession, targetAdapterId);
if (binaryResourceConsumer == null) {
// Request was already processed and adapter does not exist anymore
return;
}
if (httpServletRequest.getParameter("legacy") != null) {
httpServletResponse.setContentType("text/plain");
}
// Read uploaded data
Map<String, String> uploadProperties = new HashMap<String, String>();
List<BinaryResource> uploadResources = new ArrayList<>();
try {
readUploadData(httpServletRequest, binaryResourceConsumer.getMaximumBinaryResourceUploadSize(), uploadProperties, uploadResources);
} catch (PlatformException ex) {
// NOSONAR
writeJsonResponse(httpServletResponse, m_jsonRequestHelper.createUnsafeUploadResponse());
return;
}
// GUI requests for the same session must be processed consecutively
final ReentrantLock uiSessionLock = uiSession.uiSessionLock();
uiSessionLock.lock();
try {
if (uiSession.isDisposed()) {
writeJsonResponse(httpServletResponse, m_jsonRequestHelper.createSessionTimeoutResponse());
return;
}
JSONObject jsonResp = uiSession.processFileUpload(httpServletRequest, httpServletResponse, binaryResourceConsumer, uploadResources, uploadProperties);
if (jsonResp == null) {
jsonResp = m_jsonRequestHelper.createEmptyResponse();
}
writeJsonResponse(httpServletResponse, jsonResp);
} finally {
uiSessionLock.unlock();
}
}
Aggregations