samples icon indicating copy to clipboard operation
samples copied to clipboard

java outputs has null exception

Open gongxh13 opened this issue 1 year ago • 6 comments

When I deploy java demo according this link https://github.com/OpenFunction/samples/tree/main/functions/knative/java/with-output-binding, after deploy, I access function, but has exception as:

[main] INFO org.eclipse.jetty.server.Server - jetty-11.0.9; built: 2022-03-30T17:44:47.085Z; git: 243a48a658a183130a8c8de353178d154ca04f04; jvm 18.0.1.1+2
[main] INFO org.eclipse.jetty.server.handler.ContextHandler - Started o.e.j.s.ServletContextHandler@6f5ffd5c{/,null,AVAILABLE}
[main] INFO org.eclipse.jetty.server.AbstractConnector - Started ServerConnector@5e792d1b{HTTP/1.1, (http/1.1)}{0.0.0.0:8080}
[main] INFO org.eclipse.jetty.server.Server - Started Server@ee6f42b2{STARTING}[11.0.9,sto=0] @397ms
plugin plugin-example:v1.0.0 exec pre hook for http function at 2023-03-08 11:01:55.Z
receive event: {"message":"Awesome OpenFunction!"}
Mar 08, 2023 11:01:55 AM dev.openfunction.invoker.runtime.SynchronizeRuntime$OpenFunctionServlet service
SEVERE: Failed to execute function
java.lang.NullPointerException: Cannot invoke "io.dapr.client.DaprClient.invokeBinding(java.lang.String, java.lang.String, byte[], java.util.Map)" because "this.daprClient" is null
        at dev.openfunction.invoker.context.UserContext.send(UserContext.java:116)
        at dev.openfunction.samples.OpenFunctionImpl.accept(OpenFunctionImpl.java:15)
        at dev.openfunction.invoker.runtime.SynchronizeRuntime$OpenFunctionServlet.service(SynchronizeRuntime.java:166)
        at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:587)
        at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:764)
        at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:508)
        at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:221)
        at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1375)
        at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:176)
        at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:463)
        at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:174)
        at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1297)
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:129)
        at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:122)
        at org.eclipse.jetty.server.Server.handle(Server.java:562)
        at org.eclipse.jetty.server.HttpChannel.lambda$handle$0(HttpChannel.java:505)
        at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:762)
        at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:497)
        at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:282)
        at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:319)
        at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:100)
        at org.eclipse.jetty.io.SelectableChannelEndPoint$1.run(SelectableChannelEndPoint.java:53)
        at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:894)
        at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:1038)
        at java.base/java.lang.Thread.run(Unknown Source)

From above, it may be not init dapr client for java sdk.

gongxh13 avatar Mar 08 '23 11:03 gongxh13

@wrongerror user need to add annotation manually? https://openfunction.dev/docs/concepts/baas_integration/

benjaminhuo avatar Mar 08 '23 11:03 benjaminhuo

When I deploy java demo according this link https://github.com/OpenFunction/samples/tree/main/functions/knative/java/with-output-binding, after deploy, I access function, but has exception as:

[main] INFO org.eclipse.jetty.server.Server - jetty-11.0.9; built: 2022-03-30T17:44:47.085Z; git: 243a48a658a183130a8c8de353178d154ca04f04; jvm 18.0.1.1+2
[main] INFO org.eclipse.jetty.server.handler.ContextHandler - Started o.e.j.s.ServletContextHandler@6f5ffd5c{/,null,AVAILABLE}
[main] INFO org.eclipse.jetty.server.AbstractConnector - Started ServerConnector@5e792d1b{HTTP/1.1, (http/1.1)}{0.0.0.0:8080}
[main] INFO org.eclipse.jetty.server.Server - Started Server@ee6f42b2{STARTING}[11.0.9,sto=0] @397ms
plugin plugin-example:v1.0.0 exec pre hook for http function at 2023-03-08 11:01:55.Z
receive event: {"message":"Awesome OpenFunction!"}
Mar 08, 2023 11:01:55 AM dev.openfunction.invoker.runtime.SynchronizeRuntime$OpenFunctionServlet service
SEVERE: Failed to execute function
java.lang.NullPointerException: Cannot invoke "io.dapr.client.DaprClient.invokeBinding(java.lang.String, java.lang.String, byte[], java.util.Map)" because "this.daprClient" is null
        at dev.openfunction.invoker.context.UserContext.send(UserContext.java:116)
        at dev.openfunction.samples.OpenFunctionImpl.accept(OpenFunctionImpl.java:15)
        at dev.openfunction.invoker.runtime.SynchronizeRuntime$OpenFunctionServlet.service(SynchronizeRuntime.java:166)
        at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:587)
        at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:764)
        at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:508)
        at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:221)
        at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1375)
        at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:176)
        at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:463)
        at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:174)
        at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1297)
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:129)
        at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:122)
        at org.eclipse.jetty.server.Server.handle(Server.java:562)
        at org.eclipse.jetty.server.HttpChannel.lambda$handle$0(HttpChannel.java:505)
        at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:762)
        at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:497)
        at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:282)
        at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:319)
        at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:100)
        at org.eclipse.jetty.io.SelectableChannelEndPoint$1.run(SelectableChannelEndPoint.java:53)
        at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:894)
        at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:1038)
        at java.base/java.lang.Thread.run(Unknown Source)

