users@jersey.java.net

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

From: Craig McClanahan <Craig.McClanahan_at_Sun.COM>
Date: Wed, 29 Apr 2009 12:12:04 -0700

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
>