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;
}
Aggregations