On May 11, 2008, at 2:04 AM, Jyothsna L wrote:
>
> 1) while testing the POST of restful web services, I always get a
> string content as parameter that needs to be filled while posting.
> so , I am parsing the string based some delimiters like comma and
> then saving each element in database.
> for example my database has email,name as its columns in one table.
> so if my POST parameter : content has jyothsna_at_yahoo.com, jyothsna.
> I am parsing it into two elements jyothsna_at_yahoo.com(email) and
> jyothsna(name).
> and then I am creating entries in the table.
>
> I tried to add two parameters to postxml() instead of one. but, its
> not working properly.
>
> so do you suggesting parsing one single parameter or is there any
> other good way to have multiple parameters.
>
The body of a post is mapped to a single parameter but you can use a
custom type for that parameter. If you do that you need to create a
MessageBodyReader<CustomType> which Jersey will use to convert the
posted data into an instance of the custom type.
> my second question
> 2)
>
> I need to upload an image file to the backend. I want to save the
> file on disk and its URL in the database.
>
> I am using restful webservices and ejb module.
>
> here the http PUT method definition.
> Since, I will be uploading an image, i am consuming multipart/form-
> data.
> I dont know how to handle the file. I have the struts and jersey
> plugins too. I am new to struts and a bit familiar with
> jersey(restful).
>
> @PUT
> @ConsumeMime("multipart/form-data")
> public void putXml(@PathParam("id")
> String id, MimeMultipart data ) {
> Images newImage= new Images();
> newImage.setImageURL(url);//just showing the methods
> available for Images object. this statement is not completely correct
> I need to save
> the image file on disk and set its location in the imageresource.
> newImage.setImagename(name); // 'name' needs to be extracted
> from the MimeMultipart or whatever..just wanted to show available
> methods for Images object.
> lookupImagesFacade().create(newImage);
> }
>
> My question is : how will i be able to save the file on disk and its
> url on database based on the template i have above. is the
> "MimeMultipart data " correct in the above code. which package has
> this "MimeMultipart"( I see there are different kinds of packages
> java mail etc.)
>
javax.mail.internet.MimeMultipart is the correct type. You can use
this type to get at all the parts of the message based on index or
content ID.
Marc.
---
Marc Hadley <marc.hadley at sun.com>
CTO Office, Sun Microsystems.