Changeset 713ce71 in murachi


Ignore:
Timestamp:
Aug 25, 2015, 5:08:06 PM (9 years ago)
Author:
antonioaraujob <aaraujo@…>
Branches:
master
Children:
ca297b6
Parents:
c4dd8d1
Message:

Revisión de los recursos de verificar un archivo y cargar un archivo y verificar.

File:
1 edited

Legend:

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

    rc4dd8d1 r713ce71  
    719719         *
    720720         */
     721        /*
    721722        @GET
    722723        @Path("/{idFile}")
     
    769770                String result = jsonObject.toString();
    770771                logger.info("/{"+idFile+"}: "+ result);
    771                 return Response.status(200).entity(result).build();
    772                                
     772                return Response.status(200).entity(result).build();     
    773773        }
     774        */     
     775        @GET
     776        @Path("/{idFile}")
     777        @Produces("application/json")
     778        public Response verifyAFile(@PathParam("idFile") String idFile) throws MurachiException {
     779               
     780                JSONObject jsonObject = new JSONObject();
     781                String result = "";
     782                String path = "";
     783               
     784                // verificar si existe como contenedor BDOC serializado
     785                if (checkFileExists(SERVER_UPLOAD_LOCATION_FOLDER + idFile + "-serialized.bin")) {
     786                   
     787                        path = SERVER_UPLOAD_LOCATION_FOLDER + idFile + "-serialized.bin";
     788                       
     789                        logger.debug("  verificar contenedor BDOC serializado: " + SERVER_UPLOAD_LOCATION_FOLDER + idFile + "-serialized.bin");
     790                    jsonObject = verifySignaturesInBdoc(path, true);
     791                        result = jsonObject.toString();
     792                        logger.info("/{"+idFile+"}: "+ result);
     793                       
     794                    return Response.status(200).entity(result).build();
     795                }
     796                // verificar si existe el archivo
     797                else if (checkFileExists(SERVER_UPLOAD_LOCATION_FOLDER + idFile)) {
     798                        // archivo si existe y es BDOC no serializado
     799                        path = SERVER_UPLOAD_LOCATION_FOLDER + idFile;
     800                                       
     801                        String mime = getMimeType(path);
     802                        System.out.println("mimetype : " + mime);
     803                       
     804                       
     805                        if (mime.equals("application/zip")) {
     806                                jsonObject = verifySignaturesInBdoc(path, false);
     807                                result = jsonObject.toString();
     808                                logger.info("/{"+idFile+"}: "+ result);
     809                               
     810                                return Response.status(200).entity(result).build();
     811                        }
     812                        // archivo si existe y es un pdf
     813                        else if (mime.equals("application/pdf")) {
     814                                path = SERVER_UPLOAD_LOCATION_FOLDER + idFile;
     815                               
     816                                jsonObject = verifySignaturesInPdf(path);
     817                                result = jsonObject.toString();
     818                                logger.info("/{"+idFile+"}: "+ result);
     819                               
     820                                return Response.status(200).entity(result).build();                             
     821                        }
     822                        // el archivo existe pero es una extension no reconocida
     823                        else
     824                        {
     825                                jsonObject.put("fileExist", "true");
     826                                jsonObject.put("error", "extension not supported");
     827                                return Response.status(200).entity(jsonObject.toString()).build();
     828                        }                       
     829                }       
     830                // definitivamente el archivo no existe en el sistema de archivos
     831                else
     832                {
     833                        jsonObject.put("fileExist", "false");
     834                        logger.error("fileExist: false");
     835                       
     836                        return Response.status(404).entity(jsonObject.toString()).build();
     837                         
     838                }
     839                               
     840        }
     841       
    774842       
    775843        /**
     
    781849         * @throws MurachiException
    782850         */
     851        /*
    783852        public JSONObject verifyALocalFile(String idFile) throws MurachiException {
    784853               
     
    819888                                //jsonObject.put("resultado", "NO IMPLEMENTADO");
    820889                               
    821                                 jsonObject = verifySignaturesInBdoc(file);
     890                                jsonObject = verifySignaturesInBdoc(file, false);
    822891                        }else{
    823892                                System.out.println("extension no reconocida");
     
    829898                return jsonObject;
    830899        }
     900        */
     901        public JSONObject verifyALocalFile(String idFile) throws MurachiException {
     902               
     903                JSONObject jsonObject = new JSONObject();
     904                String result = "";
     905                String path = "";
     906               
     907                // verificar si existe como contenedor BDOC serializado
     908                if (checkFileExists(SERVER_UPLOAD_LOCATION_FOLDER + idFile + "-serialized.bin")) {
     909                   
     910                        path = SERVER_UPLOAD_LOCATION_FOLDER + idFile + "-serialized.bin";
     911                       
     912                        logger.debug("  verificar contenedor BDOC serializado: " + SERVER_UPLOAD_LOCATION_FOLDER + idFile + "-serialized.bin");
     913                    jsonObject = verifySignaturesInBdoc(path, true);
     914                        result = jsonObject.toString();
     915                        logger.info("/{"+idFile+"}: "+ result);
     916                       
     917                    return jsonObject;
     918                }
     919                // verificar si existe el archivo
     920                else if (checkFileExists(SERVER_UPLOAD_LOCATION_FOLDER + idFile)) {
     921                        // archivo si existe y es BDOC no serializado
     922                        path = SERVER_UPLOAD_LOCATION_FOLDER + idFile;
     923                                       
     924                        String mime = getMimeType(path);
     925                        System.out.println("mimetype : " + mime);
     926                       
     927                       
     928                        if (mime.equals("application/zip")) {
     929                                jsonObject = verifySignaturesInBdoc(path, false);
     930                                result = jsonObject.toString();
     931                                logger.info("/{"+idFile+"}: "+ result);
     932                               
     933                                return jsonObject;
     934                        }
     935                        // archivo si existe y es un pdf
     936                        else if (mime.equals("application/pdf")) {
     937                                path = SERVER_UPLOAD_LOCATION_FOLDER + idFile;
     938                               
     939                                jsonObject = verifySignaturesInPdf(path);
     940                                result = jsonObject.toString();
     941                                logger.info("/{"+idFile+"}: "+ result);
     942                               
     943                                return jsonObject;                             
     944                        }
     945                        // el archivo existe pero es una extension no reconocida
     946                        else
     947                        {
     948                                jsonObject.put("fileExist", "true");
     949                                jsonObject.put("error", "extension not supported");
     950                                return jsonObject;
     951                        }                       
     952                }       
     953                // definitivamente el archivo no existe en el sistema de archivos
     954                else
     955                {
     956                        jsonObject.put("fileExist", "false");
     957                        logger.error("fileExist: false");
     958                       
     959                        return jsonObject;
     960                         
     961                }
     962        }
     963       
     964       
     965       
    831966       
    832967       
     
    17561891         * Retorna un JSON con informacion de las firmas del documento BDOC
    17571892         * @param bdocFile archivo BDOC a verificar
     1893         * @param serialized verdadero si el contenedor a verificar esta serializado
    17581894         * @return JSON con informacion de las firmas del documento BDOC
    17591895         */
    1760         private JSONObject verifySignaturesInBdoc(String bdocFile) {
     1896        private JSONObject verifySignaturesInBdoc(String bdocFile, Boolean serialized) {
    17611897       
    17621898                logger.debug("verifySignaturesInBdoc("+bdocFile+")");
     
    17711907                String idFile = path.getFileName().toString();
    17721908               
    1773                
    1774                 Security.addProvider(new BouncyCastleProvider());
    17751909                Container container = null;
    17761910               
     
    17821916                try
    17831917                {
    1784                         container = Container.open(bdocFile, configuration);
    1785                         logger.debug("Container.open("+bdocFile+", DIGIDOC4J_CONFIGURATION)");
     1918                        Security.addProvider(new BouncyCastleProvider());
     1919                        if (!serialized)
     1920                        {
     1921                                container = Container.open(bdocFile, configuration);
     1922                                logger.debug("Container.open("+bdocFile+", DIGIDOC4J_CONFIGURATION)"); 
     1923                        }
     1924                        else
     1925                        {
     1926                                container = deserialize(bdocFile);
     1927                                logger.debug("container deserialized: " + bdocFile);
     1928                        }
     1929                                               
    17861930                } catch(DigiDoc4JException e)
    17871931                {
    17881932                        jsonSignatures.put("error", "File is not a valid BDOC container");
     1933                        return jsonSignatures;
     1934                } catch (ClassNotFoundException e) {
     1935                        jsonSignatures.put("error", "error al deserializar el contendor");
     1936                        return jsonSignatures;
     1937                } catch (IOException e) {
     1938                        jsonSignatures.put("error", "error al deserializar el contendor");
    17891939                        return jsonSignatures;
    17901940                }
     
    17981948                        jsonSignatures.put("fileExist", "true");
    17991949                        System.out.println("fileExist: true");
    1800                        
    1801                         jsonSignatures.put("fileId", idFile);
     1950                                               
     1951                        if (serialized){
     1952                                jsonSignatures.put("fileId", idFile.split("-serialized.bin")[0]);
     1953                        }
     1954                        else {
     1955                                jsonSignatures.put("fileId", idFile);
     1956                        }
     1957                       
    18021958                        jsonSignatures.put("mimeType", "application/vnd.etsi.asic-e+zip");
    18031959                       
Note: See TracChangeset for help on using the changeset viewer.