/** * Do carga archivo. * * @param mapping the mapping * @param form the form * @param request the request * @param response the response * @return the action forward * @throws Exception the exception */ public final ActionForward doCargaArchivo( final ActionMapping mapping, final ActionForm form, final HttpServletRequest request, final HttpServletResponse response) throws Exception { ReporteConciliacionForm fondosForm = (ReporteConciliacionForm) form; String mensaje = "Información cargada exitosamente. Se realizara la conciliación " + "la cual puede tardar unos minutos."; try { FormFile archivo = (FormFile) fondosForm.getArchivo(); InputStream is = archivo.getInputStream(); String fechaCarga = ""; if (is.available() == 0) { LOG.warn("El archivo " + archivo.getFileName() + " no existe o esta vacio"); mensaje = "El archivo no contiene información."; } else { // crear el archivo para bajarlo a disco String path = request.getSession().getServletContext().getRealPath(archivo.getFileName()); FileOutputStream fos = new FileOutputStream(path); // recibir los bytes y escribirlos en disco para crear el // archivo byte[] buffer = new byte[32768]; int n = 0; while ((n = is.read(buffer)) != -1) { fos.write(buffer, 0, n); fos.flush(); } // cerrar archivo del post is.close(); // cerrar archivo del disco archivo.destroy(); fos.flush(); fos.close(); // Guarda ruta del archivo en sesion request.getSession().removeAttribute("rutaArchTxt"); request.getSession().setAttribute("rutaArchTxt", path); final ReporteConciliacionService service = (ReporteConciliacionService) getWebApplicationContext().getBean(REPORTE_CONCILIACION_SERVICE); fechaCarga = service.guardaReporteConciliacion(path); } // cerrar la ventana de carga del txt response .getWriter() .println( "<script>function cancelaTxt(){" + "window.opener.cargaPartTxt(); window.hide();}" + "window.opener.cargaParticulares=true; " + "window.opener.fechaCarga='" + fechaCarga + "';" + "window.opener.cargaParticularesMensaje='" + mensaje + "'; cancelaTxt();</script>"); } catch (Exception e) { mensaje = e.getMessage(); response .getWriter() .println( "<script>function cancelaTxt(){" + "window.opener.cargaPartTxt(); window.close();}" + "window.opener.cargaParticulares=false;" + "window.opener.cargaParticularesMensaje='" + mensaje + "'; cancelaTxt();</script>"); } finally { fondosForm.setArchivo(null); } return null; }