I have spring cloud function deployed to azure function app.The API works perfectly fine in the local developer machine. Whereas when deployed to azure, upon calling from postman/client throws a null pointer exception. Java Run time Version : 11 Function Extension Version : ~3
2022-02-25T10:14:10.644 [Information] 2022-02-25 10:14:10.629 ERROR 2880 --- [pool-2-thread-1] : Error null
2022-02-25T10:14:10.645 [Information] java.lang.NullPointerException
2022-02-25T10:14:10.645 [Information] at org.springframework.cloud.function.adapter.azure.FunctionInvoker.handleRequest(FunctionInvoker.java:129)
2022-02-25T10:14:10.645 [Information] at ProductController.getProduct(ProductController.java:53)
Below is the snippet from the product controller where the exception is thrown.
@FunctionName("getProduct")
public HttpResponseMessage getProduct(@HttpTrigger(name = "getRequest", methods = {
HttpMethod.GET }, authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<String> getProductRequest,
ExecutionContext context) {
ProductRequestDTO productRequestDTO = new ProductRequestDTO();
try {
String id = getProductRequest.getQueryParameters().get("id");
if (id != null) {
log.info("Request Received for id: " + id);
productRequestDTO.setId(id);
}
return getProductRequest.createResponseBuilder(HttpStatus.OK).body(handleRequest(productRequestDTO,context)).build();
}
catch (NullPointerException e) {
l
log.error("Error " + e.getMessage());
return getProductRequest.createResponseBuilder(HttpStatus.INTERNAL_SERVER_ERROR).build();
}
}
pom.xml
=============
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<azure.functions.maven.plugin.version>1.14.2</azure.functions.maven.plugin.version>
<azure.functions.java.library.version>1.4.2</azure.functions.java.library.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-function-adapter-azur
e</artifactId>
<version>3.2.2</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-function-webflux</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>