opentable / wiremock-body-transformer Goto Github PK
View Code? Open in Web Editor NEWWiremock Body Transformer Extension
License: Apache License 2.0
Wiremock Body Transformer Extension
License: Apache License 2.0
Due to a restriction of environment I need to run wiremock with java 7 and it works fine.
I saw in #12 that you don't support java 7, so it will not work for my case. But I just copied the code to a java 7 project, generated a jar, ran with wiremock and the extension worked fine.
So my question is: Why java 7 is not supported even if the code is compatible and wiremock supports it?
Can you please help? The bellow example works fine when using version 1.1.3 but it does not work when using version 1.1.6.. Can you please let me know what i am missing?
Thanks!
FROM rodolpheche/wiremock
COPY stubs /home/wiremock
ADD https://repo1.maven.org/maven2/com/opentable/wiremock-body-transformer/1.1.3/wiremock-body-transformer-1.1.3.jar /var/wiremock/extensions/
CMD ["--extensions", "com.opentable.extension.BodyTransformer"]
When trying to execute /random request example using 1.1.6 it gives me. If i execute this using version 1.1.3 everything works fine
`HTTP ERROR 500
Problem accessing /random. Reason:
Server Error
Caused by:
java.lang.IllegalArgumentException: urlRegex' not present
at wiremock.com.google.common.base.Preconditions.checkArgument(Preconditions.java:141)
at com.github.tomakehurst.wiremock.common.Metadata.checkKeyPresent(Metadata.java:88)
at com.github.tomakehurst.wiremock.common.Metadata.checkPresenceValidityAndCast(Metadata.java:73)
at com.github.tomakehurst.wiremock.common.Metadata.getString(Metadata.java:53)
at com.opentable.extension.BodyTransformer.transform(BodyTransformer.java:112)
at com.github.tomakehurst.wiremock.stubbing.InMemoryStubMappings.applyTransformations(InMemoryStubMappings.java:100)
at com.github.tomakehurst.wiremock.stubbing.InMemoryStubMappings.serveFor(InMemoryStubMappings.java:79)
at com.github.tomakehurst.wiremock.core.WireMockApp.serveStubFor(WireMockApp.java:179)
at com.github.tomakehurst.wiremock.http.StubRequestHandler.handleRequest(StubRequestHandler.java:50)
at com.github.tomakehurst.wiremock.http.AbstractRequestHandler.handle(AbstractRequestHandler.java:47)
at com.github.tomakehurst.wiremock.servlet.WireMockHandlerDispatchingServlet.service(WireMockHandlerDispatchingServlet.java:120)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at wiremock.org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:873)
at wiremock.org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:542)
at wiremock.org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:255)
at wiremock.org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1345)
at wiremock.org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:203)
at wiremock.org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:480)
at wiremock.org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:201)
at wiremock.org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1247)
at wiremock.org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:144)
at wiremock.org.eclipse.jetty.server.handler.gzip.GzipHandler.handle(GzipHandler.java:753)
at wiremock.org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:126)
at wiremock.org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
at wiremock.org.eclipse.jetty.server.Server.handle(Server.java:502)
at wiremock.org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:370)
at wiremock.org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:267)
at wiremock.org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:305)
at wiremock.org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103)
at wiremock.org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:117)
at wiremock.org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:333)
at wiremock.org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:310)
at wiremock.org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:168)
at wiremock.org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.produce(EatWhatYouKill.java:132)
at wiremock.org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:765)
at wiremock.org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:683)
at java.lang.Thread.run(Thread.java:748)
`
I am using wiremock to stubbing the requests. I have created a json file to stub a request:
{
"request": {
"method": "POST",
"urlPath": "/nested/transform",
"bodyPatterns": [
{
"matchesJsonPath": "$.names.[0].['first']"
},
{
"matchesJsonPath": "$.names.[0].['last']"
}
]
},
"response": {
"status": 200,
"body": "{"firstName": "$(names[0].first)", "lastName": "$(names[1].last)"}",
"headers": {
"Content-Type": "application/json"
},
"transformers": ["body-transformer"]
}
}
My request and response are as below:
{
"names": [
{
"first": "Vijay",
"last": "Rajput"
}
]
}
Receiving response is -
{
"firstName": "[{first=Vijay, last=Rajput}]",
"lastName": "[{first=Vijay, last=Rajput}]"
}
Expected response is -
{
"firstName": "Vijay",
"lastName": "Rajput"
}
Is it possible to fetch?
Hello,
First of all, congrats for this amazing software!
My question is, how can I get the value form a tag with ":" ?
For example,
<soap:Envelope> <soap:Body> <CONVERS2_x002F_1Response xmlns="urn:APTLU0WS.APT.pragmasis.pt"> <foo> <C_USERID>PIPO</C_USERID> </foo> </CONVERS2_x002F_1Response> </soap:Body> </soap:Envelope>
My question is, how to get the C_USERID tag?
I see that the $(soap.soap.CONVERS2_x002F_1Response.foo.C_USERID.value) is not working because of the ":" in the soap:Envelope and soap:Body....
Thank you!
On the wiremock-users mailing list archive I was looking for a solution for a variable BodyFile solution and was lead here with the expectation that this would be supported. I might be misinformed, which is why I'm creating this issue/question.
The aim of the rule is that I have several response file and I'd like to use the ID in the request to respond with the content of a file with the same name. Now, I am aware that I could create a rule for each case but having a variable bodyfile name would eliminate that. Does this project support this usecase?
I am trying to fetch the value from the request and injecting in my response. but always getting NULL.
SOAP REQUEST :
<soapenv:Envelope xmlns:ser="http://xml.comcast.com/accountmanagement/services" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:typ="http://xml.comcast.com/types" xmlns:typ1="http://xml.comcast.com/accountmanagement/types">
soapenv:Header
<wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-08CC34A9F5B164432115099955232841">
wsse:Usernameactuser</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">!hd2Za63a</wsse:Password>
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">nqqNC/VJ3O1h7Xhjo118ZA==</wsse:Nonce>
wsu:Created2017-11-06T19:12:03.281Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
typ:requestHeader
typ:timestamp2017-09-13-04:00</typ:timestamp>
typ:sourceSystemIdESP-SPARROW-PO</typ:sourceSystemId>
typ:sourceSystemUserIdactuser</typ:sourceSystemUserId>
typ:sourceServerIdSPARROW_G1_G2</typ:sourceServerId>
typ:trackingId332234542112334441123</typ:trackingId>
</typ:requestHeader>
</soapenv:Header>
soapenv:Body
<ser:getBillingArrangement xmlns="http://xml.comcast.com/common/types" xmlns:ns2="http://xml.comcast.com/accountmanagement/types" xmlns:ns3="http://xml.comcast.com/accountmanagement/service" xmlns:ns4="http://xml.comcast.com/types">
ser:getBillingArrangementRequest
ns2:billingArrangementID
ns2:string8155100092001035</ns2:string>
</ns2:billingArrangementID>
ns2:billingArrangementProfile
ns2:billingArrangementProfileBILLING_ARRANGEMENT_STATUS</ns2:billingArrangementProfile>
ns2:billingArrangementProfileCONTACT_INFO</ns2:billingArrangementProfile>
ns2:billingArrangementProfileBILLING_ADDRESS_CONTACT</ns2:billingArrangementProfile>
ns2:billingArrangementProfileDELINQUENT_STATUS</ns2:billingArrangementProfile>
</ns2:billingArrangementProfile>
</ser:getBillingArrangementRequest>
</ser:getBillingArrangement>
</soapenv:Body>
</soapenv:Envelope>
RESPONSE :
Always get NULL for below variable definition.
ns2:billingArrangementID$(Body.ser:getBillingArrangement.ser:getBillingArrangementRequest.ns2:billingArrangementID.ns2:string)</ns2:billingArrangementID>
OUTPUT: ns2:billingArrangementIDnull</ns2:billingArrangementID
Body transformer always find the key value pair in the body of the request and not recognising if the key value pair is in the headers
Hi. Project looks great, thank you very much for the effort. But I've got a problem with it.
Any of my tries end up with null. Could you help me figured out what may be the problem in here please?
config:
private WireMockServer wireMockServer = new WireMockServer(WireMockConfiguration.options()
.port(8089)
.usingFilesUnderDirectory("src/e2etest/resources/")
.extensions(new BodyTransformer()));
private Date now = new Date();
public void stubStart() {
wireMockServer.start();
wireMockServer.stubFor(post(urlEqualTo("xxx"))
.willReturn(aResponse()
.withStatus(200)
.withBodyFile("response.xml")
.withTransformers("body-transformer")
.withHeader("Content-Type", "text/xml")
.withHeader("Server", "Apache-Coyote/1.1")
.withHeader("X-OPNET-Transaction-Trace", "xxx")
.withHeader("Date", now.toString())
.withHeader("Connection", "keep-alive")
.withHeader("Set-Cookie", "xxx"))
);
}
request.xml:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
...
<soap:Header>
<soap:Body>
<requestMessage xmlns="xxx">
<merchantID>xxx</merchantID>
<merchantReferenceCode>test-4</merchantReferenceCode>
...
</requestMessage>
</soap:Body>
</soap:Envelope>
response.xml:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
...
<soap:Header>
<soap:Body>
<c:replyMessage xmlns:c="xxx">
<c:merchantReferenceCode>$(Envelope.Body.requestMessage.merchantReferenceCode.value</c:merchantReferenceCode>
...
</c:replyMessage>
</soap:Body>
</soap:Envelope>
hi,
I am using body transformer to transform my response and it is working well.My question is is ther any way to send the transformed response file as input to a service.
is there any way to save the transformed response to a file.
Thanks,
Sri
Example: $.offers[0].id return the whole list, but I want only the element with 'id'
Hello,
are you planning to update wiremock to the newest release 2.18.0? This version has updates for Jetty configuration to use wiremock for performance testing.
Hi,
I am new to wiremock and wiremock-body-transformer i have a soap request(namespaced) for which i am using wiremock. my response should be dynamic . Response has to be changed based on the request data. i am providing the sample request.
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xalan="http://xml.apache.org/xslt" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Header xmlns:SOAP-SEC="http://schemas.xmlsoap.org/soap/security/2000-12">
<payloadManifest xmlns="http://www.starstandards.org/webservices/2005/10/transport">
<manifest contentID="Content0" element="ProcessCreditContract" namespaceURI="http://www.starstandards.org/STAR" version="4.3.3" />
</payloadManifest>
</soap:Header>
<soap:Body>
<PutMessage xmlns="http://www.starstandards.org/webservices/2005/10/transport">
<payload>
<content id="Content0">
<Process xmlns="http://www.starstandards.org/STAR" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.starstandards.org/STAR \STAR\Standalone\sample.xsd" revision="4.3.3" release="8.1-Lite" environment="Production" lang="en-US">
<apparea>
<Sender>
<site>www.abc.com</site>
<Component>validate</Component>
<Task>contract</Task>
</Sender>
<CreationDateTime>2017-07-24T07:51:21-04:00</CreationDateTime>
<BODId>ABC220000005170411</BODId>
</apparea>
<Data>
<PersonName>
<GivenName>TRACY</GivenName>
<MiddleName>RICHARD</MiddleName>
<FamilyName>FRITZ</FamilyName>
<Suffix>SR</Suffix>
</PersonName>
</Data>
</Process>
</content>
<content id="Content1">
<SenderID>1234</SenderID>
<TargetID>2232</TargetID>
<ConversationID>AD-1-324324</ConversationID>
<SentTimeStamp>2018-07-05T03:01:49-04:00</SentTimeStamp>
<MessageType>DSPCreditApplication</MessageType>
<SequenceNo>1</SequenceNo>
</content>
</payload>
</PutMessage>
</soap:Body>
</soap:Envelope>
When Iam accessing $(Body.ProcessMessage.payload.content.Process.apparea.sender.Component), then iam getting null value.
I observed that the $(Body.ProcessMessage.payload.content) is returning the values of second content tag.
I need to access the data in the first content tag.
Could you please help me on it.
Hi all!
In the bodyPatterns I need to have two variables, and show them in the response. The problem that I have is that these two variables are inside a node, so when I try to create the stub I receive a 500 error.
Error:
<h2>HTTP ERROR: 500</h2>
<p>Problem accessing /__admin/mappings. Reason:
<pre> com.fasterxml.jackson.databind.JsonMappingException: {"user":{"matchesJsonPath":"$.lastName"}} is not a valid comparison (through reference chain: com.github.tomakehurst.wiremock.stubbing.StubMapping["request"]->com.github.tomakehurst.wiremock.matching.RequestPattern["bodyPatterns"]->java.util.ArrayList[0])</pre>
</p>
I have the following stub:
{
"request": {
"method": "POST",
"url": "/api/mytest",
"bodyPatterns": [
{
"user": {
"matchesJsonPath": "$.name",
"matchesJsonPath": "$.lastName"
}
}
]
},
"response": {
"status": 200,
"jsonBody": {
"user": {
"name": "$(name)",
"lastName": "$(lastName)"
}
},
"headers": {
"Content-Type": "application/json"
},
"transformers": [
"body-transformer"
]
}
}
### REQUEST BODY EXAMPLE:
{
"user": {
"name": "Joe",
"lastName": "Doe"
}
}
### EXPECTED BODY RESPONSE:
{
"user": {
"name": "Joe",
"lastName": "Doe"
}
}
Any suggestion of what I should put in the STUB in order to obtain the expected response? Thanks in advance!!
Request Json is :
{
"overrideStandardShippingAsFree":false,
"requestInfos":
[
{
"skuId":"4423521",
"itemSeqNumber":"hgvbh",
"postalCode":"55423",
"poBox":false,
"quantity":1,
"fulfillmentType":"SHIPPING"
}
]
}
I need to send the response based on the request.For say i need to send the skuId as response.I have used the wiremock transformer
stubFor(post(urlEqualTo("/url")).withRequestBody(matchingJsonPath("$.requestInfos[0].skuId"))
.willReturn(aResponse()
.withStatus(200)
.withHeader("content-type", "application/json")
.withBody("{"responseName": "$($.requestInfos[0].skuId)"}")
.withTransformers("body-transformer")));
It is returning null in the place of the json path
The current behaviour of wire mock-body-transformer is:
1. Try to create request-map from json,
if failed - try to create request-map from xml
if failed - try to create request-map from key/value
if failed - try to create request-map from url query parameters
2. Enrich request-map using urlRegex parameters if exists (replace fields whith same names).
3. Transform response body using request-map.
This behaviour is not supports to use query parameters with request body look like json,xml,key/value from the box (without using urlRegex parameters).
What you think about to change the behaviour? Which variant is better?
Variant a)
1. Try to create request-map from url query parameters
2. Enrich request-map from json,
if failed - try to create request-map from xml
if failed - try to create request-map from key/value
(replace fields whith same names)
3. Enrich request-map using urlRegex parameters if exists (replace fields whith same names).
Variant b)
1. Try to create request-map from json,
if failed - try to create request-map from xml
if failed - try to create request-map from key/value
2. Enrich request-map from url query parameters (replace fields whith same names).
3. Enrich request-map using urlRegex parameters if exists (replace fields whith same names).
The variant a will save backward compatibility if someone uses query parameters with body with same field names. But I think the variant b is more logical for setting priorities for the names of fields.
I can create pr :)
Run from command line java -jar wiremock-1.57-standalone.jar -verbose -extensions com.opentable.extension.BodyTransformer
Exception in thread "main" java.lang.ClassNotFoundException: com.opentable.extension.BodyTransformer
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
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.(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)
I am trying to start the transformer with wiremock standalone in proxy mode using the following command -
java -cp "wiremock-body-transformer-1.1.1.jar:wiremock-standalone-2.1.12.jar:./lib/*" com.github.tomakehurst.wiremock.standalone.WireMockServerRunner --proxy-all="http://proxy.com" --port=8090 --record-mappings --verbose --extensions com.opentable.extension.BodyTransformer
but am getting the following error
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:75)
at com.github.tomakehurst.wiremock.extension.ExtensionLoader$3.apply(ExtensionLoader.java:71)
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.extension.ExtensionLoader.load(ExtensionLoader.java:39)
at com.github.tomakehurst.wiremock.standalone.CommandLineOptions.extensionsOfType(CommandLineOptions.java:263)
at com.github.tomakehurst.wiremock.WireMockServer.(WireMockServer.java:84)
at com.github.tomakehurst.wiremock.standalone.WireMockServerRunner.run(WireMockServerRunner.java:65)
at com.github.tomakehurst.wiremock.standalone.WireMockServerRunner.main(WireMockServerRunner.java:113)
any suggestions on how to resolve this please?
Hi, I noticed a little mistake in the example in README file:
when you pass variable via url it's called baz
:
myurl.com?foo=bar&baz=bak
but when you use the variable in json, it's called bar
:
{ "msg": "This is a json response file", "param1": "$(foo)", "param2": "$(bar)" }
:)
Hi,
Created a simple stub in mappings folder , copied from one of the examples you provided, used the below Command to start & on startup see the below error.
NOTE : Java version 1.8, I am using wiremock-body-transformer-1.0.4 since I had trouble using the latest version.
{
"request": {
"method": "GET",
"url": "/local-transform"
},
"response": {
"status": 200,
"body": "{"name": "$(var)"}",
"transformers": ["body-transformer"]
}
}
java -cp "wiremock-body-transformer-1.0.4.jar;wiremock-1.57-standalone.jar" com.github.tomakehurst.wiremock.standalone.WireMockServerRunner --verbose --extensions com.opentable.extension.BodyTransformer --port 9999
ERROR
2016-05-11 16:30:18.492 Verbose logging enabled
Exception in thread "main" java.lang.RuntimeException: Unable to bind JSON to object. Reason: Unrecognized field "transformers" (class com.github.tomakehurst.wiremock.http.ResponseDefinition), not mar
ked as ignorable (11 known properties: "fixedDelayMilliseconds", "body", "fault", "headers", "bodyFileName", "proxyBaseUrl", "base64Body", "status", "responseTransformers", "additionalProxyRequestHead
ers", "originalRequest" [truncated]])
at [Source: {
"request": {
"method": "GET",
"url": "/local-transform"
},
"response": {
"status": 200,
"body": "{"name": "$(var)"}",
"transformers": ["body-transformer"]
}
}; line: 9, column: 26](through reference chain: com.github.tomakehurst.wiremock.stubbing.StubMapping["response"]->com.github.tomakehurst.wiremock.http.ResponseDefinition["transformers"]) JSON:{
"request": {
"method": "GET",
"url": "/local-transform"
},
"response": {
"status": 200,
"body": "{"name": "$(var)"}",
"transformers": ["body-transformer"]
}
}
at com.github.tomakehurst.wiremock.common.Json.read(Json.java:33)
at com.github.tomakehurst.wiremock.stubbing.StubMapping.buildFrom(StubMapping.java:56)
at com.github.tomakehurst.wiremock.stubbing.JsonStubMappingCreator.addMappingFrom(JsonStubMappingCreator.java:28)
at com.github.tomakehurst.wiremock.standalone.JsonFileMappingsLoader.loadMappingsInto(JsonFileMappingsLoader.java:39)
at com.github.tomakehurst.wiremock.core.WireMockApp.loadMappingsUsing(WireMockApp.java:87)
at com.github.tomakehurst.wiremock.core.WireMockApp.loadDefaultMappings(WireMockApp.java:83)
at com.github.tomakehurst.wiremock.core.WireMockApp.(WireMockApp.java:75)
at com.github.tomakehurst.wiremock.WireMockServer.(WireMockServer.java:78)
at com.github.tomakehurst.wiremock.standalone.WireMockServerRunner.run(WireMockServerRunner.java:62)
at com.github.tomakehurst.wiremock.standalone.WireMockServerRunner.main(WireMockServerRunner.java:108)
Caused by: com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "transformers" (class com.github.tomakehurst.wiremock.http.ResponseDefinition), not marked as ignorable
(11 known properties: "fixedDelayMilliseconds", "body", "fault", "headers", "bodyFileName", "proxyBaseUrl", "base64Body", "status", "responseTransformers", "additionalProxyRequestHeaders", "originalRe
quest" [truncated]])
at [Source: {
"request": {
"method": "GET",
"url": "/local-transform"
},
"response": {
"status": 200,
"body": "{"name": "$(var)"}",
"transformers": ["body-transformer"]
}
}; line: 9, column: 26](through reference chain: com.github.tomakehurst.wiremock.stubbing.StubMapping["response"]->com.github.tomakehurst.wiremock.http.ResponseDefinition["transformers"])
at com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException.from(UnrecognizedPropertyException.java:51)
at com.fasterxml.jackson.databind.DeserializationContext.reportUnknownProperty(DeserializationContext.java:744)
at com.fasterxml.jackson.databind.deser.std.StdDeserializer.handleUnknownProperty(StdDeserializer.java:915)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownProperty(BeanDeserializerBase.java:1306)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownVanilla(BeanDeserializerBase.java:1284)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:243)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:118)
at com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:538)
at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:99)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:238)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:118)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3066)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2161)
at com.github.tomakehurst.wiremock.common.Json.read(Json.java:31)
... 9 more
I am running wiremock in a war file and integrate transformer into it. How can I do it?
Have both wiremock jar and WBT jar in cd. Running with:
java -cp "wiremock-body-transformer-1.0.8.jar:wiremock-1.57-standalone.jar" \
com.github.tomakehurst.wiremock.standalone.WireMockServerRunner \
--extensions com.opentable.extension.BodyTransformer
I get:
Exception in thread "main" java.lang.UnsupportedClassVersionError: com/opentable/extension/BodyTransformer : Unsupported major.minor version 52.0
OS: OSX El Capitan 10.11.3
Please help check the issue , it works with wiremock-body-transformer-1.0.4.jar but not latest jar
Java 1.8, Microsoft Windows 7 Enterprise
Command
java -cp "wiremock-body-transformer-1.0.8.jar;wiremock-1.57-standalone.jar" com.github.tomakehurst.wiremock.standalone.WireMockServerRunner --verbose --extensions com.ope
ntable.extension.BodyTransformer --port 9999
2016-05-11 16:35:45.385 Verbose logging enabled
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/HttpRequest
at com.github.tomakehurst.wiremock.WireMockServer.(WireMockServer.java:98)
at com.github.tomakehurst.wiremock.standalone.WireMockServerRunner.run(WireMockServerRunner.java:62)
at com.github.tomakehurst.wiremock.standalone.WireMockServerRunner.main(WireMockServerRunner.java:110)
Caused by: java.lang.ClassNotFoundException: org.apache.http.HttpRequest
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 3 more
C:\Users\17raro\work\wiremock>dir
Wiremock library seems to have updated the interface for the Extension. The ResponseTransformers should be implementing the getName() method instead of name().
Error: java.lang.AbstractMethodError: com.opentable.extension.BodyTransformer.getName
Wiremock version : 2.1.10
I'm trying to run a standalone wiremock server with the body transformer using the following command
java -cp "wiremock-body-transformer-1.0.8.jar:wiremock-2.0.10-beta.jar" com.github.tomakehurst.wiremock.standalone.WireMockServerRunner --port 9876 --verbose --extensions com.opentable.extension.BodyTransformer
and I get the following error
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/HttpRequest
at com.github.tomakehurst.wiremock.WireMockServer.(WireMockServer.java:98)
at com.github.tomakehurst.wiremock.standalone.WireMockServerRunner.run(WireMockServerRunner.java:62)
at com.github.tomakehurst.wiremock.standalone.WireMockServerRunner.main(WireMockServerRunner.java:110)
Caused by: java.lang.ClassNotFoundException: org.apache.http.HttpRequest
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
Hi,
I am new to wiremock and wiremock-body-transformer i have a soap request(namespaced) for which i am using wiremock. my response should be dynamic . Response has to be changed based on the request data. i am providing the sample request and response below.
<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xalan="http://xml.apache.org/xslt">
<soap:Header xmlns:SOAP-SEC="http://schemas.xmlsoap.org/soap/security/2000-12">
<payloadManifest xmlns="http://www.starstandards.org/webservices/2005/10/transport">
<manifest contentID="Content0" element="ProcessCreditContract"
namespaceURI="http://www.starstandards.org/STAR" version="4.3.3"/>
</payloadManifest>
</soap:Header>
<soap:Body>
<PutMessage xmlns="http://www.starstandards.org/webservices/2005/10/transport">
<payload>
<content id="Content0">
<Process xmlns="http://www.starstandards.org/STAR"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.starstandards.org/STAR \STAR\Standalone\sample.xsd"
revision="4.3.3" release="8.1-Lite" environment="Production" lang="en-US">
<apparea>
<Sender>
<site>www.abc.com</LogicalId>
<Component>validate</Component>
<Task>contract</Task>
</Sender>
<CreationDateTime>2017-07-24T07:51:21-04:00</CreationDateTime>
<BODId>ABC220000005170411</BODId>
</apparea>
<Data>
<PersonName>
<GivenName>TRACY</GivenName>
<MiddleName>RICHARD</MiddleName>
<FamilyName>FRITZ</FamilyName>
<Suffix>SR</Suffix>
</PersonName>
</Data>
</Process>
</content>
</payload>
</PutMessage>
</soap:Body>
</soap:Envelope>
response should be something like
<?xml>
<BODID>ABC220000005170411</BODID>
<provider>abc</provider>
<name>Suffix + GivenName + MiddleName +FamilyName</name>
<status>success</status>
i tried with the below xml
<root><foo type="string" xmlns="urn:APTLU0WS.APT.pragmasis.pt">Travis</foo></root>
and got the response like
<xml>
<name>hello Travis</name>
</xml>
it is working fine
if i have namespaces in the requst xml and not enclose in "<root>"
or if it find "<soap>"
in the request xml it is not working.
Can you please guide me how to transform without "<root>"
and for the namespaced soap request.
The current build process only produces a jar that packages up all of its dependencies into the one jar (a shaded jar) This may be useful in some cases, but there are other cases where having all of those classes jammed into the jar is problematic. having the build produce both jars will allow users of your tool to choose which best suits their situation.
There are some warnings while tests are running.
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Is it is it really necessary?
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<scope>runtime</scope>
</dependency>
And there are all logs in the application created via System.err.println
Hi,
Am trying to use wiremock-body-transformer when deployed wiremock as WAR.
These are the changes have made to WireMockWebContextListener to use BodyTransformer().
On running the server, am seeing "java.lang.NoClassDefFoundError: com/opentable/extension/BodyTransformer". I want to deploy as war so that I can easily have LoadBalancer and all the internal features of the tools.
Appreciate any help on this!
@Override
public void contextInitialized(ServletContextEvent sce) {
ServletContext context = sce.getServletContext();
boolean verboseLoggingEnabled = Boolean.parseBoolean(
firstNonNull(context.getInitParameter("verboseLoggingEnabled"), "true"));
// WireMockApp wireMockApp = new WireMockApp(new WarConfiguration(context), new NotImplementedContainer());
Map<String, ResponseDefinitionTransformer> transformers = new HashMap<String, ResponseDefinitionTransformer>();
transformers.put("body-transformer", new BodyTransformer());
Optional<Integer> maxRequestJournalEntries = readMaxRequestJournalEntries(context);
String fileSourceRoot = context.getInitParameter(FILE_SOURCE_ROOT_KEY);
ServletContextFileSource fileSource = new ServletContextFileSource(context, fileSourceRoot);
JsonFileMappingsSource defaultMappingsLoader = new JsonFileMappingsSource(fileSource.child("mappings"));
MappingsSaver mappingsSaver = new NotImplementedMappingsSaver();
WireMockApp wireMockApp = new WireMockApp(false, defaultMappingsLoader,
mappingsSaver, false, maxRequestJournalEntries,
transformers,
Collections.<String, RequestMatcherExtension> emptyMap(),
fileSource, new NotImplementedContainer());
context.setAttribute(APP_CONTEXT_KEY, wireMockApp);
context.setAttribute(StubRequestHandler.class.getName(), wireMockApp.buildStubRequestHandler());
context.setAttribute(AdminRequestHandler.class.getName(), wireMockApp.buildAdminRequestHandler());
context.setAttribute(Notifier.KEY, new Slf4jNotifier(verboseLoggingEnabled));
}
Thanks,
mmaraka
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.