public ContextPathCompositeHandler(Map<String, ? extends HttpHandler> handlerMap) { Assert.notEmpty(handlerMap, "Handler map must not be empty"); this.handlerMap = initHandlers(handlerMap); }
private ServerHttpResponse testHandle(String pathToHandle, Map<String, HttpHandler> handlerMap) { ServerHttpRequest request = MockServerHttpRequest.get(pathToHandle).build(); ServerHttpResponse response = new MockServerHttpResponse(); new ContextPathCompositeHandler(handlerMap).handle(request, response).block(Duration.ofSeconds(5)); return response; }
private void testInvalid(String contextPath, String expectedError) { try { new ContextPathCompositeHandler(Collections.singletonMap(contextPath, new TestHttpHandler())); fail(); } catch (IllegalArgumentException ex) { assertEquals(expectedError, ex.getMessage()); } }
protected HttpHandler resolveHttpHandler() { return (getHttpHandlerMap() != null ? new ContextPathCompositeHandler(getHttpHandlerMap()) : getHttpHandler()); }
public ContextPathCompositeHandler(Map<String, ? extends HttpHandler> handlerMap) { Assert.notEmpty(handlerMap, "Handler map must not be empty"); this.handlerMap = initHandlers(handlerMap); }
@Test // SPR-17144 public void notFoundWithCommitAction() { AtomicBoolean commitInvoked = new AtomicBoolean(false); ServerHttpRequest request = MockServerHttpRequest.get("/unknown/path").build(); ServerHttpResponse response = new MockServerHttpResponse(); response.beforeCommit(() -> { commitInvoked.set(true); return Mono.empty(); }); Map<String, HttpHandler> map = new HashMap<>(); TestHttpHandler handler = new TestHttpHandler(); map.put("/path", handler); new ContextPathCompositeHandler(map).handle(request, response).block(Duration.ofSeconds(5)); assertNotInvoked(handler); assertEquals(HttpStatus.NOT_FOUND, response.getStatusCode()); assertTrue(commitInvoked.get()); }
protected HttpHandler resolveHttpHandler() { return (getHttpHandlerMap() != null ? new ContextPathCompositeHandler(getHttpHandlerMap()) : getHttpHandler()); }
public ContextPathCompositeHandler(Map<String, ? extends HttpHandler> handlerMap) { Assert.notEmpty(handlerMap, "Handler map must not be empty"); this.handlerMap = initHandlers(handlerMap); }
@Test public void matchWithNativeContextPath() { MockServerHttpRequest request = MockServerHttpRequest .get("/yet/another/path") .contextPath("/yet") // contextPath in underlying request .build(); TestHttpHandler handler = new TestHttpHandler(); Map<String, HttpHandler> map = Collections.singletonMap("/another/path", handler); new ContextPathCompositeHandler(map).handle(request, new MockServerHttpResponse()); assertTrue(handler.wasInvoked()); assertEquals("/yet/another/path", handler.getRequest().getPath().contextPath().value()); }
public ContextPathCompositeHandler(Map<String, ? extends HttpHandler> handlerMap) { Assert.notEmpty(handlerMap, "Handler map must not be empty"); this.handlerMap = initHandlers(handlerMap); }