users@jersey.java.net

[Jersey] Re: how to preserve HTML formatting for a byte[] by Jersey client

From: Jitesh Sinha -X (jisinha - Siliconweb Inc. at Cisco) <"Jitesh>
Date: Tue, 19 Jul 2011 09:09:02 -0700

Can someone please provide help about this?

 

From: Jitesh Sinha -X (jisinha - Siliconweb Inc. at Cisco)
Sent: Monday, July 18, 2011 3:21 PM
To: users_at_jersey.java.net
Subject: [Jersey] how to preserve HTML formatting for a byte[] by Jersey
client

 

Hi All,

 

I need to send a byte[] to a web service.I am writing both client and
web service side code. Somehow when I get byte[] on server side I see
garbled characters in place of bullet points. These bullet points are
absolutely fine at client side.

I get byte[] from an HTML form that has an upload field and Users can
upload a file in UTF-8 encoding.

 

Here is the code at client side -

 

byte[] uploadFile = testCommand.getUploadFile() ;

FormDataMultiPart formData = new FormDataMultiPart() ;

formData.field("uploadFile", uploadFile,
MediaType.MULTIPART_FORM_DATA_TYPE);

 

Client client = Client.create();

                                

WebResource service =
client.resource(AltCsoUtil.loadProperties().getProperty("requestUrl"));

 

ClientResponse response =
service.type(MediaType.MULTIPART_FORM_DATA).header("appKey",appkey).post
(ClientResponse.class,formData);

 

 

Code at server side is pretty simple - I just get this field from Spring
framework's Command class -

Server side code -

byte[] uploadFile = clientCommand.getUploadFile() ;

 

FileOutputStream fos = new FileOutputStream("input.html") ;

                                                

fos.write(clientCommand.getUploadFile()) ;

fos.flush() ;

fos.close() ;

 

I have put same FileOutputStream statements on client side also - it all
comes fine. On server side ,as I said bullet points become garbled.

 

Thanks

-Jitesh