Changeset 8105f09 in murachi


Ignore:
Timestamp:
Oct 15, 2015, 5:05:19 PM (9 years ago)
Author:
antonioaraujob <aaraujo@…>
Branches:
master
Children:
f346e17
Parents:
28fc3c9
Message:

Revisión de recurso /cargar para subir un archivo al servidor. Recurso de prueba.

File:
1 edited

Legend:

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

    r28fc3c9 r8105f09  
    127127       
    128128        // debe colocarse la barra al final de la ruta
    129         //private static final String SERVER_UPLOAD_LOCATION_FOLDER = "/tmp/murachi/";
    130         private static final String SERVER_UPLOAD_LOCATION_FOLDER = "/var/lib/tomcat7/murachiWorkingDirectory/";
     129        private static final String SERVER_UPLOAD_LOCATION_FOLDER = "/tmp/murachi/";
     130        //private static final String SERVER_UPLOAD_LOCATION_FOLDER = "/var/lib/tomcat7/murachiWorkingDirectory/";
    131131               
    132132        private static final String SHA256_MESSAGE_DIGEST = "SHA256";
     
    52925292       
    52935293         
    5294         // ************************************************************************
    5295         // ************************************************************************
    5296         // ************************************************************************
     5294// ************************************************************************
     5295// ************************************************************************
     5296// ************************************************************************
    52975297         
     5298        // prueba de Jorge
     5299        @POST
     5300        @Path("/cargar")
     5301        @Consumes(MediaType.MULTIPART_FORM_DATA)
     5302        @Produces(MediaType.APPLICATION_JSON)
     5303        @Authenticator
     5304        public Response uploadFile(FormDataMultiPart formParams) throws MurachiException {
     5305                //return null;
     5306               
     5307                logger.info("recurso /cargar");
     5308                logger.debug("  uploadFile...");
     5309               
     5310                // cadena con la respuesta
     5311                String result = "";
     5312               
     5313                if (formParams == null) {
     5314                        logger.error("solicitud mal formada.");
     5315                        result = "\"error\":\"solicitud mal formada\"";
     5316                        return Response.status(400).entity(result).build();
     5317                }
     5318               
     5319                JSONObject jsonObjectResult = new JSONObject();
     5320               
     5321               
     5322                Map<String, List<FormDataBodyPart>> fieldsByName = formParams.getFields();
     5323                logger.debug("  contenido de Map: " + Integer.toString(fieldsByName.size()));
     5324               
     5325                for (List<FormDataBodyPart> fields : fieldsByName.values())
     5326            {
     5327                for (FormDataBodyPart field : fields)
     5328                {
     5329                    InputStream is = field.getEntityAs(InputStream.class);
     5330                   
     5331                    if (is == null)
     5332                    {
     5333                        // registrar error de firma en estadisticas
     5334                                registerASignatureError(0);
     5335                               
     5336                        logger.debug("is: null");
     5337                        result = "\"error\":\"archivo pasado al recurso es nulo.\"";
     5338                                return Response.status(500).entity(result).build();
     5339                    }             
     5340                   
     5341                    FormDataContentDisposition file = field.getFormDataContentDisposition();               
     5342                    String fileName = file.getFileName();
     5343                    logger.debug("fileName: " + fileName);                 
     5344                   
     5345                    if (fileName == null)
     5346                    {
     5347                        logger.debug("fileName: null");
     5348                        result = "\"error\":\"nombre del archivo pasado al recurso es nulo. Debe especificar un nombre de archivo.\"";
     5349                                return Response.status(500).entity(result).build();
     5350                    }               
     5351                   
     5352                    String mimeType = field.getMediaType().toString();                             
     5353                    logger.debug("mimeType: " + mimeType);
     5354                   
     5355                    if (mimeType == null)
     5356                    {
     5357                        logger.debug("mimeType: null");
     5358                        result = "\"error\":\"tipo mime del archivo pasado al recurso es nulo.\"";
     5359                                return Response.status(500).entity(result).build();
     5360                    }
     5361                             
     5362                    String fileId = UUID.randomUUID().toString();
     5363                    System.out.println(fileId);
     5364                    logger.debug("fileId: " + fileId);
     5365                   
     5366                    try {
     5367                        saveToDisk(is, null, fileId);
     5368                            logger.debug("fileId: " + fileId + "guardado en el sistema de archivos");
     5369                    }
     5370                    catch(MurachiException e) {
     5371                        logger.error("error de carga de archivo: "+ e.getMessage());
     5372                        jsonObjectResult.put("error", "fallo carga del archivo "+fileName+ " al servidor.");
     5373                        result = jsonObjectResult.toString();                   
     5374                        return Response.status(500).entity(result).build();                     
     5375                    }
     5376                    //result = "\"fileId\":" + fileId;
     5377                    jsonObjectResult.put("fileId", fileId);                                               
     5378                }
     5379            }
     5380                //result = "\"msg\":\"continuar con la prueba\"";
     5381               
     5382                result = jsonObjectResult.toString();
     5383               
     5384                return Response.status(200).entity(result).build();             
     5385        }
    52985386         
    5299        
    53005387
    53015388        // pruebas de funciones para gestionar un contenedor BDOC
Note: See TracChangeset for help on using the changeset viewer.