This is an automated email from the ASF dual-hosted git repository.

hanicz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/knox.git


The following commit(s) were added to refs/heads/master by this push:
     new e47e58b39 KNOX-3199: Topology level async support (#1105)
e47e58b39 is described below

commit e47e58b39cf164c4c5b01ee61bd0d8e32faff1d8
Author: hanicz <[email protected]>
AuthorDate: Mon Nov 17 17:42:01 2025 +0100

    KNOX-3199: Topology level async support (#1105)
---
 .../gateway/ha/dispatch/SSEHaDispatchTest.java     |  4 ++
 .../gateway/config/impl/GatewayConfigImpl.java     | 10 ++++
 .../knox/gateway/deploy/DeploymentFactory.java     |  5 +-
 .../gateway/config/impl/GatewayConfigImplTest.java | 20 +++++++
 .../org/apache/knox/gateway/GatewayTestConfig.java |  5 ++
 .../apache/knox/gateway/config/GatewayConfig.java  |  4 +-
 .../org/apache/knox/gateway/sse/SSEDispatch.java   |  4 +-
 .../apache/knox/gateway/sse/SSEDispatchTest.java   | 64 ++++++++++++++++------
 8 files changed, 96 insertions(+), 20 deletions(-)

diff --git 
a/gateway-provider-ha/src/test/java/org/apache/knox/gateway/ha/dispatch/SSEHaDispatchTest.java
 
b/gateway-provider-ha/src/test/java/org/apache/knox/gateway/ha/dispatch/SSEHaDispatchTest.java
index b8b224735..6e74177f0 100644
--- 
a/gateway-provider-ha/src/test/java/org/apache/knox/gateway/ha/dispatch/SSEHaDispatchTest.java
+++ 
b/gateway-provider-ha/src/test/java/org/apache/knox/gateway/ha/dispatch/SSEHaDispatchTest.java
@@ -110,6 +110,7 @@ public class SSEHaDispatchTest {
         
expect(gatewayConfig.getHttpClientSocketTimeout()).andReturn(20000).once();
         
expect(gatewayConfig.getHttpClientCookieSpec()).andReturn(CookieSpecs.STANDARD).anyTimes();
         expect(gatewayConfig.isAsyncSupported()).andReturn(true).anyTimes();
+        
expect(gatewayConfig.isTopologyAsyncSupported("SSE")).andReturn(false).anyTimes();
 
         GatewayServices gatewayServices = createMock(GatewayServices.class);
         
expect(gatewayServices.getService(ServiceType.KEYSTORE_SERVICE)).andReturn(keystoreService).once();
@@ -117,6 +118,7 @@ public class SSEHaDispatchTest {
         ServletContext servletContext = createMock(ServletContext.class);
         
expect(servletContext.getAttribute(GatewayConfig.GATEWAY_CONFIG_ATTRIBUTE)).andReturn(gatewayConfig).atLeastOnce();
         
expect(servletContext.getAttribute(GatewayServices.GATEWAY_SERVICES_ATTRIBUTE)).andReturn(gatewayServices).atLeastOnce();
+        
expect(servletContext.getAttribute(GatewayServices.GATEWAY_CLUSTER_ATTRIBUTE)).andReturn("SSE").atLeastOnce();
 
         FilterConfig filterConfig = createMock(FilterConfig.class);
         
expect(filterConfig.getServletContext()).andReturn(servletContext).atLeastOnce();
@@ -688,6 +690,7 @@ public class SSEHaDispatchTest {
         
expect(gatewayConfig.getHttpClientSocketTimeout()).andReturn(20000).once();
         
expect(gatewayConfig.getHttpClientCookieSpec()).andReturn(CookieSpecs.STANDARD).anyTimes();
         expect(gatewayConfig.isAsyncSupported()).andReturn(true).anyTimes();
+        
expect(gatewayConfig.isTopologyAsyncSupported("SSE")).andReturn(false).once();
 
         GatewayServices gatewayServices = createMock(GatewayServices.class);
         
expect(gatewayServices.getService(ServiceType.KEYSTORE_SERVICE)).andReturn(keystoreService).once();
@@ -695,6 +698,7 @@ public class SSEHaDispatchTest {
         ServletContext servletContext = createMock(ServletContext.class);
         
expect(servletContext.getAttribute(GatewayConfig.GATEWAY_CONFIG_ATTRIBUTE)).andReturn(gatewayConfig).atLeastOnce();
         
expect(servletContext.getAttribute(GatewayServices.GATEWAY_SERVICES_ATTRIBUTE)).andReturn(gatewayServices).atLeastOnce();
+        
expect(servletContext.getAttribute(GatewayServices.GATEWAY_CLUSTER_ATTRIBUTE)).andReturn("SSE").atLeastOnce();
 
         FilterConfig filterConfig = createMock(FilterConfig.class);
         
expect(filterConfig.getServletContext()).andReturn(servletContext).atLeastOnce();
diff --git 
a/gateway-server/src/main/java/org/apache/knox/gateway/config/impl/GatewayConfigImpl.java
 
b/gateway-server/src/main/java/org/apache/knox/gateway/config/impl/GatewayConfigImpl.java
index 22429bab0..495d82646 100644
--- 
a/gateway-server/src/main/java/org/apache/knox/gateway/config/impl/GatewayConfigImpl.java
+++ 
b/gateway-server/src/main/java/org/apache/knox/gateway/config/impl/GatewayConfigImpl.java
@@ -356,6 +356,7 @@ public class GatewayConfigImpl extends Configuration 
implements GatewayConfig {
 
   private static final String GATEWAY_SERVLET_ASYNC_SUPPORTED = 
GATEWAY_CONFIG_FILE_PREFIX + ".servlet.async.supported";
   private static final boolean GATEWAY_SERVLET_ASYNC_SUPPORTED_DEFAULT = false;
+  private static final String GATEWAY_SERVLET_ASYNC_SUPPORTED_TOPOLOGIES = 
GATEWAY_SERVLET_ASYNC_SUPPORTED + ".topologies";
 
   private static final String GATEWAY_HEALTH_CHECK_TOPOLOGIES = 
GATEWAY_CONFIG_FILE_PREFIX + ".health.check.topologies";
 
@@ -1568,6 +1569,15 @@ public class GatewayConfigImpl extends Configuration 
implements GatewayConfig {
     return getBoolean(GATEWAY_SERVLET_ASYNC_SUPPORTED, 
GATEWAY_SERVLET_ASYNC_SUPPORTED_DEFAULT);
   }
 
+  @Override
+  public boolean isTopologyAsyncSupported(String topology) {
+      String topologies = get(GATEWAY_SERVLET_ASYNC_SUPPORTED_TOPOLOGIES);
+      if (StringUtils.isBlank(topologies)) {
+          return false;
+      }
+      return Arrays.stream(topologies.split(",")).anyMatch(t -> 
t.trim().equalsIgnoreCase(topology));
+  }
+
   @Override
   public boolean canSeeAllTokens(String userName) {
     final Collection<String> usersCanSeeAllTokens = 
getTrimmedStringCollection(USERS_CAN_SEE_ALL_TOKENS);
diff --git 
a/gateway-server/src/main/java/org/apache/knox/gateway/deploy/DeploymentFactory.java
 
b/gateway-server/src/main/java/org/apache/knox/gateway/deploy/DeploymentFactory.java
index a8ae6c810..cc0861f41 100644
--- 
a/gateway-server/src/main/java/org/apache/knox/gateway/deploy/DeploymentFactory.java
+++ 
b/gateway-server/src/main/java/org/apache/knox/gateway/deploy/DeploymentFactory.java
@@ -374,13 +374,14 @@ public abstract class DeploymentFactory {
       GatewayConfig gatewayConfig) {
     WebAppDescriptor wad = context.getWebAppDescriptor();
     String topoName = context.getTopology().getName();
+    boolean asyncSupported = gatewayConfig.isAsyncSupported() || 
gatewayConfig.isTopologyAsyncSupported(topoName);
     if( applications == null ) {
       String servletName = topoName + SERVLET_NAME_SUFFIX;
-      
wad.createServlet().asyncSupported(gatewayConfig.isAsyncSupported()).servletName(servletName).servletClass(GatewayServlet.class.getName());
+      
wad.createServlet().asyncSupported(asyncSupported).servletName(servletName).servletClass(GatewayServlet.class.getName());
       wad.createServletMapping().servletName( servletName ).urlPattern( "/*" );
     } else {
       String filterName = topoName + FILTER_NAME_SUFFIX;
-      
wad.createFilter().asyncSupported(gatewayConfig.isAsyncSupported()).filterName(filterName).filterClass(GatewayServlet.class.getName());
+      
wad.createFilter().asyncSupported(asyncSupported).filterName(filterName).filterClass(GatewayServlet.class.getName());
       wad.createFilterMapping().filterName( filterName ).urlPattern( "/*" );
     }
     if (gatewayServices != null) {
diff --git 
a/gateway-server/src/test/java/org/apache/knox/gateway/config/impl/GatewayConfigImplTest.java
 
b/gateway-server/src/test/java/org/apache/knox/gateway/config/impl/GatewayConfigImplTest.java
index 9d57a579c..484386871 100644
--- 
a/gateway-server/src/test/java/org/apache/knox/gateway/config/impl/GatewayConfigImplTest.java
+++ 
b/gateway-server/src/test/java/org/apache/knox/gateway/config/impl/GatewayConfigImplTest.java
@@ -514,4 +514,24 @@ public class GatewayConfigImplTest {
     
assertThat(config.getConcurrentSessionVerifierExpiredTokensCleaningPeriod(), 
is(1000L));
   }
 
+    @Test
+    public void testIsTopologyAsyncSupported() {
+      GatewayConfigImpl config = new GatewayConfigImpl();
+
+      config.set("gateway.servlet.async.supported.topologies", "");
+      assertThat(config.isTopologyAsyncSupported("sandbox"), is(false));
+      config.set("gateway.servlet.async.supported.topologies", "sandbox");
+      assertThat(config.isTopologyAsyncSupported("sandbox"), is(true));
+      config.set("gateway.servlet.async.supported.topologies", " sandbox ");
+      assertThat(config.isTopologyAsyncSupported("sandbox"), is(true));
+      config.set("gateway.servlet.async.supported.topologies", "sandbox2");
+      assertThat(config.isTopologyAsyncSupported("sandbox"), is(false));
+      config.set("gateway.servlet.async.supported.topologies", 
"sandbox,health");
+      assertThat(config.isTopologyAsyncSupported("sandbox"), is(true));
+      assertThat(config.isTopologyAsyncSupported("health"), is(true));
+      config.set("gateway.servlet.async.supported.topologies", 
"sandbox2,health");
+      assertThat(config.isTopologyAsyncSupported("sandbox"), is(false));
+      assertThat(config.isTopologyAsyncSupported("sandbox2"), is(true));
+      assertThat(config.isTopologyAsyncSupported("health"), is(true));
+    }
 }
diff --git 
a/gateway-spi-common/src/main/java/org/apache/knox/gateway/GatewayTestConfig.java
 
b/gateway-spi-common/src/main/java/org/apache/knox/gateway/GatewayTestConfig.java
index b945f495b..5d96dfbb4 100644
--- 
a/gateway-spi-common/src/main/java/org/apache/knox/gateway/GatewayTestConfig.java
+++ 
b/gateway-spi-common/src/main/java/org/apache/knox/gateway/GatewayTestConfig.java
@@ -1197,4 +1197,9 @@ public class GatewayTestConfig extends Configuration 
implements GatewayConfig {
   public String getStrictTransportOption() {
     return "max-age=3001";
   }
+
+  @Override
+  public boolean isTopologyAsyncSupported(String topology) {
+    return false;
+  }
 }
diff --git 
a/gateway-spi/src/main/java/org/apache/knox/gateway/config/GatewayConfig.java 
b/gateway-spi/src/main/java/org/apache/knox/gateway/config/GatewayConfig.java
index c2198f5c1..ad3fee6d8 100644
--- 
a/gateway-spi/src/main/java/org/apache/knox/gateway/config/GatewayConfig.java
+++ 
b/gateway-spi/src/main/java/org/apache/knox/gateway/config/GatewayConfig.java
@@ -919,7 +919,9 @@ public interface GatewayConfig {
    */
   boolean isAsyncSupported();
 
-  /**
+  boolean isTopologyAsyncSupported(String topology);
+
+    /**
    * @return <code>true</code> if the supplied user is allowed to see all 
tokens
    *         (i.e. not only tokens where userName or createdBy equals to the
    *         userName) on the Token Management page; <code>false</code> 
otherwise
diff --git 
a/gateway-spi/src/main/java/org/apache/knox/gateway/sse/SSEDispatch.java 
b/gateway-spi/src/main/java/org/apache/knox/gateway/sse/SSEDispatch.java
index 2683d91b8..247536d71 100644
--- a/gateway-spi/src/main/java/org/apache/knox/gateway/sse/SSEDispatch.java
+++ b/gateway-spi/src/main/java/org/apache/knox/gateway/sse/SSEDispatch.java
@@ -40,6 +40,7 @@ import org.apache.knox.gateway.dispatch.AsyncDispatch;
 import org.apache.knox.gateway.dispatch.ConfigurableDispatch;
 import org.apache.knox.gateway.dispatch.DefaultHttpAsyncClientFactory;
 import org.apache.knox.gateway.dispatch.HttpAsyncClientFactory;
+import org.apache.knox.gateway.services.GatewayServices;
 
 import javax.servlet.AsyncContext;
 import javax.servlet.FilterConfig;
@@ -59,7 +60,8 @@ public class SSEDispatch extends ConfigurableDispatch 
implements AsyncDispatch {
 
     public SSEDispatch(FilterConfig filterConfig) {
         GatewayConfig gatewayConfig = (GatewayConfig) 
filterConfig.getServletContext().getAttribute(GatewayConfig.GATEWAY_CONFIG_ATTRIBUTE);
-        this.asyncSupported = gatewayConfig.isAsyncSupported();
+        String topologyName = (String) 
filterConfig.getServletContext().getAttribute(GatewayServices.GATEWAY_CLUSTER_ATTRIBUTE);
+        this.asyncSupported = gatewayConfig.isAsyncSupported() || 
gatewayConfig.isTopologyAsyncSupported(topologyName);
         if(asyncSupported) {
             HttpAsyncClientFactory asyncClientFactory = new 
DefaultHttpAsyncClientFactory();
             this.asyncClient = 
asyncClientFactory.createAsyncHttpClient(filterConfig);
diff --git 
a/gateway-spi/src/test/java/org/apache/knox/gateway/sse/SSEDispatchTest.java 
b/gateway-spi/src/test/java/org/apache/knox/gateway/sse/SSEDispatchTest.java
index 4981b8b2b..f0c6336dc 100644
--- a/gateway-spi/src/test/java/org/apache/knox/gateway/sse/SSEDispatchTest.java
+++ b/gateway-spi/src/test/java/org/apache/knox/gateway/sse/SSEDispatchTest.java
@@ -67,7 +67,7 @@ public class SSEDispatchTest {
 
     @Test
     public void testCreateAndDestroyClient() throws Exception {
-        SSEDispatch sseDispatch = this.createDispatch(true);
+        SSEDispatch sseDispatch = this.createDispatch(true, false);
         assertNotNull(sseDispatch.getAsyncClient());
 
         sseDispatch.destroy();
@@ -77,7 +77,7 @@ public class SSEDispatchTest {
     @Test
     public void testGet2xx() throws Exception {
         CountDownLatch latch = new CountDownLatch(1);
-        SSEDispatch sseDispatch = this.createDispatch(true);
+        SSEDispatch sseDispatch = this.createDispatch(true, false);
         PrintWriter printWriter = EasyMock.createNiceMock(PrintWriter.class);
         HttpServletResponse outboundResponse = 
this.getServletResponse(HttpStatus.SC_OK);
         AsyncContext asyncContext = this.getAsyncContext(latch, 
outboundResponse);
@@ -107,7 +107,7 @@ public class SSEDispatchTest {
     @Test
     public void testGet4xx() throws Exception {
         CountDownLatch latch = new CountDownLatch(1);
-        SSEDispatch sseDispatch = this.createDispatch(true);
+        SSEDispatch sseDispatch = this.createDispatch(true, false);
         HttpServletResponse outboundResponse = 
this.getServletResponse(HttpStatus.SC_BAD_REQUEST);
         AsyncContext asyncContext = this.getAsyncContext(latch, 
outboundResponse);
         HttpServletRequest inboundRequest = 
this.getHttpServletRequest(asyncContext);
@@ -130,7 +130,7 @@ public class SSEDispatchTest {
     @Test
     public void testGet5xx() throws Exception {
         CountDownLatch latch = new CountDownLatch(1);
-        SSEDispatch sseDispatch = this.createDispatch(true);
+        SSEDispatch sseDispatch = this.createDispatch(true, false);
         HttpServletResponse outboundResponse = 
this.getServletResponse(HttpStatus.SC_INTERNAL_SERVER_ERROR);
         AsyncContext asyncContext = this.getAsyncContext(latch, 
outboundResponse);
         HttpServletRequest inboundRequest = 
this.getHttpServletRequest(asyncContext);
@@ -153,7 +153,7 @@ public class SSEDispatchTest {
     @Test
     public void testPost2xx() throws Exception {
         CountDownLatch latch = new CountDownLatch(1);
-        SSEDispatch sseDispatch = this.createDispatch(true);
+        SSEDispatch sseDispatch = this.createDispatch(true, false);
         PrintWriter printWriter = EasyMock.createNiceMock(PrintWriter.class);
         HttpServletResponse outboundResponse = 
this.getServletResponse(HttpStatus.SC_OK);
         AsyncContext asyncContext = this.getAsyncContext(latch, 
outboundResponse);
@@ -184,7 +184,7 @@ public class SSEDispatchTest {
     @Test
     public void testPost4xx() throws Exception {
         CountDownLatch latch = new CountDownLatch(1);
-        SSEDispatch sseDispatch = this.createDispatch(true);
+        SSEDispatch sseDispatch = this.createDispatch(true, false);
         HttpServletResponse outboundResponse = 
this.getServletResponse(HttpStatus.SC_NOT_FOUND);
         AsyncContext asyncContext = this.getAsyncContext(latch, 
outboundResponse);
         HttpServletRequest inboundRequest = 
this.getHttpServletRequest(asyncContext);
@@ -207,7 +207,7 @@ public class SSEDispatchTest {
     @Test
     public void testPost5xx() throws Exception {
         CountDownLatch latch = new CountDownLatch(1);
-        SSEDispatch sseDispatch = this.createDispatch(true);
+        SSEDispatch sseDispatch = this.createDispatch(true, false);
         HttpServletResponse outboundResponse = 
this.getServletResponse(HttpStatus.SC_INTERNAL_SERVER_ERROR);
         AsyncContext asyncContext = this.getAsyncContext(latch, 
outboundResponse);
         HttpServletRequest inboundRequest = 
this.getHttpServletRequest(asyncContext);
@@ -230,7 +230,7 @@ public class SSEDispatchTest {
     @Test
     public void testPut2xx() throws Exception {
         CountDownLatch latch = new CountDownLatch(1);
-        SSEDispatch sseDispatch = this.createDispatch(true);
+        SSEDispatch sseDispatch = this.createDispatch(true, false);
         PrintWriter printWriter = EasyMock.createNiceMock(PrintWriter.class);
         HttpServletResponse outboundResponse = 
this.getServletResponse(HttpStatus.SC_OK);
         AsyncContext asyncContext = this.getAsyncContext(latch, 
outboundResponse);
@@ -261,7 +261,7 @@ public class SSEDispatchTest {
     @Test
     public void testPut4xx() throws Exception {
         CountDownLatch latch = new CountDownLatch(1);
-        SSEDispatch sseDispatch = this.createDispatch(true);
+        SSEDispatch sseDispatch = this.createDispatch(true, false);
         HttpServletResponse outboundResponse = 
this.getServletResponse(HttpStatus.SC_NOT_FOUND);
         AsyncContext asyncContext = this.getAsyncContext(latch, 
outboundResponse);
         HttpServletRequest inboundRequest = 
this.getHttpServletRequest(asyncContext);
@@ -284,7 +284,7 @@ public class SSEDispatchTest {
     @Test
     public void testPut5xx() throws Exception {
         CountDownLatch latch = new CountDownLatch(1);
-        SSEDispatch sseDispatch = this.createDispatch(true);
+        SSEDispatch sseDispatch = this.createDispatch(true, false);
         HttpServletResponse outboundResponse = 
this.getServletResponse(HttpStatus.SC_INTERNAL_SERVER_ERROR);
         AsyncContext asyncContext = this.getAsyncContext(latch, 
outboundResponse);
         HttpServletRequest inboundRequest = 
this.getHttpServletRequest(asyncContext);
@@ -307,7 +307,7 @@ public class SSEDispatchTest {
     @Test
     public void testPatch2xx() throws Exception {
         CountDownLatch latch = new CountDownLatch(1);
-        SSEDispatch sseDispatch = this.createDispatch(true);
+        SSEDispatch sseDispatch = this.createDispatch(true, false);
         PrintWriter printWriter = EasyMock.createNiceMock(PrintWriter.class);
         HttpServletResponse outboundResponse = 
this.getServletResponse(HttpStatus.SC_OK);
         AsyncContext asyncContext = this.getAsyncContext(latch, 
outboundResponse);
@@ -338,7 +338,7 @@ public class SSEDispatchTest {
     @Test
     public void testPatch4xx() throws Exception {
         CountDownLatch latch = new CountDownLatch(1);
-        SSEDispatch sseDispatch = this.createDispatch(true);
+        SSEDispatch sseDispatch = this.createDispatch(true, false);
         HttpServletResponse outboundResponse = 
this.getServletResponse(HttpStatus.SC_NOT_FOUND);
         AsyncContext asyncContext = this.getAsyncContext(latch, 
outboundResponse);
         HttpServletRequest inboundRequest = 
this.getHttpServletRequest(asyncContext);
@@ -361,7 +361,7 @@ public class SSEDispatchTest {
     @Test
     public void testPatch5xx() throws Exception {
         CountDownLatch latch = new CountDownLatch(1);
-        SSEDispatch sseDispatch = this.createDispatch(true);
+        SSEDispatch sseDispatch = this.createDispatch(true, false);
         HttpServletResponse outboundResponse = 
this.getServletResponse(HttpStatus.SC_INTERNAL_SERVER_ERROR);
         AsyncContext asyncContext = this.getAsyncContext(latch, 
outboundResponse);
         HttpServletRequest inboundRequest = 
this.getHttpServletRequest(asyncContext);
@@ -384,7 +384,7 @@ public class SSEDispatchTest {
     @Test
     public void testServerNotAvailable() throws Exception {
         CountDownLatch latch = new CountDownLatch(1);
-        SSEDispatch sseDispatch = this.createDispatch(true);
+        SSEDispatch sseDispatch = this.createDispatch(true, false);
         HttpServletResponse outboundResponse = 
EasyMock.createNiceMock(HttpServletResponse.class);
         outboundResponse.sendError(HttpServletResponse.SC_BAD_GATEWAY, 
"Service connection error");
         EasyMock.expectLastCall().once();
@@ -402,7 +402,7 @@ public class SSEDispatchTest {
     @Test
     public void testAsyncNotSupported() throws Exception {
         CountDownLatch latch = new CountDownLatch(1);
-        SSEDispatch sseDispatch = this.createDispatch(false);
+        SSEDispatch sseDispatch = this.createDispatch(false, false);
         HttpServletResponse outboundResponse = 
EasyMock.createNiceMock(HttpServletResponse.class);
         
outboundResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                 "Async support is not enabled. SSE requests cannot be 
processed.");
@@ -416,6 +416,36 @@ public class SSEDispatchTest {
         EasyMock.verify(outboundResponse);
     }
 
+    @Test
+    public void testAsyncSupportedTopology() throws Exception {
+        CountDownLatch latch = new CountDownLatch(1);
+        SSEDispatch sseDispatch = this.createDispatch(false, true);
+        PrintWriter printWriter = EasyMock.createNiceMock(PrintWriter.class);
+        HttpServletResponse outboundResponse = 
this.getServletResponse(HttpStatus.SC_OK);
+        AsyncContext asyncContext = this.getAsyncContext(latch, 
outboundResponse);
+        HttpServletRequest inboundRequest = 
this.getHttpServletRequest(asyncContext);
+
+        this.expectResponseBodyAndHeader(printWriter, outboundResponse);
+        replay(inboundRequest, asyncContext, outboundResponse, printWriter);
+
+        MOCK_SSE_SERVER.expect()
+                .method("GET")
+                .pathInfo("/sse")
+                .header("request", "header")
+                .header("Accept", "text/event-stream")
+                .respond()
+                .status(HttpStatus.SC_OK)
+                
.content("id:1\ndata:data1\nevent:event1\n\ndata:data2\nevent:event2\nid:2\nretry:1\n:testing\n\n",
 StandardCharsets.UTF_8)
+                .header("response", "header")
+                .contentType("text/event-stream");
+
+        sseDispatch.doGet(URL, inboundRequest, outboundResponse);
+
+        latch.await(1L, TimeUnit.SECONDS);
+        EasyMock.verify(asyncContext, outboundResponse, inboundRequest, 
printWriter);
+        assertTrue(MOCK_SSE_SERVER.isEmpty());
+    }
+
     private HttpServletRequest getHttpServletRequest(AsyncContext 
asyncContext) throws Exception {
         Map<String, String> headers = new HashMap<>();
         headers.put("request", "header");
@@ -468,7 +498,7 @@ public class SSEDispatchTest {
         EasyMock.expectLastCall().times(2);
     }
 
-    private SSEDispatch createDispatch(boolean asyncSupported) throws 
Exception {
+    private SSEDispatch createDispatch(boolean asyncSupported, boolean 
asyncSupportedTopology) throws Exception {
         KeystoreService keystoreService = createMock(KeystoreService.class);
         
expect(keystoreService.getTruststoreForHttpClient()).andReturn(null).once();
 
@@ -479,6 +509,7 @@ public class SSEDispatchTest {
         
expect(gatewayConfig.getHttpClientSocketTimeout()).andReturn(20000).once();
         
expect(gatewayConfig.getHttpClientCookieSpec()).andReturn(CookieSpecs.STANDARD).anyTimes();
         
expect(gatewayConfig.isAsyncSupported()).andReturn(asyncSupported).once();
+        
expect(gatewayConfig.isTopologyAsyncSupported("SSE")).andReturn(asyncSupportedTopology).once();
 
         GatewayServices gatewayServices = createMock(GatewayServices.class);
         
expect(gatewayServices.getService(ServiceType.KEYSTORE_SERVICE)).andReturn(keystoreService).once();
@@ -486,6 +517,7 @@ public class SSEDispatchTest {
         ServletContext servletContext = createMock(ServletContext.class);
         
expect(servletContext.getAttribute(GatewayConfig.GATEWAY_CONFIG_ATTRIBUTE)).andReturn(gatewayConfig).atLeastOnce();
         
expect(servletContext.getAttribute(GatewayServices.GATEWAY_SERVICES_ATTRIBUTE)).andReturn(gatewayServices).atLeastOnce();
+        
expect(servletContext.getAttribute(GatewayServices.GATEWAY_CLUSTER_ATTRIBUTE)).andReturn("SSE").atLeastOnce();
 
         FilterConfig filterConfig = createMock(FilterConfig.class);
         
expect(filterConfig.getServletContext()).andReturn(servletContext).atLeastOnce();

Reply via email to