https://linen.dev logo
#general
Title
# general
r

Ramya Vedagiri

03/23/2023, 9:36 AM
Hi. I am trying to find a way to mock protobuf response. I have a json mapping. Want to convert that as protobuf response.
Wondering if wiremock supports that
t

Tom

03/23/2023, 9:51 AM
Hi @Ramya Vedagiri WireMock doesn’t support Protobuf right now, but you could write a custom matcher extension to do this
r

Ramya Vedagiri

03/23/2023, 9:52 AM
I see. Thanks for the info
@Tom Looks like custom matcher is for extensive use. Like if we are looking for something specific in request . However, my requirement is simple: I just look for the URI and header tag. If it matches then it need to return the response back as a protobuf
So, would I still need custom matcher for this?
t

Tom

03/23/2023, 10:09 AM
If you don’t need to match on a protobuf request, and just need a protobuf response then you shouldn’t need to write an extension.
You’d need to encode the protobuf as base64 then return it as a binary response
r

Ramya Vedagiri

03/23/2023, 10:34 AM
Cool. Any samples would be great
t

Tom

03/23/2023, 11:35 AM
Are you configuring your stubs via Java or JSON?
r

Ramya Vedagiri

03/23/2023, 5:17 PM
Json
t

Tom

03/23/2023, 5:40 PM
In that case you should be able to put the protobuf response in a file under the
__files
folder and create a stub mapping like:
Copy code
{
    "request": {
        "method": "POST",
        "url": "/proto"
    },
    "response": {
        "status": 200,
        "bodyFileName": "my-data.proto" // The name of the file under __files
    }
}
r

Ramya Vedagiri

04/01/2023, 8:11 AM
@Tom I tried use the suggested way, and I see exception on client side when I deserialize 'EntityResponse response = response.getEntity(EntityResponse.class)' com.google.protobuf.InvalidProtocolBufferException$InvalidWireTypeException: Protocol message tag had invalid wire type. The message is encoded and sent as binary. Not sure what am I missing here