Changeset 962f860 in murachi


Ignore:
Timestamp:
May 8, 2015, 12:27:39 PM (9 years ago)
Author:
antonioaraujob <antonioaraujob@…>
Branches:
master
Children:
4ac0cf4
Parents:
7c45d87
Message:

Incorporación de gestión de excepciones

File:
1 edited

Legend:

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

    r7c45d87 r962f860  
    528528         * @throws GeneralSecurityException falla en
    529529         * @throws IOException cuando ca
    530          */
    531         public HashMap<String, String> verifySignature(AcroFields fields, String name) throws GeneralSecurityException, IOException {
     530         * @throws MurachiException
     531         */
     532        public HashMap<String, String> verifySignature(AcroFields fields, String name) throws GeneralSecurityException, IOException, MurachiException {
    532533                               
    533534                HashMap<String, String> integrityMap = new HashMap<String, String>();
     
    660661         * de firmas
    661662         * @return KeyStore con certificados confiables
    662          */
    663         private KeyStore setupKeyStore() {
     663         * @throws MurachiException
     664         */
     665        private KeyStore setupKeyStore() throws MurachiException {
    664666               
    665667                KeyStore ks = null;
     
    674676                       
    675677                       
    676                 } catch (KeyStoreException e) {
    677                         // TODO Auto-generated catch block
    678                         e.printStackTrace();
     678                } catch (KeyStoreException e) {                 
     679                        e.printStackTrace();
     680                        throw new MurachiException(e.getMessage());
    679681                } catch (NoSuchAlgorithmException e) {
    680                         // TODO Auto-generated catch block
    681                         e.printStackTrace();
     682                        e.printStackTrace();
     683                        throw new MurachiException(e.getMessage());
    682684                } catch (CertificateException e) {
    683                         // TODO Auto-generated catch block
    684                         e.printStackTrace();
     685                        e.printStackTrace();
     686                        throw new MurachiException(e.getMessage());
    685687                } catch (IOException e) {
    686                         // TODO Auto-generated catch block
    687                         e.printStackTrace();
     688                        e.printStackTrace();
     689                        throw new MurachiException(e.getMessage());
    688690                }               
    689691                return ks;
     
    760762         * @param req objeto request para crear una sesion y mantener elementos del
    761763         * pdf en la misma.
     764         * @throws MurachiException
    762765         *
    763766         */
     
    767770        @Produces(MediaType.APPLICATION_JSON)
    768771        //public PresignHash presignPdf(PresignParameters presignPar, @Context HttpServletRequest req) {
    769         public Response presignPdf(PresignParameters presignPar, @Context HttpServletRequest req) {
    770                
    771                 String result = null;
     772        public Response presignPdf(PresignParameters presignPar, @Context HttpServletRequest req) throws MurachiException {
    772773               
    773774                PresignHash presignHash = new PresignHash();
     
    919920                       
    920921                } catch (CertificateException e1) {
    921                         // TODO Auto-generated catch block
    922922                        e1.printStackTrace();
     923                        throw new MurachiException(e1.getMessage());
    923924                } catch (InvalidPdfException e) {
    924                         // TODO Auto-generated catch block
    925925                        e.printStackTrace();
    926926                        presignHash.setError("No se pudo leer el archivo PDF en el servidor");
     927                        throw new MurachiException(e.getMessage());
    927928                } catch (IOException e) {
    928                         // TODO Auto-generated catch block
    929                         e.printStackTrace();
    930                                                
    931                        
     929                        e.printStackTrace();
     930                        throw new MurachiException(e.getMessage());
    932931                } catch (DocumentException e) {
    933                         // TODO Auto-generated catch block
    934                         e.printStackTrace();
     932                        e.printStackTrace();
     933                        throw new MurachiException(e.getMessage());
    935934                } catch (InvalidKeyException e) {
    936                         // TODO Auto-generated catch block
    937                         e.printStackTrace();
     935                        e.printStackTrace();
     936                        throw new MurachiException(e.getMessage());
    938937                } catch (NoSuchProviderException e) {
    939                         // TODO Auto-generated catch block
    940                         e.printStackTrace();
     938                        e.printStackTrace();
     939                        throw new MurachiException(e.getMessage());
    941940                } catch (NoSuchAlgorithmException e) {
    942                         // TODO Auto-generated catch block
    943                         e.printStackTrace();
     941                        e.printStackTrace();
     942                        throw new MurachiException(e.getMessage());
    944943                } catch (GeneralSecurityException e) {
    945                         // TODO Auto-generated catch block
    946                         e.printStackTrace();
     944                        e.printStackTrace();
     945                        throw new MurachiException(e.getMessage());
    947946                }
    948947               
     
    992991         * pdf en la misma.
    993992         * @throws IOException
     993         * @throws MurachiException
    994994         */
    995995        @POST
     
    997997        @Consumes(MediaType.APPLICATION_JSON)
    998998        @Produces(MediaType.APPLICATION_JSON)   
    999         public Response postsignPdf(PostsignParameters postsignPar, @Context HttpServletRequest req) throws IOException {
    1000                
    1001                
    1002                 // cadena resultado de la funcion
    1003                 String result = "";
     999        public Response postsignPdf(PostsignParameters postsignPar, @Context HttpServletRequest req) throws IOException, MurachiException {
     1000               
    10041001                               
    10051002                // cadena con la firma
     
    10261023                if (sgn == null) {
    10271024                        System.out.println("sgn == null");
     1025                        throw new MurachiException("Error en completacion de firma: estructura PdfPKCS7 nula");
    10281026                }
    10291027                if (hash == null) {
    10301028                        System.out.println("hash == null");
     1029                        throw new MurachiException("Error en completacion de firma: hash nulo");
    10311030                }
    10321031                if (cal == null) {
    10331032                        System.out.println("cal == null");
     1033                        throw new MurachiException("Error en completacion de firma: estructura de fecha nula");
    10341034                }
    10351035                if (sap == null) {
    10361036                        System.out.println("sap == null");
     1037                        throw new MurachiException("Error en completacion de firma: estructura de apariencia de firma pdf nula");
    10371038                }
    10381039                if (os == null) {
    10391040                        System.out.println("os == null");
    1040                 }
    1041                
    1042                
    1043                
     1041                        throw new MurachiException("Error en completacion de firma: bytes de archivo nulos");
     1042                }
     1043
     1044                System.out.println("antes de  hexStringToByteArray(signature)");
    10441045                // convertir signature en bytes         
    10451046                byte[] signatureInBytes = hexStringToByteArray(signature);
     
    10521053                PdfDictionary dic2 = new PdfDictionary();
    10531054                dic2.put(PdfName.CONTENTS, new PdfString(paddedSig).setHexWriting(true));
     1055               
    10541056                try {
    1055                         sap.close(dic2);
    1056                        
     1057                        sap.close(dic2);                       
    10571058                        stamper.close();
    10581059                        System.out.println("stamper.close");
    10591060                       
    10601061                }catch(DocumentException e) {
    1061                        
    10621062                        System.out.println("throw new IOException");
    1063                         throw new IOException(e);
     1063                        throw new MurachiException(e.getMessage());
    10641064                       
    10651065                } catch (IOException e) {
    1066                         // TODO Auto-generated catch block
    10671066                        System.out.println("IOException e");
    10681067                        e.printStackTrace();
     1068                        throw new MurachiException(e.getMessage());
    10691069                       
    10701070                }
     
    10761076                os.writeTo(signedFile);
    10771077                os.flush();
    1078                
    1079                
    1080                
     1078                               
    10811079                // en este punto el archivo pdf debe estar disponible en la ruta
    1082                 // SERVER_UPLOAD_LOCATION_FOLDER + fileId;
    1083                
    1084                 // llamar a una funcion que permita descargar el archivo
    1085                
    1086                 result = "Archivo firmado correctamente";
     1080                // SERVER_UPLOAD_LOCATION_FOLDER + fileId;             
    10871081                System.out.println("Archivo firmado correctamente");
    1088                
    10891082                       
    10901083                PostsignMessage message = new PostsignMessage();
    10911084                //message.setMessage(SERVER_UPLOAD_LOCATION_FOLDER + fileId + "-signed.pdf");
    1092                 message.setMessage(fileId + "-signed.pdf");
    1093                 return Response.status(200).entity(message).build();
     1085                message.setMessage("{\"signedFile\":"+fileId + "-signed.pdf}");
     1086                //return Response.status(200).entity(message).build();
     1087               
     1088                JSONObject jsonFinalResult = new JSONObject();
     1089                jsonFinalResult.put("signedFileId",fileId + "-signed.pdf");
     1090                return Response.status(200).entity(jsonFinalResult.toString()).build();
    10941091        }
    10951092       
     
    11951192                                }
    11961193                                                               
    1197                                 jsonSignatures.put("signatures", jsonSignaturesArray);
    1198                                                                
     1194                                jsonSignatures.put("signatures", jsonSignaturesArray);                                                         
    11991195                                System.out.println(jsonSignatures.toString());                         
    1200                         }
    1201                                                
    1202                        
     1196                        }                       
    12031197                }
    12041198                //verifyBdocContainer(container);               
Note: See TracChangeset for help on using the changeset viewer.