Stubbing Asynchronous Http Services using Wiremock
- Posted by Chathurika Sandarenu
- Thursday, December 06, 2012
One weakness of wiremock was it only supported synchronous http request mocking(i.e: You send the request and stubbed wiremock server send the response). But I wanted to mock Asynchronous REST server. In asynchronous scenario in addition direct http response, server is initiating another call back request to the server. This method is commonly used by web service operations which take lots of time to process. Flow of such operation would look like follows.
When a client want to get some operation done;
1) Client sends the request to the server
2) Server accept that request and give that accepted response as direct http response
3) Server do the processing and send the actual result as a new http request to the client
This feature is implemented in my wiremock forked repository. Still this is not being merged to main wiremock repository. So if you are interested in this you'll have to clone my forked repo, build it locally and publish the jar file to your local maven repository.
Stubbing asynchronous request is easy.
In most asynchronous http services, some kind of Id is being used to map original request with the asynchronous response. There can be two ways of doing this.
1) Server generates transactionId and sends it with the immediate response
2) Client sends the transactionId and server echo that when it sends back asynchronous response
If you want to use the second method with wiremock, you can use setEchoField method.
At the moment there is a one limitation with this. You can only use this facility with JSON requests and responses.
You can find the complete test class at github.
Useful GIT Commands
- Posted by Chathurika Sandarenu
- Wednesday, July 25, 2012
This is collection of useful GIT commands I use in my day today work. Just posting here to keep as my own reference.
Revert changes made to your working copy:
git checkout .
Revert changes made to the index (i.e., that you have added):
git reset
Revert a change that you have committed, do this:
git revert ...
View commits not yet pushed to remote:
git log --branches --not --remotes
Not pushed most recent commit with branch name:
git log --branches --not --remotes --simplify-by-decoration --decorate --oneline
Difference between two branches:
git diff --stat --color master..branch
Here the order of branch name is merge-target..merge-source.
Create remote tracking branch:
git branch --track feature1 origin/my-remote-branch
Here git fetch/pull from feature1 branch will get the updates from my-remote-branch
Create new local branch from remote branch:
git branch --no-track feature2 origin/master
Push local branch to remote repository:
git push origing feature2
Checkout specific file from differrent branch:
git checkout remote/branch path/to/file
- Labels:
- Git
- 0 comments
- Leave A Comment
Exclude resource files from jar file created with SBT
- Posted by Chathurika Sandarenu
- Friday, April 27, 2012
When I build the jar file using SBT package command all of those resource files also get included in the jar file. When those resource files are included inside the jar, modifying them becomes difficult. I have to extract the jar file, edit them and create the jar file again.
Ideal way of handling resource files are not to include them in the jar file, rather keep them separately and include them in the class path when running the application. How to exclude them from SBT package task was the problem I had. After some googling I found out that this can be achieved by including mapping task in the build. Following is sample build file which uses mapping to exclude various types of resource files.
lazy val myapp = Project(id = "myapp", base = file("myapp"),
settings = baseSettings ++ Seq(
name := "My App",
mappings in (Compile, packageBin) ~= { (ms: Seq[(File, String)]) =>
ms filter {
case (file, toPath) =>{
val shouldExclude = excludeFileRegx.pattern.matcher(file.getName).matches
// println("===========" + file + " " + shouldExclude)
!shouldExclude
}
}
},
libraryDependencies ++= Seq (dispatch),
libraryDependencies ++= testDependencies))
- Labels:
- Programming
- Scala
- 3 comments
- Leave A Comment
Solving no-interface issue in Wireshark on Ubuntu 11.10
- Posted by Chathurika Sandarenu
- Thursday, January 19, 2012
So after doing some googleing found a solution at a blog post by tavshed.
sudo groupadd wireshark sudo usermod -a -G wireshark YOUR_USER_NAME sudo chgrp wireshark /usr/bin/dumpcap sudo chmod 750 /usr/bin/dumpcap sudo setcap cap_net_raw,cap_net_admin=eip /usr/bin/dumpcap sudo getcap /usr/bin/dumpcap
sudo chmod +xs /usr/bin/dumpcap
- Labels:
- Linux
- Ubuntu
- 2 comments
- Leave A Comment
Labels
- ASP (1)
- Blogger Hacks (1)
- C# (1)
- diGIT (1)
- Eclipse (5)
- Fedora (4)
- Firefox (3)
- Git (2)
- Github (1)
- Google (11)
- Google Reader (1)
- Hibernate (1)
- hSenid Mobile (1)
- Java (18)
- Javascript (2)
- Linux (2)
- Maven (1)
- Microsoft (16)
- MsSqlServer (1)
- MySQL (1)
- OpenCV (3)
- OpenJDK (3)
- Other (18)
- Personal (28)
- Productivity (14)
- Programming (39)
- React (1)
- React-Native (1)
- REST (1)
- Scala (2)
- Scala-Ide (1)
- Scalaz (1)
- SCTP (3)
- SDP (1)
- Soltura (1)
- Spring (1)
- SQL (2)
- Time Management (7)
- Tips and Tricks (22)
- Ubuntu (1)
- Utilities (20)
- Wiremock (1)