I am getting below exception while I tried to copy a azure blob from container1 to container2 using eventGrid trigger with azure spring cloud java function. It seems issue is in input binding in handle request of azure function handler. I don't find any examples with eventGrid trigger in azure documentation.
Can someone please provide your inputs in resolving this issue.
Error Details:
Result: Failure Exception: NullPointerException: Stack: java.lang.reflect.InvocationTargetException at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at com.microsoft.azure.functions.worker.broker.JavaMethodInvokeInfo.invoke(JavaMethodInvokeInfo.java:22) at com.microsoft.azure.functions.worker.broker.EnhancedJavaMethodExecutorImpl.execute(EnhancedJavaMethodExecutorImpl.java:55) at com.microsoft.azure.functions.worker.broker.JavaFunctionBroker.invokeMethod(JavaFunctionBroker.java:57) at com.microsoft.azure.functions.worker.handler.InvocationRequestHandler.execute(InvocationRequestHandler.java:33) at
Below are my classes
- TestInputArgs.java
@Data
@AllArgsConstructor
public class TestInputArgs {
private EventSchema event;
private byte[] content;
}
- TestblobHandler.java
public class TestblobHandler extends FunctionInvoker<TestInputArgs,String> {
@FunctionName("testblobupload")
@StorageAccount("AzureWebJobsStorage")
public String run(
@EventGridTrigger(name = "TestEventTrg") EventSchema event,
@BlobInput(name = "blob", dataType = "binary", path = "{data.url}") byte[] content,
final ExecutionContext context)
throws StorageException, IOException {
handleRequest(new TestInputArgs(event,content),context);
return "Success";
}
- TestBlobUpload.java
@Component
public class TestBlobUpload implements Function<TestInputArgs,String> {
public String apply(TestInputArgs input) {
EventSchema event = input.getEvent();
byte[] content = input.getContent();
storageAccountDest = CloudStorageAccount.parse(storageConnectionStringDest);
blobClientDest = storageAccountDest.createCloudBlobClient();
containerDest = blobClientDest.getContainerReference("Targetcontainer");
CloudBlob blobDest = containerDest.getBlockBlobReference("test.jpg");
try {
blobDest.uploadFromByteArray(content, 0, content.length);
} catch (URISyntaxException e) {
e.printStackTrace();
} catch (StorageException e) {
e.printStackTrace();
}
return ("SUCCESS");
}
}