diff --git a/build.gradle b/build.gradle index dd857586e6..b77d97947c 100644 --- a/build.gradle +++ b/build.gradle @@ -60,7 +60,7 @@ dependencies { api "org.eclipse.jetty:jetty-alpn-java-client" api "org.eclipse.jetty:jetty-alpn-client" - api "org.eclipse.jetty.websocket:websocket-jakarta-server" + api "org.eclipse.jetty.websocket:websocket-jakarta-server:$versions.jetty" api "io.jsonwebtoken:jjwt-api:0.11.5" api "io.jsonwebtoken:jjwt-impl:0.11.5" @@ -219,9 +219,6 @@ allprojects { version = '1.0.0-Snapshot' } - sourceCompatibility = 11 - targetCompatibility = 11 - compileJava { options.encoding = 'UTF-8' diff --git a/wiremock-jetty12/build.gradle b/wiremock-jetty12/build.gradle index 4887b46d5e..780d1a36bb 100644 --- a/wiremock-jetty12/build.gradle +++ b/wiremock-jetty12/build.gradle @@ -55,6 +55,9 @@ dependencies { api "org.eclipse.jetty.http2:jetty-http2-server:$versions.jetty" api "org.eclipse.jetty:jetty-alpn-java-server:$versions.jetty" + api "org.eclipse.jetty:jetty-rewrite:$versions.jetty" + api "org.eclipse.jetty.ee10.websocket:jetty-ee10-websocket-jakarta-server:$versions.jetty" + testImplementation "org.eclipse.jetty.http2:jetty-http2-client:$versions.jetty" testImplementation "org.eclipse.jetty.http2:jetty-http2-client-transport:$versions.jetty" testImplementation "org.eclipse.jetty:jetty-alpn-java-client:$versions.jetty" diff --git a/wiremock-jetty12/src/main/java/com/github/tomakehurst/wiremock/jetty12/Jetty12HttpServer.java b/wiremock-jetty12/src/main/java/com/github/tomakehurst/wiremock/jetty12/Jetty12HttpServer.java index 9cd8e07b2c..d0bee2b4ce 100644 --- a/wiremock-jetty12/src/main/java/com/github/tomakehurst/wiremock/jetty12/Jetty12HttpServer.java +++ b/wiremock-jetty12/src/main/java/com/github/tomakehurst/wiremock/jetty12/Jetty12HttpServer.java @@ -35,6 +35,7 @@ import com.github.tomakehurst.wiremock.jetty.JettyFaultInjectorFactory; import com.github.tomakehurst.wiremock.jetty.JettyHttpServer; import com.github.tomakehurst.wiremock.jetty.JettyHttpUtils; +import com.github.tomakehurst.wiremock.jetty.websockets.WebSocketEndpoint; import com.github.tomakehurst.wiremock.jetty11.Jetty11Utils; import com.github.tomakehurst.wiremock.jetty11.SslContexts; import com.github.tomakehurst.wiremock.servlet.ContentTypeSettingFilter; @@ -53,11 +54,14 @@ import org.eclipse.jetty.ee10.servlet.ServletContextRequest; import org.eclipse.jetty.ee10.servlet.ServletHolder; import org.eclipse.jetty.ee10.servlets.CrossOriginFilter; +import org.eclipse.jetty.ee10.websocket.jakarta.server.config.JakartaWebSocketServletContainerInitializer; import org.eclipse.jetty.http.HttpVersion; import org.eclipse.jetty.http.MimeTypes; import org.eclipse.jetty.http2.server.HTTP2CServerConnectionFactory; import org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory; import org.eclipse.jetty.io.NetworkTrafficListener; +import org.eclipse.jetty.rewrite.handler.RewriteHandler; +import org.eclipse.jetty.rewrite.handler.RewriteRegexRule; import org.eclipse.jetty.server.*; import org.eclipse.jetty.server.handler.gzip.GzipHandler; import org.eclipse.jetty.util.Callback; @@ -211,6 +215,12 @@ protected Handler createHandler( notifier); final List handlers = new ArrayList<>(); + // wiremock-gui + // We prepend the rewrite handle for the wiremock gui web app to make sure that we route the + // requests properly + final RewriteHandler rewriteHandler = webAppRewriteContext(adminContext); + handlers.add(rewriteHandler); + Handler.Abstract asyncTimeoutSettingHandler = new Handler.Abstract() { @Override @@ -247,6 +257,29 @@ protected void decorateAdminServiceContextBeforeConfig( protected void decorateAdminServiceContextAfterConfig( ServletContextHandler adminServiceContext) {} + // wiremock-gui + /** + * Rewrite web app. We use Angular. We must rewrite every /__admin/webapp path to the index.html + * of our single page application. + * + * @param adminContextHandler admin context handler is used to provide the static file content + * @return the rewrite handler + */ + private RewriteHandler webAppRewriteContext(ServletContextHandler adminContextHandler) { + final RewriteHandler rewrite = new RewriteHandler(); + // rewrite.setRewriteRequestURI(true); + // rewrite.setRewritePathInfo(true); + + RewriteRegexRule rewriteRule = new RewriteRegexRule(); + rewriteRule.setRegex("/__admin/webapp/(mappings|matched|unmatched|state|files).*"); + rewriteRule.setReplacement("/__admin/webapp/index.html"); + rewrite.addRule(rewriteRule); + + rewrite.setHandler(adminContextHandler); + + return rewrite; + } + private void addCorsFilter(ServletContextHandler context) { context.addFilter(buildCorsFilter(), "/*", EnumSet.of(DispatcherType.REQUEST)); } @@ -301,6 +334,17 @@ private ServletContextHandler addAdminContext( adminContext.addServlet(NotMatchedServlet.class, "/not-matched"); + // wiremock-gui Include into admin context + ServletHolder webapp = adminContext.addServlet(DefaultServlet.class, "/webapp/*"); + webapp.setAsyncSupported(false); + + // wiremock-gui Include websocket into admin context + JakartaWebSocketServletContainerInitializer.configure( + adminContext, + (servletContext, serverContainer) -> { + serverContainer.addEndpoint(WebSocketEndpoint.class); + }); + addCorsFilter(adminContext); decorateAdminServiceContextAfterConfig(adminContext);