users@jersey.java.net

Re: [Jersey] sending word doc file as attachment using jersey-multipart [NC]

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Thu, 30 Apr 2009 11:39:39 +0200

Hi,

As i said you need to verify whether bytes you are sending are the
same as the bytes you are receiving.

You can utilize any media type when sending content using byte[] or
InputStream, there is no restriction or modification of the octets
that are sent.

Attached is a very simple maven example testing uploading of content
directly or using mutlipart/mixed. The example verifies that the bytes
received are the same as those sent. I cannot reproduce your error.

You can modify the source to change the location of where the original
bytes are obtained from (just change the URL e.g. point to an MS word
file online) or change the code to create the bytes from an MS word
document.

Paul.






On Apr 30, 2009, at 6:56 AM, Vidhya MAHADEVAN wrote:

> Thankyou Craig and Paul.
> Here is some more data on my problem.
> Simple docs that dont have any complex content (like images etc)
> work fine.
> Images , exe dont work.
>
> I have tried setting the octet-stream.
> I have used byte[] and stream to the entity for a body part.
> This does not work though.
>
> Does jersey client support all these media content types ?
> http://www.usf.uni-osnabrueck.de/infoservice/wwwfaq/mime.htm
>
> Thanks again,
> Vidhya
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> |------------------------------
> | Craig McClanahan
> | <Craig.McClanahan
> | @Sun.COM>
> | Sent by:
> | Craig.McClanahan@
> | Sun.COM
> |
> |
> | 04/30/2009 12:42
> | AM
> |
>
>
> To
>
> users_at_jersey.dev.java.net
> cc
> Vidhya
> MAHADEVAN/ia/
> socgen_at_socgen
>
> Subject
> Re: [Jersey] sending
> word
> doc file as attachment
> using jersey-multipart
> [C1]
>
>
>
>
>
>
>
>
>
>
> Craig McClanahan wrote:
>> Paul Sandoz wrote:
>>> Hi,
>>>
>>> What client are you using? How are you sending the MIME multipart
>>> message?
>>>
>>> Can you present the code for the resource class and resource method
>>> that is consuming the mime body part that contains the binary
>>> document?
>>>
>>> Is it possible to do compare byte-per-byte compare tests of the
>>> source bytes and received bytes?
>>>
>>> Since you are sending binary documents as MIME body parts there is
>>> no
>>> specific reader/writer as you are just dealing with either byte[] or
>>> InputStream.
>>>
>> I would definitely suggest using one of these two approaches, so you
>> don't have to write a MessageBodyWriter of your own. The simplest
>> approach might be to open an InputStream to the bytes of your word
>> document, and use that stream as the "entity" for a body part. You'd
>> also want to set the media type for this body part to
>> "application/octet-stream".
>>> Paul.
>> Craig
>>
> I should also mention that, if you really *do* want to get your hands
> dirty with MBR/MBW implementations, the jersey-multipart source code
> itself includes such implementations for the MultiPart class. If you
> check out the source tree of the Jersey subversion repository, check
> out
> the following files:
>
> *
> contribs/jersey-multipart/src/main/java/com/sun/jersey/multipart/
> impl/MultiPartWriter.java
>
> *
> contribs/jersey-multipart/src/main/java/com/sun/jersey/multipart/
> impl/MultiPartReader.java
>
>
> The first class is used when writing out a MultiPart instance into the
> "multipart/mixed" (or whatever) format that corresponds to the
> standard. There's a bit of trickery inside that reuses the standard
> Jersey providers for each body part (so that the multipart can contain
> any media type that Jersey already has support for). The second class
> is used at the opposite end, to convert the byte stream of the
> incoming
> message back in to a MultiPart instance with appropriate BodyPart
> children.
>
> The fact that Jersey gave me the capability to do this (and not have
> to
> go reinvent a translation mechanism for all the body parts) is *way*
> cool ... props to Paul and the Jersey team for making it possible.
>
> Craig
>
>>>
>>> On Apr 29, 2009, at 10:51 AM, Vidhya MAHADEVAN wrote:
>>>
>>>>
>>>>
>>>> Hello,
>>>> I have a requirement to send a word doc file to a RESTful service
>>>> built
>>>> using Jersey 1.0.3.
>>>> I am using jersey-multipart for this purpose.
>>>> The file is sent. But then, I have a problem with the file being
>>>> unreadable
>>>> although the number of bytes of the source and destination file
>>>> are the
>>>> same.
>>>> This works well with txt or XML files though
>>>> I read some posts by Craig Mclanahan on custom MessageBodyWriters.
>>>> Would you have any samples for custom MessageBodyWriters that can
>>>> handle
>>>> word doc, excel files, exe files ?
>>>>
>>>>
>>>> Appreciate any response,
>>>> Vidhya
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
> *************************************************************************
>>>>
>>>> This message and any attachments (the "message") are confidential,
>>>> intended solely for the addressee(s), and may contain legally
>>>> privileged information.
>>>> Any unauthorised use or dissemination is prohibited. E-mails are
>>>> susceptible to alteration.
>>>> Neither SOCIETE GENERALE nor any of its subsidiaries or affiliates
>>>> shall be liable for the message if altered, changed or
>>>> falsified.
>>>> ************
>>>> Ce message et toutes les pieces jointes (ci-apres le "message")
>>>> sont
>>>> confidentiels et susceptibles de contenir des informations
>>>> couvertes
>>>> par le secret professionnel.
>>>> Ce message est etabli a l'intention exclusive de ses destinataires.
>>>> Toute utilisation ou diffusion non autorisee est interdite.
>>>> Tout message electronique est susceptible d'alteration.
>>>> La SOCIETE GENERALE et ses filiales declinent toute responsabilite
>>>> au titre de ce message s'il a ete altere, deforme ou falsifie.
>>>>
> *************************************************************************
>>>>
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>>>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>