Skip to content

Commit ae52354

Browse files
pritidesaimrutkows
authored andcommitted
Reading Jar Contents from Env. (#297)
* reading code from env. * reading a filename instead of code. * converting string to path * cleaning up
1 parent 6cf0fbb commit ae52354

1 file changed

Lines changed: 22 additions & 2 deletions

File tree

  • knative-build/runtimes/java/core/java8/proxy/src/main/java/org/apache/openwhisk/runtime/java/action

knative-build/runtimes/java/core/java8/proxy/src/main/java/org/apache/openwhisk/runtime/java/action/Proxy.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.net.InetSocketAddress;
2828
import java.nio.charset.StandardCharsets;
2929
import java.nio.file.Path;
30+
import java.nio.file.Paths;
3031
import java.util.HashMap;
3132
import java.util.Map;
3233
import java.util.Set;
@@ -42,6 +43,8 @@ public class Proxy {
4243
private HttpServer server;
4344
private JarLoader loader = null;
4445
private boolean allowMultipleInits = false;
46+
private static final String OW_AUTO_INIT = "OW_AUTO_INIT";
47+
private static final String OW_AUTO_INIT_MAIN = "OW_AUTO_INIT_MAIN";
4548

4649
public Proxy(int port) throws IOException {
4750
long startTime = Debug.start();
@@ -158,8 +161,25 @@ private class RunHandler implements HttpHandler {
158161
public void handle(HttpExchange t) throws IOException {
159162
long startTime = Debug.start();
160163
if (loader == null) {
161-
Proxy.writeError(t, "Cannot invoke an uninitialized action.");
162-
return;
164+
// check if the Jar file contents are set in the enviorment
165+
// OW_AUTO_INIT: Jar file with absolute/relative path
166+
// OW_AUTO_INIT_MAIN: name of the function in the "OW_AUTO_INIT" to call as the action handler
167+
String ow_auto_init = System.getenv(OW_AUTO_INIT);
168+
String ow_auto_init_main = System.getenv(OW_AUTO_INIT_MAIN);
169+
if (ow_auto_init == null || ow_auto_init.isEmpty()) {
170+
Proxy.writeError(t, "Cannot invoke an uninitialized action.");
171+
return;
172+
} else {
173+
try {
174+
Path jarPath = Paths.get(ow_auto_init);
175+
loader = new JarLoader(jarPath, ow_auto_init_main);
176+
} catch (Exception e) {
177+
e.printStackTrace(System.err);
178+
writeLogMarkers();
179+
Proxy.writeError(t, "An error has occurred (see logs for details): " + e);
180+
return;
181+
}
182+
}
163183
}
164184

165185
ClassLoader cl = Thread.currentThread().getContextClassLoader();

0 commit comments

Comments
 (0)