Hi,
I want to be able to pass a function or an object (with a run() method for instance) from Python to Java. I would create the object in Python, pass to java and execute in Java at a later time.
I tried having a java method with a PyObject as a parameter and then calling that from Python and passing the object, afterwards I tried the method but no success:
import io.undertow.Undertow;
import jep.python.PyObject;
public class Server {
public void run(PyObject handler, Integer port, String url) {
Undertow server = Undertow.builder()
.addHttpListener(port, url)
.setHandler(new HandlerManager().buildHandler(handler)).build();
server.start();
}
}
Python Code
import datetime
class Handler:
def __init__(self, name):
self.name = name
def run(self):
return self.name + ": Test from Python - " + datetime.datetime.now().isoformat() + "\n"
Server().run(Handler("test"), 8080, "localhost")
This is the exception I get:
jep.JepException: <class 'TypeError'>: Error converting parameter 1: Expected jep.python.PyObject but received a Sample.
Any thoughts?