From above, it may be not init dapr client for java sdk.

Add these annotations to the Function.

openfunction.io/enable-dapr: true
openfunction.io/dapr-service-mode: sidecar

wanjunlei avatar Mar 09 '23 01:03 wanjunlei

Add these annotations to the Function.

openfunction.io/enable-dapr: true
openfunction.io/dapr-service-mode: sidecar

All samples should work under both proxy and sidecar modes, why proxy mode doesn't work for java? @wanjunlei @wrongerror

benjaminhuo avatar Mar 09 '23 01:03 benjaminhuo

When I deploy java demo according this link https://github.com/OpenFunction/samples/tree/main/functions/knative/java/with-output-binding, after deploy, I access function, but has exception as:

[main] INFO org.eclipse.jetty.server.Server - jetty-11.0.9; built: 2022-03-30T17:44:47.085Z; git: 243a48a658a183130a8c8de353178d154ca04f04; jvm 18.0.1.1+2
[main] INFO org.eclipse.jetty.server.handler.ContextHandler - Started o.e.j.s.ServletContextHandler@6f5ffd5c{/,null,AVAILABLE}
[main] INFO org.eclipse.jetty.server.AbstractConnector - Started ServerConnector@5e792d1b{HTTP/1.1, (http/1.1)}{0.0.0.0:8080}
[main] INFO org.eclipse.jetty.server.Server - Started Server@ee6f42b2{STARTING}[11.0.9,sto=0] @397ms
plugin plugin-example:v1.0.0 exec pre hook for http function at 2023-03-08 11:01:55.Z
receive event: {"message":"Awesome OpenFunction!"}
Mar 08, 2023 11:01:55 AM dev.openfunction.invoker.runtime.SynchronizeRuntime$OpenFunctionServlet service
SEVERE: Failed to execute function
java.lang.NullPointerException: Cannot invoke "io.dapr.client.DaprClient.invokeBinding(java.lang.String, java.lang.String, byte[], java.util.Map)" because "this.daprClient" is null
        at dev.openfunction.invoker.context.UserContext.send(UserContext.java:116)
        at dev.openfunction.samples.OpenFunctionImpl.accept(OpenFunctionImpl.java:15)
        at dev.openfunction.invoker.runtime.SynchronizeRuntime$OpenFunctionServlet.service(SynchronizeRuntime.java:166)
        at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:587)
        at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:764)
        at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:508)
        at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:221)
        at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1375)
        at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:176)
        at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:463)
        at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:174)
        at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1297)
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:129)
        at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:122)
        at org.eclipse.jetty.server.Server.handle(Server.java:562)
        at org.eclipse.jetty.server.HttpChannel.lambda$handle$0(HttpChannel.java:505)
        at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:762)
        at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:497)
        at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:282)
        at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:319)
        at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:100)
        at org.eclipse.jetty.io.SelectableChannelEndPoint$1.run(SelectableChannelEndPoint.java:53)
        at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:894)
        at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:1038)
        at java.base/java.lang.Thread.run(Unknown Source)

From above, it may be not init dapr client for java sdk.

Add these annotations to the Function.

openfunction.io/enable-dapr: true
openfunction.io/dapr-service-mode: sidecar

I has try this and can work well. But another question is I has try go with-binding demo, it's can work well not need this annotation, demo link is https://github.com/OpenFunction/samples/tree/main/functions/knative/with-output-binding. Can you explain this why?

Add these annotations to the Function.

openfunction.io/enable-dapr: true
openfunction.io/dapr-service-mode: sidecar

All samples should work under both proxy and sidecar modes, why proxy mode doesn't work for java? @wanjunlei @wrongerror

For java, just sidecar mode is well, but go two mode are well, whether is because openfunction has not complete this for java?

gongxh13 avatar Mar 09 '23 14:03 gongxh13

For java, just sidecar mode is well, but go two mode are well, whether is because openfunction has not complete this for java?

It's a bug, the proxy mode should work for Java as well. @wanjunlei has fix that. @wanjunlei would you update all the readme, docs, samples to reflect the new java functions framework version?

benjaminhuo avatar Mar 10 '23 02:03 benjaminhuo

For java, just sidecar mode is well, but go two mode are well, whether is because openfunction has not complete this for java?

@wanjunlei has fixed this you can delete the old builder @gongxh13 https://github.com/OpenFunction/samples/blob/main/functions/knative/java/with-output-binding/function-front.yaml#L18 and download the new one.

image

benjaminhuo avatar Mar 13 '23 14:03 benjaminhuo