https://linen.dev logo
r

RASHMI K YAMAKANAMARDI

09/11/2023, 3:26 PM
Hi all.. I'm new to Wiremock standalone. I want to add the webhooks extension to the java class path to use it in wiremock. can someone give a detailed step-wise instruction for the same
l

Lee Turner

09/11/2023, 3:50 PM
Hi • First download the latest standalone jar from the bottom of this page - https://wiremock.org/docs/download-and-installation/ • You can test this standalone jar as detailed on this page -
java -jar wiremock-standalone-3.0.4.jar
• Then you need to download the webhooks extension from this page - https://wiremock.org/docs/webhooks-and-callbacks/ Make sure both jars are in the same directory. • You then need to add both the wiremock jar and the extension to the classpath, start wiremock passing in the webhooks extension as a parameter. This is also detailed on the above page: Mac OS/Linux:
Copy code
java -cp wiremock-standalone-3.0.4.jar:wiremock-webhooks-extension-3.0.4.jar \
  wiremock.Run --extensions org.wiremock.webhooks.Webhooks
Windows:
Copy code
java -cp wiremock-standalone-3.0.4.jar;wiremock-webhooks-extension-3.0.4.jar \
  wiremock.Run --extensions org.wiremock.webhooks.Webhooks
r

RASHMI K YAMAKANAMARDI

09/11/2023, 5:10 PM
Thank you @Lee Turner I tried doing that but I get the below: Error: Could not find or load main class wiremock.Run Caused by: java.lang.ClassNotFoundException: wiremock.Run
l

Lee Turner

09/11/2023, 5:19 PM
Ah, interesting, What happens when you try
java -jar wiremock-standalone-3.0.4.jar
?
b

Brandon Trautmann

09/11/2023, 5:34 PM
FWIW I found success last week in just building a fat jar using
shadowJar
plugin.
Copy code
plugins {
    id 'com.github.johnrengelman.shadow' version '8.1.0'
}
...
dependencies {
    implementation group: 'org.wiremock', name: 'wiremock', version: '3.0.4'
}
...
jar {
    manifest {
        attributes 'Main-Class': 'wiremock.Run'
    }
}
...
assemble.dependsOn 'shadowJar'

shadowJar {
    archiveBaseName.set('my-wiremock-extensions')
    archiveClassifier.set('')
}
Then when you build, it’ll create a fat jar with both standalone and your extensions and they can be invoked doing simply
Copy code
java -jar my-wiremock-extensions-1.0-SNAPSHOT.jar --bind-address 127.0.0.1 --extensions com.example.MyExtensions --verbose --disable-banner &
I like this because you just need 1 jar and it’s a bit simpler to understand for outsiders
r

RASHMI K YAMAKANAMARDI

09/11/2023, 5:38 PM
message has been deleted
@Lee Turner I realised that I was putting in wrong version number of standalone. As I corrected it, I am getting the following:
l

Lee Turner

09/11/2023, 5:47 PM
OK, cool. What version of standalone are you using ? Also, do you have the correct version of the webhooks extension ?
r

RASHMI K YAMAKANAMARDI

09/11/2023, 5:47 PM
I'm using version 3.0.1 for standalone and 3.0.4 for webhooks
l

Lee Turner

09/11/2023, 5:48 PM
Not sure if it makes a difference but could you upgrade to
3.0.4
of standalone ?
I think the
ProhibitedNetworkAddressException
was introduced recently
And it is used by the most recent webhooks extension
r

RASHMI K YAMAKANAMARDI

09/11/2023, 6:02 PM
Thank you @Lee Turner I updated the version to 3.0.4 Its working.. Thanks for your time 🙌
Thank you @Brandon Trautmann for the time and efforts🙌
l

Lee Turner

09/11/2023, 6:03 PM
Excellent.
r

RASHMI K YAMAKANAMARDI

09/12/2023, 2:19 AM
I also had one more doubt. Can I make a POST call to an API, from the Wiremock using PostServeActions?
l

Lee Turner

09/12/2023, 6:50 AM
Yes. There is an example of a post on this page here - https://wiremock.org/docs/webhooks-and-callbacks/
r

RASHMI K YAMAKANAMARDI

09/13/2023, 6:00 AM
Thank you @Lee Turner
👍 1