Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android How To Simulate HTTP Communication for Offline Demo

Tags:

android

http

I have an Android App which uses http communication for nearly every operation. I want to be able to demo without connection to the internet by somehow replaying the http exchange. How can this be done? So I want to somehow almost like mock objects but really mock http session so I can always demo the app on or offline. This is really a very cool thing to be able to do. Since you can demo the app easily and reliably. Does anyone know how I could do this. Replicating the whole server side is just not an options its got too much stuff. Its important not to just show screencast but the real data exchange. I just want to be able to run thru the app and replay. Maybe debug as well. Thanks

like image 572
Androider Avatar asked Jun 04 '11 01:06

Androider


2 Answers

Here's a hybrid solution using similar ideas from other answers:

You could write a dead simple HTTP server that listens on "localhost:80" (or whatever the port is on the server you're targeting) and point your application to this host instead by factoring out the host name from requests. Your local server has a reference to the actual remote server and does the following:

  • If ONLINE, forwards the request as-is to the real server, gets the response, saves it locally either in an in-memory cache keyed by the request URL or a file named with the URL as its identifier (munged appropriately)
  • If OFFLINE, looks up a request in its (in-memory or file system) cache and returns the contents from the cache instead

This is kind of like the record/playback mode that @nicholas.hauschild says.

Now you can just run your app once when ONLINE, causing your localhost server to save away requests that it issues against the real server. Then when you run your app OFFLINE, it just returns these cached contents instead whenever the same URLs are issued.

Hope this helps.

like image 93
scorpiodawg Avatar answered Sep 23 '22 02:09

scorpiodawg


  • If you're device is rooted, you can use tcpdump as explained in this post: http://www.vbsteven.be/blog/android-debugging-inspectin-network-traffic-with-tcpdump/
  • or use AndroShark (get if from xda-developers here: http://forum.xda-developers.com/showthread.php?t=725692)
  • or this one (wifi only): http://www.9bitlabs.com/default.aspx
like image 38
Aleadam Avatar answered Sep 24 '22 02:09

Aleadam