0

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

  1. TestInputArgs.java
 @Data
  @AllArgsConstructor
public class TestInputArgs {
    private EventSchema event;
    private byte[] content;
 }
  1. 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";
    
    }
  1. 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");
        
}
}
Augustus
  • 1
  • 1
  • You can refer to [Use a function as an event handler for Event Grid events](https://learn.microsoft.com/en-us/azure/event-grid/handler-functions), [Azure functions, azureFunctionsPackage task failing with java.lang.NullPointerException](https://stackoverflow.com/questions/60857725/azure-functions-azurefunctionspackage-task-failing-with-java-lang-nullpointerex) and [Java NullPointerException](https://howtodoinjava.com/java/exception-handling/how-to-effectively-handle-nullpointerexception-in-java/) – Ecstasy Dec 03 '21 at 05:03
  • 1
    Thanks DeepDave. I will give a try and let you know. – Augustus Dec 15 '21 at 14:27

0 Answers0