GH-386 Fixed NPE for non-existing functions invoked as REST endpoints
Resolves #386
This commit is contained in:
@@ -233,7 +233,11 @@ public class RequestProcessor {
|
||||
}
|
||||
Mono<ResponseEntity<?>> responseEntityMono = null;
|
||||
|
||||
if (function instanceof FluxedConsumer || function instanceof FluxConsumer) {
|
||||
if (function == null) {
|
||||
responseEntityMono = Mono.just(ResponseEntity.status(HttpStatus.NOT_FOUND)
|
||||
.body("Function for provided path can not be found"));
|
||||
}
|
||||
else if (function instanceof FluxedConsumer || function instanceof FluxConsumer) {
|
||||
((Mono<?>) function.apply(flux)).subscribe();
|
||||
logger.debug("Handled POST with consumer");
|
||||
responseEntityMono = Mono
|
||||
|
||||
@@ -30,6 +30,7 @@ import org.springframework.cloud.function.context.FunctionType;
|
||||
import org.springframework.cloud.function.context.FunctionalSpringApplication;
|
||||
import org.springframework.context.ApplicationContextInitializer;
|
||||
import org.springframework.context.support.GenericApplicationContext;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.util.SocketUtils;
|
||||
|
||||
@@ -54,6 +55,17 @@ public class FunctionEndpointInitializerTests {
|
||||
System.clearProperty("server.port");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonExistingFunction() throws Exception {
|
||||
FunctionalSpringApplication.run(ApplicationConfiguration.class);
|
||||
TestRestTemplate testRestTemplate = new TestRestTemplate();
|
||||
String port = System.getProperty("server.port");
|
||||
Thread.sleep(200);
|
||||
ResponseEntity<String> response = testRestTemplate
|
||||
.postForEntity(new URI("http://localhost:" + port + "/foo"), "stressed", String.class);
|
||||
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingleFunctionMapping() throws Exception {
|
||||
FunctionalSpringApplication.run(ApplicationConfiguration.class);
|
||||
|
||||
Reference in New Issue
Block a user