Azure function (with Quarkus) getting RpcHttpRequestDataSource error on POST only while deployed

425 Views Asked by At

I followed the Quarkus Azure Functions guide to create a new project. I added a POST to the vert.x greeting class and to the servlet class. Both return a 500 with no body, and when viewed from the Application Insights page, contain similar errors related to converting RpcHttpRequestDataSource to byte[]. But locally, both work fine.

Here's the servlet POST which works when running locally via mvn quarkus:dev:

import java.io.IOException;
import java.util.stream.Collectors;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet(name = "ServletGreeting", urlPatterns = "/servlet/hello")
public class GreetingServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setStatus(200);
        resp.addHeader("Content-Type", "text/plain");
        resp.getWriter().write("hello servlet");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
        resp.setStatus(200);
        resp.addHeader("Content-Type", "text/plain");;
        resp.getWriter().write("hello " + req.getReader().lines().collect(Collectors.joining(System.lineSeparator())));
    }
}
    Exception while executing function: Functions.quarkus Result: Failure
    Exception: ClassCastException: Cannot convert com.microsoft.azure.functions.worker.binding.RpcHttpRequestDataSource@7e569681to type com.microsoft.azure.functions.HttpRequestMessage<java.util.Optional<byte[]>>
    Stack: java.lang.ClassCastException: Cannot convert com.microsoft.azure.functions.worker.binding.RpcHttpRequestDataSource@7e569681to type com.microsoft.azure.functions.HttpRequestMessage<java.util.Optional<byte[]>>
        at com.microsoft.azure.functions.worker.binding.DataOperations.generalAssignment(DataOperations.java:191)
        at com.microsoft.azure.functions.worker.binding.DataOperations.apply(DataOperations.java:120)
        at com.microsoft.azure.functions.worker.binding.DataSource.computeByType(DataSource.java:56)
        at com.microsoft.azure.functions.worker.binding.RpcHttpRequestDataSource.computeByType(RpcHttpRequestDataSource.java:20)
        at com.microsoft.azure.functions.worker.binding.DataSource.computeByName(DataSource.java:42)
        at com.microsoft.azure.functions.worker.binding.RpcHttpRequestDataSource.computeByName(RpcHttpRequestDataSource.java:20)
        at com.microsoft.azure.functions.worker.binding.BindingDataStore.getDataByName(BindingDataStore.java:55)
        at com.microsoft.azure.functions.worker.broker.ParameterResolver.resolve(ParameterResolver.java:59)
        at com.microsoft.azure.functions.worker.broker.ParameterResolver.resolve(ParameterResolver.java:42)
        at com.microsoft.azure.functions.worker.broker.JavaMethodExecutorImpl.execute(JavaMethodExecutorImpl.java:52)
        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 com.microsoft.azure.functions.worker.handler.InvocationRequestHandler.execute(InvocationRequestHandler.java:10)
        at com.microsoft.azure.functions.worker.handler.MessageHandler.handle(MessageHandler.java:45)
        at com.microsoft.azure.functions.worker.JavaWorkerClient$StreamingMessagePeer.lambda$onNext$0(JavaWorkerClient.java:92)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)

Is this a Quarkus issue, or something else?

1

There are 1 best solutions below

0
On

This should only work if you start the runtime infrastructure required for your servlet - e.g. with quarkus-undertow. Quarkus (and the guide) are based on vert.x which does not support the jakarta servlet API.

The extension azure-functions-http implements the required adapter to connect the azure-runtime-api to the vert.x api.

The guide does not provide a solution to use the servlet API for azure functions. It provides a solution to deploy a service using the jakarta rs ws API to azure functions!