java - Socket get incomplete data from server -
i have java application deployed in weblogic principal role app communication api via socket. api installed in server. ok
sometime here java app started getting incomplete data socket. have analyzed logs on api side. api return complete data on weblogic server java app deployed not read complete data. locally java app work well.
i suppose have server memory. have no idea solve problem.
i search on google have no answers.
below original message returned locally succes:
@**@0 100-autorizado o uso da nf-e 33170845242914003465652000000007511200000067 http://www4.fazenda.rj.gov.br/retrieve/qrcode?chnfe=33170845242914003465652000000007511200000067&nversao=100&tpamb=2&cdest=12345678998&dhemi=323031372d30382d31385431333a30343a32302d30333a3030&vnf=110.00&vicms=22.80&digval=6b6e3774696b652f616b4878574a35414d766367347074497a62343d&cidtoken=000001&chashqrcode=998144c803f3f5e56a0e1764647ccd6928c2a70d 333170000817607|2017-08-18t13:04:23-03:00|svrsnfce201707171030|100 http://www4.fazenda.rj.gov.br/consultanfce/qrcode? 6989*@@*
below message returned in weblogic server incomplete:
@**@0 100-autorizado o uso da nf-e 33170845242914003465652000000007501000000449 http://www4.fazenda.rj.gov.br/consultanfce/qrcode?chnfe=33170845242914003465652000000007501000000449&nversao=100&tpamb=2&cdest=22233344405&dhemi=323031372d30382d31385431323a35343a30342d30333a3030&vnf=325.00&vicms=61.75&digval=7955796b6b4e64687a7342335470755166495847516c4343566e453d&cidtoken=000001&chashqrcode=03e10ca5299ed5cb5acd7de5dc5db98df9c49d0e 333170000817573|2017-08-18t12:54:06-03:00|svrsnfce201707171030|100 http://www4.fazenda.rj.go
below responsible class send , read data:
@repository public class socketrepository implements baserepository {
private static final logger logger = loggerfactory.getlogger(socketrepository.class); private socket socket; private static int buffer_size = 2048; private bufferedoutputstream bos; private bufferedinputstream bis; @override public synchronized string senddatasocket(string buff, final osbrequestdto osbdto) throws exception { try { logger.info("start send data. "); url url = new url(osbdto.getemissor().geturlloja()); openconnection(url.gethost(), url.getport()); if (this.bos == null) { this.bos = new bufferedoutputstream(this.socket.getoutputstream(), buffer_size); } if (this.bis == null) { this.bis = new bufferedinputstream(this.socket.getinputstream(), buffer_size); } this.bos.write(buff.getbytes(standardcharsets.utf_8)); this.bos.flush(); logger.info("end send data. "); return readmessagepaperless(bis); } catch (exception e) { logger.error("erro :" + e.getmessage()); throw e; } { logger.info("start block. "); closeconnection(); logger.info("end block."); } } private string readmessagepaperless(final bufferedinputstream bis) throws ioexception { try { logger.info("start read data ."); byte[] buffersize = new byte[512 * 1024]; int data = bis.read(buffersize); if (data == -1) { return ""; } logger.info("end read data."); return new string(buffersize, 0, data, standardcharsets.utf_8); } catch (exception e) { logger.error("err." + e.getmessage()); throw e; } } private void closeconnection() throws exception { try { if (this.bos != null && this.bis != null) { try { this.bos.close(); this.bis.close(); } catch (exception e) { logger.error("err :" + e.getmessage()); throw e; } } if (this.socket == null) { return; } this.socket.close(); this.socket = null; this.bis = null; this.bos = null; } catch (exception e) { logger.error("err :" + e.getmessage()); throw e; } } private void openconnection(final string host, final int port) throws unknownhostexception, ioexception { logger.info("start open socket conn."); if (this.socket != null) { return; } this.socket = new socket(host, port); logger.info("end."); } }
the read read chunk of data provided network, around 1500 bytes depending on various factors. should continue reading until have received complete message. when connection local works differently.
Comments
Post a Comment