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 <be...@basistech.com> on 2015/07/29 20:03:50 UTC

Consuming multi-part/mixed

The WADL for this shows only one parameter. Did I miss something?


@POST
@Consumes("multipart/mixed")
@Produces({"application/json", "application/x-jackson-smile"})
@Path("annotate")
public Response annotate(
    @Multipart(value = "options", type = "application/json")
    Map<String, String> options,
    @Multipart(value = "text") InputStream text) throws IOException,
RosetteException {

    final ObjectMapper mapper = getMapper();
    AnnotatedText inputText = mapper.readValue(text, AnnotatedText.class);
    final AnnotatedText result = pipeline.createAnnotator().annotate(inputText);

    StreamingOutput stream = new StreamingOutput() {
        @Override
        public void write(OutputStream os) throws IOException,
WebApplicationException {
            mapper.writeValue(os, result);
        }
    };
    return Response.ok(stream).build();
}

Re: Consuming multi-part/mixed

Posted by Sergey Beryozkin <sb...@gmail.com>.
Multipart annotation references application/json, so I guess it can be 
referenced too, though WADL says that representation parameters are 
simple ones. On the other hand WADL describing multipart is in itself 
quite undefined so may be we can indeed refer to complex parameters...

Sergey
On 30/07/15 19:45, Sergey Beryozkin wrote:
> Hi Benson
> I see WADLGenerator restricting that only simple or InputStream types
> are recognized as multipart parameters, I can deal with it next week
> once I got back, though the best you'll get is a WADL request
> representation fragment with two parameters of type xs:anyType in this case
>
> Cheers, Sergey
> On 29/07/15 21:07, Benson Margulies wrote:
>> <application xmlns="http://wadl.dev.java.net/2009/02"
>> xmlns:xs="http://www.w3.org/2001/XMLSchema">
>> <grammars/>
>> <resources base="http://192.168.59.103:8181/cxf/annotator">
>> <resource path="/">
>> <resource path="annotate">
>> <method name="POST">
>> <request>
>> <representation mediaType="multipart/mixed">
>> <param name="text" style="query" type="xs:anyType"/>
>> </representation>
>> </request>
>> <response>
>> <representation mediaType="application/json"/>
>> <representation mediaType="application/x-jackson-smile"/>
>> </response>
>> </method>
>> </resource>
>> <resource path="annotatePlain">
>> <method name="POST">
>> <request>
>> <representation mediaType="text/plain">
>> <param name="request" style="plain" type="xs:string"/>
>> </representation>
>> </request>
>> <response>
>> <representation mediaType="application/json"/>
>> </response>
>> </method>
>> </resource>
>> </resource>
>> </resources>
>> </application>
>>
>> On Wed, Jul 29, 2015 at 2:07 PM, Benson Margulies
>> <be...@basistech.com> wrote:
>>> Here's the perplexing wadl...
>>>
>>> On Wed, Jul 29, 2015 at 2:03 PM, Benson Margulies
>>> <be...@basistech.com> wrote:
>>>> The WADL for this shows only one parameter. Did I miss something?
>>>>
>>>>
>>>> @POST
>>>> @Consumes("multipart/mixed")
>>>> @Produces({"application/json", "application/x-jackson-smile"})
>>>> @Path("annotate")
>>>> public Response annotate(
>>>>      @Multipart(value = "options", type = "application/json")
>>>>      Map<String, String> options,
>>>>      @Multipart(value = "text") InputStream text) throws IOException,
>>>> RosetteException {
>>>>
>>>>      final ObjectMapper mapper = getMapper();
>>>>      AnnotatedText inputText = mapper.readValue(text,
>>>> AnnotatedText.class);
>>>>      final AnnotatedText result =
>>>> pipeline.createAnnotator().annotate(inputText);
>>>>
>>>>      StreamingOutput stream = new StreamingOutput() {
>>>>          @Override
>>>>          public void write(OutputStream os) throws IOException,
>>>> WebApplicationException {
>>>>              mapper.writeValue(os, result);
>>>>          }
>>>>      };
>>>>      return Response.ok(stream).build();
>>>> }
>


-- 
Sergey Beryozkin

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

Blog: http://sberyozkin.blogspot.com

Re: Consuming multi-part/mixed

Posted by Benson Margulies <be...@basistech.com>.
Thanks. I don't actually need a good WADL, I thought that the WADL was
a symptom for other problems but it turned out to be unrelated.


