- Timestamp:
- Sep 22, 2015, 1:41:28 PM (9 years ago)
- Branches:
- master
- Children:
- 0c30a25
- Parents:
- 6c39b8a
- Location:
- murachi/src/main/java/ve/gob/cenditel/murachi
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
murachi/src/main/java/ve/gob/cenditel/murachi/MURACHIStatistic.java
rfc4d3bb r5d188ab 72 72 73 73 sql = "CREATE TABLE VERIFICATIONS " + 74 "(VERIFICATION_ID SERIAL PRIMARY KEY NOT NULL)"; 74 "(VERIFICATION_ID SERIAL PRIMARY KEY NOT NULL,"+ 75 "TYPE CHAR(4) NOT NULL)"; 75 76 stmt.executeUpdate(sql); 76 77 System.out.println("table VERIFICATIONS created!"); … … 79 80 80 81 sql = "CREATE TABLE SIGNATURES_ERROR " + 81 "(SIGNATURE_ERROR_ID SERIAL PRIMARY KEY NOT NULL)"; 82 "(SIGNATURE_ERROR_ID SERIAL PRIMARY KEY NOT NULL, "+ 83 "TYPE CHAR(4) NOT NULL)"; 82 84 stmt.executeUpdate(sql); 83 85 System.out.println("table SIGNATURE_ERROR created!"); … … 148 150 149 151 /** 152 * Incrementa en una unidad la cuenta de las firmas incompletas realizadas con el servicio 153 * 154 * @param type tipo de firma: 0->PDF, 1->BDOC 155 * 156 */ 157 public void incrementErrorSignatures(int type) { 158 Connection c = null; 159 Statement stmt = null; 160 try { 161 Class.forName("org.postgresql.Driver"); 162 163 //c = DriverManager.getConnection("jdbc:postgresql://localhost:5432/databasemurachi", databaseLogin, databasePassword); 164 c = DriverManager.getConnection(databaseConnection, databaseLogin, databasePassword); 165 166 c.setAutoCommit(false); 167 //System.out.println("Opened database successfully"); 168 169 stmt = c.createStatement(); 170 String signatureType = ""; 171 172 if (type == 0) { 173 signatureType = "pdf"; 174 }else if (type == 1){ 175 signatureType = "bdoc"; 176 }else{ 177 signatureType = "unknown"; 178 } 179 180 String sql = "INSERT INTO SIGNATURES_ERROR (TYPE) VALUES ('"+ signatureType +"');"; 181 stmt.executeUpdate(sql); 182 stmt.close(); 183 c.commit(); 184 c.close(); 185 } catch (Exception e) { 186 logger.error(e.getClass().getName()+": "+ e.getMessage()); 187 System.err.println( e.getClass().getName()+": "+ e.getMessage() ); 188 } 189 //System.out.println("Records created successfully"); 190 } 191 192 193 /** 194 * Incrementa en una unidad la cuenta de las verificaciones de firmas realizadas con el servicio 195 * 196 * @param type tipo de firma: 0->PDF, 1->BDOC 197 * 198 */ 199 public void incrementVerifications(int type) { 200 Connection c = null; 201 Statement stmt = null; 202 try { 203 Class.forName("org.postgresql.Driver"); 204 205 //c = DriverManager.getConnection("jdbc:postgresql://localhost:5432/databasemurachi", databaseLogin, databasePassword); 206 c = DriverManager.getConnection(databaseConnection, databaseLogin, databasePassword); 207 208 c.setAutoCommit(false); 209 //System.out.println("Opened database successfully"); 210 211 stmt = c.createStatement(); 212 String signatureType = ""; 213 214 if (type == 0) { 215 signatureType = "pdf"; 216 }else if (type == 1){ 217 signatureType = "bdoc"; 218 }else{ 219 signatureType = "unkn"; 220 } 221 222 String sql = "INSERT INTO VERIFICATIONS (TYPE) VALUES ('"+ signatureType +"');"; 223 stmt.executeUpdate(sql); 224 stmt.close(); 225 c.commit(); 226 c.close(); 227 } catch (Exception e) { 228 logger.error(e.getClass().getName()+": "+ e.getMessage()); 229 System.err.println( e.getClass().getName()+": "+ e.getMessage() ); 230 } 231 232 } 233 234 235 236 /** 150 237 * Retorna el número de firmas realizadas exitosamente con el servicio. 151 238 * -
murachi/src/main/java/ve/gob/cenditel/murachi/MurachiRESTWS.java
r6c39b8a r5d188ab 625 625 jsonObject = verifyALocalFile(fileId); 626 626 logger.info("/firmados: " + jsonObject.toString()); 627 627 628 628 return Response.status(200).entity(jsonObject.toString()).build(); 629 629 } … … 840 840 logger.info("/{"+idFile+"}: "+ result); 841 841 842 // registrar la verificacion exitosa en el contador de verificaciones 843 registerAVerification(1); 844 842 845 return Response.status(200).entity(result).build(); 843 846 } … … 850 853 logger.info("/{"+idFile+"}: "+ result); 851 854 855 // registrar la verificacion exitosa en el contador de verificaciones 856 registerAVerification(0); 857 852 858 return Response.status(200).entity(result).build(); 853 859 } … … 855 861 else 856 862 { 863 // registrar la verificacion exitosa en el contador de verificaciones 864 registerAVerification(2); 865 857 866 jsonObject.put("fileExist", "true"); 858 867 jsonObject.put("error", "extension not supported"); … … 956 965 String mime = getMimeType(path); 957 966 System.out.println("mimetype : " + mime); 958 959 967 960 968 if (mime.equals("application/zip")) { 961 969 jsonObject = verifySignaturesInBdoc(path, false); 962 970 result = jsonObject.toString(); 963 971 logger.info("/{"+idFile+"}: "+ result); 972 973 // registrar la verificacion exitosa en el contador de verificaciones 974 registerAVerification(1); 964 975 965 976 return jsonObject; … … 972 983 result = jsonObject.toString(); 973 984 logger.info("/{"+idFile+"}: "+ result); 985 986 // registrar la verificacion exitosa en el contador de verificaciones 987 registerAVerification(0); 974 988 975 989 return jsonObject; … … 980 994 jsonObject.put("fileExist", "true"); 981 995 jsonObject.put("error", "extension not supported"); 996 997 // registrar la verificacion exitosa en el contador de verificaciones 998 registerAVerification(2); 999 982 1000 return jsonObject; 983 1001 } … … 1833 1851 1834 1852 if (postsignPar == null) { 1853 1854 // registrar error de firma en estadisticas 1855 registerASignatureError(0); 1856 1835 1857 logger.error("solicitud mal formada."); 1836 1858 result = "\"error\":\"solicitud mal formada\""; 1859 1837 1860 return Response.status(400).entity(result).build(); 1838 1861 } … … 1841 1864 String signature = postsignPar.getSignature(); 1842 1865 if (signature == null) { 1866 1867 // registrar error de firma en estadisticas 1868 registerASignatureError(0); 1869 1843 1870 logger.debug("signature == null"); 1844 1871 logger.error("solicitud mal formada: no esta especificada la firma realizada en el cliente."); … … 1869 1896 1870 1897 if (fileId == null) { 1898 1899 // registrar error de firma en estadisticas 1900 registerASignatureError(0); 1901 1871 1902 System.out.println("fileId == null"); 1872 1903 logger.error("Error en completacion de firma: identificador de archivo nulo"); … … 1878 1909 1879 1910 if (stamper == null) { 1911 // registrar error de firma en estadisticas 1912 registerASignatureError(0); 1913 1880 1914 System.out.println("stamper == null"); 1881 1915 logger.error("Error en completacion de firma: estructura PdfStamper nula"); … … 1887 1921 1888 1922 if (sgn == null) { 1923 // registrar error de firma en estadisticas 1924 registerASignatureError(0); 1925 1889 1926 System.out.println("sgn == null"); 1890 1927 logger.error("Error en completacion de firma: estructura PdfPKCS7 nula"); … … 1895 1932 } 1896 1933 if (hash == null) { 1934 // registrar error de firma en estadisticas 1935 registerASignatureError(0); 1936 1897 1937 System.out.println("hash == null"); 1898 1938 logger.error("Error en completacion de firma: hash nulo"); … … 1902 1942 } 1903 1943 if (cal == null) { 1944 // registrar error de firma en estadisticas 1945 registerASignatureError(0); 1946 1904 1947 System.out.println("cal == null"); 1905 1948 logger.error("Error en completacion de firma: estructura de fecha nula"); … … 1910 1953 } 1911 1954 if (sap == null) { 1955 // registrar error de firma en estadisticas 1956 registerASignatureError(0); 1957 1912 1958 System.out.println("sap == null"); 1913 1959 logger.error("Error en completacion de firma: estructura de apariencia de firma pdf nula"); … … 1918 1964 } 1919 1965 if (os == null) { 1966 // registrar error de firma en estadisticas 1967 registerASignatureError(0); 1968 1920 1969 System.out.println("os == null"); 1921 1970 logger.error("Error en completacion de firma: bytes de archivo nulos"); … … 1944 1993 1945 1994 }catch(DocumentException e) { 1995 // registrar error de firma en estadisticas 1996 registerASignatureError(0); 1997 1998 1946 1999 System.out.println("throw new IOException"); 1947 2000 logger.error("postsignPdf: ocurrio una excepcion", e); … … 1951 2004 1952 2005 } catch (IOException e) { 2006 // registrar error de firma en estadisticas 2007 registerASignatureError(0); 2008 1953 2009 System.out.println("IOException e"); 1954 2010 logger.error("postsignPdf: ocurrio una excepcion", e); … … 1984 2040 1985 2041 // registrar la firma exitosa en el contador de firmas 1986 MURACHIStatistic statistic = new MURACHIStatistic(databaseHost, databasePort, databaseName, databaseLogin, databasePassword); 1987 statistic.incrementSignatures(0); 1988 2042 registerASignature(0); 2043 1989 2044 return Response.status(200).entity(jsonFinalResult.toString()).build(); 1990 2045 } … … 2636 2691 } catch(IOException e) 2637 2692 { 2693 // registrar error de firma en estadisticas 2694 registerASignatureError(1); 2695 2638 2696 presignHash.setError(e.getMessage()); 2639 2697 presignHash.setHash(""); … … 2641 2699 } catch(CertificateException e) 2642 2700 { 2701 // registrar error de firma en estadisticas 2702 registerASignatureError(1); 2703 2643 2704 presignHash.setError(e.getMessage()); 2644 2705 presignHash.setHash(""); 2645 2706 return Response.status(500).entity(presignHash).build(); 2646 2707 } 2647 2648 2708 2649 2709 // creacion del json 2650 2710 JSONObject jsonHash = new JSONObject(); … … 2751 2811 //e.printStackTrace(); 2752 2812 2813 // registrar error de firma en estadisticas 2814 registerASignatureError(1); 2815 2753 2816 JSONObject jsonError = new JSONObject(); 2754 2817 … … 2774 2837 2775 2838 // registrar la firma exitosa en el contador de firmas 2776 MURACHIStatistic statistic = new MURACHIStatistic(databaseHost, databasePort, databaseName, databaseLogin, databasePassword); 2777 statistic.incrementSignatures(1); 2839 //MURACHIStatistic statistic = new MURACHIStatistic(databaseHost, databasePort, databaseName, databaseLogin, databasePassword); 2840 //statistic.incrementSignatures(1); 2841 registerASignature(1); 2778 2842 2779 2843 return Response.status(200).entity(jsonFinalResult.toString()).build(); … … 2882 2946 if (is == null) 2883 2947 { 2948 // registrar error de firma en estadisticas 2949 registerASignatureError(1); 2950 2884 2951 logger.debug("is: null"); 2885 2952 result = "\"error\":\"archivo pasado al recurso es nulo.\""; … … 4093 4160 4094 4161 if (presignPar == null) { 4162 // registrar error de firma en estadisticas 4163 registerASignatureError(1); 4164 4095 4165 logger.error("solicitud mal formada."); 4096 4166 result = "\"error\":\"solicitud mal formada\""; … … 4101 4171 String containerId = presignPar.getFileId(); 4102 4172 if (containerId == null) { 4173 // registrar error de firma en estadisticas 4174 registerASignatureError(1); 4175 4103 4176 logger.debug("containerId == null"); 4104 4177 logger.error("solicitud mal formada: no esta especificado el identificador del contenedor."); … … 4111 4184 String certHex = presignPar.getCertificate(); 4112 4185 if (certHex == null) { 4186 // registrar error de firma en estadisticas 4187 registerASignatureError(1); 4188 4113 4189 logger.debug("certHex == null"); 4114 4190 logger.error("solicitud mal formada: no esta especificado el certificado firmante en hexadecimal."); … … 4120 4196 String city = presignPar.getCity(); 4121 4197 if (city == null) { 4198 // registrar error de firma en estadisticas 4199 registerASignatureError(1); 4200 4122 4201 logger.debug("city == null"); 4123 4202 logger.error("solicitud mal formada: no esta especificada la ciudad donde se realiza la firma."); … … 4129 4208 String state = presignPar.getState(); 4130 4209 if (state == null) { 4210 // registrar error de firma en estadisticas 4211 registerASignatureError(1); 4212 4131 4213 logger.debug("state == null"); 4132 4214 logger.error("solicitud mal formada: no esta especificado el estado donde se realiza la firma."); … … 4138 4220 String postalCode = presignPar.getPostalCode(); 4139 4221 if (postalCode == null) { 4222 // registrar error de firma en estadisticas 4223 registerASignatureError(1); 4224 4140 4225 logger.debug("state == null"); 4141 4226 logger.error("solicitud mal formada: no esta especificado el codigo postal donde se realiza la firma."); … … 4147 4232 String country = presignPar.getCountry(); 4148 4233 if (country == null) { 4234 // registrar error de firma en estadisticas 4235 registerASignatureError(1); 4236 4149 4237 logger.debug("country == null"); 4150 4238 logger.error("solicitud mal formada: no esta especificado el pais donde se realiza la firma."); … … 4156 4244 String role = presignPar.getRole(); 4157 4245 if (role == null) { 4246 // registrar error de firma en estadisticas 4247 registerASignatureError(1); 4248 4158 4249 logger.debug("role == null"); 4159 4250 logger.error("solicitud mal formada: no esta especificado el rol del firmante."); … … 4188 4279 4189 4280 if (!f.exists()) { 4281 // registrar error de firma en estadisticas 4282 registerASignatureError(1); 4283 4190 4284 logger.error("el contenedor "+ fullPathContainerId + " no existe."); 4191 4285 result = "\"error\":\"el contenedor "+ fullPathContainerId + " no existe\""; … … 4307 4401 } catch(IOException e) 4308 4402 { 4403 // registrar error de firma en estadisticas 4404 registerASignatureError(1); 4405 4406 // registrar error de firma en estadisticas 4407 registerASignatureError(1); 4309 4408 presignHash.setError(e.getMessage()); 4310 4409 presignHash.setHash(""); … … 4312 4411 } catch(CertificateException e) 4313 4412 { 4413 // registrar error de firma en estadisticas 4414 registerASignatureError(1); 4415 4314 4416 presignHash.setError(e.getMessage()); 4315 4417 presignHash.setHash(""); 4316 4418 return Response.status(500).entity(presignHash).build(); 4317 4419 } catch (ClassNotFoundException e) { 4420 // registrar error de firma en estadisticas 4421 registerASignatureError(1); 4422 4318 4423 presignHash.setError(e.getMessage()); 4319 4424 presignHash.setHash(""); … … 4405 4510 4406 4511 if (postsignPar == null) { 4512 // registrar error de firma en estadisticas 4513 registerASignatureError(1); 4514 4407 4515 logger.error("solicitud mal formada."); 4408 4516 result = "\"error\":\"solicitud mal formada\""; … … 4413 4521 String signature = postsignPar.getSignature(); 4414 4522 if (signature == null) { 4523 // registrar error de firma en estadisticas 4524 registerASignatureError(1); 4525 4415 4526 logger.debug("signature == null"); 4416 4527 logger.error("solicitud mal formada: no esta especificada la firma realizada en el cliente."); … … 4423 4534 String containerId = postsignPar.getContainerId(); 4424 4535 if (containerId == null) { 4536 // registrar error de firma en estadisticas 4537 registerASignatureError(1); 4538 4425 4539 logger.debug("containerId == null"); 4426 4540 logger.error("solicitud mal formada: no esta especificado el identificador del contenedor."); … … 4440 4554 4441 4555 if (!f.exists()) { 4556 // registrar error de firma en estadisticas 4557 registerASignatureError(1); 4558 4442 4559 logger.error("el contenedor "+ serializedContainerId + " no existe."); 4443 4560 result = "\"error\":\"el contenedor "+ serializedContainerId + " no existe\""; … … 4535 4652 } catch (ClassNotFoundException e) { 4536 4653 //e.printStackTrace(); 4654 4655 // registrar error de firma en estadisticas 4656 registerASignatureError(1); 4537 4657 4538 4658 JSONObject jsonError = new JSONObject(); … … 4544 4664 return Response.status(500).entity(jsonError).build(); 4545 4665 } catch (DSSException e) { 4666 4667 // registrar error de firma en estadisticas 4668 registerASignatureError(1); 4669 4546 4670 JSONObject jsonError = new JSONObject(); 4547 4671 … … 4567 4691 4568 4692 // registrar la firma exitosa en el contador de firmas 4569 MURACHIStatistic statistic = new MURACHIStatistic(databaseHost, databasePort, databaseName, databaseLogin, databasePassword); 4570 statistic.incrementSignatures(1); 4571 4693 registerASignature(1); 4572 4694 4573 4695 return Response.status(200).entity(jsonFinalResult.toString()).build(); … … 5025 5147 5026 5148 5149 5027 5150 //statistic.incrementSignatures(0); 5028 5151 … … 5035 5158 int countSignaturesError = statistic.countOfSiganturesFailed(); 5036 5159 jsonObject.put("numeroDeFimasIncompletas", Integer.toString(countSignaturesError)); 5160 logger.debug("firmas incorrectas: "+ Integer.toString(countSignaturesError)); 5037 5161 5038 5162 int countVerifications = statistic.countOfVerifications(); 5039 5163 jsonObject.put("numeroDeVerificaciones", Integer.toString(countVerifications)); 5164 logger.debug("verificaciones realizadas correctamente: "+ Integer.toString(countVerifications)); 5040 5165 5041 5166 result = jsonObject.toString(); … … 5044 5169 } 5045 5170 5171 /** 5172 * Registra un evento de firma electrónica en la base de datos de estadisticas 5173 * @param type 0-> PDF; 1->BDOC; 2->UNKN 5174 */ 5175 private void registerASignature(int type) { 5176 // registrar la verificacion exitosa en el contador de verificaciones 5177 MURACHIStatistic statistic = new MURACHIStatistic(databaseHost, databasePort, databaseName, databaseLogin, databasePassword); 5178 statistic.incrementSignatures(type); 5179 } 5046 5180 5181 /** 5182 * Registra un evento de verificacion de firma electrónica en la base de datos de estadisticas 5183 * @param type 0-> PDF; 1->BDOC; 2->UNKN 5184 */ 5185 private void registerAVerification(int type) { 5186 // registrar la verificacion exitosa en el contador de verificaciones 5187 MURACHIStatistic statistic = new MURACHIStatistic(databaseHost, databasePort, databaseName, databaseLogin, databasePassword); 5188 statistic.incrementVerifications(type); 5189 } 5190 5191 /** 5192 * Registra un evento de firma electrónica incompleta en la base de datos de estadisticas 5193 * @param type 0-> PDF; 1->BDOC; 2->UNKN 5194 */ 5195 private void registerASignatureError(int type) { 5196 // registrar la verificacion exitosa en el contador de verificaciones 5197 MURACHIStatistic statistic = new MURACHIStatistic(databaseHost, databasePort, databaseName, databaseLogin, databasePassword); 5198 statistic.incrementErrorSignatures(type); 5199 } 5200 5201 5202 5203 5047 5204 5048 5205 … … 6016 6173 6017 6174 6018 6175 @POST 6176 @Path("/phpcargas") 6177 @Consumes(MediaType.MULTIPART_FORM_DATA) 6178 @Produces(MediaType.APPLICATION_JSON) 6179 @Authenticator 6180 public Response uploadPHP(FormDataMultiPart formParams) throws MurachiException { 6181 6182 logger.info("recurso /phpcargas"); 6183 logger.debug(" uploadPHP..."); 6184 6185 // cadena con la respuesta 6186 String result = ""; 6187 6188 String fileId = ""; 6189 6190 if (formParams == null) { 6191 logger.error("solicitud mal formada."); 6192 result = "\"error\":\"solicitud mal formada\""; 6193 return Response.status(400).entity(result).build(); 6194 } 6195 6196 Map<String, List<FormDataBodyPart>> fieldsByName = formParams.getFields(); 6197 logger.debug(" contenido de Map: " + Integer.toString(fieldsByName.size())); 6198 6199 for (List<FormDataBodyPart> fields : fieldsByName.values()) 6200 { 6201 for (FormDataBodyPart field : fields) 6202 { 6203 InputStream is = field.getEntityAs(InputStream.class); 6204 6205 if (is == null) 6206 { 6207 logger.debug("is: null"); 6208 result = "\"error\":\"archivo pasado al recurso es nulo.\""; 6209 return Response.status(500).entity(result).build(); 6210 } 6211 6212 FormDataContentDisposition file = field.getFormDataContentDisposition(); 6213 String fileName = file.getFileName(); 6214 logger.debug("fileName: " + fileName); 6215 /* 6216 if (fileName == null) 6217 { 6218 logger.debug("fileName: null"); 6219 result = "\"error\":\"nombre del archivo pasado al recurso es nulo. Debe especificar un nombre de archivo.\""; 6220 return Response.status(500).entity(result).build(); 6221 } 6222 6223 String mimeType = field.getMediaType().toString(); 6224 logger.debug("mimeType: " + mimeType); 6225 6226 if (mimeType == null) 6227 { 6228 logger.debug("mimeType: null"); 6229 result = "\"error\":\"tipo mime del archivo pasado al recurso es nulo.\""; 6230 return Response.status(500).entity(result).build(); 6231 } 6232 */ 6233 6234 try 6235 { 6236 //addFileToBDOCContainer(is, fileName, mimeType, c); 6237 6238 fileId = UUID.randomUUID().toString(); 6239 System.out.println(fileId); 6240 6241 saveToDisk(is, null, fileId); 6242 logger.info("se guardó el archivo" + fileId + "en el disco"); 6243 } 6244 catch(Exception e) 6245 { 6246 logger.debug("excepcion: " + e.getMessage()); 6247 result = "\"error\":\"no se pudo guardar el archivo en el servidor.\""; 6248 return Response.status(500).entity(result).build(); 6249 } 6250 6251 } 6252 } 6253 6254 //logger.debug("cantidad de DataFile del contenedor: " + Integer.toString(c.getDataFiles().size())); 6255 //String fileId = UUID.randomUUID().toString(); 6256 //System.out.println("id contenedor serializado: "+fileId); 6257 6258 // establecer el nombre del archivo a serializar 6259 //String serializedContainerId = SERVER_UPLOAD_LOCATION_FOLDER + fileId + "-serialized"; 6260 //logger.debug(" id de contenedor serializado: "+ serializedContainerId); 6261 6262 result = "{\"fileId\":\""+ fileId +"\"}"; 6263 logger.debug(result); 6264 6265 logger.debug(" {containerId:"+ fileId+"}"); 6266 return Response.status(200).entity(result).build(); 6267 } 6019 6268 6020 6269
Note: See TracChangeset
for help on using the changeset viewer.