Skip to content

Commit

Permalink
Emit log frame markers. Check for missing code.
Browse files Browse the repository at this point in the history
  • Loading branch information
rabbah committed Jul 8, 2018
1 parent 04f39ea commit 1614225
Showing 1 changed file with 30 additions and 14 deletions.
44 changes: 30 additions & 14 deletions core/java8/proxy/src/main/java/openwhisk/java/action/Proxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ private static void writeError(HttpExchange t, String errorMessage) throws IOExc
writeResponse(t, 502, message.toString());
}

private static void writeLogMarkers() {
System.out.println("XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX");
System.err.println("XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX");
System.out.flush();
System.err.flush();
}

private class InitHandler implements HttpHandler {
public void handle(HttpExchange t) throws IOException {
if (loader != null) {
Expand All @@ -82,26 +89,34 @@ public void handle(HttpExchange t) throws IOException {
JsonElement ie = parser.parse(new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8)));
JsonObject inputObject = ie.getAsJsonObject();

JsonObject message = inputObject.getAsJsonObject("value");
String mainClass = message.getAsJsonPrimitive("main").getAsString();
String base64Jar = message.getAsJsonPrimitive("code").getAsString();
if (inputObject.has("value")) {
JsonObject message = inputObject.getAsJsonObject("value");
if (message.has("main") && message.has("code")) {
String mainClass = message.getAsJsonPrimitive("main").getAsString();
String base64Jar = message.getAsJsonPrimitive("code").getAsString();

// FIXME: this is obviously not very useful. The idea is that we
// will implement/use a streaming parser for the incoming JSON object so that we
// can stream the contents of the jar straight to a file.
InputStream jarIs = new ByteArrayInputStream(base64Jar.getBytes(StandardCharsets.UTF_8));
// FIXME: this is obviously not very useful. The idea is that we
// will implement/use a streaming parser for the incoming JSON object so that we
// can stream the contents of the jar straight to a file.
InputStream jarIs = new ByteArrayInputStream(base64Jar.getBytes(StandardCharsets.UTF_8));

// Save the bytes to a file.
Path jarPath = JarLoader.saveBase64EncodedFile(jarIs);
// Save the bytes to a file.
Path jarPath = JarLoader.saveBase64EncodedFile(jarIs);

// Start up the custom classloader. This also checks that the
// main method exists.
loader = new JarLoader(jarPath, mainClass);
// Start up the custom classloader. This also checks that the
// main method exists.
loader = new JarLoader(jarPath, mainClass);

Proxy.writeResponse(t, 200, "OK");
return;
}
}

Proxy.writeResponse(t, 200, "OK");
Proxy.writeError(t, "Missing main/no code to execute.");
return;
} catch (Exception e) {
e.printStackTrace(System.err);
writeLogMarkers();
Proxy.writeError(t, "An error has occurred (see logs for details): " + e);
return;
}
Expand Down Expand Up @@ -139,7 +154,7 @@ public void handle(HttpExchange t) throws IOException {
JsonObject output = loader.invokeMain(inputObject, env);
// User code finished running here.

if(output == null) {
if (output == null) {
throw new NullPointerException("The action returned null");
}

Expand All @@ -156,6 +171,7 @@ public void handle(HttpExchange t) throws IOException {
e.printStackTrace(System.err);
Proxy.writeError(t, "An error has occurred (see logs for details): " + e);
} finally {
writeLogMarkers();
System.setSecurityManager(sm);
Thread.currentThread().setContextClassLoader(cl);
}
Expand Down

0 comments on commit 1614225

Please sign in to comment.