Search in sources :

Example 1 with StreamReceiver

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

the class StreamRequestHandler method handleRequest.

@Override
public boolean handleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response) throws IOException {
    String pathInfo = request.getPathInfo();
    if (pathInfo == null) {
        return false;
    }
    // remove leading '/'
    assert pathInfo.startsWith(Character.toString(PATH_SEPARATOR));
    pathInfo = pathInfo.substring(1);
    if (!pathInfo.startsWith(DYN_RES_PREFIX)) {
        return false;
    }
    Optional<AbstractStreamResource> abstractStreamResource;
    session.lock();
    try {
        abstractStreamResource = StreamRequestHandler.getPathUri(pathInfo).flatMap(session.getResourceRegistry()::getResource);
        if (!abstractStreamResource.isPresent()) {
            response.sendError(HttpServletResponse.SC_NOT_FOUND, "Resource is not found for path=" + pathInfo);
            return true;
        }
    } finally {
        session.unlock();
    }
    if (abstractStreamResource.isPresent()) {
        AbstractStreamResource resource = abstractStreamResource.get();
        if (resource instanceof StreamResource) {
            resourceHandler.handleRequest(session, request, response, (StreamResource) resource);
        } else if (resource instanceof StreamReceiver) {
            StreamReceiver streamReceiver = (StreamReceiver) resource;
            String[] parts = parsePath(pathInfo);
            receiverHandler.handleRequest(session, request, response, streamReceiver, parts[0], parts[1]);
        } else {
            getLogger().warn("Received unknown stream resource.");
        }
    }
    return true;
}
Also used : AbstractStreamResource(com.vaadin.flow.server.AbstractStreamResource) StreamResource(com.vaadin.flow.server.StreamResource) StreamReceiver(com.vaadin.flow.server.StreamReceiver) AbstractStreamResource(com.vaadin.flow.server.AbstractStreamResource)

Aggregations

AbstractStreamResource (com.vaadin.flow.server.AbstractStreamResource)1 StreamReceiver (com.vaadin.flow.server.StreamReceiver)1 StreamResource (com.vaadin.flow.server.StreamResource)1