Skip to content

Commit

Permalink
Merge pull request #588 from olegz/GH-577a
Browse files Browse the repository at this point in the history
GH-577 Ensure listeners are notified after dispatch
  • Loading branch information
deki authored Jun 22, 2023
2 parents c767944 + 55be671 commit dcad0a2
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ public void dispatch() {
throw new IllegalStateException("Dispatching already started");
}
dispatched.set(true);
notifyListeners(NotificationType.START_ASYNC, null);
handler.doFilter(req, res, ((AwsServletContext)req.getServletContext()).getServletForPath(req.getRequestURI()));
notifyListeners(NotificationType.START_ASYNC, null);
} catch (ServletException | IOException e) {
notifyListeners(NotificationType.ERROR, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,10 @@ public void write(int b) throws IOException {
}
}

@Override
public void flush() throws IOException {
flushBuffer();
}

@Override
public void close()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ public void initServletAppTest(String reqType) {
handler = new LambdaHandler(type);
}

@MethodSource("data")
@ParameterizedTest
void asyncRequest(String reqType) {
initServletAppTest(reqType);
AwsProxyRequestBuilder req = new AwsProxyRequestBuilder("/async", "POST")
.json()
.body("{\"name\":\"bob\"}");
AwsProxyResponse resp = handler.handleRequest(req, lambdaContext);
assertEquals("{\"name\":\"BOB\"}", resp.getBody());
}

@MethodSource("data")
@ParameterizedTest
void helloRequest_respondsWithSingleMessage(String reqType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
import org.springframework.http.ResponseEntity;
import org.springframework.validation.Errors;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.async.DeferredResult;
import org.springframework.web.server.ResponseStatusException;

import jakarta.validation.Valid;
import reactor.core.publisher.Mono;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

Expand All @@ -18,6 +22,22 @@ public class MessageController {
public static final String UTF8_RESPONSE = "öüäß фрыцшщ";
public static final String EX_MESSAGE = "404 exception message";


@RequestMapping(path="/hi", method=RequestMethod.GET, produces = {"text/plain"})
public Mono<String> hi() {
return Mono.just(HELLO_MESSAGE);
}

@SuppressWarnings({ "unchecked", "rawtypes" })
@RequestMapping(path = "/async", method = RequestMethod.POST)
@ResponseBody
public DeferredResult<Map<String, String>> asyncResult(@RequestBody Map<String, String> value) {
DeferredResult result = new DeferredResult<>();
result.setResult(Collections.singletonMap("name", value.get("name").toUpperCase()));
return result;
}


@RequestMapping(path="/hello", method=RequestMethod.GET, produces = {"text/plain"})
public String hello() {
return HELLO_MESSAGE;
Expand Down

0 comments on commit dcad0a2

Please sign in to comment.