Wiremock customize recording and playback - wiremock

I am using Wiremock for stubbing the service. So that I can continue working on client application while service is down. I am recording the request and response by creating the proxy to service and using the recordings while service is down.
Their is one problem here. The api I am calling accepts xml input. One of the parameter is guid which changes every time. Now for Wiremock change in guid is another request it does another recording. Also when running playback the request does not match because of new guid in every request. Is their any way to ignore this parameter completely while doing recording and responding through playback ?
TIA

You can create an implementation of StubMappingTransformer in Java and register it as an extension with WireMock via wireMockConfig().extensions(new MyStubMappingTransformer() when you're starting it programmatically.
This will be called after a recording is completed and passed each stub that gets created, so you can add code that will e.g. swap the fields you don't want to match on exactly for placeholders.

Related

How to make a Play-based web application reactive?

I'm new to Play, so bear with me. I'd like to understand the "reactiveness" of Play and how to best make use of it.
My web application needs to do the following:
Receive an HTTP request (json format)
Pass the request to a controller
The controller needs to read a table (using Slick)
The controller needs to populate a response (json format)
The response is sent back to the browser
If I understand correctly, the application is Reactive when it uses asynchronous function calls to improve performance as a thread may be doing more that one thing at a specific time. But I don't see how the web application that I described can call a method and not wait for a response, there's nothing to do in parallel. What am I missing?

Streaming data to/from Play framework on an open connection

I need to send a stream of data to Play server. The length of the stream is unknown and I need to get a response every line break \n or for every several lines. Rather then wait for the whole data to be sent.
Think of the following usecase:
lets say i'm intended to write a console application, that when launched, connects to my web server, and all the user input are being sent to play on every line break, and gets responded asynchronously. All above should be performed on a single connection, i.e. I don't want to open a new connection on every request I send to Play (a good analog would be 2 processes communicating through 2 pipes).
What is the best way to achieve this?
And is it possible to achieve with a client that communicates with the server only via http (with a single http connection)?
EDIT:
my current thoughts on how to approach this are as follows:
i can define a new BodyParser[Future[String]] which is basically an Iteratee[Array[Byte],Future[String]]. while the parsing takes place, i can compute the result asynchronously and the action can return the result as ChunkedResult in the future's onComplete method.
does this sound like the right approach?
any suggestions on how to achieve this?
Maybe you should look at websockets.
Java: http://www.playframework.com/documentation/2.1-RC3/JavaWebSockets
Scala: http://www.playframework.com/documentation/2.0/ScalaWebSockets

Creation of proxy objects in GWT RequestFactory

Is it possible to create a proxy object in the client code without using any request context?
I want this behavior because I want to send the object to the server multiple times and I cant do so if its associated to single request context.
You can create your proxy with one RequestContext and send it. Once the response is received, the object is frozen and no longer attached to a RequestContext, you can thus send it with another RequestContext (as before, you'll have to wait for the response before being able to use it yet another RequestContext).
I'll investigate if these constraints can be relaxed in a future version of GWT.

OpenRasta streaming response

Does anyone know if it is possible to write to the response stream in OpenRasta rather than returning an object as a response resource? Alternatively, am I able to implement an HTTP handler but still leverage OpenRasta's URL rewriting?
Thanks
Chris
You can always keep an http handler on the side to do specialized things, but that ties you to asp.net and will prevent your code from being portable on other hosts. If that's something you're ok with, any handler that's registered for a specific route will get executed before openrasta on asp.net.
that said, codecs are the ones writing to the response stream, so provided you have a custom IMediaTypeWriter you can write the resource instance on a stream whichever way you want.
Say for example that you returned an IEnumerable from your handler, as those get deferred executed, you can just start the enumeration of those in your custom codec without any problem.

AutoResponder in FiddleCore

is it possible to develop an AutoResponder like actions for FiddleCore?
in this question it said that we should wait for new version of Fiddler. it's out. what now?
Yes, you can write an AutoResponder-like feature using FiddlerCore. The FiddlerCore package includes a class that allows you to load a .SAZ traffic archive capture.
You can then play back the responses that you loaded by hooking the BeforeRequest method, and using the oSession.utilCreateResponseAndBypassServer() method.
You'd check the URL and/or other data to figure out which response to return, and copy the response data out of the loaded session into the new response.