Search in sources :

Example 1 with ErrorEvent

use of com.vaadin.flow.server.ErrorEvent in project flow by vaadin.

the class ServerRpcHandler method handleInvocationData.

private void handleInvocationData(UI ui, JsonObject invocationJson) {
    String type = invocationJson.getString(JsonConstants.RPC_TYPE);
    RpcInvocationHandler handler = getInvocationHandlers().get(type);
    if (handler == null) {
        throw new IllegalArgumentException("Unsupported event type: " + type);
    }
    try {
        Optional<Runnable> handle = handler.handle(ui, invocationJson);
        assert !handle.isPresent() : "RPC handler " + handler.getClass().getName() + " returned a Runnable even though it shouldn't";
    } catch (Throwable throwable) {
        ui.getSession().getErrorHandler().error(new ErrorEvent(throwable));
    }
}
Also used : RpcInvocationHandler(com.vaadin.flow.server.communication.rpc.RpcInvocationHandler) ErrorEvent(com.vaadin.flow.server.ErrorEvent)

Example 2 with ErrorEvent

use of com.vaadin.flow.server.ErrorEvent in project flow by vaadin.

the class StreamReceiverHandler method handleStream.

private boolean handleStream(VaadinSession session, StreamReceiver streamReceiver, StateNode owner, long contentLength, FileItemStream item) throws IOException {
    String name = item.getName();
    InputStream stream = item.openStream();
    try {
        return handleFileUploadValidationAndData(session, stream, streamReceiver, name, item.getContentType(), contentLength, owner);
    } catch (UploadException e) {
        session.getErrorHandler().error(new ErrorEvent(e));
    }
    return false;
}
Also used : InputStream(java.io.InputStream) UploadException(com.vaadin.flow.server.UploadException) FileUploadException(org.apache.commons.fileupload.FileUploadException) ErrorEvent(com.vaadin.flow.server.ErrorEvent)

Example 3 with ErrorEvent

use of com.vaadin.flow.server.ErrorEvent in project flow by vaadin.

the class StreamReceiverHandler method handleStream.

private boolean handleStream(VaadinSession session, StreamReceiver streamReceiver, StateNode owner, Part part) throws IOException {
    String name = part.getSubmittedFileName();
    InputStream stream = part.getInputStream();
    try {
        return handleFileUploadValidationAndData(session, stream, streamReceiver, name, part.getContentType(), part.getSize(), owner);
    } catch (UploadException e) {
        session.getErrorHandler().error(new ErrorEvent(e));
    }
    return false;
}
Also used : InputStream(java.io.InputStream) UploadException(com.vaadin.flow.server.UploadException) FileUploadException(org.apache.commons.fileupload.FileUploadException) ErrorEvent(com.vaadin.flow.server.ErrorEvent)

Example 4 with ErrorEvent

use of com.vaadin.flow.server.ErrorEvent in project flow by vaadin.

the class StreamReceiverHandler method doHandleXhrFilePost.

/**
 * Used to stream plain file post (aka XHR2.post(File))
 * <p>
 * This method takes care of locking the session as needed and does not
 * assume the caller has locked the session. This allows the session to be
 * locked only when needed and not when handling the upload data.
 * </p>
 *
 * @param session
 *            The session containing the stream variable
 * @param request
 *            The upload request
 * @param response
 *            The upload response
 * @param streamReceiver
 *            the receiver containing the destination stream variable
 * @param owner
 *            The owner of the stream
 * @param contentLength
 *            The length of the request content
 * @throws IOException
 *             If there is a problem reading the request or writing the
 *             response
 */
protected void doHandleXhrFilePost(VaadinSession session, VaadinRequest request, VaadinResponse response, StreamReceiver streamReceiver, StateNode owner, long contentLength) throws IOException {
    // These are unknown in filexhr ATM, maybe add to Accept header that
    // is accessible in portlets
    final String filename = "unknown";
    final String mimeType = filename;
    final InputStream stream = request.getInputStream();
    boolean success = false;
    try {
        success = handleFileUploadValidationAndData(session, stream, streamReceiver, filename, mimeType, contentLength, owner);
    } catch (UploadException e) {
        session.getErrorHandler().error(new ErrorEvent(e));
    }
    sendUploadResponse(response, success);
}
Also used : InputStream(java.io.InputStream) UploadException(com.vaadin.flow.server.UploadException) FileUploadException(org.apache.commons.fileupload.FileUploadException) ErrorEvent(com.vaadin.flow.server.ErrorEvent)

Aggregations

ErrorEvent (com.vaadin.flow.server.ErrorEvent)4 UploadException (com.vaadin.flow.server.UploadException)3 InputStream (java.io.InputStream)3 FileUploadException (org.apache.commons.fileupload.FileUploadException)3 RpcInvocationHandler (com.vaadin.flow.server.communication.rpc.RpcInvocationHandler)1