- Timestamp:
- May 12, 2015, 9:55:04 AM (9 years ago)
- Branches:
- master
- Children:
- 90b2952
- Parents:
- 4ac0cf4
- 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 116 116 public class MurachiRESTWS { 117 117 118 static Logger logger = Logger.getLogger(MurachiRESTWS.class); 118 final static Logger logger = Logger.getLogger(MurachiRESTWS.class); 119 119 120 120 121 private static final String API_VERSION = "0.1.0"; … … 148 149 @Produces(MediaType.TEXT_HTML) 149 150 public String returnVersion() { 151 logger.info("/version: Murachi Version: " + API_VERSION); 150 152 return "<p>Murachi Version: " + API_VERSION + "</p>"; 151 153 } … … 168 170 @FormDataParam("upload") FormDataContentDisposition fileDetails) throws MurachiException { 169 171 170 //TODO manejar las excepciones correctamente 172 logger.info("/: uploadFile"); 173 171 174 if (uploadedInputStream == null) { 172 175 System.out.println("uploadedInputStream == null"); 176 logger.error("uploadedInputStream != null. datos recibidos del formulario son nulos."); 173 177 throw new MurachiException("uploadedInputStream != null. datos recibidos del formulario son nulos."); 174 178 } … … 176 180 if (fileDetails == null) { 177 181 System.out.println("fileDetails == null"); 182 logger.error("fileDetails == null. datos recibidos del formulario son nulos."); 178 183 throw new MurachiException("fileDetails == null. datos recibidos del formulario son nulos."); 179 184 } … … 187 192 uploadedInputStream.close(); 188 193 } catch (IOException e) { 194 logger.error("Ocurrio una excepcion: ", e); 189 195 e.printStackTrace(); 190 196 throw new MurachiException(e.getMessage()); … … 196 202 System.out.println("File saved to server location : " + SERVER_UPLOAD_LOCATION_FOLDER + fileId); 197 203 String result = jsonObject.toString(); 204 logger.info("/: " + result); 198 205 199 206 return Response.status(200).entity(result).build(); … … 209 216 @Produces(MediaType.APPLICATION_OCTET_STREAM) 210 217 public Response downloadFilebyPath(@PathParam("filename") String fileName) { 218 logger.info("/descargas/{"+fileName+"}"); 211 219 return downloadFileFromServer(fileName); 212 220 } … … 266 274 @FormDataParam("upload") FormDataContentDisposition fileDetails) throws MurachiException { 267 275 276 logger.info("/firmados: uploadFileAndVerify"); 277 268 278 if (uploadedInputStream == null) { 269 279 System.out.println("uploadedInputStream == null"); 280 logger.error("uploadedInputStream != null. datos recibidos del formulario son nulos."); 270 281 throw new MurachiException("uploadedInputStream != null. datos recibidos del formulario son nulos."); 271 282 } … … 273 284 if (fileDetails == null) { 274 285 System.out.println("fileDetails == null"); 286 logger.error("fileDetails == null. datos recibidos del formulario son nulos."); 275 287 throw new MurachiException("fileDetails == null. datos recibidos del formulario son nulos."); 276 288 } … … 284 296 uploadedInputStream.close(); 285 297 } catch (IOException e) { 298 logger.error("Ocurrio una excepcion: ", e); 286 299 e.printStackTrace(); 287 300 throw new MurachiException(e.getMessage()); … … 293 306 294 307 jsonObject = verifyALocalFile(fileId); 308 logger.info("/firmados: " + jsonObject.toString()); 295 309 296 310 return Response.status(200).entity(jsonObject.toString()).build(); … … 309 323 310 324 System.out.println("uploadedFileLocation: " + uploadedFileLocation); 325 logger.debug("uploadedFileLocation: " + uploadedFileLocation); 311 326 312 327 try { … … 324 339 } 325 340 catch(IOException e) { 341 logger.error("saveToDisk: ocurrio una excepcion", e); 326 342 e.printStackTrace(); 327 343 throw new MurachiException(e.getMessage()); … … 341 357 @Produces("application/json") 342 358 public Response verifyAFile(@PathParam("idFile") String idFile) throws MurachiException { 343 /* 359 344 360 System.out.println("/{idFile}"); 345 346 String result = "";361 logger.info("/{"+idFile+"}"); 362 347 363 String file = SERVER_UPLOAD_LOCATION_FOLDER + idFile; 348 364 … … 354 370 System.out.println("File : " + file + " does not exists."); 355 371 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"); 391 373 392 374 }else{ … … 412 394 System.out.println("extension no reconocida"); 413 395 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"); 415 398 } 416 399 } 417 400 String result = jsonObject.toString(); 401 logger.info("/{"+idFile+"}: result"); 418 402 return Response.status(200).entity(result).build(); 419 420 403 421 404 } 422 405 … … 432 415 433 416 System.out.println("verifyALocalFile: " + idFile); 417 logger.debug("verifyALocalFile: " + idFile); 434 418 435 419 String file = SERVER_UPLOAD_LOCATION_FOLDER + idFile; … … 442 426 System.out.println("File : " + file + " does not exists."); 443 427 jsonObject.put("fileExist", "false"); 428 logger.debug("fileExist: false"); 444 429 445 430 }else{ … … 465 450 System.out.println("extension no reconocida"); 466 451 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"); 468 454 } 469 455 } … … 479 465 */ 480 466 private JSONObject verifySignaturesInPdf(String pdfFile) throws MurachiException { 467 468 logger.debug("verifySignaturesInPdf: "+ pdfFile); 481 469 482 470 JSONObject jsonSignatures = new JSONObject(); … … 513 501 } 514 502 515 } catch (IOException e) { 503 } catch (IOException e) { 504 logger.error("verifySignaturesInPdf ocurrio una excepcion", e); 516 505 e.printStackTrace(); 517 506 throw new MurachiException(e.getMessage()); 518 507 } catch (GeneralSecurityException e) { 508 logger.error("verifySignaturesInPdf ocurrio una excepcion", e); 519 509 e.printStackTrace(); 520 510 throw new MurachiException(e.getMessage()); … … 533 523 * @throws MurachiException 534 524 */ 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()"); 537 529 HashMap<String, String> integrityMap = new HashMap<String, String>(); 538 530 … … 651 643 public JSONObject getJSONFromASignature(HashMap<String, String> hashMap) { 652 644 645 logger.debug("getJSONFromASignature()"); 653 646 JSONObject jsonSignature = new JSONObject(); 654 647 … … 667 660 */ 668 661 private KeyStore setupKeyStore() throws MurachiException { 669 662 logger.debug("setupKeyStore()"); 670 663 KeyStore ks = null; 671 664 try { … … 679 672 680 673 681 } catch (KeyStoreException e) { 674 } catch (KeyStoreException e) { 675 logger.error("setupKeyStore() ocurrio una excepcion", e); 682 676 e.printStackTrace(); 683 677 throw new MurachiException(e.getMessage()); 684 678 } catch (NoSuchAlgorithmException e) { 679 logger.error("setupKeyStore() ocurrio una excepcion", e); 685 680 e.printStackTrace(); 686 681 throw new MurachiException(e.getMessage()); 687 682 } catch (CertificateException e) { 683 logger.error("setupKeyStore() ocurrio una excepcion", e); 688 684 e.printStackTrace(); 689 685 throw new MurachiException(e.getMessage()); 690 686 } catch (IOException e) { 687 logger.error("setupKeyStore() ocurrio una excepcion", e); 691 688 e.printStackTrace(); 692 689 throw new MurachiException(e.getMessage()); … … 700 697 * @param signDate fecha en que se realizo la firma 701 698 * @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()"); 705 703 HashMap<String, String> signerCertificateMap = new HashMap<String, String>(); 706 704 … … 728 726 .println("The certificate was expired at the time of signing."); 729 727 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()); 730 730 } catch (CertificateNotYetValidException e) { 731 731 System.out 732 732 .println("The certificate wasn't valid yet at the time of signing."); 733 733 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()); 734 736 } 735 737 try { … … 740 742 System.out.println("The certificate has expired."); 741 743 signerCertificateMap.put("signerCertificateHasExpired", "true"); 744 logger.error("getSignerCertificateInfo() ocurrio una excepcion: The certificate has expired"); 745 throw new MurachiException(e.getMessage()); 742 746 } catch (CertificateNotYetValidException e) { 743 747 System.out.println("The certificate isn't valid yet."); 744 748 signerCertificateMap.put("signerCertificateNotValidYet", "true"); 749 logger.error("getSignerCertificateInfo() ocurrio una excepcion: The certificate isn't valid yet"); 750 throw new MurachiException(e.getMessage()); 745 751 } 746 752 return signerCertificateMap; … … 775 781 public Response presignPdf(PresignParameters presignPar, @Context HttpServletRequest req) throws MurachiException { 776 782 783 logger.info("/pdfs"); 784 777 785 PresignHash presignHash = new PresignHash(); 778 786 … … 793 801 String pdf = SERVER_UPLOAD_LOCATION_FOLDER + fileId; 794 802 System.out.println("archivo a firmar: " + pdf); 803 logger.debug("archivo a firmar: " + pdf); 795 804 796 805 String mime = getMimeType(pdf); … … 802 811 803 812 //result = presignHash.toString(); 813 logger.info("El archivo que desea firmar no es un PDF."); 804 814 return Response.status(400).entity(presignHash).build(); 805 815 … … 816 826 if (chain[0] == null) { 817 827 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"); 818 830 }else { 819 831 820 832 System.out.println("se cargo el certificado correctamente"); 821 833 System.out.println(chain[0].toString()); 834 logger.debug("se cargo el certificado correctamente"); 835 logger.debug(chain[0].toString()); 822 836 } 823 837 … … 892 906 893 907 System.out.println("sh length: "+ sh.length); 908 logger.debug("sh length: "+ sh.length); 894 909 895 910 String hashToSign = byteArrayToHexString(sh); 911 logger.debug("hashToSign: "+ hashToSign); 912 logger.debug("length: " +hashToSign.length()); 896 913 System.out.println("***************************************************************"); 897 914 System.out.println("HASH EN HEXADECIMAL:"); … … 923 940 924 941 } catch (CertificateException e1) { 942 logger.error("presignPdf ocurrio una excepcion ", e1); 925 943 e1.printStackTrace(); 926 944 throw new MurachiException(e1.getMessage()); 927 945 } catch (InvalidPdfException e) { 946 logger.error("presignPdf ocurrio una excepcion ", e); 928 947 e.printStackTrace(); 929 948 presignHash.setError("No se pudo leer el archivo PDF en el servidor"); 930 949 throw new MurachiException(e.getMessage()); 931 950 } catch (IOException e) { 951 logger.error("presignPdf ocurrio una excepcion ", e); 932 952 e.printStackTrace(); 933 953 throw new MurachiException(e.getMessage()); 934 954 } catch (DocumentException e) { 955 logger.error("presignPdf ocurrio una excepcion ", e); 935 956 e.printStackTrace(); 936 957 throw new MurachiException(e.getMessage()); 937 958 } catch (InvalidKeyException e) { 959 logger.error("presignPdf ocurrio una excepcion ", e); 938 960 e.printStackTrace(); 939 961 throw new MurachiException(e.getMessage()); 940 962 } catch (NoSuchProviderException e) { 963 logger.error("presignPdf ocurrio una excepcion ", e); 941 964 e.printStackTrace(); 942 965 throw new MurachiException(e.getMessage()); 943 966 } catch (NoSuchAlgorithmException e) { 967 logger.error("presignPdf ocurrio una excepcion ", e); 944 968 e.printStackTrace(); 945 969 throw new MurachiException(e.getMessage()); 946 970 } catch (GeneralSecurityException e) { 971 logger.error("presignPdf ocurrio una excepcion ", e); 947 972 e.printStackTrace(); 948 973 throw new MurachiException(e.getMessage()); 949 974 } 950 975 976 logger.debug("presignPdf: "+ presignHash.toString()); 951 977 return Response.status(200).entity(presignHash).build(); 952 978 //return presignHash; … … 962 988 */ 963 989 private Boolean pdfAlreadySigned(PdfReader pdfReader) throws IOException { 990 991 logger.debug("pdfAlreadySigned()"); 964 992 Security.addProvider(new BouncyCastleProvider()); 965 993 … … 979 1007 */ 980 1008 private int numberOfSignatures(PdfReader pdfReader) { 1009 logger.debug("numberOfSignatures()"); 981 1010 Security.addProvider(new BouncyCastleProvider()); 982 1011 … … 1002 1031 public Response postsignPdf(PostsignParameters postsignPar, @Context HttpServletRequest req) throws IOException, MurachiException { 1003 1032 1004 1033 logger.info("/pdfs/resenas"); 1005 1034 // cadena con la firma 1006 1035 String signature = postsignPar.getSignature(); … … 1011 1040 String fileId = (String) session.getAttribute("fileId"); 1012 1041 System.out.println("fileId: " + fileId); 1042 logger.debug("fileId: " + fileId); 1013 1043 1014 1044 PdfStamper stamper = (PdfStamper) session.getAttribute("stamper"); … … 1026 1056 if (sgn == null) { 1027 1057 System.out.println("sgn == null"); 1058 logger.error("Error en completacion de firma: estructura PdfPKCS7 nula"); 1028 1059 throw new MurachiException("Error en completacion de firma: estructura PdfPKCS7 nula"); 1029 1060 } 1030 1061 if (hash == null) { 1031 1062 System.out.println("hash == null"); 1063 logger.error("Error en completacion de firma: hash nulo"); 1032 1064 throw new MurachiException("Error en completacion de firma: hash nulo"); 1033 1065 } 1034 1066 if (cal == null) { 1035 1067 System.out.println("cal == null"); 1068 logger.error("Error en completacion de firma: estructura de fecha nula"); 1036 1069 throw new MurachiException("Error en completacion de firma: estructura de fecha nula"); 1037 1070 } 1038 1071 if (sap == null) { 1039 1072 System.out.println("sap == null"); 1073 logger.error("Error en completacion de firma: estructura de apariencia de firma pdf nula"); 1040 1074 throw new MurachiException("Error en completacion de firma: estructura de apariencia de firma pdf nula"); 1041 1075 } 1042 1076 if (os == null) { 1043 1077 System.out.println("os == null"); 1078 logger.error("Error en completacion de firma: bytes de archivo nulos"); 1044 1079 throw new MurachiException("Error en completacion de firma: bytes de archivo nulos"); 1045 1080 } … … 1064 1099 }catch(DocumentException e) { 1065 1100 System.out.println("throw new IOException"); 1101 logger.error("postsignPdf: ocurrio una excepcion", e); 1066 1102 throw new MurachiException(e.getMessage()); 1067 1103 1068 1104 } catch (IOException e) { 1069 1105 System.out.println("IOException e"); 1106 logger.error("postsignPdf: ocurrio una excepcion", e); 1070 1107 e.printStackTrace(); 1071 1108 throw new MurachiException(e.getMessage()); … … 1083 1120 // SERVER_UPLOAD_LOCATION_FOLDER + fileId; 1084 1121 System.out.println("Archivo firmado correctamente"); 1122 logger.debug("Archivo firmado correctamente"); 1085 1123 1086 1124 PostsignMessage message = new PostsignMessage(); … … 1091 1129 JSONObject jsonFinalResult = new JSONObject(); 1092 1130 jsonFinalResult.put("signedFileId",fileId + "-signed.pdf"); 1131 1132 logger.info(jsonFinalResult.toString()); 1093 1133 return Response.status(200).entity(jsonFinalResult.toString()).build(); 1094 1134 } … … 1102 1142 @Path("/pdfs/{idFile}") 1103 1143 public Response getPdfSigned(@PathParam("idFile") String idFile) { 1144 logger.info("/pdfs/{idFile}"); 1104 1145 File file = null; 1105 1146
Note: See TracChangeset
for help on using the changeset viewer.