You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Benson Margulies <bi...@gmail.com> on 2012/01/26 22:07:46 UTC

maybe multipart, maybe not

So, say that sometimes something posts multipart/form-data, and other
time it posts some other thing.

Do I need two JAX-RS service functions, or if I declare Consumes("*")
and have a MultipartBody param (and an InputStream param?) will CXF
just null or not null the right one?

Re: maybe multipart, maybe not

Posted by Sergey Beryozkin <sb...@gmail.com>.
Yes, for a combined case you can just say "*/*" or just omit @Consumes

Sergey

On 26/01/12 21:32, Benson Margulies wrote:
> application/octet-stream? Can't I say "*"? Someone might send text/html.
>
> On Thu, Jan 26, 2012 at 4:26 PM, Sergey Beryozkin<sb...@gmail.com>  wrote:
>> On 26/01/12 21:07, Benson Margulies wrote:
>>>
>>> So, say that sometimes something posts multipart/form-data, and other
>>> time it posts some other thing.{
>>>
>>> Do I need two JAX-RS service functions, or if I declare Consumes("*")
>>> and have a MultipartBody param (and an InputStream param?) will CXF
>>> just null or not null the right one?
>>
>>
>> One option is indeed to have two methods, one with
>>
>> @Consumes({"multipart/form-data"}),
>>
>> and another one with say
>>
>> @Consumes({"application/octet-stream"})
>>
>> The other option is to get them combined:
>>
>>
>> @Context
>> private MessageContext mc;
>>
>> @Consumes({"multipart/form-data", "application/octet-stream"})
>> public void upload(InputStream is) {
>>
>>    MediaType contentType = mc.getHttpHeaders().getMediaType();
>>    if (contentType.equals("multipart/form-data")) {
>>        MultipartBody body = AttachmentUtils.getMultipartBody(mc);
>>        ...
>>    } else {
>>        // read the is
>>    }
>>
>>
>> }
>>
>>
>> HTH
>> Sergey

Re: maybe multipart, maybe not

Posted by Benson Margulies <bi...@gmail.com>.
application/octet-stream? Can't I say "*"? Someone might send text/html.

On Thu, Jan 26, 2012 at 4:26 PM, Sergey Beryozkin <sb...@gmail.com> wrote:
> On 26/01/12 21:07, Benson Margulies wrote:
>>
>> So, say that sometimes something posts multipart/form-data, and other
>> time it posts some other thing.{
>>
>> Do I need two JAX-RS service functions, or if I declare Consumes("*")
>> and have a MultipartBody param (and an InputStream param?) will CXF
>> just null or not null the right one?
>
>
> One option is indeed to have two methods, one with
>
> @Consumes({"multipart/form-data"}),
>
> and another one with say
>
> @Consumes({"application/octet-stream"})
>
> The other option is to get them combined:
>
>
> @Context
> private MessageContext mc;
>
> @Consumes({"multipart/form-data", "application/octet-stream"})
> public void upload(InputStream is) {
>
>   MediaType contentType = mc.getHttpHeaders().getMediaType();
>   if (contentType.equals("multipart/form-data")) {
>       MultipartBody body = AttachmentUtils.getMultipartBody(mc);
>       ...
>   } else {
>       // read the is
>   }
>
>
> }
>
>
> HTH
> Sergey

Re: maybe multipart, maybe not

Posted by Sergey Beryozkin <sb...@gmail.com>.
On 26/01/12 21:07, Benson Margulies wrote:
> So, say that sometimes something posts multipart/form-data, and other
> time it posts some other thing.{
>
> Do I need two JAX-RS service functions, or if I declare Consumes("*")
> and have a MultipartBody param (and an InputStream param?) will CXF
> just null or not null the right one?

One option is indeed to have two methods, one with

@Consumes({"multipart/form-data"}),

and another one with say

@Consumes({"application/octet-stream"})

The other option is to get them combined:


@Context
private MessageContext mc;

@Consumes({"multipart/form-data", "application/octet-stream"})
public void upload(InputStream is) {

    MediaType contentType = mc.getHttpHeaders().getMediaType();
    if (contentType.equals("multipart/form-data")) {
        MultipartBody body = AttachmentUtils.getMultipartBody(mc);
        ...
    } else {
        // read the is
    }


}


HTH
Sergey