Changeset 2c5fcda in murachi


Ignore:
Timestamp:
Jun 15, 2015, 6:11:27 PM (9 years ago)
Author:
antonioaraujob <aaraujo@…>
Branches:
master
Children:
6bb4976
Parents:
11d82e1
Message:

Agregada documentación de recursos usando la herramienta apidoc

File:
1 edited

Legend:

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

    r11d82e1 r2c5fcda  
    178178         * un json con el id del archivo en el servidor para futuras consultas
    179179         * de estado de firmas
     180         *
    180181         * @param uploadedInputStream stream para obtener el archivo
    181182         * @param fileDetails datos del archivo
    182183         * @return
    183184         * @throws MurachiException
     185         *
     186         * @api {post} /Murachi/0.1/archivos/ Carga un archivo
     187         * @apiName Archivos
     188         * @apiGroup Archivos
     189         * @apiVersion 0.1.0
     190         * @apiDescription Carga un archivo a través de un formulario y retorna un json con el id del archivo en el servidor
     191         *
     192         *
     193         * @apiExample Example usage:
     194     * 
     195     *  var formData = new FormData();
     196     *  formData.append("upload", $("#file-sign")[0].files[0]);           
     197     *  $.ajax({
     198     *           url: "https://murachi.cenditel.gob.ve/Murachi/0.1/archivos",
     199     *           type: "post",
     200     *           dataType: "json",
     201     *           data: formData,
     202     *           cache: false,
     203     *           contentType: false,
     204         *           processData: false,
     205     *           success: function(response) {
     206     *                  //identificador del archivo en el servidor
     207         *                  var fileId = response.fileId.toString();
     208         *                  alert("fileId: "+ fileId);
     209         *           },
     210         *           error: function(response){
     211         *                  alert("error: " + response.error.toString());
     212         *           }
     213     *  });
     214         *
     215         * @apiErrorExample {json} Error-Response:
     216         *     HTTP/1.1 400 Bad Request
     217         *     {
     218         *       "error": "datos recibidos del formulario son nulos"
     219         *     }
     220         *     
     221         *     HTTP/1.1 500
     222         *     {
     223         *       "error": "IOException"
     224         *     }
     225         *
     226         * @apiSuccess {String} fileId Identificador único del archivo cargado en el servidor.
     227         *
    184228         */     
    185229        @POST
     
    196240                        System.out.println("uploadedInputStream == null");
    197241                        logger.error("uploadedInputStream != null. datos recibidos del formulario son nulos.");
    198                         throw new MurachiException("uploadedInputStream != null. datos recibidos del formulario son nulos.");
     242                        //throw new MurachiException("uploadedInputStream != null. datos recibidos del formulario son nulos.");
     243                       
     244                        return Response.status(400).entity("{\"error\": \"datos recibidos del formulario son nulos\"}").type(MediaType.APPLICATION_JSON).build();
    199245                }
    200246               
     
    202248                        System.out.println("fileDetails == null");
    203249                        logger.error("fileDetails == null. datos recibidos del formulario son nulos.");
    204                         throw new MurachiException("fileDetails == null. datos recibidos del formulario son nulos.");
     250                        //throw new MurachiException("fileDetails == null. datos recibidos del formulario son nulos.");
     251                        return Response.status(400).entity("{\"error\": \"datos recibidos del formulario son nulos\"}").type(MediaType.APPLICATION_JSON).build();
    205252                }
    206253                               
     
    215262                        logger.error("Ocurrio una excepcion: ", e);
    216263                        e.printStackTrace();
    217                         throw new MurachiException(e.getMessage());
     264                        //throw new MurachiException(e.getMessage());
     265                        return Response.status(500).entity("{\"error\":" + e.getMessage()).build();
     266                       
    218267                }
    219268               
     
    245294         *
    246295         * @apiErrorExample {json} Error-Response:
    247          *     HTTP/1.1 401 Not Authenticated
     296         *     HTTP/1.1 404 Not Found
    248297         *     {
    249298         *       "fileExist": false
     
    299348         * en caso de que este firmado
    300349         *
    301          * @param uploadedInputStream stream para obtener el archivo
     350         * @param uploadedInputStream stream para obtener el archivo 
    302351         * @param fileDetails datos del archivo
    303352         * @return
    304353         * @throws MurachiException
     354         *
     355         * @api {post} /Murachi/0.1/archivos/firmados Carga un archivo y verifica
     356         * @apiName Firmados
     357         * @apiGroup Archivos
     358         * @apiVersion 0.1.0
     359         * @apiDescription Carga un archivo a través de un formulario y retorna un json con la información de la firma.
     360         *
     361         * @apiSuccess {Boolean} fileExist El archivo se cargó exitosamente en el servidor.
     362         * @apiSuccess {String} error Extension not supported. En caso de que el archivo sea diferente de PDF y BDOC.
     363         *
     364         * @apiSuccess {Number} numberOfSignatures Número de firmas existentes en el archivo.
     365         * @apiSuccess {Object[]} signatures Lista de firmas.
     366         * @apiSuccess {String}   signatures.signatureType Tipo de firma de archivo PDF: approval
     367         * @apiSuccess {String}   signatures.signedOn Fecha en que se realiza la firma.
     368         * @apiSuccess {Boolean}   signatures.integrityCheck Chequea la integridad de la firma.
     369         * @apiSuccess {String}   signatures.timeStamp Estampilla de tiempo
     370         * @apiSuccess {String}   signatures.reason Razón de la firma.
     371         * @apiSuccess {String}   signatures.location Ubicación donde se realiza la firma.
     372         * @apiSuccess {String}   signatures.alternativeNameOfTheSigner Nombre alternativo del firmante.
     373         * @apiSuccess {String}   signatures.signerCertificateValidFrom Fecha de inicio de validez del certificado.
     374         * @apiSuccess {Boolean}   signatures.signerCertificateStillValid El certificado todavía está válido.
     375         * @apiSuccess {Boolean}   signatures.signerCertificateHasExpired El certificado expiró.
     376         * @apiSuccess {Boolean}   signatures.signatureCoversWholeDocument La firma abarca todo el documento PDF.
     377         * @apiSuccess {String}   signatures.filterSubtype Tipo de subfiltro: /adbe.pkcs7.sha1, /adbe.pkcs7.detached.
     378         * @apiSuccess {String}   signatures.signerCertificateSubject Sujeto firmante.
     379         * @apiSuccess {Boolean}   signatures.signerCertificateValidAtTimeOfSigning El certificado es válido en el momento de la firma.
     380         * @apiSuccess {String}   signatures.encryptionAlgorithm Algoritmo de cifrado.
     381         * @apiSuccess {String}   signatures.timeStampService Servicio de estampillado de tiempo.
     382         * @apiSuccess {String}   signatures.digestAlgorithm Algoritmo hash (reseña).
     383         * @apiSuccess {Boolean}   signatures.certificatesVerifiedAgainstTheKeyStore Certificado verificado contra el repositorio de certificados confiables.
     384         * @apiSuccess {Number}   signatures.documentRevision Número de revisión del documento PDF.
     385         * @apiSuccess {String}   signatures.nameOfTheSigner Nombre del firmante.
     386         * @apiSuccess {Number}   signatures.totalDocumentRevisions Número total de revisiones del documento PDF.
     387         * @apiSuccess {String}   signatures.contactInfo Información de contacto del firmante.
     388         * @apiSuccess {Boolean}   signatures.timeStampVerified Estampilla de tiempo verificada.
     389         * @apiSuccess {String}   signatures.signerCertificateIssuer Emisor del certificado firmante.
     390         * @apiSuccess {String}   signatures.signerCertificateValidTo Fecha de fin de validez del certificado.
     391         *
     392         * @apiExample Example usage:
     393         *
     394         *  var formData = new FormData();
     395     *  formData.append("upload", $("#file-sign")[0].files[0]);           
     396     *  $.ajax({
     397     *           url: "https://murachi.cenditel.gob.ve/Murachi/0.1/archivos/firmados",
     398     *           type: "post",
     399     *           dataType: "json",
     400     *           data: formData,
     401     *           cache: false,
     402     *           contentType: false,
     403         *           processData: false,
     404     *           success: function(response) {
     405         *                  var json = JSON.stringify(response);
     406         *                  alert(json);
     407         *           },
     408         *           error: function(response){
     409         *                  alert("error: " + response.error.toString());
     410         *           }
     411     *  });
     412         *
     413         *
     414         *
     415         * @apiErrorExample {json} Error-Response:
     416         *     HTTP/1.1 400 Bad Request
     417         *     {
     418         *       "error": "datos recibidos del formulario son nulos"
     419         *     }
     420         *     
     421         *     
     422         *     HTTP/1.1 500
     423         *     {
     424         *       "error": "IOException"
     425         *     }
     426         *     
    305427         */
    306428        @POST
     
    317439                        System.out.println("uploadedInputStream == null");
    318440                        logger.error("uploadedInputStream != null. datos recibidos del formulario son nulos.");
    319                         throw new MurachiException("uploadedInputStream != null. datos recibidos del formulario son nulos.");
     441                        //throw new MurachiException("uploadedInputStream != null. datos recibidos del formulario son nulos.");
     442                        return Response.status(400).entity("{\"error\": \"datos recibidos del formulario son nulos\"}").type(MediaType.APPLICATION_JSON).build();
    320443                }
    321444               
     
    323446                        System.out.println("fileDetails == null");
    324447                        logger.error("fileDetails == null. datos recibidos del formulario son nulos.");
    325                         throw new MurachiException("fileDetails == null. datos recibidos del formulario son nulos.");
     448                        //throw new MurachiException("fileDetails == null. datos recibidos del formulario son nulos.");
     449                        return Response.status(400).entity("{\"error\": \"datos recibidos del formulario son nulos\"}").type(MediaType.APPLICATION_JSON).build();
     450                       
    326451                }
    327452                               
     
    336461                        logger.error("Ocurrio una excepcion: ", e);
    337462                        e.printStackTrace();
    338                         throw new MurachiException(e.getMessage());
     463                        //throw new MurachiException(e.getMessage());
     464                        return Response.status(500).entity("{\"error\":" + e.getMessage()).build();
    339465                }
    340466               
     
    834960         * @throws MurachiException
    835961         *
     962         * @api {post} /Murachi/0.1/archivos/firmados/pdfs Prepara la firma del documento PDF.
     963         * @apiName Pdfs
     964         * @apiGroup PDFS
     965         * @apiVersion 0.1.0
     966         * @apiDescription Prepara la firma de un documento PDF. Se debe pasar un JSON con la siguiente estructura:
     967         *  {"fileId":"file_id",                               
     968         *      "certificate":"hex_cert_value",
     969         *  "reason":"reason",
     970         *  "location":"location",
     971         *  "contact":"contact"
     972         *  }
     973         *
     974         * @apiSuccess {String} hash Reseña o hash del archivo que se debe cifrar con la clave privada protegida por el
     975         * dispositivo criptográfico.
     976         *
     977         * @apiExample Example usage:
     978         *
     979         * var parameters = JSON.stringify({
     980         *                             "fileId":fileId,
     981         *                             "certificate":cert.hex,
     982         *                             "reason":"prueba firma web",
     983         *                             "location":"Oficina",
     984         *                             "contact":"582746574336"
     985         *                             });
     986         *
     987         * $.ajax({
     988     *           url: "https://murachi.cenditel.gob.ve/Murachi/0.1/archivos/pdfs",
     989     *           type: "post",
     990     *           dataType: "json",
     991     *           data: parameters,
     992     *           contentType: "application/json",
     993     *           success: function(data, textStatus, jqXHR){
     994         *                              var json_x = data;
     995     *                              var hash = json_x['hash'];
     996     *                              alert("hash recibido del servidor "+hash);
     997     *           },
     998         *           error: function(jqXHR, textStatus, errorThrown){
     999         *                              //alert('error: ' + textStatus);
     1000         *                              //var responseText = jQuery.parseJSON(jqXHR.responseText);
     1001         *                              alert('ajax error function: ' + jqXHR.responseText);
     1002         *                             
     1003         *           }
     1004     *  });
     1005         *
     1006         *
     1007         *
     1008         * @apiErrorExample {json} Error-Response:
     1009         *     HTTP/1.1 400 Bad Request
     1010         *     {
     1011         *       "hash": "",
     1012         *       "error": "El archivo que desea firmar no es un PDF."
     1013         *     }
     1014         *     
     1015         *     HTTP/1.1 500 Internal Server Error
     1016         *     {
     1017         *       "hash": "",
     1018         *       "error": "error en carga de certificado de firmante"
     1019         *     }
     1020         *
     1021         *
    8361022         */
    8371023        @POST
     
    8881074                                System.out.println("error chain[0] == null");
    8891075                                logger.error("presignPdf: error en carga de certificado de firmante");
    890                                 throw new MurachiException("presignPdf: error en carga de certificado de firmante");
     1076                                //throw new MurachiException("presignPdf: error en carga de certificado de firmante");
     1077                               
     1078                                presignHash.setError("error en carga de certificado de firmante");
     1079                                presignHash.setHash("");
     1080                                return Response.status(500).entity(presignHash).build();
     1081                                                               
    8911082                        }else {
    8921083                               
     
    10031194                        logger.error("presignPdf ocurrio una excepcion ", e1);
    10041195                        e1.printStackTrace();
    1005                         throw new MurachiException(e1.getMessage());
     1196                        //throw new MurachiException(e1.getMessage());
     1197                        presignHash.setError(e1.getMessage());
     1198                        presignHash.setHash("");
     1199                        return Response.status(500).entity(presignHash).build();                       
     1200                       
    10061201                } catch (InvalidPdfException e) {
    10071202                        logger.error("presignPdf ocurrio una excepcion ", e);
    10081203                        e.printStackTrace();
     1204                        //presignHash.setError("No se pudo leer el archivo PDF en el servidor");
     1205                        //throw new MurachiException(e.getMessage());
    10091206                        presignHash.setError("No se pudo leer el archivo PDF en el servidor");
    1010                         throw new MurachiException(e.getMessage());
     1207                        presignHash.setHash("");
     1208                        return Response.status(500).entity(presignHash).build();
     1209                       
    10111210                } catch (IOException e) {
    10121211                        logger.error("presignPdf ocurrio una excepcion ", e);
    10131212                        e.printStackTrace();
    1014                         throw new MurachiException(e.getMessage());
     1213                        //throw new MurachiException(e.getMessage());
     1214                       
     1215                        presignHash.setError(e.getMessage());
     1216                        presignHash.setHash("");
     1217                        return Response.status(500).entity(presignHash).build();
     1218                       
    10151219                } catch (DocumentException e) {
    10161220                        logger.error("presignPdf ocurrio una excepcion ", e);
    10171221                        e.printStackTrace();
    1018                         throw new MurachiException(e.getMessage());
     1222                        //throw new MurachiException(e.getMessage());
     1223                       
     1224                        presignHash.setError(e.getMessage());
     1225                        presignHash.setHash("");
     1226                        return Response.status(500).entity(presignHash).build();
     1227                       
    10191228                } catch (InvalidKeyException e) {
    10201229                        logger.error("presignPdf ocurrio una excepcion ", e);
    10211230                        e.printStackTrace();
    1022                         throw new MurachiException(e.getMessage());
     1231                        //throw new MurachiException(e.getMessage());
     1232                       
     1233                        presignHash.setError(e.getMessage());
     1234                        presignHash.setHash("");
     1235                        return Response.status(500).entity(presignHash).build();
     1236                       
    10231237                } catch (NoSuchProviderException e) {
    10241238                        logger.error("presignPdf ocurrio una excepcion ", e);
    10251239                        e.printStackTrace();
    1026                         throw new MurachiException(e.getMessage());
     1240                        //throw new MurachiException(e.getMessage());
     1241                       
     1242                        presignHash.setError(e.getMessage());
     1243                        presignHash.setHash("");
     1244                        return Response.status(500).entity(presignHash).build();
     1245                       
    10271246                } catch (NoSuchAlgorithmException e) {
    10281247                        logger.error("presignPdf ocurrio una excepcion ", e);
    10291248                        e.printStackTrace();
    1030                         throw new MurachiException(e.getMessage());
     1249                        //throw new MurachiException(e.getMessage());
     1250                       
     1251                        presignHash.setError(e.getMessage());
     1252                        presignHash.setHash("");
     1253                        return Response.status(500).entity(presignHash).build();
     1254                       
    10311255                } catch (GeneralSecurityException e) {
    10321256                        logger.error("presignPdf ocurrio una excepcion ", e);
    10331257                        e.printStackTrace();
    1034                         throw new MurachiException(e.getMessage());
     1258                        //throw new MurachiException(e.getMessage());
     1259                       
     1260                        presignHash.setError(e.getMessage());
     1261                        presignHash.setHash("");
     1262                        return Response.status(500).entity(presignHash).build();
     1263                       
    10351264                }
    10361265               
     
    10851314         * @throws IOException
    10861315         * @throws MurachiException
     1316         *
     1317         *
     1318         * @api {post} /Murachi/0.1/archivos/firmados/pdfs/resenas Completa la firma del documento PDF.
     1319         * @apiName PdfsResenas
     1320         * @apiGroup PDFS
     1321         * @apiVersion 0.1.0
     1322         * @apiDescription Completa la firma del documento PDF. Recibe el hash cifrado del cliente y termina de completar la firma del
     1323         * archivo PDF.
     1324         *
     1325         * @apiSuccess {String} signedFileId Identificador único del archivo firmado en el servidor.
     1326         *
     1327         * @apiExample Example usage:
     1328         *
     1329         * $.ajax({
     1330     *           url: "https://murachi.cenditel.gob.ve/Murachi/0.1/archivos/pdfs/resenas",
     1331     *           type: "post",
     1332     *           dataType: "json",
     1333     *           data: JSON.stringify({"signature":signature.hex}),
     1334     *           contentType: "application/json",
     1335     *           success: function(data, textStatus, jqXHR){
     1336     *                              alert('Archivo firmado correctamente: ' + data['signedFileId']);
     1337     *           },
     1338         *           error: function(jqXHR, textStatus, errorThrown){
     1339         *                              alert('error en pdfs/resenas: ' + textStatus);
     1340         *           }
     1341     *  });
     1342         *
     1343         *
     1344         *
     1345         * @apiErrorExample {json} Error-Response:
     1346         *     HTTP/1.1 500 Internal Server Error
     1347         *     {
     1348         *       "error": "El archivo que desea firmar no es un PDF."
     1349         *     }
     1350         *
    10871351         */
    10881352        @POST
     
    11151379                ByteArrayOutputStream os = (ByteArrayOutputStream) session.getAttribute("baos");
    11161380               
     1381                JSONObject jsonError = new JSONObject();
     1382               
    11171383                if (sgn == null) {
    11181384                        System.out.println("sgn == null");
    11191385                        logger.error("Error en completacion de firma: estructura PdfPKCS7 nula");
    1120                         throw new MurachiException("Error en completacion de firma: estructura PdfPKCS7 nula");
     1386                        //throw new MurachiException("Error en completacion de firma: estructura PdfPKCS7 nula");
     1387                       
     1388                        jsonError.put("error", "estructura PdfPKCS7 nula");
     1389                        return Response.status(500).entity(jsonError).build();                 
    11211390                }
    11221391                if (hash == null) {
    11231392                        System.out.println("hash == null");
    11241393                        logger.error("Error en completacion de firma: hash nulo");
    1125                         throw new MurachiException("Error en completacion de firma: hash nulo");
     1394                        //throw new MurachiException("Error en completacion de firma: hash nulo");
     1395                        jsonError.put("error", "hash nulo");
     1396                        return Response.status(500).entity(jsonError).build();
    11261397                }
    11271398                if (cal == null) {
    11281399                        System.out.println("cal == null");
    11291400                        logger.error("Error en completacion de firma: estructura de fecha nula");
    1130                         throw new MurachiException("Error en completacion de firma: estructura de fecha nula");
     1401                        //throw new MurachiException("Error en completacion de firma: estructura de fecha nula");
     1402                       
     1403                        jsonError.put("error", "estructura de fecha nula");
     1404                        return Response.status(500).entity(jsonError).build();
    11311405                }
    11321406                if (sap == null) {
    11331407                        System.out.println("sap == null");
    11341408                        logger.error("Error en completacion de firma: estructura de apariencia de firma pdf nula");
    1135                         throw new MurachiException("Error en completacion de firma: estructura de apariencia de firma pdf nula");
     1409                        //throw new MurachiException("Error en completacion de firma: estructura de apariencia de firma pdf nula");
     1410                       
     1411                        jsonError.put("error", "estructura de apariencia de firma pdf nula");
     1412                        return Response.status(500).entity(jsonError).build();
    11361413                }
    11371414                if (os == null) {
    11381415                        System.out.println("os == null");
    11391416                        logger.error("Error en completacion de firma: bytes de archivo nulos");
    1140                         throw new MurachiException("Error en completacion de firma: bytes de archivo nulos");
     1417                        //throw new MurachiException("Error en completacion de firma: bytes de archivo nulos");
     1418                       
     1419                        jsonError.put("error", "bytes de archivo nulos");
     1420                        return Response.status(500).entity(jsonError).build();
    11411421                }
    11421422
     
    11611441                        System.out.println("throw new IOException");
    11621442                        logger.error("postsignPdf: ocurrio una excepcion", e);
    1163                         throw new MurachiException(e.getMessage());
     1443                        //throw new MurachiException(e.getMessage());
     1444                        jsonError.put("error", e.getMessage());
     1445                        return Response.status(500).entity(jsonError).build();                 
    11641446                       
    11651447                } catch (IOException e) {
     
    11671449                        logger.error("postsignPdf: ocurrio una excepcion", e);
    11681450                        e.printStackTrace();
    1169                         throw new MurachiException(e.getMessage());
     1451                        //throw new MurachiException(e.getMessage());
     1452                       
     1453                        jsonError.put("error", e.getMessage());
     1454                        return Response.status(500).entity(jsonError).build();
    11701455                       
    11711456                }
Note: See TracChangeset for help on using the changeset viewer.