Search in sources :

Example 1 with IBinaryResourceConsumer

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();
    }
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) BinaryResource(org.eclipse.scout.rt.platform.resource.BinaryResource) JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) PlatformException(org.eclipse.scout.rt.platform.exception.PlatformException) ArrayList(java.util.ArrayList) IBinaryResourceConsumer(org.eclipse.scout.rt.ui.html.res.IBinaryResourceConsumer)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ReentrantLock (java.util.concurrent.locks.ReentrantLock)1 PlatformException (org.eclipse.scout.rt.platform.exception.PlatformException)1 BinaryResource (org.eclipse.scout.rt.platform.resource.BinaryResource)1 IBinaryResourceConsumer (org.eclipse.scout.rt.ui.html.res.IBinaryResourceConsumer)1 JSONObject (org.json.JSONObject)1