Skip to content

Instantly share code, notes, and snippets.

@neeraj9
Last active February 9, 2019 22:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save neeraj9/2e893cc48e6675b58d2695bfdc5a56ad to your computer and use it in GitHub Desktop.
Save neeraj9/2e893cc48e6675b58d2695bfdc5a56ad to your computer and use it in GitHub Desktop.
BeamParticle Java 8 Dynamic function for /post/ HTTP POST JSON handler
#!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.
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) {
return postBody.toString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment