Skip to content

Commit

Permalink
Merge branch 'main' into remove-middleware-in-a-better-way
Browse files Browse the repository at this point in the history
  • Loading branch information
Artur- authored Jan 22, 2024
2 parents cc27a52 + b00aa55 commit 1b933e9
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@
import java.io.Serializable;
import java.io.UncheckedIOException;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashSet;
Expand Down Expand Up @@ -161,7 +164,7 @@ private static Logger getLogger() {

private URL getResourceUrl(ServletContext context, String path)
throws MalformedURLException {
URL resourceUrl = context.getResource(path);
URL resourceUrl = VaadinServletService.getStaticResource(context, path);
if (resourceUrl == null) {
// this is a workaround specific for Spring default static resources
// location: see #8705
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,27 @@ public boolean serveStaticResource(HttpServletRequest request,
return true;
}
} catch (IOException e) {
getLogger().error("Unable to load " + filenameWithPath
+ " from the frontend dev server: " + e.getMessage());
if (getLogger().isTraceEnabled()) {
getLogger().trace("Unable to load " + filenameWithPath
+ " from the frontend dev server", e);
} else {
getLogger().error("Unable to load " + filenameWithPath
+ " from the frontend dev server: " + e.getMessage());
}
try {
response.sendError(
HttpStatusCode.INTERNAL_SERVER_ERROR.getCode(),
"Unable to load " + filenameWithPath
+ " from the frontend dev server: "
+ e.getMessage());
} catch (Exception ee) {
// The server might have partly written an output. If so, let's
// just go with that
getLogger().trace(
"Ignoring exception when writing dev server error response",
ee);
}
return true;
}

URL resourceUrl = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@

import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
Expand Down Expand Up @@ -240,7 +243,7 @@ public String resolveResource(String url) {
@Override
public URL getStaticResource(String path) {
try {
return getServlet().getServletContext().getResource(path);
return getStaticResource(getServlet().getServletContext(), path);
} catch (MalformedURLException e) {
getLogger().warn("Error finding resource for '{}'", path, e);
}
Expand Down Expand Up @@ -316,4 +319,22 @@ protected VaadinContext constructVaadinContext() {
protected void setDefaultClassLoader() {
setClassLoader(getServlet().getServletContext().getClassLoader());
}

static URL getStaticResource(ServletContext servletContext, String path)
throws MalformedURLException {
URL url = servletContext.getResource(path);
if (url != null && Optional.ofNullable(servletContext.getServerInfo())
.orElse("").contains("jetty/12.")) {
// Making sure that resource exists before returning it. Jetty
// 12 may return URL for non-existing resource.
try {
if (!Files.exists(Path.of(url.toURI()))) {
url = null;
}
} catch (URISyntaxException e) {
url = null;
}
}
return url;
}
}
2 changes: 1 addition & 1 deletion flow-tests/vaadin-spring-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

<properties>
<maven.deploy.skip>true</maven.deploy.skip>
<component.version>24.3.2</component.version>
<component.version>24.3.3</component.version>
<nimbus-jose-jwt.version>9.37.3</nimbus-jose-jwt.version>
</properties>

Expand Down

0 comments on commit 1b933e9

Please sign in to comment.