У меня есть веб-сервис Java, который запускается для интеграции через обмен файлами XML с ERP, он прекрасно работал со дня его разработки. Вчера утром он начал генерировать пустые файлы XML без каких-либо изменений в своем исходном коде. Любой сделанный запрос генерирует пустые файлы, что делает невозможным взаимодействие между платформами.
Анализируя журнал сервера, появляется следующая ошибка
ERROR: 'Input/output error'
javax.xml.transform.TransformerException: org.xml.sax.SAXException: Input/output error
java.io.IOException: Input/output error
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:743)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:345)
at br.com.allis.XMLFiles.RequisicaoReembolso.createXML(RequisicaoReembolso.java:252)
at br.com.allis.XMLFiles.XMLParser.generateXML(XMLParser.java:63)
at br.com.allis.ws.AllisWS.generateXML(AllisWS.java:1126)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.axis2.rpc.receivers.RPCUtil.invokeServiceClass(RPCUtil.java:212)
at org.apache.axis2.rpc.receivers.RPCMessageReceiver.invokeBusinessLogic(RPCMessageReceiver.java:121)
at org.apache.axis2.receivers.AbstractInOutMessageReceiver.invokeBusinessLogic(AbstractInOutMessageReceiver.java:40)
at org.apache.axis2.receivers.AbstractMessageReceiver.receive(AbstractMessageReceiver.java:114)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:181)
at org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java:172)
at org.apache.axis2.transport.http.AxisServlet.doPost(AxisServlet.java:146)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:221)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:107)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:76)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:934)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:90)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:522)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1015)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:646)
at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:223)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1576)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1534)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1152)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:622)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.xml.sax.SAXException: Input/output error
java.io.IOException: Input/output error
at com.sun.org.apache.xml.internal.serializer.ToStream.flushWriter(ToStream.java:304)
at com.sun.org.apache.xml.internal.serializer.ToXMLStream.endDocument(ToXMLStream.java:213)
at com.sun.org.apache.xml.internal.serializer.ToUnknownStream.endDocument(ToUnknownStream.java:829)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(DOM2TO.java:139)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(DOM2TO.java:98)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transformIdentity(TransformerImpl.java:687)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:731)
... 38 more
Caused by: java.io.IOException: Input/output error
at java.io.FileOutputStream.writeBytes(Native Method)
at java.io.FileOutputStream.write(FileOutputStream.java:345)
at com.sun.org.apache.xml.internal.serializer.WriterToUTF8Buffered.flushBuffer(WriterToUTF8Buffered.java:450)
at com.sun.org.apache.xml.internal.serializer.WriterToUTF8Buffered.flush(WriterToUTF8Buffered.java:469)
at com.sun.org.apache.xml.internal.serializer.ToStream.flushWriter(ToStream.java:285)
... 44 more
Я уже пытался повторно развернуть его, поскольку не было никаких изменений в его коде, но без успеха.
Когда я запускаю приложение локально, оно работает нормально ...
public ReturnMsg createXML(String paramsJson) {
ReturnMsg retorno = new ReturnMsg();
try {
JsonParser parser = new JsonParser();
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
Document doc = docBuilder.newDocument();
Element root = doc.createElement("DEMANDA");
doc.appendChild(root);
JsonObject requisicao = parser.parse(paramsJson).getAsJsonObject();
String numDemanda = requisicao.get("NUM_DEM").getAsString();
int numRequisicao = Integer.parseInt(numDemanda);
this.log.setNumeroDemanda(numRequisicao);
String tpDemanda = requisicao.get("TIP_DEM").getAsString();
String codEmpresa = requisicao.get("COD_EMP").getAsString();
String cnpj = requisicao.get("CNPJ_FOR").getAsString();
String cpf = requisicao.get("CPF_FOR").getAsString();
String dtFaturamento = requisicao.get("DAT_FAT").getAsString();
String textExp = requisicao.get("TEX_EXP").getAsString();
String textCab = requisicao.get("TEX_CAB").getAsString();
String destRecurso = requisicao.get("DEST_REC").getAsString();
String motivoDespesa = requisicao.get("MOT_DESP").getAsString()
int numDestRecurso = Integer.parseInt(destRecurso);
int numMotivoDespesa = motivoDespesa != "" ? Integer.parseInt(motivoDespesa) : 0;
Element src = doc.createElement("SRC");
String txtSrc = "fluig";
Element nDemanda = doc.createElement("NUM_DEM");
Element tDemanda = doc.createElement("TIP_DEM");
Element cEmpresa = doc.createElement("COD_EMP");
Element cnpjF = doc.createElement("CNPJ_FOR");
Element cpfF = doc.createElement("CPF_FOR");
Element dtFat = doc.createElement("DAT_FAT");
Element txtExp = doc.createElement("TEX_EXP");
Element txtCab = doc.createElement("TEX_CAB");
Element itens = doc.createElement("ITENS");
src.appendChild(doc.createTextNode(txtSrc));
nDemanda.appendChild(doc.createTextNode(numDemanda));
tDemanda.appendChild(doc.createTextNode(tpDemanda));
cEmpresa.appendChild(doc.createTextNode(codEmpresa));
cnpjF.appendChild(doc.createTextNode(cnpj));
cpfF.appendChild(doc.createTextNode(cpf));
dtFat.appendChild(doc.createTextNode(dtFaturamento));
txtExp.appendChild(doc.createTextNode(textExp));
txtCab.appendChild(doc.createTextNode(textCab));
root.appendChild(src);
root.appendChild(nDemanda);
root.appendChild(tDemanda);
root.appendChild(cEmpresa);
root.appendChild(cnpjF);
root.appendChild(cpfF);
root.appendChild(dtFat);
root.appendChild(txtExp);
root.appendChild(txtCab);
JsonArray itensJson = requisicao.get("ITENS").getAsJsonArray();
for (int i = 0, size = itensJson.size(); i < size; i++) {
JsonObject obj = (JsonObject) itensJson.get(i);
Element item = doc.createElement("ITEM");
Element tipDes = doc.createElement("TIP_DES");
Element valLin = doc.createElement("VAL_LIN");
Element cCusto = doc.createElement("C_CUSTO");
Element ePep = doc.createElement("E_PEP");
if( i == 0 ){
String cenCusto = !obj.get("C_CUSTO").getAsString().isEmpty() ? obj.get("C_CUSTO").getAsString() : obj.get("E_PEP").getAsString();
}
item.appendChild(doc.createTextNode(obj.get("ITEM").getAsString()));
tipDes.appendChild(doc.createTextNode(obj.get("TIP_DES").getAsString()));
valLin.appendChild(doc.createTextNode(obj.get("VAL_LIN").getAsString()));
cCusto.appendChild(doc.createTextNode(obj.get("C_CUSTO").getAsString()));
ePep.appendChild(doc.createTextNode(obj.get("E_PEP").getAsString()));
item.appendChild(tipDes);
item.appendChild(valLin);
item.appendChild(cCusto);
item.appendChild(ePep);
itens.appendChild(item);
}
root.appendChild(itens);
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
DOMSource source = new DOMSource(doc);
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,"yes");
transformer.setOutputProperty(OutputKeys.METHOD,"xml");
StreamResult result = new StreamResult(new File(this.getNomeArq()));
transformer.transform(source, result); // error triggers here
retorno.setSuccess(true);
retorno.setMotivo("Sucesso");
retorno.setObs("Arquivo gerado com sucesso");
retorno.setTipoRetorno("ok");
} catch (ParserConfigurationException pce) {
pce.printStackTrace();
retorno.setSuccess(false);
retorno.setMotivo("Erro");
retorno.setObs("Erro criação do arquivo XML");
retorno.setTipoRetorno("exc");
} catch (TransformerException te) {
te.printStackTrace();
retorno.setSuccess(false);
retorno.setMotivo("Erro");
retorno.setObs("Erro criação do arquivo XML");
retorno.setTipoRetorno("exc");
} catch (Exception e) {
e.printStackTrace();
retorno.setSuccess(false);
retorno.setMotivo("Erro");
retorno.setObs("Erro criação do arquivo XML");
retorno.setTipoRetorno("exc");
}
return retorno;
}
Ожидаемый вывод должен быть XML-файл с этой структурой
<DEMANDA>
<SRC></SRC>
<NUM_DEM></NUM_DEM>
<TIP_DEM></TIP_DEM>
<COD_EMP></COD_EMP>
<CNPJ_FOR></CNPJ_FOR>
<CPF_FOR></CPF_FOR>
<DAT_FAT></DAT_FAT>
<TEX_EXP></TEX_EXP>
<TEX_CAB></TEX_CAB>
<ITENS>
<ITEM>
<TIP_DES></TIP_DES>
<VAL_LIN></VAL_LIN>
<C_CUSTO></C_CUSTO>
<E_PEP></E_PEP>
</ITEM>
</ITENS>
</DEMANDA>