Changeset 9ab4eef in murachi
- Timestamp:
- May 6, 2015, 9:15:42 AM (9 years ago)
- Branches:
- master
- Children:
- 7c45d87
- Parents:
- 83a7c4e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
murachi/src/main/java/ve/gob/cenditel/murachi/MurachiRESTWS.java
r83a7c4e r9ab4eef 39 39 import java.util.UUID; 40 40 import java.text.DateFormat; 41 import java.text.NumberFormat; 41 42 import java.text.SimpleDateFormat; 42 43 … … 110 111 111 112 import ve.gob.cenditel.murachi.MurachiException; 113 import org.apache.log4j.Logger; 112 114 113 115 @Path("/archivos") 114 116 public class MurachiRESTWS { 115 117 118 static Logger logger = Logger.getLogger(MurachiRESTWS.class); 119 120 private static final String api_version = "0.1.0"; 121 116 122 private static final String SERVER_UPLOAD_LOCATION_FOLDER = "/tmp/"; 117 123 … … 130 136 private static boolean bdocVerboseMode = true; 131 137 138 /** 139 * Retorna la version del api del servicio 140 * @return version del api del servicio 141 */ 142 @Path("/version") 143 @GET 144 @Produces(MediaType.TEXT_HTML) 145 public String returnVersion() { 146 return "<p>Murachi Version: " + api_version + "</p>"; 147 } 132 148 133 149 /** … … 139 155 * @return 140 156 * @throws MurachiException 141 */ 142 157 */ 143 158 @POST 144 159 @Path("/") … … 181 196 } 182 197 198 /** 199 * Descarga un archivo existente en el servidor 200 * @param fileName nombre (identificador) del archivo que se desea descargar 201 * @return archivo existente en el servidor y pasado como argumento 202 */ 203 @GET 204 @Path("/descargas/{filename}") 205 @Produces(MediaType.APPLICATION_OCTET_STREAM) 206 public Response downloadFilebyPath(@PathParam("filename") String fileName) { 207 return downloadFileFromServer(fileName); 208 } 209 210 /** 211 * Descarga un archivo pasado como argumento del servidor 212 * @param fileName nombre o identificador del archivo que se desea descargar 213 * @return archivo pasado como argumento del servidor 214 */ 215 private Response downloadFileFromServer(String fileName) { 216 String fileLocation = SERVER_UPLOAD_LOCATION_FOLDER + fileName; 217 Response response = null; 218 NumberFormat myFormat = NumberFormat.getInstance(); 219 myFormat.setGroupingUsed(true); 220 221 // Retrieve the file 222 File file = new File(SERVER_UPLOAD_LOCATION_FOLDER + fileName); 223 if (file.exists()) { 224 ResponseBuilder builder = Response.ok(file); 225 builder.header("Content-Disposition", "attachment; filename=" + file.getName()); 226 response = builder.build(); 227 228 long file_size = file.length(); 229 logger.info(String.format("Inside downloadFile==> fileName: %s, fileSize: %s bytes", 230 fileName, myFormat.format(file_size))); 231 } else { 232 logger.error(String.format("Inside downloadFile==> FILE NOT FOUND: fileName: %s", 233 fileName)); 234 235 response = Response.status(404).entity("FILE NOT FOUND: " + fileLocation). 236 type("text/plain").build(); 237 } 238 239 return response; 240 } 241 183 242 184 243 /**
Note: See TracChangeset
for help on using the changeset viewer.