Changeset 81c864a in murachi for murachi


Ignore:
Timestamp:
May 12, 2015, 9:55:04 AM (9 years ago)
Author:
antonioaraujob <aaraujo@…>
Branches:
master
Children:
90b2952
Parents:
4ac0cf4
Message:

Se comienza a utilizar el log4j para mantener trazas de los eventos ocurridos en la ejecución del servicio.

Location:
murachi/src/main
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • murachi/src/main/java/ve/gob/cenditel/murachi/MurachiRESTWS.java

    r4ac0cf4 r81c864a  
    116116public class MurachiRESTWS {
    117117       
    118         static Logger logger = Logger.getLogger(MurachiRESTWS.class);
     118        final static Logger logger = Logger.getLogger(MurachiRESTWS.class);
     119       
    119120
    120121        private static final String API_VERSION = "0.1.0";
     
    148149        @Produces(MediaType.TEXT_HTML)
    149150        public String returnVersion() {
     151                logger.info("/version: Murachi Version: " + API_VERSION);
    150152                return "<p>Murachi Version: " + API_VERSION + "</p>";
    151153        }
     
    168170                        @FormDataParam("upload") FormDataContentDisposition fileDetails) throws MurachiException {
    169171               
    170                 //TODO manejar las excepciones correctamente
     172                logger.info("/: uploadFile");
     173               
    171174                if (uploadedInputStream == null) {
    172175                        System.out.println("uploadedInputStream == null");
     176                        logger.error("uploadedInputStream != null. datos recibidos del formulario son nulos.");
    173177                        throw new MurachiException("uploadedInputStream != null. datos recibidos del formulario son nulos.");
    174178                }
     
    176180                if (fileDetails == null) {
    177181                        System.out.println("fileDetails == null");
     182                        logger.error("fileDetails == null. datos recibidos del formulario son nulos.");
    178183                        throw new MurachiException("fileDetails == null. datos recibidos del formulario son nulos.");
    179184                }
     
    187192                        uploadedInputStream.close();
    188193                } catch (IOException e) {
     194                        logger.error("Ocurrio una excepcion: ", e);
    189195                        e.printStackTrace();
    190196                        throw new MurachiException(e.getMessage());
     
    196202                System.out.println("File saved to server location : " + SERVER_UPLOAD_LOCATION_FOLDER + fileId);
    197203                String result = jsonObject.toString();
     204                logger.info("/: " + result);
    198205               
    199206                return Response.status(200).entity(result).build();
     
    209216        @Produces(MediaType.APPLICATION_OCTET_STREAM)
    210217        public Response downloadFilebyPath(@PathParam("filename")  String fileName) {
     218                logger.info("/descargas/{"+fileName+"}");
    211219                return downloadFileFromServer(fileName);
    212220        }
     
    266274                        @FormDataParam("upload") FormDataContentDisposition fileDetails) throws MurachiException {
    267275               
     276                logger.info("/firmados: uploadFileAndVerify");
     277               
    268278                if (uploadedInputStream == null) {
    269279                        System.out.println("uploadedInputStream == null");
     280                        logger.error("uploadedInputStream != null. datos recibidos del formulario son nulos.");
    270281                        throw new MurachiException("uploadedInputStream != null. datos recibidos del formulario son nulos.");
    271282                }
     
    273284                if (fileDetails == null) {
    274285                        System.out.println("fileDetails == null");
     286                        logger.error("fileDetails == null. datos recibidos del formulario son nulos.");
    275287                        throw new MurachiException("fileDetails == null. datos recibidos del formulario son nulos.");
    276288                }
     
    284296                        uploadedInputStream.close();
    285297                } catch (IOException e) {
     298                        logger.error("Ocurrio una excepcion: ", e);
    286299                        e.printStackTrace();
    287300                        throw new MurachiException(e.getMessage());
     
    293306                                       
    294307                jsonObject = verifyALocalFile(fileId);
     308                logger.info("/firmados: " + jsonObject.toString());
    295309               
    296310                return Response.status(200).entity(jsonObject.toString()).build();
     
    309323               
    310324                System.out.println("uploadedFileLocation: " + uploadedFileLocation);
     325                logger.debug("uploadedFileLocation: " + uploadedFileLocation);
    311326               
    312327                try {
     
    324339                }
    325340                catch(IOException e) {
     341                        logger.error("saveToDisk: ocurrio una excepcion", e);
    326342                        e.printStackTrace();
    327343                        throw new MurachiException(e.getMessage());
     
    341357        @Produces("application/json")
    342358        public Response verifyAFile(@PathParam("idFile") String idFile) throws MurachiException {
    343 /*             
     359
    344360                System.out.println("/{idFile}");
    345                
    346                 String result = "";
     361                logger.info("/{"+idFile+"}");
     362               
    347363                String file = SERVER_UPLOAD_LOCATION_FOLDER + idFile;
    348364               
     
    354370                        System.out.println("File : " + file + " does not exists.");
    355371                        jsonObject.put("fileExist", "false");
    356                        
    357                 }else{
    358                         System.out.println("File : " + file + " exists.");
    359                         jsonObject.put("fileExist", "true");
    360                        
    361                         String mime = getMimeType(file);
    362                         System.out.println("mimetype : " + mime);
    363                        
    364                         if (mime.equals("application/pdf")){
    365                                 System.out.println(" PDF ");
    366                                
    367                                 jsonObject = verifySignaturesInPdf(file);
    368                                
    369                         }else{
    370                                 System.out.println("BDOC");
    371                                 //jsonObject.put("formato", "BDOC");
    372                                 //jsonObject.put("resultado", "NO IMPLEMENTADO");
    373                                
    374                                 jsonObject = verifySignaturesInBdoc(file);
    375                         }                       
    376                 }
    377                 result = jsonObject.toString();
    378                 return Response.status(200).entity(result).build();
    379 */
    380                 System.out.println("/{idFile}");
    381                
    382                 String file = SERVER_UPLOAD_LOCATION_FOLDER + idFile;
    383                
    384                 File tmpFile = new File(file);
    385                
    386                 JSONObject jsonObject = new JSONObject();
    387                
    388                 if (!tmpFile.exists()) {
    389                         System.out.println("File : " + file + " does not exists.");
    390                         jsonObject.put("fileExist", "false");
     372                        logger.debug("fileExist: false");
    391373                       
    392374                }else{
     
    412394                                System.out.println("extension no reconocida");
    413395                                jsonObject.put("fileExist", "true");
    414                                 jsonObject.put("error", "extension not supported");                             
     396                                jsonObject.put("error", "extension not supported");
     397                                logger.debug("error: extension not supported");
    415398                        }
    416399                }
    417400                String result = jsonObject.toString();
     401                logger.info("/{"+idFile+"}: result");
    418402                return Response.status(200).entity(result).build();
    419                
    420                
     403                               
    421404        }
    422405       
     
    432415               
    433416                System.out.println("verifyALocalFile: " + idFile);
     417                logger.debug("verifyALocalFile: " + idFile);
    434418               
    435419                String file = SERVER_UPLOAD_LOCATION_FOLDER + idFile;
     
    442426                        System.out.println("File : " + file + " does not exists.");
    443427                        jsonObject.put("fileExist", "false");
     428                        logger.debug("fileExist: false");
    444429                       
    445430                }else{
     
    465450                                System.out.println("extension no reconocida");
    466451                                jsonObject.put("fileExist", "true");
    467                                 jsonObject.put("error", "extension not supported");                             
     452                                jsonObject.put("error", "extension not supported");     
     453                                logger.debug("error: extension not supported");
    468454                        }
    469455                }
     
    479465         */
    480466        private JSONObject verifySignaturesInPdf(String pdfFile) throws MurachiException {
     467               
     468                logger.debug("verifySignaturesInPdf: "+ pdfFile);
    481469               
    482470                JSONObject jsonSignatures = new JSONObject();
     
    513501                        }
    514502                       
    515                 } catch (IOException e) {               
     503                } catch (IOException e) {
     504                        logger.error("verifySignaturesInPdf ocurrio una excepcion", e);
    516505                        e.printStackTrace();
    517506                        throw new MurachiException(e.getMessage());
    518507                } catch (GeneralSecurityException e) {
     508                        logger.error("verifySignaturesInPdf ocurrio una excepcion", e);
    519509                        e.printStackTrace();
    520510                        throw new MurachiException(e.getMessage());
     
    533523         * @throws MurachiException
    534524         */
    535         public HashMap<String, String> verifySignature(AcroFields fields, String name) throws GeneralSecurityException, IOException, MurachiException {
    536                                
     525        public HashMap<String, String> verifySignature(AcroFields fields, String name)
     526                        throws GeneralSecurityException, IOException, MurachiException {
     527                       
     528                logger.debug("verifySignature()");
    537529                HashMap<String, String> integrityMap = new HashMap<String, String>();
    538530               
     
    651643        public JSONObject getJSONFromASignature(HashMap<String, String> hashMap) {
    652644               
     645                logger.debug("getJSONFromASignature()");
    653646                JSONObject jsonSignature = new JSONObject();
    654647               
     
    667660         */
    668661        private KeyStore setupKeyStore() throws MurachiException {
    669                
     662                logger.debug("setupKeyStore()");
    670663                KeyStore ks = null;
    671664                try {
     
    679672                       
    680673                       
    681                 } catch (KeyStoreException e) {                 
     674                } catch (KeyStoreException e) {
     675                        logger.error("setupKeyStore() ocurrio una excepcion", e);
    682676                        e.printStackTrace();
    683677                        throw new MurachiException(e.getMessage());
    684678                } catch (NoSuchAlgorithmException e) {
     679                        logger.error("setupKeyStore() ocurrio una excepcion", e);
    685680                        e.printStackTrace();
    686681                        throw new MurachiException(e.getMessage());
    687682                } catch (CertificateException e) {
     683                        logger.error("setupKeyStore() ocurrio una excepcion", e);
    688684                        e.printStackTrace();
    689685                        throw new MurachiException(e.getMessage());
    690686                } catch (IOException e) {
     687                        logger.error("setupKeyStore() ocurrio una excepcion", e);
    691688                        e.printStackTrace();
    692689                        throw new MurachiException(e.getMessage());
     
    700697         * @param signDate fecha en que se realizo la firma
    701698         * @return informacion del certificado firmante de una revision en forma de HashMap
    702          */
    703         public HashMap<String, String> getSignerCertificateInfo(X509Certificate cert, Date signDate) {
    704                
     699         * @throws MurachiException
     700         */
     701        public HashMap<String, String> getSignerCertificateInfo(X509Certificate cert, Date signDate) throws MurachiException {
     702                logger.debug("getSignerCertificateInfo()");
    705703                HashMap<String, String> signerCertificateMap = new HashMap<String, String>();
    706704               
     
    728726                                        .println("The certificate was expired at the time of signing.");
    729727                        signerCertificateMap.put("signerCertificateExpiredAtTimeOfSigning", "true");
     728                        logger.error("getSignerCertificateInfo() ocurrio una excepcion: The certificate was expired at the time of signing");
     729                        throw new MurachiException(e.getMessage());
    730730                } catch (CertificateNotYetValidException e) {
    731731                        System.out
    732732                                        .println("The certificate wasn't valid yet at the time of signing.");
    733733                        signerCertificateMap.put("signerCertificateNotValidYetAtTimeOfSigning", "true");
     734                        logger.error("getSignerCertificateInfo() ocurrio una excepcion: The certificate wasn't valid yet at the time of signing");
     735                        throw new MurachiException(e.getMessage());
    734736                }
    735737                try {
     
    740742                        System.out.println("The certificate has expired.");
    741743                        signerCertificateMap.put("signerCertificateHasExpired", "true");
     744                        logger.error("getSignerCertificateInfo() ocurrio una excepcion: The certificate has expired");
     745                        throw new MurachiException(e.getMessage());
    742746                } catch (CertificateNotYetValidException e) {
    743747                        System.out.println("The certificate isn't valid yet.");
    744748                        signerCertificateMap.put("signerCertificateNotValidYet", "true");
     749                        logger.error("getSignerCertificateInfo() ocurrio una excepcion: The certificate isn't valid yet");
     750                        throw new MurachiException(e.getMessage());
    745751                }
    746752                return signerCertificateMap;
     
    775781        public Response presignPdf(PresignParameters presignPar, @Context HttpServletRequest req) throws MurachiException {
    776782               
     783                logger.info("/pdfs");
     784               
    777785                PresignHash presignHash = new PresignHash();
    778786
     
    793801                String pdf = SERVER_UPLOAD_LOCATION_FOLDER + fileId;
    794802                System.out.println("archivo a firmar: " + pdf);
     803                logger.debug("archivo a firmar: " + pdf);
    795804               
    796805                String mime = getMimeType(pdf);
     
    802811                                                                       
    803812                        //result = presignHash.toString();
     813                        logger.info("El archivo que desea firmar no es un PDF.");
    804814                        return Response.status(400).entity(presignHash).build();
    805815                       
     
    816826                        if (chain[0] == null) {
    817827                                System.out.println("error chain[0] == null");
     828                                logger.error("presignPdf: error en carga de certificado de firmante");
     829                                throw new MurachiException("presignPdf: error en carga de certificado de firmante");
    818830                        }else {
    819831                               
    820832                                System.out.println("se cargo el certificado correctamente");
    821833                                System.out.println(chain[0].toString());
     834                                logger.debug("se cargo el certificado correctamente");
     835                                logger.debug(chain[0].toString());
    822836                        }                       
    823837                       
     
    892906               
    893907                System.out.println("sh length: "+ sh.length);
     908                logger.debug("sh length: "+ sh.length);
    894909                       
    895910                String hashToSign = byteArrayToHexString(sh);
     911                logger.debug("hashToSign: "+ hashToSign);
     912                logger.debug("length: " +hashToSign.length());
    896913                System.out.println("***************************************************************");
    897914                System.out.println("HASH EN HEXADECIMAL:");
     
    923940                       
    924941                } catch (CertificateException e1) {
     942                        logger.error("presignPdf ocurrio una excepcion ", e1);
    925943                        e1.printStackTrace();
    926944                        throw new MurachiException(e1.getMessage());
    927945                } catch (InvalidPdfException e) {
     946                        logger.error("presignPdf ocurrio una excepcion ", e);
    928947                        e.printStackTrace();
    929948                        presignHash.setError("No se pudo leer el archivo PDF en el servidor");
    930949                        throw new MurachiException(e.getMessage());
    931950                } catch (IOException e) {
     951                        logger.error("presignPdf ocurrio una excepcion ", e);
    932952                        e.printStackTrace();
    933953                        throw new MurachiException(e.getMessage());
    934954                } catch (DocumentException e) {
     955                        logger.error("presignPdf ocurrio una excepcion ", e);
    935956                        e.printStackTrace();
    936957                        throw new MurachiException(e.getMessage());
    937958                } catch (InvalidKeyException e) {
     959                        logger.error("presignPdf ocurrio una excepcion ", e);
    938960                        e.printStackTrace();
    939961                        throw new MurachiException(e.getMessage());
    940962                } catch (NoSuchProviderException e) {
     963                        logger.error("presignPdf ocurrio una excepcion ", e);
    941964                        e.printStackTrace();
    942965                        throw new MurachiException(e.getMessage());
    943966                } catch (NoSuchAlgorithmException e) {
     967                        logger.error("presignPdf ocurrio una excepcion ", e);
    944968                        e.printStackTrace();
    945969                        throw new MurachiException(e.getMessage());
    946970                } catch (GeneralSecurityException e) {
     971                        logger.error("presignPdf ocurrio una excepcion ", e);
    947972                        e.printStackTrace();
    948973                        throw new MurachiException(e.getMessage());
    949974                }
    950975               
     976                logger.debug("presignPdf: "+ presignHash.toString());
    951977                return Response.status(200).entity(presignHash).build();
    952978                //return presignHash;
     
    962988         */
    963989        private Boolean pdfAlreadySigned(PdfReader pdfReader) throws IOException {
     990               
     991                logger.debug("pdfAlreadySigned()");
    964992                Security.addProvider(new BouncyCastleProvider());
    965993               
     
    9791007         */
    9801008        private int numberOfSignatures(PdfReader pdfReader) {
     1009                logger.debug("numberOfSignatures()");
    9811010                Security.addProvider(new BouncyCastleProvider());
    9821011               
     
    10021031        public Response postsignPdf(PostsignParameters postsignPar, @Context HttpServletRequest req) throws IOException, MurachiException {
    10031032               
    1004                                
     1033                logger.info("/pdfs/resenas");
    10051034                // cadena con la firma
    10061035                String signature = postsignPar.getSignature();
     
    10111040                String fileId = (String) session.getAttribute("fileId");
    10121041                System.out.println("fileId: " + fileId);
     1042                logger.debug("fileId: " + fileId);
    10131043               
    10141044                PdfStamper stamper = (PdfStamper) session.getAttribute("stamper");
     
    10261056                if (sgn == null) {
    10271057                        System.out.println("sgn == null");
     1058                        logger.error("Error en completacion de firma: estructura PdfPKCS7 nula");
    10281059                        throw new MurachiException("Error en completacion de firma: estructura PdfPKCS7 nula");
    10291060                }
    10301061                if (hash == null) {
    10311062                        System.out.println("hash == null");
     1063                        logger.error("Error en completacion de firma: hash nulo");
    10321064                        throw new MurachiException("Error en completacion de firma: hash nulo");
    10331065                }
    10341066                if (cal == null) {
    10351067                        System.out.println("cal == null");
     1068                        logger.error("Error en completacion de firma: estructura de fecha nula");
    10361069                        throw new MurachiException("Error en completacion de firma: estructura de fecha nula");
    10371070                }
    10381071                if (sap == null) {
    10391072                        System.out.println("sap == null");
     1073                        logger.error("Error en completacion de firma: estructura de apariencia de firma pdf nula");
    10401074                        throw new MurachiException("Error en completacion de firma: estructura de apariencia de firma pdf nula");
    10411075                }
    10421076                if (os == null) {
    10431077                        System.out.println("os == null");
     1078                        logger.error("Error en completacion de firma: bytes de archivo nulos");
    10441079                        throw new MurachiException("Error en completacion de firma: bytes de archivo nulos");
    10451080                }
     
    10641099                }catch(DocumentException e) {
    10651100                        System.out.println("throw new IOException");
     1101                        logger.error("postsignPdf: ocurrio una excepcion", e);
    10661102                        throw new MurachiException(e.getMessage());
    10671103                       
    10681104                } catch (IOException e) {
    10691105                        System.out.println("IOException e");
     1106                        logger.error("postsignPdf: ocurrio una excepcion", e);
    10701107                        e.printStackTrace();
    10711108                        throw new MurachiException(e.getMessage());
     
    10831120                // SERVER_UPLOAD_LOCATION_FOLDER + fileId;             
    10841121                System.out.println("Archivo firmado correctamente");
     1122                logger.debug("Archivo firmado correctamente");
    10851123                       
    10861124                PostsignMessage message = new PostsignMessage();
     
    10911129                JSONObject jsonFinalResult = new JSONObject();
    10921130                jsonFinalResult.put("signedFileId",fileId + "-signed.pdf");
     1131               
     1132                logger.info(jsonFinalResult.toString());
    10931133                return Response.status(200).entity(jsonFinalResult.toString()).build();
    10941134        }
     
    11021142        @Path("/pdfs/{idFile}")
    11031143        public Response getPdfSigned(@PathParam("idFile") String idFile) {
     1144                logger.info("/pdfs/{idFile}");
    11041145                File file = null;
    11051146               
Note: See TracChangeset for help on using the changeset viewer.