java - DefaultClient keep alive -


where issue ? when use same request , setup httpclient 3.1, persistent connection keep, no in httpclient 4.x [defaultclient].

javax.net.ssl.sslcontext ctx = javax.net.ssl.sslcontext.getinstance("tls"); ctx.init(keyfactory.getkeymanagers(), tmfactory.gettrustmanagers(), new    securerandom()); .. schemeregistry schemeregistry = new schemeregistry(); schemeregistry.register(new scheme("https", 443, new mysslfactory(ctx)));  poolingclientconnectionmanager cm = new poolingclientconnectionmanager(schemeregistry); cm.setmaxtotal(20); cm.setdefaultmaxperroute(5); cm.setmaxperroute(new httproute(localhost), 5); httpparams httpparameters = new basichttpparams(); httpconnectionparams.setconnectiontimeout(httpparameters, 5000); // connection timeout httpconnectionparams.setsotimeout(httpparameters, 0); httpclient client = new defaulthttpclient(cm,httpparameters);            while (i<200) {     httppost post = new httppost(send.geturl().tostring());     header[] heads =  post.getallheaders();     system.out.println("request headers size:"+heads.length);     (int ii=0; ii<heads.length; ii++) {         header head = heads[ii];         system.out.println("name:"+head.getname()+",  value:"+head.getvalue());      }            contenttype contenttype =     contenttype.create("text/xml","utf-8");            httpentity entity = new stringentity(data,contenttype );     post.setentity(entity);     httpresponse resp = client.execute(post); ... } client.getconnectionmanager().shutdown(); 

this log output:

