This is an automated email from the ASF dual-hosted git repository.
mrutkowski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/openwhisk-devtools.git
The following commit(s) were added to refs/heads/master by this push:
new ae52354 Reading Jar Contents from Env. (#297)
ae52354 is described below
commit ae52354059af3a046499c8801329ab9eeedf196d
Author: Priti Desai <pdesai@us.ibm.com>
AuthorDate: Wed Oct 16 14:20:08 2019 -0700
Reading Jar Contents from Env. (#297)
* reading code from env.
* reading a filename instead of code.
* converting string to path
* cleaning up
---
.../openwhisk/runtime/java/action/Proxy.java | 24 ++++++++++++++++++++--
1 file changed, 22 insertions(+), 2 deletions(-)
diff --git a/knative-build/runtimes/java/core/java8/proxy/src/main/java/org/apache/openwhisk/runtime/java/action/Proxy.java
b/knative-build/runtimes/java/core/java8/proxy/src/main/java/org/apache/openwhisk/runtime/java/action/Proxy.java
index 91b5c94..d6328c8 100644
--- a/knative-build/runtimes/java/core/java8/proxy/src/main/java/org/apache/openwhisk/runtime/java/action/Proxy.java
+++ b/knative-build/runtimes/java/core/java8/proxy/src/main/java/org/apache/openwhisk/runtime/java/action/Proxy.java
@@ -27,6 +27,7 @@ import java.lang.reflect.InvocationTargetException;
import java.net.InetSocketAddress;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
+import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
@@ -42,6 +43,8 @@ public class Proxy {
private HttpServer server;
private JarLoader loader = null;
private boolean allowMultipleInits = false;
+ private static final String OW_AUTO_INIT = "OW_AUTO_INIT";
+ private static final String OW_AUTO_INIT_MAIN = "OW_AUTO_INIT_MAIN";
public Proxy(int port) throws IOException {
long startTime = Debug.start();
@@ -158,8 +161,25 @@ public class Proxy {
public void handle(HttpExchange t) throws IOException {
long startTime = Debug.start();
if (loader == null) {
- Proxy.writeError(t, "Cannot invoke an uninitialized action.");
- return;
+ // check if the Jar file contents are set in the enviorment
+ // OW_AUTO_INIT: Jar file with absolute/relative path
+ // OW_AUTO_INIT_MAIN: name of the function in the "OW_AUTO_INIT" to call
as the action handler
+ String ow_auto_init = System.getenv(OW_AUTO_INIT);
+ String ow_auto_init_main = System.getenv(OW_AUTO_INIT_MAIN);
+ if (ow_auto_init == null || ow_auto_init.isEmpty()) {
+ Proxy.writeError(t, "Cannot invoke an uninitialized action.");
+ return;
+ } else {
+ try {
+ Path jarPath = Paths.get(ow_auto_init);
+ loader = new JarLoader(jarPath, ow_auto_init_main);
+ } catch (Exception e) {
+ e.printStackTrace(System.err);
+ writeLogMarkers();
+ Proxy.writeError(t, "An error has occurred (see logs for details):
" + e);
+ return;
+ }
+ }
}
ClassLoader cl = Thread.currentThread().getContextClassLoader();
|