Skip to content

Commit

Permalink
android: wire up on trailers (#514)
Browse files Browse the repository at this point in the history
Description: this PR wires up on trailers callback for android, which was previously missing.
Risk Level: low - using already battled tested code paths for accumulating headers.
Testing: pending testing with gRPC on the Lyft android app

Fixes #506

Signed-off-by: Jose Nino <[email protected]>
Signed-off-by: JP Simard <[email protected]>
  • Loading branch information
junr03 authored and jpsim committed Nov 29, 2022
1 parent d8a854b commit 0b57e34
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
13 changes: 12 additions & 1 deletion mobile/library/common/jni_interface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,18 @@ static void jvm_on_metadata(envoy_headers metadata, void* context) {

static void jvm_on_trailers(envoy_headers trailers, void* context) {
__android_log_write(ANDROID_LOG_ERROR, "jni_lib", "jvm_on_trailers");
__android_log_write(ANDROID_LOG_ERROR, "jni_lib", std::to_string(trailers.length).c_str());

JNIEnv* env = get_env();
jobject j_context = static_cast<jobject>(context);

jclass jcls_JvmCallbackContext = env->GetObjectClass(j_context);
jmethodID jmid_onTrailers = env->GetMethodID(jcls_JvmCallbackContext, "onTrailers", "(J)V");
// Note: be careful of JVM types
// FIXME: make this cast safer
env->CallVoidMethod(j_context, jmid_onTrailers, (jlong)trailers.length);

env->DeleteLocalRef(jcls_JvmCallbackContext);
pass_headers(env, trailers, j_context);
}

static void jvm_on_error(envoy_error error, void* context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ public void onHeaders(long length, boolean endStream) {
startAccumulation(FrameType.HEADERS, length, endStream);
}

/**
* Initializes state for accumulating trailer pairs via passHeaders, ultimately
* to be dispatched via the callback.
*
* @param length, the total number of trailers included in this header block.
*/
public void onTrailers(long length) { startAccumulation(FrameType.TRAILERS, length, true); }

/**
* Allows pairs of strings to be passed across the JVM, reducing overall calls
* (at the expense of some complexity).
Expand Down

0 comments on commit 0b57e34

Please sign in to comment.