Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into collect-telemetry
Browse files Browse the repository at this point in the history
  • Loading branch information
ricklue committed Jul 17, 2024
2 parents 310a96d + 01654ba commit 8c65d2f
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 25 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/start-frontend-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ jobs:
workflow_id: 'testing.js.yml',
ref: 'master',
inputs: {
useRealFrontend: 'true',
frontendCommitToCheckout: 'tags/v${{ steps.get_frontendVersion.outputs.frontendVersion }}',
frontendCommitToCheckout: 'master',
backendCommitToCheckout: '${{ github.ref_name }}',
mergeMasterToBranch: 'true'
}
Expand Down
24 changes: 21 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
<properties>
<revision>3.0-SNAPSHOT</revision>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<frontend.version>0.0.57</frontend.version><!-- Is parsed by the GitHub actions test that triggers the ladybug-frontend Cypress test -->
<maven.compiler.release>11</maven.compiler.release>
<frontend.version>0.1.0-20240711.113931</frontend.version><!-- Is parsed by the GitHub actions test that triggers the ladybug-frontend Cypress test -->
<spring.version>6.1.7</spring.version>
<cxf.version>4.0.4</cxf.version>
<jackson.version>2.17.1</jackson.version>
Expand Down Expand Up @@ -70,10 +71,27 @@
https://search.maven.org/artifact/org.webjars.npm/wearefrank__ladybug
-->
<dependency>
<groupId>org.webjars.npm</groupId>
<artifactId>wearefrank__ladybug</artifactId>
<groupId>org.wearefrank</groupId>
<artifactId>ladybug-frontend</artifactId>
<version>${frontend.version}</version>
</dependency>
<!-- Dit soort dependencies gaan gebruiken? moeten eigenlijk via transitive dependencies van frontend project meekomen?
<dependency>
<groupId>org.webjars.npm</groupId>
<artifactId>monaco-editor</artifactId>
<version>0.28.1</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>3.6.0</version>
</dependency>
-->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-rs-client</artifactId>
Expand Down
75 changes: 57 additions & 18 deletions src/main/java/nl/nn/testtool/web/AngularServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

import jakarta.servlet.RequestDispatcher;
import jakarta.servlet.ServletException;
Expand Down Expand Up @@ -62,6 +63,7 @@ public class AngularServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private String artifactId;
private String version = "";
private boolean useRequestDispatcher = false;

/**
* Set artifactId of WebJars jar that contains the Angular app to be served. In case of a Maven project the pom.xml
Expand All @@ -83,6 +85,18 @@ public void setVersion(String version) {
this.version = "/" + version;
}

/**
* The servlet 3 specification allows static resources from /META-INF/resources to be served by the application
* server. For Tomcat this means that the JarScanner should not be configured to skip the WebJar (see also
* https://www.webjars.org/documentation#servlet3). Hence useRequestDispatcher is false by default (works in all
* situations).
*
* @param useRequestDispatcher set to true to dispatch requests and make the application server serve the resources
*/
public void setUseRequestDispatcher(boolean useRequestDispatcher) {
this.useRequestDispatcher = useRequestDispatcher;
}

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
Expand Down Expand Up @@ -124,32 +138,57 @@ public ServletOutputStream getOutputStream() throws IOException {
} else {
webJarsRequestURI = webJarsBase + artifactId + version + pathInfo;
}
// When Servlet 3 method (see https://www.webjars.org/documentation#servlet3) is used the Content-Type header
// isn't set (tested with Tomcat 9.0.60) which will cause problems when X-Content-Type-Options: nosniff is being
// used. Hence set the header like it is done by WebJars Servlet 2
// (https://www.webjars.org/documentation#servlet2)
// Set Content-Type header to prevent problems when X-Content-Type-Options: nosniff is being used.
// Copied from WebJars Servlet 2. Would maybe be nice to set caching related headers also.
// https://www.webjars.org/documentation#servlet2
// https://github.com/webjars/webjars-servlet-2.x/blob/master/src/main/java/org/webjars/servlet/WebjarsServlet.java
String[] tokens = webJarsRequestURI.split("/");
String filename = tokens[tokens.length - 1];
String mimeType = getServletContext().getMimeType(filename);
response.setContentType(mimeType != null ? mimeType : "application/octet-stream");
HttpServletRequestWrapper requestWrapper = new HttpServletRequestWrapper(request) {
@Override
public String getServletPath() {
return webJarsBase;
if (!useRequestDispatcher) {
String resourceName = "/META-INF/resources" + webJarsRequestURI;
try (InputStream inputStream = this.getClass().getResourceAsStream(resourceName)) {
if (inputStream != null) {
inputStream.transferTo(response.getOutputStream());
} else {
if (forceIndexHtml) {
// Prevent infinite recursion when index.html is not found
throw new FileNotFoundException("The requested resource [" + webJarsRequestURI + "] is not available");
} else {
// Serve index.html when a resource is not found
includeWebJarAsset(request, response, true);
}
}
}
@Override
public String getRequestURI() {
return webJarsRequestURI;
} else {
HttpServletRequestWrapper requestWrapper = new HttpServletRequestWrapper(request) {
@Override
public String getServletPath() {
return webJarsBase;
}
@Override
public String getRequestURI() {
return webJarsRequestURI;
}
};
try {
RequestDispatcher requestDispatcher = request.getRequestDispatcher(webJarsRequestURI);
// Using forward instead of include would set Content-Type and caching related headers but doesn't
// throw an exception when resource is not found (allowing for index.html to be served)
requestDispatcher.include(requestWrapper, response);
} catch(RuntimeException e) {
if (forceIndexHtml) {
// Prevent infinite recursion when index.html is not found
throw e;
} else {
// Serve index.html when a resource is not found
includeWebJarAsset(request, response, true);
}
}
};
try {
RequestDispatcher requestDispatcher = request.getRequestDispatcher(webJarsRequestURI);
requestDispatcher.include(requestWrapper, response);
} catch(FileNotFoundException e) {
// Serve index.html when a resource is not found
includeWebJarAsset(request, response, true);
}
}

}

class BaseRewritingServletOutputStream extends ServletOutputStream {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/nl/nn/testtool/web/FrontendServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ public static String getDefaultMapping() {

@Override
public void init() throws ServletException {
String artifactId = "wearefrank__ladybug";
String artifactId = "ladybug-frontend";
setArtifactId(artifactId);
try {
String resource = "/META-INF/maven/org.webjars.npm/" + artifactId + "/pom.properties";
String resource = "/META-INF/maven/org.wearefrank/" + artifactId + "/pom.properties";
InputStream inputStream = this.getClass().getResourceAsStream(resource);
if (inputStream != null) {
Properties properties = new Properties();
Expand Down

0 comments on commit 8c65d2f

Please sign in to comment.