2013/04/05 10:52:12:337 cest [debug] poolingclientconnectionmanager - connection request: [route:  {s}->https://smsconnector.cz][total kept alive: 0; route allocated: 0 of 5; total allocated: 0 of 5]  2013/04/05 10:52:12:400 cest [debug] poolingclientconnectionmanager - connection leased: [id: 0][route:  {s}->https://smsconnector.cz][total kept alive: 0; route allocated: 1 of 5; total allocated: 1 of 5]  2013/04/05 10:52:13:294 cest [debug] defaultclientconnectionoperator - connecting smsconnector.cz:443  2013/04/05 10:52:13:382 cest [debug] requestaddcookies - cookiespec selected: best-match  2013/04/05 10:52:13:404 cest [debug] requestauthcache - auth cache not set in context  2013/04/05 10:52:13:405 cest [debug] requesttargetauthentication - target auth state: unchallenged  2013/04/05 10:52:13:405 cest [debug] requestproxyauthentication - proxy auth state: unchallenged  2013/04/05 10:52:13:405 cest [debug] defaulthttpclient - attempt 1 execute request  2013/04/05 10:52:13:405 cest [debug] defaultclientconnection - sending request: post  /smsconnector/services/ppgwport?method=post http/1.1  2013/04/05 10:52:13:406 cest [debug] wire - >> "post /smsconnector/services/ppgwport?method=post http/1.1[\r][\n]"  2013/04/05 10:52:13:407 cest [debug] wire - >> "connection: keep-alive[\r][\n]"  2013/04/05 10:52:13:407 cest [debug] wire - >> "keep-alive: timeout=5, max=5[\r][\n]"  2013/04/05 10:52:13:407 cest [debug] wire - >> "content-length: 222[\r][\n]"  2013/04/05 10:52:13:407 cest [debug] wire - >> "content-type: text/xml; charset=utf-8[\r][\n]"  2013/04/05 10:52:13:408 cest [debug] wire - >> "host: smsconnector.cz[\r][\n]"  2013/04/05 10:52:13:408 cest [debug] wire - >> "[\r][\n]"  2013/04/05 10:52:13:408 cest [debug] headers - >> post /smsconnector/services/ppgwport?method=post http/1.1  2013/04/05 10:52:13:408 cest [debug] headers - >> connection: keep-alive  2013/04/05 10:52:13:408 cest [debug] headers - >> keep-alive: timeout=5, max=5  2013/04/05 10:52:13:408 cest [debug] headers - >> content-length: 222  2013/04/05 10:52:13:408 cest [debug] headers - >> content-type: text/xml; charset=utf-8  2013/04/05 10:52:13:408 cest [debug] headers - >> host: smsconnector.cz  2013/04/05 10:52:13:408 cest [debug] wire - >> "<soapenv:envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:b2b="http://b2b.et.cz"><soapenv:header/><soapenv:body><b2b:receive><baid>123456</baid></b2b:receive></soapenv:bod y></soapenv:envelope>"  2013/04/05 10:52:43:812 cest [debug] wire - << "http/1.1 200 ok[\r][\n]"  2013/04/05 10:52:43:815 cest [debug] wire - << "date: fri, 05 apr 2013 08:52:13 gmt[\r][\n]"  2013/04/05 10:52:43:815 cest [debug] wire - << "server: apache/2.2.8 (unix) mod_ssl/2.2.8 openssl/0.9.8h resin/3.1.9[\r][\n]"  2013/04/05 10:52:43:815 cest [debug] wire - << "content-type: text/xml; charset=utf-8[\r][\n]"  2013/04/05 10:52:43:815 cest [debug] wire - << "vary: accept-encoding[\r][\n]"  2013/04/05 10:52:43:815 cest [debug] wire - << "keep-alive: timeout=60, max=2000[\r][\n]"  2013/04/05 10:52:43:816 cest [debug] wire - << "connection: keep-alive[\r][\n]"  2013/04/05 10:52:43:816 cest [debug] wire - << "transfer-encoding: chunked[\r][\n]"  2013/04/05 10:52:43:816 cest [debug] wire - << "[\r][\n]"  2013/04/05 10:52:43:817 cest [debug] defaultclientconnection - receiving response: http/1.1 200 ok  2013/04/05 10:52:43:817 cest [debug] headers - << http/1.1 200 ok  2013/04/05 10:52:43:817 cest [debug] headers - << date: fri, 05 apr 2013 08:52:13 gmt   2013/04/05 10:52:43:818 cest [debug] headers - << server: apache/2.2.8 (unix) mod_ssl/2.2.8 openssl/0.9.8h resin/3.1.9  2013/04/05 10:52:43:818 cest [debug] headers - << content-type: text/xml; charset=utf-8   2013/04/05 10:52:43:818 cest [debug] headers - << vary: accept-encoding   2013/04/05 10:52:43:818 cest [debug] headers - << keep-alive: timeout=60, max=2000   2013/04/05 10:52:43:818 cest [debug] headers - << connection: keep-alive   2013/04/05 10:52:43:818 cest [debug] headers - << transfer-encoding: chunked   2013/04/05 10:52:43:822 cest [debug] defaulthttpclient - connection can kept alive 60000 milliseconds   2013/04/05 10:52:43:825 cest [debug] wire - << "108[\r][\n]"   2013/04/05 10:52:43:825 cest [debug] wire - << "<soap:envelope  xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:body><ns2:receiveresponse xmlns:ns2="http://b2b.et.cz"><result xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"  xsi:nil="true"/></ns2:receiveresponse></soap:body></soap:envelope>"  2013/04/05 10:52:43:825 cest [debug] wire - << "[\r][\n]"   2013/04/05 10:52:43:825 cest [debug] wire - << "0[\r][\n]"   2013/04/05 10:52:43:825 cest [debug] wire - << "[\r][\n]"   2013/04/05 10:52:43:826 cest [debug] poolingclientconnectionmanager - connection [id: 0][route:  {s}->https://smsconnector.cz][state: emailaddress=lab@draft.cz, cn=endtoend test, ou=vas,  o="endtoend test, ico: 00000000", l="jecna 1, praha 2, 123", st=., c=cz] can kept alive 60000 milliseconds   2013/04/05 10:52:43:826 cest [debug] poolingclientconnectionmanager - connection released: [id: 0][route:  {s}->https://smsconnector.cz][state: emailaddress=lab@draft.cz, cn=endtoend test, ou=vas,  o="endtoend test, ico: 00000000", l="jecna 1, praha 2, 123", st=., c=cz][total kept alive: 1; route allocated: 1 of 5;  total allocated: 1 of 5]  2013/04/05 10:52:43:826 cest [debug] poolingclientconnectionmanager - connection request: [route:  {s}->https://smsconnector.cz][total kept alive: 1; route allocated: 1 of 5; total allocated: 1 of 5]   2013/04/05 10:52:43:826 cest [debug] poolingclientconnectionmanager - connection leased: [id: 1][route:  {s}->https://smsconnector.cz][total kept alive: 1; route allocated: 2 of 5; total allocated: 2 of 5]  

different session-id

defaultclient

>  operation/cn=endtoend test/emailaddress=lab@draft.cz > c2730afb1ee8a769f642861f3e167fc961a115e540bf06d2cdb21fc75921758e > success [05/apr/2013:11:12:29 +0200] 160.218.43.253 tlsv1 rc4-md5 > "post /smsconnector/services/ppgwport?method=post http/1.1" 264 > /c=cz/st=./l=jecna 1, praha 2, 123/o=endtoend test, ico: > 00000000/ou=vas/cn=endtoend test/emailaddress=lab@draft.cz > c5520d9fca38e1a6beb5994a4eba7f9ea28165ae51c8a0976f6b137c93a0128d > success [05/apr/2013:11:12:59 +0200] 160.218.43.253 tlsv1 rc4-md5 > "post /smsconnector/services/ppgwport?method=post http/1.1" 264 > /c=cz/st=./l=jecna 1, praha 2, 123/o=endtoend test, ico: > 00000000/ou=vas/cn=endtoend test/emailaddress=lab@draft.cz > 431fd618f6093bd94b0df845765dc96f45a8b7f499cec0ea1bd66ce6fe9f12e4 > success [05/apr/2013:11:13:30 +0200] 160.218.43.253 tlsv1 rc4-md5 > "post /smsconnector/services/ppgwport?method=post http/1.1" 264 > /c=cz/st=./l=jecna 1, praha 2, 123/o=endtoend test, ico: > 00000000/ou=vas/cn=endtoend test/emailaddress=lab@draft.cz > f6ea63b12adb023fcd13e88b44cae86d1a5ad4b28019783b331edbbf6f8106f8 > success [05/apr/2013:11:14:00 +0200] 160.218.43.253 tlsv1 rc4-md5 > "post /smsconnector/services/ppgwport?method=post http/1.1" 264 > /c=cz/st=./l=jecna 1, praha 2, 123/o=endtoend test, ico: > 00000000/ou=vas/cn=endtoend test/emailaddress=lab@draft.cz > caf1b53a029112edc0cf7124acb0d8ee662312a9cb672c96190ebf60f7add6ff > success [05/apr/2013:11:14:30 +0200] 160.218.43.253 tlsv1 rc4-md5 > "post /smsconnector/services/ppgwport?method=post http/1.1" 264 > /c=cz/st=./l=jecna 1, praha 2, 123/o=endtoend test, ico: > 00000000/ou=vas/cn=endtoend test/emailaddress=lab@draft.cz > 3e212288d658d95c69ea7001588d0a9dd9113f8cd0ced406bce5658076628b2f > success 

httpclient 3.1

session-id same - persistent connection

> [05/apr/2013:11:15:18 +0200] 160.218.43.253 tlsv1 rc4-md5 "post > /smsconnector/services/ppgwport?method=post http/1.1" 264 > /c=cz/st=./l=jecna 1, praha 2, 123/o=endtoend test, ico: > 00000000/ou=vas/cn=endtoend test/emailaddress=lab@draft.cz > f46c2de76c881fd21b7235f4e3bcc778358baf73687a433a7e4e46a3a9dcf539 > success [05/apr/2013:11:15:49 +0200] 160.218.43.253 tlsv1 rc4-md5 > "post /smsconnector/services/ppgwport?method=post http/1.1" 264 > /c=cz/st=./l=jecna 1, praha 2, 123/o=endtoend test, ico: > 00000000/ou=vas/cn=endtoend test/emailaddress=lab@draft.cz > f46c2de76c881fd21b7235f4e3bcc778358baf73687a433a7e4e46a3a9dcf539 > success [05/apr/2013:11:16:22 +0200] 160.218.43.253 tlsv1 rc4-md5 > "post /smsconnector/services/ppgwport?method=post http/1.1" 264 > /c=cz/st=./l=jecna 1, praha 2, 123/o=endtoend test, ico: > 00000000/ou=vas/cn=endtoend test/emailaddress=lab@draft.cz > f46c2de76c881fd21b7235f4e3bcc778358baf73687a433a7e4e46a3a9dcf539 > success [05/apr/2013:11:16:52 +0200] 160.218.43.253 tlsv1 rc4-md5 > "post /smsconnector/services/ppgwport?method=post http/1.1" 264 > /c=cz/st=./l=jecna 1, praha 2, 123/o=endtoend test, ico: > 00000000/ou=vas/cn=endtoend test/emailaddress=lab@draft.cz > f46c2de76c881fd21b7235f4e3bcc778358baf73687a433a7e4e46a3a9dcf539 > success [05/apr/2013:11:17:41 +0200] 160.218.43.253 tlsv1 rc4-md5 > "post /smsconnector/services/ppgwport?method=post http/1.1" 264 > /c=cz/st=./l=jecna 1, praha 2, 123/o=endtoend test, ico: > 00000000/ou=vas/cn=endtoend test/emailaddress=lab@draft.cz > f46c2de76c881fd21b7235f4e3bcc778358baf73687a433a7e4e46a3a9dcf539 > success 

i'm not 100% sure try keeping local context?

httpclient client = new defaulthttpclient(cm,httpparameters); // create local context httpcontext context= new basichttpcontext(); while (i<200) {     httppost post = new httppost(send.geturl().tostring());     header[] heads =  post.getallheaders();     system.out.println("request headers size:"+heads.length);     (int ii=0; ii<heads.length; ii++) {         header head = heads[ii];         system.out.println("name:"+head.getname()+",  value:"+head.getvalue());      }            contenttype contenttype =     contenttype.create("text/xml","utf-8");            httpentity entity = new stringentity(data,contenttype );     post.setentity(entity);     // pass context execution     httpresponse resp = client.execute(post, context); ... } 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -