Examples of BodyPartEntity


Examples of com.sun.jersey.multipart.BodyPartEntity

        String street1=null, street2=null, city=null, state=null, zip=null, timezone=null, country=null;
        String contentHeader=null, filename=null;
        InputStream imageStream = null;
        boolean doesExist = false;

        BodyPartEntity bpe = null;
        MultivaluedMap <String, String> mvMap = null;
        List<String> headerList = null;

         Map<String,List<FormDataBodyPart>> bodyList = multiPart.getFields();
         for (String key:bodyList.keySet()){
             logger.finer("key is "+ key);
         }
         //if(multiPart.getField("first_name")!=null) firstName = multiPart.getField("first_name").getValue();
         userName = getFieldValue(multiPart, USERNAME, true);
         //determine if this is an update or create
         personEntity = mf.getPerson(userName);
         doesExist =  personEntity == null ? false : true;

         firstName = getFieldValue(multiPart, FIRSTNAME, true);
         lastName = getFieldValue(multiPart, LASTNAME, true);
         password = getFieldValue(multiPart, PASSWORD, true);
         summary = getFieldValue(multiPart, SUMMARY, false);
         telephone = getFieldValue(multiPart,TELEPHONE, false);
         email = getFieldValue(multiPart, EMAIL, false);
         timezone = getFieldValue(multiPart, TIMEZONE, false);
         logger.finer("in POST - multipart first name is "+ firstName);

         //address
         street1 = getFieldValue(multiPart, STREET1, false);
         street2 = getFieldValue(multiPart, STREET2, false);
         city = getFieldValue(multiPart, CITY, false);
         state = getFieldValue(multiPart, STATE, false);
         zip =  getFieldValue(multiPart, ZIP, false);
         country = getFieldValue(multiPart, COUNTRY, false);
         Address address=WebappUtil.handleAddress(null, street1, street2, city, state, zip, country);

       
         //image processing
         if(multiPart.getField(IMAGEFILE)!=null){
            bpe = ((BodyPartEntity) multiPart.getField(IMAGEFILE).getEntity());
            logger.finer("the value of the imageFile body part is "+ multiPart.getField(IMAGEFILE).getHeaders());
            mvMap = multiPart.getField(IMAGEFILE).getHeaders();
            headerList  =  (List)mvMap.get("Content-Disposition");
            contentHeader = headerList.get(0);
            filename = WebappUtil.parseValueFromHeader(contentHeader, "filename");
            imageStream = bpe.getInputStream();
         } else {
             logger.finer("parameter " + IMAGEFILE + " is missing");
         }

         /* temporary - testing multipart post
         File tempFile = new File("/tmp/copyImagefile.jpg");
         FileOutputStream fos = new FileOutputStream(tempFile);
         BufferedImage bi = ImageIO.read(stream);
         ImageIO.write(bi, "jpg", tempFile);
         fos.flush();
         fos.close();
         bpe.cleanup();
          */
         
         HashMap<String,String> fileInfo = saveImageWithThumbnail(userName, imageStream, filename);
          
         //create Person
         Person person = new Person(userName, password, firstName, lastName,
                 summary, email, telephone, fileInfo.get(FILE_LOCATION), fileInfo.get(THUMBNAIL_LOCATION), timezone, address);
          mf = (ModelFacade)getServletContext().getAttribute(WebConstants.MF_KEY);
         if (!doesExist)
            userName = mf.addPerson(person);
         else
            mf.updatePerson(person);
         logger.finer("after adding/updating person " + userName);

         //cleanup
         imageStream.close();
         //delete the temporary file from multipart
         bpe.cleanup();


         return Response.ok().build();

    }
View Full Code Here

Examples of com.sun.jersey.multipart.BodyPartEntity

            } catch (IllegalArgumentException ex) {
                throw new WebApplicationException(ex, Status.BAD_REQUEST);
            }

            // Copy data into a BodyPartEntity structure
            bodyPart.setEntity(new BodyPartEntity(mp));
            // Add this BodyPart to our MultiPart
            multiPart.getBodyParts().add(bodyPart);
        }

        return multiPart;
View Full Code Here

Examples of com.sun.jersey.multipart.BodyPartEntity

        BodyPart part1 = multiPart.getBodyParts().get(1);
        if (!(part1.getMediaType().equals(new MediaType("x-application", "x-format")))) {
            return Response.ok("FAILED:  Second media type is " + part1.getMediaType()).build();
        }

        BodyPartEntity bpe = (BodyPartEntity) part0.getEntity();
        StringBuilder sb = new StringBuilder();
        InputStream stream = bpe.getInputStream();
        InputStreamReader reader = new InputStreamReader(stream);
        char[] buffer = new char[2048];
        while (true) {
            int n = reader.read(buffer);
            if (n < 0) {
View Full Code Here

Examples of com.sun.jersey.multipart.BodyPartEntity

        if (!(mp.getBodyParts().size() == 2)) {
            return Response.ok("FAILED:  Body part count is " + mp.getBodyParts().size() + " instead of 2").build();
        } else if (!(mp.getBodyParts().get(1).getEntity() instanceof BodyPartEntity)) {
            return Response.ok("FAILED:  Second body part is " + mp.getBodyParts().get(1).getClass().getName() + " instead of BodyPartEntity").build();
        }
        BodyPartEntity bpe = (BodyPartEntity) mp.getBodyParts().get(1).getEntity();
        try {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            InputStream stream = bpe.getInputStream();
            byte[] buffer = new byte[2048];
            while (true) {
                int n = stream.read(buffer);
                if (n < 0) {
                    break;
View Full Code Here

Examples of com.sun.jersey.multipart.BodyPartEntity

    @Path("eleven")
    @PUT
    @Consumes("multipart/mixed")
    @Produces("multipart/mixed")
    public Response eleven(MultiPart multiPart) throws IOException {
        BodyPartEntity bpe = (BodyPartEntity) multiPart.getBodyParts().get(0).getEntity();
        StringBuilder sb = new StringBuilder();
        InputStream stream = bpe.getInputStream();
        InputStreamReader reader = new InputStreamReader(stream);
        char[] buffer = new char[2048];
        while (true) {
            int n = reader.read(buffer);
            if (n < 0) {
View Full Code Here

Examples of com.sun.jersey.multipart.BodyPartEntity

                                final Map<String, String> parameters = contentDisposition.getParameters();
                                if (parameters != null) {
                                    final String name = parameters.get("name");
                                    if ("photo".equals(name)) {
                                        // found the photo part
                                        final BodyPartEntity bodyPartEntity = (BodyPartEntity)bodyPart.getEntity();
                                        photoBytes = IOUtils.toByteArray(bodyPartEntity.getInputStream());
                                    }
                                    else if ("metadata".equals(name)) {
                                        // found the metadata part
                                        jsonMetadata = bodyPart.getEntityAs(String.class);
                                    }
View Full Code Here

Examples of com.sun.jersey.multipart.BodyPartEntity

                                final Map<String, String> parameters = contentDisposition.getParameters();
                                if (parameters != null) {
                                    final String name = parameters.get("name");
                                    if ("photo".equals(name)) {
                                        // found the photo part
                                        final BodyPartEntity bodyPartEntity = (BodyPartEntity)bodyPart.getEntity();
                                        photoBytes = IOUtils.toByteArray(bodyPartEntity.getInputStream());
                                    }
                                    else if ("metadata".equals(name)) {
                                        // found the metadata part
                                        jsonMetadata = bodyPart.getEntityAs(String.class);
                                    }
View Full Code Here

Examples of com.sun.jersey.multipart.BodyPartEntity

        BodyPart part1 = multiPart.getBodyParts().get(1);
        if (!(part1.getMediaType().equals(new MediaType("x-application", "x-format")))) {
            return Response.ok("FAILED:  Second media type is " + part1.getMediaType()).build();
        }

        BodyPartEntity bpe = (BodyPartEntity) part0.getEntity();
        StringBuilder sb = new StringBuilder();
        InputStream stream = bpe.getInputStream();
        InputStreamReader reader = new InputStreamReader(stream);
        char[] buffer = new char[2048];
        while (true) {
            int n = reader.read(buffer);
            if (n < 0) {
View Full Code Here

Examples of com.sun.jersey.multipart.BodyPartEntity

        if (!(mp.getBodyParts().size() == 2)) {
            return Response.ok("FAILED:  Body part count is " + mp.getBodyParts().size() + " instead of 2").build();
        } else if (!(mp.getBodyParts().get(1).getEntity() instanceof BodyPartEntity)) {
            return Response.ok("FAILED:  Second body part is " + mp.getBodyParts().get(1).getClass().getName() + " instead of BodyPartEntity").build();
        }
        BodyPartEntity bpe = (BodyPartEntity) mp.getBodyParts().get(1).getEntity();
        try {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            InputStream stream = bpe.getInputStream();
            byte[] buffer = new byte[2048];
            while (true) {
                int n = stream.read(buffer);
                if (n < 0) {
                    break;
View Full Code Here

Examples of com.sun.jersey.multipart.BodyPartEntity

    @Path("eleven")
    @PUT
    @Consumes("multipart/mixed")
    @Produces("multipart/mixed")
    public Response eleven(MultiPart multiPart) throws IOException {
        BodyPartEntity bpe = (BodyPartEntity) multiPart.getBodyParts().get(0).getEntity();
        StringBuilder sb = new StringBuilder();
        InputStream stream = bpe.getInputStream();
        InputStreamReader reader = new InputStreamReader(stream);
        char[] buffer = new char[2048];
        while (true) {
            int n = reader.read(buffer);
            if (n < 0) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.