use of com.vaadin.flow.shared.ApplicationConstants.CONTENT_TYPE_TEXT_JAVASCRIPT_UTF_8 in project flow by vaadin.
the class WebComponentProvider method synchronizedHandleRequest.
@Override
public boolean synchronizedHandleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response) throws IOException {
String pathInfo = request.getPathInfo();
final ComponentInfo componentInfo = new ComponentInfo(pathInfo);
if (!componentInfo.hasExtension()) {
LoggerFactory.getLogger(WebComponentProvider.class).info("Received web-component request without extension " + "information (.js/.html) with request path {}", pathInfo);
return false;
}
if (componentInfo.getTag() == null) {
LoggerFactory.getLogger(WebComponentProvider.class).info("Received web-component request for non-custom element with request path {}", pathInfo);
return false;
}
if (componentInfo.isHTML()) {
LoggerFactory.getLogger(WebComponentProvider.class).info("Received web-component request for html component in npm" + " mode with request path {}", pathInfo);
return false;
}
WebComponentConfigurationRegistry registry = WebComponentConfigurationRegistry.getInstance(request.getService().getContext());
Optional<WebComponentConfiguration<? extends Component>> optionalWebComponentConfiguration = registry.getConfiguration(componentInfo.tag);
if (optionalWebComponentConfiguration.isPresent()) {
WebComponentConfiguration<? extends Component> webComponentConfiguration = optionalWebComponentConfiguration.get();
String generated;
Supplier<String> responder;
response.setContentType(CONTENT_TYPE_TEXT_JAVASCRIPT_UTF_8);
responder = () -> generateNPMResponse(webComponentConfiguration.getTag(), request, response);
if (cache == null) {
generated = responder.get();
} else {
generated = cache.computeIfAbsent(componentInfo.tag, moduleTag -> responder.get());
}
IOUtils.write(generated, response.getOutputStream(), StandardCharsets.UTF_8);
} else {
response.sendError(HttpServletResponse.SC_NOT_FOUND, "No web component for " + Optional.ofNullable(componentInfo.tag).orElse("<null>"));
}
return true;
}
Aggregations