On Thu, Jul 30, 2015 at 12:45 PM, Sergey Beryozkin <sb...@gmail.com> wrote:
> Hi Benson
> I see WADLGenerator restricting that only simple or InputStream types are
> recognized as multipart parameters, I can deal with it next week once I got
> back, though the best you'll get is a WADL request representation fragment
> with two parameters of type xs:anyType in this case
>
> Cheers, Sergey
> On 29/07/15 21:07, Benson Margulies wrote:
>>
>> <application xmlns="http://wadl.dev.java.net/2009/02"
>> xmlns:xs="http://www.w3.org/2001/XMLSchema">
>> <grammars/>
>> <resources base="http://192.168.59.103:8181/cxf/annotator">
>>
>> <resource path="/">
>> <resource path="annotate">
>> <method name="POST">
>> <request>
>> <representation mediaType="multipart/mixed">
>> <param name="text" style="query" type="xs:anyType"/>
>> </representation>
>> </request>
>> <response>
>> <representation mediaType="application/json"/>
>> <representation mediaType="application/x-jackson-smile"/>
>> </response>
>> </method>
>> </resource>
>> <resource path="annotatePlain">
>> <method name="POST">
>> <request>
>> <representation mediaType="text/plain">
>> <param name="request" style="plain" type="xs:string"/>
>> </representation>
>> </request>
>> <response>
>> <representation mediaType="application/json"/>
>> </response>
>> </method>
>> </resource>
>> </resource>
>> </resources>
>> </application>
>>
>> On Wed, Jul 29, 2015 at 2:07 PM, Benson Margulies <be...@basistech.com>
>> wrote:
>>>
>>> Here's the perplexing wadl...
>>>
>>> On Wed, Jul 29, 2015 at 2:03 PM, Benson Margulies <be...@basistech.com>
>>> wrote:
>>>>
>>>> The WADL for this shows only one parameter. Did I miss something?
>>>>
>>>>
>>>> @POST
>>>> @Consumes("multipart/mixed")
>>>> @Produces({"application/json", "application/x-jackson-smile"})
>>>> @Path("annotate")
>>>> public Response annotate(
>>>>      @Multipart(value = "options", type = "application/json")
>>>>      Map<String, String> options,
>>>>      @Multipart(value = "text") InputStream text) throws IOException,
>>>> RosetteException {
>>>>
>>>>      final ObjectMapper mapper = getMapper();
>>>>      AnnotatedText inputText = mapper.readValue(text,
>>>> AnnotatedText.class);
>>>>      final AnnotatedText result =
>>>> pipeline.createAnnotator().annotate(inputText);
>>>>
>>>>      StreamingOutput stream = new StreamingOutput() {
>>>>          @Override
>>>>          public void write(OutputStream os) throws IOException,
>>>> WebApplicationException {
>>>>              mapper.writeValue(os, result);
>>>>          }
>>>>      };
>>>>      return Response.ok(stream).build();
>>>> }
>
>

Re: Consuming multi-part/mixed

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi Benson
I see WADLGenerator restricting that only simple or InputStream types 
are recognized as multipart parameters, I can deal with it next week 
once I got back, though the best you'll get is a WADL request 
representation fragment with two parameters of type xs:anyType in this case

