Changeset 713ce71 in murachi
- Timestamp:
- Aug 25, 2015, 5:08:06 PM (9 years ago)
- Branches:
- master
- Children:
- ca297b6
- Parents:
- c4dd8d1
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
murachi/src/main/java/ve/gob/cenditel/murachi/MurachiRESTWS.java
rc4dd8d1 r713ce71 719 719 * 720 720 */ 721 /* 721 722 @GET 722 723 @Path("/{idFile}") … … 769 770 String result = jsonObject.toString(); 770 771 logger.info("/{"+idFile+"}: "+ result); 771 return Response.status(200).entity(result).build(); 772 772 return Response.status(200).entity(result).build(); 773 773 } 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 774 842 775 843 /** … … 781 849 * @throws MurachiException 782 850 */ 851 /* 783 852 public JSONObject verifyALocalFile(String idFile) throws MurachiException { 784 853 … … 819 888 //jsonObject.put("resultado", "NO IMPLEMENTADO"); 820 889 821 jsonObject = verifySignaturesInBdoc(file );890 jsonObject = verifySignaturesInBdoc(file, false); 822 891 }else{ 823 892 System.out.println("extension no reconocida"); … … 829 898 return jsonObject; 830 899 } 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 831 966 832 967 … … 1756 1891 * Retorna un JSON con informacion de las firmas del documento BDOC 1757 1892 * @param bdocFile archivo BDOC a verificar 1893 * @param serialized verdadero si el contenedor a verificar esta serializado 1758 1894 * @return JSON con informacion de las firmas del documento BDOC 1759 1895 */ 1760 private JSONObject verifySignaturesInBdoc(String bdocFile ) {1896 private JSONObject verifySignaturesInBdoc(String bdocFile, Boolean serialized) { 1761 1897 1762 1898 logger.debug("verifySignaturesInBdoc("+bdocFile+")"); … … 1771 1907 String idFile = path.getFileName().toString(); 1772 1908 1773 1774 Security.addProvider(new BouncyCastleProvider());1775 1909 Container container = null; 1776 1910 … … 1782 1916 try 1783 1917 { 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 1786 1930 } catch(DigiDoc4JException e) 1787 1931 { 1788 1932 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"); 1789 1939 return jsonSignatures; 1790 1940 } … … 1798 1948 jsonSignatures.put("fileExist", "true"); 1799 1949 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 1802 1958 jsonSignatures.put("mimeType", "application/vnd.etsi.asic-e+zip"); 1803 1959
Note: See TracChangeset
for help on using the changeset viewer.