opentable / wiremock-body-transformer

Wiremock Body Transformer Extension
Apache License 2.0
65 stars 42 forks source link

unable to start body-transformer with wiremock-standalone-2.1.12.jar #19

Open gearoidr opened 7 years ago

gearoidr commented 7 years ago

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?

AKermodeBear commented 7 years ago

I was having the same issue with 1.1.1. I ended up downloading 1.1.2 and building, then using the latest release of WireMock. It starts up when I run this:

java -classpath 'wiremock-body-transformer-1.1.2.jar:wiremock-standalone-2.3.1.jar' com.github.tomakehurst.wiremock.standalone.WireMockServerRunner --verbose --extensions com.opentable.extension.BodyTransformer

Hope that helps - I'm new to Java though so maybe I did extra work for nothing.

gearoidr commented 7 years ago

thanks Stormwing that worked for me

btw have you used the transformer with requests generated in proxy mode?

AKermodeBear commented 7 years ago

Nope - that I have not yet done, sorry. I wish you the best of luck though. Maybe the maintainers will by by soon to help the rest of the way. (o:

On Fri, Nov 11, 2016 at 9:53 AM, gearoid rogers notifications@github.com wrote:

thanks Stormwing that worked for me

btw have you used the transformer with requests generated in proxy mode?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/opentable/wiremock-body-transformer/issues/19#issuecomment-259973499, or mute the thread https://github.com/notifications/unsubscribe-auth/AAaRRrbZ46h0BR6sS6IHX9wp7Sflf325ks5q9IFTgaJpZM4Ksnd0 .

tranhungt commented 7 years ago

Thanks @Stormwing for helping figure out the issue.

@gearoidr I haven't used the proxy mode yet. Is it working for you?

gearoidr commented 7 years ago

@tranhungt yes, i've managed to get it working in proxy mode, it records mapping files and responses but it's not clear to me how to apply the body transformer to the mapping and response files as the response file is returned in this format

{ "uuid" : "39b07c7f-15d9-32bb-8841-e28dda4171d4", "request" : { "url" : "create/order", "method" : "POST", "bodyPatterns" : [ { "equalToJson" : "{\"orderName\":\"test_order\",\"governingCountry\":\"US\",\"currency\":\"USD\",\"pricingMethodId\":1,\"startDate\":\"2016-11-11T23:00:00.000Z\",\"endDate\":\"2016-11-14T23:00:00.000Z\",\"budget\":1000.0,\"addressId\":81234}", "ignoreArrayOrder" : true, "ignoreExtraElements" : true } ] }, "response" : { "status" : 200, "bodyFileName" : "body-7000026011-order-8rkM3.json", "headers" : { "Server" : "Apache-Coyote/1.1", "Content-Type" : "application/json", "Date" : "Fri, 11 Nov 2016 14:48:20 GMT" } } }

so if I wanted the start and end dates to dynamically match any POST request received and update the dates in the file body-7000026011-order-8rkM3.json, i'm not entirely sure how to get that to work using the transformer

tranhungt commented 7 years ago

@gearoidr can you copy us what's in your body-7000026011-order-8rkM3.json file? The date fields would look something like this:

{
  "startDate": $(startDate),
  "endDate": $(endDate),
  "otherattributes": "some attributes"
}
gearoidr commented 7 years ago

@tranhungt - so the request body of the POST would look like

{ "uuid" : "39b07c7f-15d9-32bb-8841-e28dda4171d4", "request" : { "url" : "create/order", "method" : "POST", "bodyPatterns" : [ { "equalToJson" : "{\"orderName\":\"test_order\",\"governingCountry\":\"US\",\"currency\":\"USD\",\"pricingMethodId\":1,\"startDate\":\"2016-11-11T23:00:00.000Z\",\"endDate\":\"2016-11-14T23:00:00.000Z\",\"budget\":1000.0,\"addressId\":81234}", "ignoreArrayOrder" : true, "ignoreExtraElements" : true } ] }, "response" : { "status" : 200, "bodyFileName" : "body-7000026011-order-8rkM3.json", "headers" : { "Server" : "Apache-Coyote/1.1", "Content-Type" : "application/json", "Date" : "Fri, 11 Nov 2016 14:48:20 GMT" } } }

and then the content of body-7000026011-order-8rkM3.json would look like

{ "PlanId" : 1234567, "version" : 1, "Name" : "test_name_12345", "currency" : "USD", "startDate" : "2016-11-18T05:00:00.000+0000", "endDate" : "2016-11-21T05:00:00.000+0000", "budget" : 1000.0, "createdBy" : "user1", "planningSystem" : "AOP", "billingId" : 123456, "addressId" : 81234, "orderId" : 1234567 }

so if I wanted the request fields sent in the POST body, startDate, endDate, bedget and addressId etc to dynamically change in the response based on those values, how can I configure both the mapping and response files to do that?

tranhungt commented 7 years ago

@gearoidr Your body-7000026011-order-8rkM3.json file would look like so:

{
"PlanId" : 1234567,
"version" : 1,
"Name" : "test_name_12345",
"currency" : "USD",
"startDate" : "$(startDate),
"endDate" : "$(endDate)",
"budget" : $(budget),
"createdBy" : "user1",
"planningSystem" : "AOP",
"billingId" : 123456,
"addressId" : $(addressId),
"orderId" : 1234567
}

And your request mapping can look like this - I removed the bodyPatterns constraint so you can get it working, so it will map the request based on the URL and http method only, but if you need your mappings to selective map based on certain request body fields, then you can add them back in.

{
    "uuid": "39b07c7f-15d9-32bb-8841-e28dda4171d4",
    "request": {
        "url": "create/order",
        "method": "POST",
    },
    "response": {
        "status": 200,
        "bodyFileName": "body-7000026011-order-8rkM3.json",
        "headers": {
            "Server": "Apache-Coyote/1.1",
            "Content-Type": "application/json",
            "Date": "Fri, 11 Nov 2016 14:48:20 GMT"
        }
    }
}
gearoidr commented 7 years ago

@tranhungt - thanks again for your input, I tried what you suggested, and while the request mapping was found - it didn't do any transformation on the fields in the response.

Matched response definition: { "status" : 200, "bodyFileName" : "body-7000026011-order-ZSj4X.json", "headers" : { "Server" : "Apache-Coyote/1.1", "Content-Type" : "application/json", "Date" : "Tue, 22 Nov 2016 09:18:07 GMT" } }

Response: HTTP/1.1 200 Server: [Apache-Coyote/1.1] Content-Type: [application/json] Date: [Tue, 22 Nov 2016 09:18:07 GMT]

{ "PlanId" : 1234567, "version" : 1, "planName" : "$(planName)", "governingCountry" : "US", "currency" : "USD", "pricingMethodId" : 1, "salesPerson" : "AOP_cdid", "startDate" : "$(startDate)", "endDate" : "$(endDate)", "budget" : $(budget), "addressId" : $(addressId), "orderId" : 1234567 }

tranhungt commented 7 years ago

@gearoidr What was your full request?

Evangeline12351458 commented 4 years ago

Hi , I am trying to use the wiremock-body-transformer for parameterize my response but I am unable to record mapping files and their respective response files