Hi, I'm trying to use wiremock grpc... I've used g...
# help
Hi, I'm trying to use wiremock grpc... I've used gradle to package all the dependencies of the wiremock grpc extension in a jar and the app starts fine, but it doesn't seem to do any of the grpc stuff. I downloaded the demo to test:
Copy code
faye@mabinogion standalone % docker run -d --rm -p 8000:8000 -v $PWD/wiremock-data:/wiremock-data nexus.txm.tools/wiremock:3.2.0-2 --port 8000 --root-dir /wiremock-data --verbose 

faye@mabinogion standalone % grpcurl -d '{"name": "Tom" }' -plaintext \
  -proto ExampleServices.proto \
  localhost:8000 com.example.grpc.GreetingService/greeting
  Code: Unknown
  Message: malformed header: missing HTTP content-type

port:                         8000
enable-browser-proxying:      false
disable-banner:               false
no-request-journal:           false
verbose:                      true

extensions:                   grpc,response-template,webhook
2023-11-07 06:41:54.642 Request received: - POST /com.example.grpc.GreetingService/greeting

content-type: [application/grpc]
user-agent: [grpcurl/1.8.7 grpc-go/1.48.0]
te: [trailers]


Matched response definition:
  "status" : 200,
  "body" : "{\"greeting\": \"Hello \"}",
  "transformers" : [ "response-template" ]

HTTP/2.0 200
Matched-Stub-Id: [4ee592b9-1554-4108-9c88-68f999296ee3]
Hi @Faye Salwin, are you able to share the Dockerfile or steps you used to build the image? It looks like what you’ve done should work, but it’s hard to tell what’s wrong without knowing what’s in the container.
sure can do
It shouldn't be too different from yours:
Copy code
ARG jre_image=eclipse-temurin:11.0.20_8-jre
FROM ${jre_image} as build
# Make sure CA are up to date and unzip for gradle
RUN --mount=type=tmpfs,target=/var/lib/apt \
    apt-get update && apt-get install -y --no-install-recommends ca-certificates unzip
# install Gradle
RUN curl -L <https://services.gradle.org/distributions/gradle-8.4-bin.zip> -o /tmp/gradle-8.4-bin.zip \
 && unzip /tmp/gradle-8.4-bin.zip -d /usr/local/
ENV PATH=${PATH}:/usr/local/gradle-8.4/bin
# working (correct?) gradle build file
COPY build.gradle .
# create a shadowJar in build/libs/
RUN --mount=type=cache,target=/root/.gradle \
    gradle shadowJar

FROM ${jre_image}

LABEL maintainer="Rodolphe CHAIGNEAU <rodolphe.chaigneau@gmail.com>"


WORKDIR /home/wiremock

# grab gosu for easy step-down from root
RUN --mount=type=tmpfs,target=/var/lib/apt \
    set -eux; \
	savedAptMark="$(apt-mark showmanual)"; \
	apt-get update; \
	apt-get install -y --no-install-recommends ca-certificates wget unzip; \
	if ! command -v gpg; then \
		apt-get install -y --no-install-recommends gnupg2 dirmngr; \
	elif gpg --version | grep -q '^gpg (GnuPG) 1\.'; then \
		apt-get install -y --no-install-recommends gnupg-curl; \
	fi; \
	dpkgArch="$(dpkg --print-architecture | awk -F- '{ print $NF }')"; \
	wget -O /usr/local/bin/gosu "<https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch>"; \
	wget -O /usr/local/bin/gosu.asc "<https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch.asc>"; \
	export GNUPGHOME="$(mktemp -d)"; \
	gpg --batch --keyserver <hkps://keys.openpgp.org> --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4; \
	gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu; \
	command -v gpgconf && gpgconf --kill all || :; \
	rm -rf "$GNUPGHOME" /usr/local/bin/gosu.asc; \
	apt-mark auto '.*' > /dev/null; \
	[ -z "$savedAptMark" ] || apt-mark manual $savedAptMark; \
	apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \
	chmod +x /usr/local/bin/gosu; \
	gosu --version; \
	gosu nobody true

# grab wiremock standalone jar
RUN mkdir -p /var/wiremock/lib/ \
  && curl <https://repo1.maven.org/maven2/org/wiremock/wiremock-standalone/$WIREMOCK_VERSION/wiremock-standalone-$WIREMOCK_VERSION.jar> \
    -o /var/wiremock/lib/wiremock-standalone.jar

