users@jersey.java.net

[Jersey] Re: How to post a file and other form fields by Jersey client

From: Pavel Bucek <pavel.bucek_at_oracle.com>
Date: Mon, 27 Jun 2011 20:34:18 +0200

not any type, just these noted in specification, but answer should be "yes".

You should be able to have something like:

server side:

@Path("myresource")
public class MyResource {

     @GET
     public File getFile() {
         return new File(...);
     }
}


and client:

Client c = Client.create();
WebResource wr = c.resource("http://contextRoot/myresource");
File f = wr.get(File.class);


// same for InputStream..


On 6/27/11 8:29 PM, Jitesh Sinha -X (jisinha - Siliconweb Inc. at Cisco)
wrote:
> So we can set any Java type(in this case File/InputStream) on server
> side and get the same type on client side - isn't it?
>
> -----Original Message-----
> From: Pavel Bucek [mailto:pavel.bucek_at_oracle.com]
> Sent: Monday, June 27, 2011 11:27 AM
> To: users_at_jersey.java.net
> Subject: [Jersey] Re: How to post a file and other form fields by Jersey
> client
>
> Ooops. Please disregard my last message.
>
> Jersey should (as any other JAX-RS implementation) support File out of
> the box. So.. you should be able to get it (same way as with
> InputStream):
>
> ClientResponse cr = ....
> File f = cr.getEntity(File.class);
>
>
>
> On 6/27/11 8:19 PM, Pavel Bucek wrote:
>> You should be able to get InputStream (File in java is used for
>> different purposes and AFAIK it can't exist without alignment to
>> filesystem).. simply try
>>
>> ClientResponse cr = ....
>> InputStream is = cr.getEntity(InputStream.class);
>>
>> You can do whatever you like with that afterwards, for example save it
>> as a file..
>>
>> Pavel
>>
>> On 6/24/11 10:36 PM, Jitesh Sinha -X (jisinha - Siliconweb Inc. at
>> Cisco) wrote:
>>> That worked! Thanks.
>>>
>>> Now I am having another issue. I need to get a file that is being
> sent
>>> from server side as an attachment.I am using Jersey client on client
>>> side.
>>>
>>> Here is the server side code -
>>>
>>> String fileToDownload = "Result.zip";
>>> response.setContentType("application/octet-stream");
>>> response.setHeader("Content-Disposition", "attachment;
>>> filename=\""
>>> + fileToDownload + "\"");
>>> ServletOutputStream sos = null;
>>> try {
>>> sos = response.getOutputStream();
>>> } catch (IOException ioex) {
>>> System.out.println("streamForDownload:::::::" +
>>> ioex);
>>> }
>>>
>>>
>>>
>>> How can I get the file from ClientResponse object on client side?
>>>
>>> Thanks
>>> -Jitesh
>>>
>>> -----Original Message-----
>>> From: Pavel Bucek [mailto:pavel.bucek_at_oracle.com]
>>> Sent: Thursday, June 23, 2011 12:13 AM
>>> To: users_at_jersey.java.net
>>> Subject: [Jersey] Re: How to post a file and other form fields by
> Jersey
>>> client
>>>
>>> yes, that will work.
>>>
>>> On 6/23/11 3:29 AM, Jitesh wrote:
>>>> Do I put it into response entity on server side like this -
>>>>
>>>> Response.ok(String.valueOf(Id)).build() ;
>>>>
>>>> where Response is javax.ws.rs.core.Response .
>>>>
>>>> and then I get it as you have mentioned in your post?
>>>>
>>>> Thanks
>>>> -Jitesh
>>>>
>>>> --
>>>> View this message in context:
> http://jersey.576304.n2.nabble.com/How-to-post-a-file-and-other-form-fie
>>> lds-by-Jersey-client-tp6502947p6506822.html
>>>> Sent from the Jersey mailing list archive at Nabble.com.
>>>>
>>
>