Skip to content

Question: Custom interceptor  #283

@nucle

Description

@nucle

Hi,

is it possible to write a custom interceptor?
Can i access the custom metadata?

In kotlin i do something like this:

CustomInterceptor :  ServerInterceptor{
private var codeKey: Metadata.Key<Int> = Metadata.Key.of("meta1", IntMarshaller())
    private var messageKey: Metadata.Key<String> =  Metadata.Key.of("meta2", UTF8Marshaller())
    override fun <ReqT : Any?, RespT : Any?> interceptCall(call: ServerCall<ReqT, RespT>?, headers: Metadata?, next: ServerCallHandler<ReqT, RespT>?): ServerCall.Listener<ReqT> {
        val delegate = next!!.startCall(call, headers)
        return object : SimpleForwardingServerCallListener<ReqT>(delegate) {

            override fun onHalfClose() {
                    call?.close(Status.UNKNOWN, customMetadata)
                }
            }
        }
    }}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions