Running standalone wiremock with custom extension

2,694 views
Skip to first unread message

enka ka

unread,
Aug 15, 2015, 7:07:44 AM8/15/15
to wiremock-user
Hello,

I am trying to run standalone wireMock with custom extension (downloaded as jar, https://github.com/opentable/wiremock-body-transformer). 
Command: java -jar wiremock-1.57-standalone.jar --extensions com.opentable.extension.BodyTransformer

The question is, where should I put jar with extension to make it visible for wiremock classLoader? Now, I constantly getting class not found exception:
Exception in thread "main" java.lang.ClassNotFoundException: com.opentable.extension.BodyTransformer
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:260)
at com.github.tomakehurst.wiremock.extension.ExtensionLoader$3.apply(ExtensionLoader.java:76)
at com.github.tomakehurst.wiremock.extension.ExtensionLoader$3.apply(ExtensionLoader.java:72)
at wiremock.com.google.common.collect.Iterators$8.transform(Iterators.java:799)
at wiremock.com.google.common.collect.TransformedIterator.next(TransformedIterator.java:48)
at wiremock.com.google.common.collect.TransformedIterator.next(TransformedIterator.java:48)
at wiremock.com.google.common.collect.Maps.uniqueIndex(Maps.java:1163)
at wiremock.com.google.common.collect.Maps.uniqueIndex(Maps.java:1140)
at com.github.tomakehurst.wiremock.extension.ExtensionLoader.asMap(ExtensionLoader.java:43)
at com.github.tomakehurst.wiremock.extension.ExtensionLoader.loadExtension(ExtensionLoader.java:32)
at com.github.tomakehurst.wiremock.standalone.CommandLineOptions.extensionsOfType(CommandLineOptions.java:237)
at com.github.tomakehurst.wiremock.WireMockServer.<init>(WireMockServer.java:85)
at com.github.tomakehurst.wiremock.standalone.WireMockServerRunner.run(WireMockServerRunner.java:62)
at com.github.tomakehurst.wiremock.standalone.WireMockServerRunner.main(WireMockServerRunner.java:110)

BR,
Norbert

 

Tom Akehurst

unread,
Aug 15, 2015, 7:32:34 AM8/15/15
to wiremock-user
The JAR containing your extension also needs to be on the classpath. Unfortunately java won't let you specify a -cp param and a -jar, so you'll need to do something like this:
java -cp <path to your JAR>:wiremock-1.57-standalone.jar com.github.tomakehurst.wiremock.standalone.WireMockServerRunner --extensions com.opentable.extension.BodyTransformer

enka ka

unread,
Aug 15, 2015, 7:51:40 AM8/15/15
to wiremock-user
Ok, so the only option is to run via main class with additional -cp option.

Thank You for immediate response.

BR,
Norbert

Tom Akehurst

unread,
Aug 15, 2015, 8:08:17 AM8/15/15
to wiremock-user
Well, actually there's another option which is to build your own fat JAR incorporating WireMock + your extension and running that with -jar. Bit more effort, but shorter command line/more shippable to colleagues etc.

Bikram Shrestha

unread,
Mar 29, 2016, 3:36:12 PM3/29/16
to wiremock-user
Hey Tom, 
I am currently trying to incorporate my ResponseTransformer file with wiremock and create a new jar out of it. How do we make sure while WireMockServer is running, it will pick my ResponseTransformer ?
Do you have any step by step tutorial to set that up? If yes, please share, I can trace back or restart my work using that tutorial. 

Bikram
Reply all
Reply to author
Forward
0 new messages