- Timestamp:
- Aug 17, 2015, 5:43:00 PM (9 years ago)
- Branches:
- master
- Children:
- 99d1e61
- Parents:
- efcd8d1
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
murachi/src/main/java/ve/gob/cenditel/murachi/MurachiRESTWS.java
refcd8d1 rf326ef1 335 335 * @return archivo pasado como argumento del servidor 336 336 */ 337 /*337 338 338 private Response downloadFileFromServer(String fileName) { 339 339 String fileLocation = SERVER_UPLOAD_LOCATION_FOLDER + fileName; … … 361 361 return response; 362 362 } 363 */ 364 363 364 365 /* 365 366 private Response downloadFileFromServer(String fileName) { 366 367 logger.info("downloadFileFromServer{"+fileName+"}"); … … 380 381 if (checkFileExists(SERVER_UPLOAD_LOCATION_FOLDER + fileName + "-serialized.bin")) { 381 382 382 logger.debug(" descarga de contenedor BDOC ");383 logger.debug(" descarga de contenedor BDOC: " + SERVER_UPLOAD_LOCATION_FOLDER + fileName + "-serialized.bin"); 383 384 384 385 try { … … 388 389 // deserializar el contenedor 389 390 c = deserialize(SERVER_UPLOAD_LOCATION_FOLDER + fileName + "-serialized.bin"); 391 logger.debug(" deserializado contenedor: " + SERVER_UPLOAD_LOCATION_FOLDER + fileName + "-serialized.bin"); 392 393 logger.debug("numero de dataFile: "+ Integer.toString(c.getDataFiles().size())); 394 logger.debug("numero de firmas: "+ Integer.toString(c.getSignatures().size())); 395 390 396 391 397 // guardar el contenedor .bdoc … … 431 437 return response; 432 438 } 439 */ 433 440 434 441 … … 2856 2863 } 2857 2864 2858 // ------------> a seguir2865 2859 2866 2860 2867 /** … … 2868 2875 @Produces(MediaType.APPLICATION_JSON) 2869 2876 public Response getSignatureNumber(@PathParam("containerId") String containerId) { 2870 logger.info("/bdocs/ archivos/"+containerId);2877 logger.info("/bdocs/firmas/"+containerId); 2871 2878 2872 2879 String fullPathBdocFile = SERVER_UPLOAD_LOCATION_FOLDER + containerId + "-serialized.bin"; … … 2918 2925 return response; 2919 2926 } 2927 2928 2929 /** 2930 * Elimina una firma de un contendor firmado 2931 * 2932 * @param containerId identificador del contenedor para eliminar la firma 2933 * @param signatureId identificador de la firma a eliminar 2934 * 2935 * @return identificador del contenedor 2936 */ 2937 @GET 2938 @Path("/bdocs/firmas/papelera/{containerId}/{signatureId}") 2939 @Produces(MediaType.APPLICATION_JSON) 2940 public Response removeSignature(@PathParam("containerId") String containerId, @PathParam("signatureId") int signatureId) { 2941 logger.info("recurso /bdocs/firmas/papelera/"+containerId+"/"+Integer.toString(signatureId)); 2942 2943 logger.debug("dataFileId: " + Integer.toString(signatureId)); 2944 2945 String fullPathBdocFile = SERVER_UPLOAD_LOCATION_FOLDER + containerId + "-serialized.bin"; 2946 logger.debug(fullPathBdocFile); 2947 2948 2949 JSONObject json = new JSONObject(); 2950 int signatureNumber = 0; 2951 2952 Response response = null; 2953 2954 // Retrieve the file 2955 File file = new File(fullPathBdocFile); 2956 if (file.exists()) { 2957 2958 Security.addProvider(new BouncyCastleProvider()); 2959 2960 Configuration configuration = new Configuration(Configuration.Mode.PROD); 2961 configuration.loadConfiguration(DIGIDOC4J_CONFIGURATION); 2962 configuration.setTslLocation(DIGIDOC4J_TSL_LOCATION); 2963 2964 Container container = null; 2965 2966 try { 2967 container = deserialize(fullPathBdocFile); 2968 logger.debug(" contenedor " + fullPathBdocFile + " deserializado"); 2969 } catch (ClassNotFoundException e) { 2970 2971 response = Response.status(500).entity("{\"error\": \"no se pudo leer el contenido del contenedor\"}").type("text/plain").build(); 2972 logger.error("no se pudo deserializar el contenedor para leer su contenido"); 2973 } 2974 catch (IOException e) { 2975 response = Response.status(500).entity("{\"error\": \"no se pudo leer el contenido del contenedor\"}").type("text/plain").build(); 2976 logger.error("no se pudo deserializar el contenedor para leer su contenido"); 2977 } 2978 2979 // contenedor deserializado, ahora verficar que este firmado 2980 signatureNumber = container.getSignatures().size(); 2981 logger.debug(" signatureNumber: "+ Integer.toString(signatureNumber)); 2982 2983 if (signatureNumber < 1) 2984 { 2985 // el archivo esta firmado y no se puede eliminar el dataFile 2986 response = Response.status(200).entity("{\"error\": \"el contenedor no está firmado\"}").type("text/plain").build(); 2987 logger.error("el contenedor no está firmado."); 2988 } 2989 else 2990 { 2991 if (signatureId >= signatureNumber) 2992 { 2993 // el dataFileId no es valido 2994 response = Response.status(200).entity("{\"error\": \"el identificador de la firma a eliminar no es valido\"}").type("text/plain").build(); 2995 logger.error("el identificador de la firma a eliminar no es valido."); 2996 } 2997 else 2998 { 2999 // eliminar la firma 3000 container.removeSignature(signatureId); 3001 logger.debug(" eliminada signature: "+Integer.toString(signatureId)); 3002 3003 // serializar el contenedor de nuevo 3004 try { 3005 serialize(container, SERVER_UPLOAD_LOCATION_FOLDER + containerId + "-serialized"); 3006 logger.debug(" serializado contenedor:" + fullPathBdocFile + " serializado."); 3007 3008 json.put("mensaje", "firma eliminada correctamente"); 3009 response = Response.status(200).entity(json.toString()).build(); 3010 3011 } catch (IOException e) { 3012 logger.error("error en la serializacion del contenedor: " + fullPathBdocFile); 3013 response = Response.status(500).entity("{\"error\": \"no se serializar el contenedor\"}").type("text/plain").build(); 3014 } 3015 } 3016 } 3017 } else { 3018 logger.error("El contenedor con id: "+containerId+ " no existe."); 3019 json.put("error", "El contenedor con id: "+containerId+ " no existe."); 3020 response = Response.status(404).entity(json.toString()).build(); 3021 } 3022 return response; 3023 3024 } 3025 3026 // ------------> a seguir 2920 3027 2921 3028 … … 3091 3198 public Response postsignBDOCContainer(PostsignParameters postsignPar) throws IOException, MurachiException { 3092 3199 3093 logger.info("recurso /bdocs/ resenas");3200 logger.info("recurso /bdocs/firmas/post"); 3094 3201 3095 3202 // cadena con la firma … … 3100 3207 // obtener el id del archivo a firmar 3101 3208 String containerId = postsignPar.getContainerId(); 3102 3103 /* 3104 HttpSession session = req.getSession(false); 3105 3106 String fileId = (String) session.getAttribute("fileId"); 3107 System.out.println("fileId: " + fileId); 3108 logger.debug("fileId: " + fileId); 3109 */ 3110 3209 3111 3210 String signedBdoc = containerId + ".bdoc"; 3112 3211 logger.debug(" sigendBdoc: " + signedBdoc); … … 3126 3225 logger.debug("asignada firma al contenedor"); 3127 3226 3128 3227 /* 3129 3228 //deserializedContainer.save(SERVER_UPLOAD_LOCATION_FOLDER + signedBdoc); 3130 3229 serialize(deserializedContainer, SERVER_UPLOAD_LOCATION_FOLDER + containerId + "-serialized"); 3131 3230 logger.debug(" serializado el contenedor: " + SERVER_UPLOAD_LOCATION_FOLDER + containerId + "-serialized"); 3132 3133 // 3134 //File f = new File(serializedContainerId); 3231 */ 3232 3233 3234 // prueba para evitar que las firmas tengan la misma hora de aplicacion 3235 3236 // escribir el contendedor 3237 deserializedContainer.save(SERVER_UPLOAD_LOCATION_FOLDER + containerId + ".bdoc"); 3238 3239 // abrir el contenedor 3240 Configuration configuration = new Configuration(Configuration.Mode.PROD); 3241 configuration.loadConfiguration(DIGIDOC4J_CONFIGURATION); 3242 configuration.setTslLocation(DIGIDOC4J_TSL_LOCATION); 3243 Container c = Container.open(SERVER_UPLOAD_LOCATION_FOLDER + containerId + ".bdoc", configuration); 3244 logger.debug(" contenedor abierto: " + SERVER_UPLOAD_LOCATION_FOLDER + containerId + ".bdoc"); 3245 3246 // serializar el contenedor 3247 serialize(c, SERVER_UPLOAD_LOCATION_FOLDER + containerId + "-serialized"); 3248 logger.debug(" serializado contenedor: " + SERVER_UPLOAD_LOCATION_FOLDER + containerId + "-serialized"); 3249 3250 // eliminar el contenedor guardado 3251 //File f = new File(SERVER_UPLOAD_LOCATION_FOLDER + containerId + ".bdoc"); 3135 3252 //f.delete(); 3136 3253 … … 3156 3273 3157 3274 JSONObject jsonFinalResult = new JSONObject(); 3158 jsonFinalResult.put("signedFileId", containerId );3275 jsonFinalResult.put("signedFileId", containerId+".bdoc"); 3159 3276 3160 3277 logger.info(jsonFinalResult.toString());
Note: See TracChangeset
for help on using the changeset viewer.