Skip to content

Instantly share code, notes, and snippets.

@dmi3coder
Last active April 19, 2020 13:51
Show Gist options
  • Save dmi3coder/1b8fe3dd40c88ae0699b78ec44a9aad6 to your computer and use it in GitHub Desktop.
Save dmi3coder/1b8fe3dd40c88ae0699b78ec44a9aad6 to your computer and use it in GitHub Desktop.
Example of EffectResource that calls effect.py from resources
package tech.donau.quarkify;
import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.Source;
import org.graalvm.polyglot.Value;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import java.io.IOException;
import java.net.URL;
@Path("/effect")
public class EffectResource {
public static Context context = Context.newBuilder().allowIO(true).allowAllAccess(true).build();
@GET
@Produces(MediaType.TEXT_PLAIN)
public String hello() throws IOException {
final URL effectPy = getClass().getClassLoader().getResource("effect.py");
System.out.println(effectPy);
Value effectValue = context.eval(Source.newBuilder("python", effectPy).build());
return effectValue.toString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment