Changeset 0f76179 in murachi


Ignore:
Timestamp:
Jul 1, 2015, 5:56:29 PM (9 years ago)
Author:
antonioaraujob <aaraujo@…>
Branches:
master
Children:
4c2406e
Parents:
b1392c3
Message:

Avance en la implementación del recurso /bdocs/archivos/{fileId}/{dataFileId} para obtener el archivo identificado con dataFileId que se encuentra dentro del contenedor BDOC fileId.

File:
1 edited

Legend:

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

    rb1392c3 r0f76179  
    21512151       
    21522152       
    2153        
    2154        
    2155        
    2156        
    2157        
    2158        
     2153        @GET
     2154        @Path("/bdocs/archivos/{fileId}/{dataFileId}")
     2155        @Produces(MediaType.APPLICATION_OCTET_STREAM)
     2156        public Response downloadDataFileFromBDOC(@PathParam("fileId")  String fileId, @PathParam("dataFileId")  int dataFileId) {
     2157                logger.info("/bdocs/archivos/"+fileId+"/"+Integer.toString(dataFileId));
     2158               
     2159                String fullPathBdocFile = SERVER_UPLOAD_LOCATION_FOLDER + fileId;
     2160               
     2161                Response response;
     2162               
     2163                // Retrieve the file
     2164            File file = new File(fullPathBdocFile);
     2165            if (file.exists()) {
     2166                               
     2167                Security.addProvider(new BouncyCastleProvider());
     2168                        Container container = null;
     2169                       
     2170                        Configuration configuration = new Configuration(Configuration.Mode.PROD);
     2171                        configuration.loadConfiguration(DIGIDOC4J_CONFIGURATION);
     2172                        configuration.setTslLocation(DIGIDOC4J_TSL_LOCATION);
     2173               
     2174                        container = Container.open(fullPathBdocFile, configuration);
     2175                        logger.debug("open container: "+ fullPathBdocFile);
     2176                       
     2177                        int dfSize = container.getDataFiles().size();
     2178                       
     2179                        if (dataFileId > dfSize-1)
     2180                        {
     2181                                // no existe el dataFile con el id pasado como argumento
     2182                                response = Response.status(404).entity("{\"error\": \"el dataFileId solicitado no existe\"}").type("text/plain").build();
     2183                                logger.error("el dataFileId solicitado: "+Integer.toString(dataFileId)+ " no existe.");
     2184                        }
     2185                        else
     2186                        {
     2187                                // el dataFile es valido
     2188                                DataFile df = container.getDataFile(dataFileId);
     2189                                logger.debug("obtenido DataFile: "+Integer.toString(dataFileId));
     2190                               
     2191                                df.saveAs("/tmp/extraido.jpg");
     2192                                logger.debug("obtenido DataFile: /tmp/extraido.jpg");
     2193                               
     2194                                File fileToDownload = new File("/tmp/extraido.jpg");
     2195                               
     2196                                ResponseBuilder builder = Response.ok(fileToDownload);
     2197                        builder.header("Content-Disposition", "attachment; filename=" + fileToDownload.getName());
     2198                        response = builder.build();
     2199                               
     2200                               
     2201                                //response = Response.status(200).entity("{\"DataFileExist\": true}").type("text/plain").build();
     2202                               
     2203                        }
     2204                       
     2205               
     2206               
     2207            } else {
     2208                logger.error("El archivo con id: "+fileId+ " no existe.");
     2209                response = Response.status(404).entity("{\"fileExist\": false}").type("text/plain").build();
     2210            }
     2211               
     2212                return response;
     2213        }
     2214       
     2215       
     2216       
     2217       
     2218        // ************************************************************************
     2219        // ************************************************************************
     2220        // ************************************************************************
    21592221       
    21602222        private static void verifyBdocContainer(Container container) {
Note: See TracChangeset for help on using the changeset viewer.