java - Android AssetServer extending NanoHTTPD -


i'm developing assetserver extending nanohttpd in order access javascript features not available file:// based pages.

this code have far:

class assetserver extends nanohttpd{      private activity activity;      public assetserver(int port, activity activity)     {         super(port);         this.activity = activity;     }      @override     public response serve(ihttpsession session){          string mime = "text/plain";          inputstream = null;         string path = "www" + session.geturi();         system.out.println("nanohttpd: serving " + path);         string response = null;          try{              = activity.getassets().open(path);             int size = is.available();             byte[] buffer = new byte[size];             is.read(buffer);             is.close();              response = new string(buffer);          }catch(ioexception ioe){             system.err.println("nanohttpd: error: " + ioe);         }          response res = new response(response.status.ok, mime, response);         return res;      }  } 

when running android app on phone, logcat output suggests page receives some, not all, files requested page. there's 5 second delay in loadurl call give server time warm before serving pages.

here's logcat output:

04-08 19:19:54.548: i/cordovalog(16411): found start page location: index.html 04-08 19:19:54.553: d/whitelist(16411): unlimited access network resources 04-08 19:19:54.553: d/cordovaactivity(16411): resuming app 04-08 19:19:54.553: d/cordovaactivity(16411): cb-3064: errorurl null 04-08 19:19:54.568: d/dalvikvm(16411): gc_concurrent freed 252k, 17% free 7664k/9156k, paused 4ms+9ms, total 33ms 04-08 19:19:54.578: d/webcore(16411):  core loadurl: called 04-08 19:19:54.578: d/webkit(16411): firewall not null 04-08 19:19:54.578: d/webkit(16411): euler: isurlblocked = false 04-08 19:19:54.588: d/softkeyboarddetect(16411): ignore event 04-08 19:19:54.673: d/libegl(16411): loaded /system/lib/egl/libegl_mali.so 04-08 19:19:54.683: d/libegl(16411): loaded /system/lib/egl/libglesv1_cm_mali.so 04-08 19:19:54.683: i/system.out(16411): nanohttpd: serving www/index.html 04-08 19:19:54.693: d/libegl(16411): loaded /system/lib/egl/libglesv2_mali.so 04-08 19:19:54.698: e/(16411): device driver api match 04-08 19:19:54.698: e/(16411): device driver api version: 20 04-08 19:19:54.698: e/(16411): user space api version: 20  04-08 19:19:54.698: e/(16411): mali: revision=linux-r3p2-01rel2 build_date=mon sep  2 14:16:28 kst 2013  04-08 19:19:54.733: d/openglrenderer(16411): enabling debug mode 0 04-08 19:19:54.738: d/webview(16411): onsizechanged - w:480 h:762 04-08 19:19:54.738: d/cordovaactivity(16411): onmessage(onpagestarted,http://localhost:16086/index.html) 04-08 19:19:54.788: d/writingbuddyimpl(16411): getcurrentwritingbuddyview()  04-08 19:19:54.798: i/system.out(16411): nanohttpd: serving www/lib/jquery-2.0.2.min.js 04-08 19:19:54.833: d/dalvikvm(16411): gc_concurrent freed 100k, 16% free 7978k/9404k, paused 8ms+3ms, total 35ms 04-08 19:19:54.863: d/softkeyboarddetect(16411): ignore event 04-08 19:19:55.198: i/gate(16411): <gate-m>dev_action_completed</gate-m> 04-08 19:19:55.198: d/cordovawebviewclient(16411): onpagefinished(http://localhost:16086/index.html) 04-08 19:19:55.198: d/cordovaactivity(16411): onmessage(onpagefinished,http://localhost:16086/index.html) 04-08 19:19:57.213: d/cordovaactivity(16411): onmessage(spinner,stop) 04-08 19:19:57.243: d/tilesmanager(16411): starting tg #0, 0x539b0050 04-08 19:19:57.243: d/tilesmanager(16411): new eglcontext framework: 52aeba78  04-08 19:19:57.243: d/glwebviewstate(16411): reinit shader 04-08 19:19:57.283: d/glwebviewstate(16411): reinit transferqueue 

it's not same files served, suggesting concurrency issue.

anyone know i'm doing wrong? in advance!

embedhttp works situation.

@override public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     super.init();     // set <content src="index.html" /> in config.xml      final activity activity = this;     httpserver server = new httpserver();     server.addrequesthandler(new httprequesthandler() {         @override         public httpresponse handlerequest(httprequest request) {             inputstream = null;             string path = "www" + request.geturi();             string response = null;              try{                  = activity.getassets().open(path);                 int size = is.available();                 byte[] buffer = new byte[size];                 is.read(buffer);                 is.close();                  response = new string(buffer);             }catch(ioexception ioe){                 ioe.printstacktrace();             }             system.out.println("embedhttp: serving: " + path + ", " + response.length() + "b");             return new httpresponse(httpstatus.ok, response);         }     });      try{         server.bind(16086);     }catch(ioexception ioe){         ioe.printstacktrace();     }      server.start();     //super.loadurl(config.getstarturl());     super.loadurl("http://localhost:16086/index.html", 5000); } 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -