Last active
April 19, 2020 13:51
-
-
Save dmi3coder/1b8fe3dd40c88ae0699b78ec44a9aad6 to your computer and use it in GitHub Desktop.
Example of EffectResource that calls effect.py from resources
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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