Cheers, Sergey
On 29/07/15 21:07, Benson Margulies wrote:
> <application xmlns="http://wadl.dev.java.net/2009/02"
> xmlns:xs="http://www.w3.org/2001/XMLSchema">
> <grammars/>
> <resources base="http://192.168.59.103:8181/cxf/annotator">
> <resource path="/">
> <resource path="annotate">
> <method name="POST">
> <request>
> <representation mediaType="multipart/mixed">
> <param name="text" style="query" type="xs:anyType"/>
> </representation>
> </request>
> <response>
> <representation mediaType="application/json"/>
> <representation mediaType="application/x-jackson-smile"/>
> </response>
> </method>
> </resource>
> <resource path="annotatePlain">
> <method name="POST">
> <request>
> <representation mediaType="text/plain">
> <param name="request" style="plain" type="xs:string"/>
> </representation>
> </request>
> <response>
> <representation mediaType="application/json"/>
> </response>
> </method>
> </resource>
> </resource>
> </resources>
> </application>
>
> On Wed, Jul 29, 2015 at 2:07 PM, Benson Margulies <be...@basistech.com> wrote:
>> Here's the perplexing wadl...
>>
>> On Wed, Jul 29, 2015 at 2:03 PM, Benson Margulies <be...@basistech.com> wrote:
>>> The WADL for this shows only one parameter. Did I miss something?
>>>
>>>
>>> @POST
>>> @Consumes("multipart/mixed")
>>> @Produces({"application/json", "application/x-jackson-smile"})
>>> @Path("annotate")
>>> public Response annotate(
>>>      @Multipart(value = "options", type = "application/json")
>>>      Map<String, String> options,
>>>      @Multipart(value = "text") InputStream text) throws IOException,
>>> RosetteException {
>>>
>>>      final ObjectMapper mapper = getMapper();
>>>      AnnotatedText inputText = mapper.readValue(text, AnnotatedText.class);
>>>      final AnnotatedText result = pipeline.createAnnotator().annotate(inputText);
>>>
>>>      StreamingOutput stream = new StreamingOutput() {
>>>          @Override
>>>          public void write(OutputStream os) throws IOException,
>>> WebApplicationException {
>>>              mapper.writeValue(os, result);
>>>          }
>>>      };
>>>      return Response.ok(stream).build();
>>> }


Re: Consuming multi-part/mixed

Posted by Benson Margulies <be...@basistech.com>.
<application xmlns="http://wadl.dev.java.net/2009/02"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<grammars/>
<resources base="http://192.168.59.103:8181/cxf/annotator">
<resource path="/">
<resource path="annotate">
<method name="POST">
<request>
<representation mediaType="multipart/mixed">
<param name="text" style="query" type="xs:anyType"/>
</representation>
</request>
<response>
<representation mediaType="application/json"/>
<representation mediaType="application/x-jackson-smile"/>
</response>
</method>
</resource>
<resource path="annotatePlain">
<method name="POST">
<request>
<representation mediaType="text/plain">
<param name="request" style="plain" type="xs:string"/>
</representation>
</request>
<response>
<representation mediaType="application/json"/>
</response>
</method>
</resource>
</resource>
</resources>
</application>

On Wed, Jul 29, 2015 at 2:07 PM, Benson Margulies <be...@basistech.com> wrote:
> Here's the perplexing wadl...
>
> On Wed, Jul 29, 2015 at 2:03 PM, Benson Margulies <be...@basistech.com> wrote:
>> The WADL for this shows only one parameter. Did I miss something?
>>
>>
>> @POST
>> @Consumes("multipart/mixed")
>> @Produces({"application/json", "application/x-jackson-smile"})
>> @Path("annotate")
>> public Response annotate(
>>     @Multipart(value = "options", type = "application/json")
>>     Map<String, String> options,
>>     @Multipart(value = "text") InputStream text) throws IOException,
>> RosetteException {
>>
>>     final ObjectMapper mapper = getMapper();
>>     AnnotatedText inputText = mapper.readValue(text, AnnotatedText.class);
>>     final AnnotatedText result = pipeline.createAnnotator().annotate(inputText);
>>
>>     StreamingOutput stream = new StreamingOutput() {
>>         @Override
>>         public void write(OutputStream os) throws IOException,
>> WebApplicationException {
>>             mapper.writeValue(os, result);
>>         }
>>     };
>>     return Response.ok(stream).build();
>> }

Re: Consuming multi-part/mixed

Posted by Benson Margulies <be...@basistech.com>.
Here's the perplexing wadl...

On Wed, Jul 29, 2015 at 2:03 PM, Benson Margulies <be...@basistech.com> wrote:
> The WADL for this shows only one parameter. Did I miss something?
>
>
> @POST
> @Consumes("multipart/mixed")
> @Produces({"application/json", "application/x-jackson-smile"})
> @Path("annotate")
> public Response annotate(
>     @Multipart(value = "options", type = "application/json")
>     Map<String, String> options,
>     @Multipart(value = "text") InputStream text) throws IOException,
> RosetteException {
>
>     final ObjectMapper mapper = getMapper();
>     AnnotatedText inputText = mapper.readValue(text, AnnotatedText.class);
>     final AnnotatedText result = pipeline.createAnnotator().annotate(inputText);
>
>     StreamingOutput stream = new StreamingOutput() {
>         @Override
>         public void write(OutputStream os) throws IOException,
> WebApplicationException {
>             mapper.writeValue(os, result);
>         }
>     };
>     return Response.ok(stream).build();
> }