Created
March 21, 2018 07:52
-
-
Save neeraj9/90f65d9eafef708daa014f374a4543e4 to your computer and use it in GitHub Desktop.
BeamParticle Java Dynamic function for /post/ HTTP POST JSON handler with sample logs and exception
This file contains 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
#!java | |
// Sample Java 8 function to return what was passed in as the first argument. | |
// Notice that this template works for the /post/<thisfun> interface, where | |
// json input is passed in the first argument postBody, while the response | |
// is a binary or a string, which must be json as well. | |
// Additionally, this function can be used to test stdout and stderr logs. | |
import java.nio.charset.StandardCharsets; | |
import com.ericsson.otp.erlang.OtpErlangAtom; | |
import com.ericsson.otp.erlang.OtpErlangBinary; | |
() -> new Object(){ | |
public OtpErlangBinary main(OtpErlangBinary postBody, OtpErlangBinary context) { | |
String bodyStr = new String(postBody.binaryValue(), StandardCharsets.UTF_8); | |
String contextStr = new String(context.binaryValue(), StandardCharsets.UTF_8); | |
String result = handleEvent(bodyStr, contextStr); | |
return new OtpErlangBinary(result.getBytes(StandardCharsets.UTF_8)); | |
} | |
public String handleEvent(String postBody, String context) { | |
System.out.println("hello stdout"); | |
System.err.println("stderr is now available in programmer interface"); | |
return postBody.toString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment