You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by java kurious <ja...@gmail.com> on 2014/10/27 14:32:51 UTC

REST web service with audio as attachment.

Hello all,

I am trying to create a REST web service which accepts HTTP POST request
with a binary attachment(an audio file) and an XML document .

I am trying to define the interface in such a way that the binary file is
received as an attachment/header in Camel message and the XML document as
the body.

So far, I have tried to define the parameters as @Multipart for receiving
attachments. Here is the interface :

*Class RestReceive*

    @POST
    @Path("/")
    public Response receive(@Multipart(type = "application/octet-stream",
value = "audio", required=false) byte[] audio,
                                        @Multipart(type = "text/xml", value
= "description") String description) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

*cxf configuration:*

<cxf:rsServer id="receive-rest-server"
                  address="/contact"
                  serviceClass="RESTReceive"/>


*Route defintion:*

<route id="receive-rest">
            <from
uri="cxfrs:bean:receive-rest-server?bindingStyle=SimpleConsumer"/>

......
.......


The SimpleConsumer binding makes it easier to access the input as headers.
However, the problem remains that the client has to send the audio file as
well as the xml document as attachment.

I tried the alternate definition as following:

    @POST
    @Path("/")
    public Response receive(@Multipart(type = "application/octet-stream",
value = "audio", required=false) byte[] audio,
                                        String description) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

I was expecting that the client can send the audio file as attachment as
text document as body.

But that didn't work. It failed with method does not exist.

Re: REST web service with audio as attachment.

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi

You also need to have @Consumes with the right multipart media type added...
The signature looks fine. What exception are you getting and are you 
sure you have the client sending a multipart formatted request ?

Cheers, Sergey
On 27/10/14 13:32, java kurious wrote:
> Hello all,
>
> I am trying to create a REST web service which accepts HTTP POST request
> with a binary attachment(an audio file) and an XML document .
>
> I am trying to define the interface in such a way that the binary file is
> received as an attachment/header in Camel message and the XML document as
> the body.
>
> So far, I have tried to define the parameters as @Multipart for receiving
> attachments. Here is the interface :
>
> *Class RestReceive*
>
>      @POST
>      @Path("/")
>      public Response receive(@Multipart(type = "application/octet-stream",
> value = "audio", required=false) byte[] audio,
>                                          @Multipart(type = "text/xml", value
> = "description") String description) {
>          throw new UnsupportedOperationException("Not supported yet.");
>      }
>
> *cxf configuration:*
>
> <cxf:rsServer id="receive-rest-server"
>                    address="/contact"
>                    serviceClass="RESTReceive"/>
>
>
> *Route defintion:*
>
> <route id="receive-rest">
>              <from
> uri="cxfrs:bean:receive-rest-server?bindingStyle=SimpleConsumer"/>
>
> ......
> .......
>
>
> The SimpleConsumer binding makes it easier to access the input as headers.
> However, the problem remains that the client has to send the audio file as
> well as the xml document as attachment.
>
> I tried the alternate definition as following:
>
>      @POST
>      @Path("/")
>      public Response receive(@Multipart(type = "application/octet-stream",
> value = "audio", required=false) byte[] audio,
>                                          String description) {
>          throw new UnsupportedOperationException("Not supported yet.");
>      }
>
> I was expecting that the client can send the audio file as attachment as
> text document as body.
>
> But that didn't work. It failed with method does not exist.
>


-- 
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Blog: http://sberyozkin.blogspot.com