私はJavaアプリケーションをweblogicにデプロイしています。アプリケーションからの主要な役割はソケット経由の別のAPIとの通信です。この別のAPIは別のサーバーにインストールされています。 [OK]をJavaのアプリをここでソケットがサーバーから不完全なデータを取得する
いつかはソケットから不完全なデータを取得し始めました。 API側のログを分析しました。 APIは完全なデータを返しますが、JavaアプリケーションがデプロイされているWeblogicサーバーでは完全なデータを読み取ることはできません。ローカルではJavaアプリケーションも同様に動作します。
私はそれがサーバのメモリで何かを持っていると仮定します。私はこの問題を解決することは考えていません。
私はGoogleで検索しかし、何の答えを持っていません。この元のメッセージの下に
は大成功で、ローカルに返さ:0 100-Autorizado O USOダ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 * @@ *
不完全WebLogic Serverで返されるメッセージです。
0 100-Autorizado O USOダ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
は、データを送信し、読むために責任を負うクラスです:
@Repository
パブリッククラスSocketRepositoryは、通常、様々な要因に応じて1500バイトの周りに、ネットワークによって提供される読み取り専用データのチャンクを読み取り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;
} finally {
LOGGER.info("start finally block. ");
closeConnection();
LOGGER.info("End finally 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.");
}
}
だから私はそれを行う。私はメソッドのreadMessageを持っているときに停止するデータ== -1文字列の終わりが返されます。 – danillonc
その後、readMessagePaperlessにループを含めなかったコードが増えていて、そこに何か問題があります。 –
@danillonc:このような方法であっても、readMessagePaperless()は間違っています。 –