# Sorting out dependencies is a pain.
COPY --from=build /build/libs/* /var/wiremock/lib/

# Init WireMock files structure
RUN mkdir -p mappings __files grpc /var/wiremock/extensions

COPY docker-entrypoint.sh /

EXPOSE 8080 8443

ENTRYPOINT ["/docker-entrypoint.sh"]
I'm using platform linux/arm64/v8 (Mac)
I tried adding the header: application/grpc to the response for the demo:
Copy code
faye@mabinogion standalone % grpcurl -vv -d '{"name": "Tom" }' -plaintext -proto ExampleServices.proto localhost:8000 com.example.grpc.GreetingService/greeting

Resolved method descriptor:
rpc greeting ( .com.example.grpc.HelloRequest ) returns ( .com.example.grpc.HelloResponse );

Request metadata to send:

Response headers received:
content-type: application/grpc
matched-stub-id: 75b8622b-d5f6-472d-b363-08f76b4e93d2

Response trailers received:
Sent 1 request and received 0 responses
  Code: ResourceExhausted
  Message: grpc: received message larger than max (577204837 vs. 4194304)
Copy code
buildscript {
	repositories {
	dependencies {
		classpath "gradle.plugin.com.github.johnrengelman:shadow:7.1.2"

plugins {
	id 'com.github.johnrengelman.shadow' version '7.1.2'
	id 'java'

repositories {

dependencies {
	implementation "org.wiremock:wiremock-grpc-extension:0.2.0"

// gradle shadowJar to create build/libs/...jar
that's the build.gradle
we're creating a jarfile in build/libs/ which is then placed into the main container along with the 3.2.0 wiremock-standalone jar
it occurs to me that it is not replacing the value of name: {{jsonPath request.body '$.name'}}\
Copy code
faye@mabinogion standalone % ls -lR wiremock-data 
total 0
drwxr-xr-x  2 faye  staff   64 Nov  6 22:34 __files
drwxr-xr-x  4 faye  staff  128 Nov  6 22:31 grpc
drwxr-xr-x  3 faye  staff   96 Nov  6 23:47 mappings

total 0

total 8
-rw-r--r--  1 faye  staff  717 Nov  6 22:31 services.dsc

total 8
-rw-r--r--  1 faye  staff  365 Nov  6 23:47 greeting.json
You could rule that in/out by removing the templat expression and hard-coding the response JSON
I mean it's probably just indicative of it not correctly parsing the message
Also, although this probably isn’t a factor - is there a reason you’re repackaging the JAR rather than just starting the standard one with the GRPC extension on the classpath?
I got a thin jar when I pulled the jar, so I was lacking a bunch of dependencies to run it
starting with jakarta something
the version with the demo is the old one
but I can try that to rule it out
Might be worth taking a look at this: https://github.com/wiremock/wiremock-grpc-demos/tree/main/standalone (versions could be upgraded, but the structure works)
If you don’t mind running a JVM locally anyway…
I’ve been meaning to add a Docker example to that project. Perhaps I’ll attempt this today if I can find a moment.
But the Docker and standalone projects work very similarly since the Docker image is just a wrapper around the standalone JAR.
Copy code
faye@mabinogion standalone % grpcurl -d '{"name": "Tom"}' -plaintext -proto ExampleServices.proto localhost:8000 com.example.grpc.GreetingService/greeting
  "greeting": "Hello Tom"
ok, so this works when I run it mounted inside the same container and use the 0.1 jar
definitely looks like this 0.1 jar is a fat one
Would be interesting to see if you get the same result with the latest JAR
do you have a URL for a fat version of 0.2?
I pulled from mavenCentral and got a thin one
The fat version is under a different artifact ID, so slightly different URL
ok, I will just use this url to get the jar
and not try building
No problem!
I love how Java is run everywhere except when it isn't 😄
ok, this version is working with the demo, now to try with my test code
thanks so much, that was driving me nuts
and now... bed - late here PST
Glad it worked eventually!
I use this command to build a multi-platform docker file:
Copy code
docker buildx build -t nexus.txm.tools/wiremock:3.2.0-3 --platform linux/arm64/v8,linux/amd64 --push .
obviously you can't use my repo, but feel free to use it to make multi-platform images for wiremock
Java is about the only thing I've found that runs really badly on Macs in Docker when using amd64 emulation
OK, thanks for sharing