Search code examples
javaazureazure-functionsserverless

Deployed Azure Serverless Function does not see classes besides Function


I have developed an Azure Serverless Function in Eclipse. The function works locally (Run As/Maven/Set Goals=test) but does not work once deployed. It fails with the following error

[Error] Executed 'Functions.HttpExample' (Failed, Id=0de9ae96-68c6-4620-ba05-63a1c1c99b97, 
Duration=24ms)
Result: FailureException: NoClassDefFoundError: 
javax/servlet/http/HttpServletStack: java.lang.reflect.InvocationTargetExceptionat
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at 

I can see from looking at the code that it is failing at the following line.

boolean tokenVerified = RecaptchaVerification.verifyRecaptchaSite(token);

This is the first line in the code that references a class not in Function.java

Here is the structure of the code in Eclipse

enter image description here

I have used WinSCP and the publish profile credentials to examine what has been deployed.

Everything is there

enter image description here

Does anybody know how to solve this problem? I could put all the code into Function.java and this would work, but I would prefer to solve this properly. (Incidentally the same issue happened to me when I did development in Visual Studio Code)

UPDATE: I tried the following also - but to no avail.

  1. I tried running on Java 11 instead of Java 8 (with appropriate changes to the pom.xml file) and trying different versions of FUNCTIONS_EXTENSION_VERSION.
  2. I made sure the artifactID was different from the functionAppName, and that both were in lowercase.
  3. I tried updating the javax.servlet version in pom.xml

Solution

  • I assumed that because the first call to classes outside of function.java failed, all others would fail as well. However the problem was peculiar to RecaptchaVerification.java.

    The class that I tried to call looked like this.

    public class RecaptchaVerification extends HttpServlet {
      /**
        *
        */
        private static final long serialVersionUID = 1L;
        private static final String SECRET_PARAM = "xxx";
        private static final String RESPONSE_PARAM = "xxxx";
    

    If I removed the extends HttpServlet then everything works. Note that I do not know why this solves the problem - I do not think that I should have known this from the error message of NoClassDefFoundError.

    (In retrospect I should have posted the code to RecaptchaVerification.java as well in my question)