Hello Beautiful people, I am kind of newbie with ...
# help
Hello Beautiful people, I am kind of newbie with Wiremock and would like to play a bit with Transformers, building my own extension. I was trying to modify test-extension and re-build the jar. Could you give me some hints how this can be done?
maybe a starting point: there's an initial version of an extension template which might give you a head start for building your own extension. https://github.com/wiremock/wiremock-extension-template . It's not much yet but should provide the basics for building your own.
Many thanks for your quick reply!
I was trying to use the template extension as is but I did not manage to do it. Could you please let me know how to produce the extension jar (in the template repo) and how to use it further with the wiremock standalone jar?
I was running:
./gradlew jar shadowJar
it generated 2 jars for me but cannot use any of them
./gradlew build
is sufficient to create both jars - but the result should be the same as with your command.
what error do you get?
The extension had a wrong class in the services configuration. Pushed a fix - hope it works but I canโ€™t verify it right now (on the road). Can you recheck it? You need to use the standalone jar
I was able to launch it like that: java -jar wiremock-standalone-3.3.1.jar wiremock-extension-template-standalone-b0fa13d.jar
๐Ÿ‘ 1
but ... unfortunately I do not get the new extension loaded ๐Ÿ˜ž . It only shows response-template and webhook as extensions:
I didn't see your extension on the command line. Every standalone jar of every extension needs to be on the classpath to be discovered. For automatic discovery, you need to adapt
to point to the correct class . The class should look somewhat similar to
in the template extension
To start with, I just would like to use the wiremock-extension-template as is, without modifying/adapting it. Is it possible? Could you please send me the command to launch it?
the lib has to be in the classpath. As POC, I copied all in one directoy and called:
java -cp "wiremock-extension-template-standalone-b0fa13d.dirty.jar:wiremock-standalone-3.3.1.jar" wiremock.Run
Many thanks, that's what was I was looking for!!!!
When you say the lib has to be in the class path, you mean the actual lib folder has to be copied there? I have the two jars in the same folder and launch your command, without dirty (java -cp "wiremock-extension-template-standalone-b0fa13d.jar:wiremock-standalone-3.3.1.jar" wiremock.Run). I am getting this error:
Copy code
Exception in thread "main" java.util.ServiceConfigurationError: com.github.tomakehurst.wiremock.extension.ExtensionFactory: Provider org.wiremock.extensions.state.StandaloneStateExtension not found
	at java.base/java.util.ServiceLoader.fail(ServiceLoader.java:593)
	at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.nextProviderClass(ServiceLoader.java:1219)
	at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNextService(ServiceLoader.java:1228)
	at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNext(ServiceLoader.java:1273)
	at java.base/java.util.ServiceLoader$2.hasNext(ServiceLoader.java:1309)
	at java.base/java.util.ServiceLoader$ProviderSpliterator.tryAdvance(ServiceLoader.java:1491)
	at java.base/java.util.Spliterator.forEachRemaining(Spliterator.java:332)
	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
	at java.base/java.util.stream.StreamSpliterators$WrappingSpliterator.forEachRemaining(StreamSpliterators.java:310)
	at java.base/java.util.stream.Streams$ConcatSpliterator.forEachRemaining(Streams.java:735)
	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
	at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682)
	at com.github.tomakehurst.wiremock.extension.Extensions.load(Extensions.java:98)
	at com.github.tomakehurst.wiremock.core.WireMockApp.<init>(WireMockApp.java:93)
	at com.github.tomakehurst.wiremock.WireMockServer.<init>(WireMockServer.java:71)
	at com.github.tomakehurst.wiremock.standalone.WireMockServerRunner.run(WireMockServerRunner.java:70)
	at wiremock.Run.main(Run.java:23)
in the example above, I added the libraries to the classpath via the
parameter. There can be other ways but that is outside of the wiremock context. Some extensions (like the tempalte) provide auto discovery mechanisms and in order to make them work, they have to be available on the classpath. The setup for docker or junit would be be different though - depends on what you need.
the error you see is probably because you miss a
git pull
. Had a bug
(the one I mentioned in https://wiremock-community.slack.com/archives/C03N1E6HFPY/p1700578257529539?thread_ts=1700491499.356719&amp;cid=C03N1E6HFPY ) . Or you need to clean your libs directory and rebuild it
Oh, I see now, many thanks! It indeed works as expected!!!! Have a nice day and thanks for all your support!
๐Ÿ‘ 1