You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by "kanu.emeka" <ka...@gmail.com> on 2015/08/27 23:40:28 UTC

Re: JAX-RS form reading, I'm stumped

Hello Sergey,

I am using cxf version 2.7.0.redhat-610379, as part of fabric and camel, and
have followed a similar path, configuring the @Multipart to my json type. I
also have an attachment as well in the request, but I get the same problem.
Is there something wrong with version 2.7.0?

ResourceClass{

.....
@POST
@Path("/stat/{statId}/status")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_JSON)
public Response createStatus(@Multipart(value="upload", required = false)
Attachment upload, @FormParam(value = "update")StatusUpdateType
statusUpdate){
return null;
}



--
View this message in context: http://cxf.547215.n5.nabble.com/JAX-RS-form-reading-I-m-stumped-tp567915p5760543.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: JAX-RS form reading, I'm stumped

Posted by Sergey Beryozkin <sb...@gmail.com>.
No problems at all

On 28/08/15 23:04, kanu.emeka wrote:
> Hello Sergey,
>
> As it turned out, my error was actually almost completely unrelated to the
> one reported by Benson. My problem was the writer and not the reader. This
> was due to a bug in my camel route and caused my route to want to write out
> the multipart.
>
> Sorry for the waste of time
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/JAX-RS-form-reading-I-m-stumped-tp567915p5760586.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>


-- 
Sergey Beryozkin

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

Re: JAX-RS form reading, I'm stumped

Posted by "kanu.emeka" <ka...@gmail.com>.
Hello Sergey,

As it turned out, my error was actually almost completely unrelated to the
one reported by Benson. My problem was the writer and not the reader. This
was due to a bug in my camel route and caused my route to want to write out
the multipart.

Sorry for the waste of time



--
View this message in context: http://cxf.547215.n5.nabble.com/JAX-RS-form-reading-I-m-stumped-tp567915p5760586.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: JAX-RS form reading, I'm stumped

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

Actually please try 2. too :-), just download the Jackson source from maven.
Re 1: you can alternatively replace a second parameter with Attachment 
and check it.



Re 4: simply replace a CXF 2.7.0 bundle with CXF 2.7.18 one in the fuse 
container in /system/org/apache/cxf/.../2.7.0/ and replace 2.7.18 with 
2.7.0 in the actual bundle file name

Sergey
On 28/08/15 14:12, kanu.emeka wrote:
> :-)
>
> That's no problem. I'll try 1 to 3 and let you know. I think 4.) is a
> problem for me because I'm using CXFRS as part of Fuse Fabric so using a
> different version might be a problem, unless I upgrade to the latest version
> of Fabric, which is a much bigger task.
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/JAX-RS-form-reading-I-m-stumped-tp567915p5760568.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>


-- 
Sergey Beryozkin

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

Re: JAX-RS form reading, I'm stumped

Posted by "kanu.emeka" <ka...@gmail.com>.
:-)

That's no problem. I'll try 1 to 3 and let you know. I think 4.) is a
problem for me because I'm using CXFRS as part of Fuse Fabric so using a
different version might be a problem, unless I upgrade to the latest version
of Fabric, which is a much bigger task.



--
View this message in context: http://cxf.547215.n5.nabble.com/JAX-RS-form-reading-I-m-stumped-tp567915p5760568.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: JAX-RS form reading, I'm stumped

Posted by Sergey Beryozkin <sb...@gmail.com>.
That was 4 instead of 2 :-)
On 28/08/15 12:23, Sergey Beryozkin wrote:
> OK, I can suggest two things:
>
> 1. Try to experiment with replacing both parameters with a single
> MultipartBody parameter and without any annotations. MultipartBody can
> let you read individual parts in a type-safe way too. You can also check
> its content in the debug mode. You can keep the original signature if
> you prefer once the issue is found.
> 2. Put a breakpoint in JacksonJaxbJsonProvider.isReadable and see if it
> is being called.
> 3. Make sure the default CXF Jettison provider is not registered
> (exclude a Jettison dep), though it should not make a difference given
> you have a custom Jackson.
> 4. Try CXF 2.7.18
>
> If you can not make any progress after 1-4, then open a JIRA with a test
> case and I'll have a look.
> Cheers, Sergey
>
>
> On 28/08/15 12:08, kanu.emeka wrote:
>> Q. Does the individual part which carries the json payload have
>>
>> Content-Type: application/json ?
>>
>> A - Yes it does. Plus I also tried setting the type in @Multipart
>> annotation
>> as well.
>>
>> Q. If yes - can JacksonJaxbJsonProvider convert it, is Status type a JAXB
>> bean ?
>>
>> Yes and yes. In previous iterations, I had this method with only the
>> StatusUpdateType and no attachment. In that instance, the @Consumes
>> contained only application/json, and it all worked fine.
>>
>> This is a new iteration, where I am attempting to add an attachment,
>> and as
>> such have made everything @Multipart as specified by the CXFRS
>> documentation.
>>
>> Yes Jackson worked fine, and has worked fine in every other service
>> that I
>> have registered as part of my APIs.
>>
>>
>>
>>
>> --
>> View this message in context:
>> http://cxf.547215.n5.nabble.com/JAX-RS-form-reading-I-m-stumped-tp567915p5760555.html
>>
>> Sent from the cxf-user mailing list archive at Nabble.com.
>>
>
>


-- 
Sergey Beryozkin

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

Re: JAX-RS form reading, I'm stumped

Posted by Sergey Beryozkin <sb...@gmail.com>.
OK, I can suggest two things:

1. Try to experiment with replacing both parameters with a single 
MultipartBody parameter and without any annotations. MultipartBody can 
let you read individual parts in a type-safe way too. You can also check 
its content in the debug mode. You can keep the original signature if 
you prefer once the issue is found.
2. Put a breakpoint in JacksonJaxbJsonProvider.isReadable and see if it 
is being called.
3. Make sure the default CXF Jettison provider is not registered 
(exclude a Jettison dep), though it should not make a difference given 
you have a custom Jackson.
4. Try CXF 2.7.18

If you can not make any progress after 1-4, then open a JIRA with a test 
case and I'll have a look.
Cheers, Sergey


On 28/08/15 12:08, kanu.emeka wrote:
> Q. Does the individual part which carries the json payload have
>
> Content-Type: application/json ?
>
> A - Yes it does. Plus I also tried setting the type in @Multipart annotation
> as well.
>
> Q. If yes - can JacksonJaxbJsonProvider convert it, is Status type a JAXB
> bean ?
>
> Yes and yes. In previous iterations, I had this method with only the
> StatusUpdateType and no attachment. In that instance, the @Consumes
> contained only application/json, and it all worked fine.
>
> This is a new iteration, where I am attempting to add an attachment, and as
> such have made everything @Multipart as specified by the CXFRS
> documentation.
>
> Yes Jackson worked fine, and has worked fine in every other service that I
> have registered as part of my APIs.
>
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/JAX-RS-form-reading-I-m-stumped-tp567915p5760555.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>


-- 
Sergey Beryozkin

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

Re: JAX-RS form reading, I'm stumped

Posted by "kanu.emeka" <ka...@gmail.com>.
Q. Does the individual part which carries the json payload have 

Content-Type: application/json ?

A - Yes it does. Plus I also tried setting the type in @Multipart annotation
as well.

Q. If yes - can JacksonJaxbJsonProvider convert it, is Status type a JAXB
bean ?

Yes and yes. In previous iterations, I had this method with only the
StatusUpdateType and no attachment. In that instance, the @Consumes
contained only application/json, and it all worked fine.

This is a new iteration, where I am attempting to add an attachment, and as
such have made everything @Multipart as specified by the CXFRS
documentation.

Yes Jackson worked fine, and has worked fine in every other service that I
have registered as part of my APIs.




--
View this message in context: http://cxf.547215.n5.nabble.com/JAX-RS-form-reading-I-m-stumped-tp567915p5760555.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: JAX-RS form reading, I'm stumped

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
Does the individual part which carries the json payload have

  Content-Type: application/json ?

If yes - can JacksonJaxbJsonProvider convert it, is Status type a JAXB 
bean ?

Finally, I do not recall exactly now but the older CXF versions could 
not handle Jackson 2.x but I'm assuming it works for you in other cases 
if you have it registered.

Sergey
On 28/08/15 11:22, kanu.emeka wrote:
> Hello Sergey,
>
> Please see the relevant configuration in my blueprint xml.
>
> <camel-cxf:rsServer id="rsServer"
> address="http://0.0.0.0:${stat.port}/stat-service"
>                          loggingFeatureEnabled="true" loggingSizeLimit="20">
>          <camel-cxf:providers>
>              <bean id="jacksonProvider"
> class="com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider">
>                  <property name="mapper" ref="livUpObjectMapperFactory"/>
>              </bean>
>              <ref component-id="orgCORSFilter"/>
>              <bean id="oauthFilter"
> class="org.apache.cxf.rs.security.oauth2.filters.OAuthRequestFilter">
>                  <property name="tokenValidator" ref="tokenValidator"/>
>              </bean>
>          </camel-cxf:providers>
>      </camel-cxf:rsServer>
>
> I already have a jackson provider configured. Do I need to provide another
> provider for Multipart?
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/JAX-RS-form-reading-I-m-stumped-tp567915p5760551.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>


Re: JAX-RS form reading, I'm stumped

Posted by "kanu.emeka" <ka...@gmail.com>.
Hello Sergey,

Please see the relevant configuration in my blueprint xml.

<camel-cxf:rsServer id="rsServer"
address="http://0.0.0.0:${stat.port}/stat-service"
                        loggingFeatureEnabled="true" loggingSizeLimit="20">
        <camel-cxf:providers>
            <bean id="jacksonProvider"
class="com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider">
                <property name="mapper" ref="livUpObjectMapperFactory"/>
            </bean>
            <ref component-id="orgCORSFilter"/>
            <bean id="oauthFilter"
class="org.apache.cxf.rs.security.oauth2.filters.OAuthRequestFilter">
                <property name="tokenValidator" ref="tokenValidator"/>
            </bean>
        </camel-cxf:providers>
    </camel-cxf:rsServer>

I already have a jackson provider configured. Do I need to provide another
provider for Multipart?



--
View this message in context: http://cxf.547215.n5.nabble.com/JAX-RS-form-reading-I-m-stumped-tp567915p5760551.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: JAX-RS form reading, I'm stumped

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
On 28/08/15 10:59, kanu.emeka wrote:
> Hello Sergey,
>
> There was a typo in the original question, which I have now corrected. This
> was because I tried so many different options. Please have a look again.
>
> But yes, StatusUpdateType is the one which cannot be read, and it comes in
> the form of application/json.
>
So you need a provider capable converting a JSON payload into 
StatusUpdateType. Try Jackson for example...

Cheers, Sergey
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/JAX-RS-form-reading-I-m-stumped-tp567915p5760549.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>


-- 
Sergey Beryozkin

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

Re: JAX-RS form reading, I'm stumped

Posted by "kanu.emeka" <ka...@gmail.com>.
Hello Sergey,

There was a typo in the original question, which I have now corrected. This
was because I tried so many different options. Please have a look again.

But yes, StatusUpdateType is the one which cannot be read, and it comes in
the form of application/json.



--
View this message in context: http://cxf.547215.n5.nabble.com/JAX-RS-form-reading-I-m-stumped-tp567915p5760549.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: JAX-RS form reading, I'm stumped

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

First of all try to use the same annotation on both parameters, 
@Multipart. As far as I recall, having @Form on parameters mapped to a 
multipart payload works only if parameters are primitives such as String.

I'm assuming StatusUpdateType can not be read. This is because when 
reading the multiparts it is the job of MessageBodyReader to convert 
InputStream representing that parameter into something like 
StatusUpdateType.

The default conversion mechanism from String to a custom type does not 
apply in this case because we do not know if InputStream can be 
meaningfully read into String.

So register a custom MBR that can convert InputStream into 
StatusUpdateType and set @Multipart on the parameter and it should work

HTH, Sergey

On 27/08/15 22:40, kanu.emeka wrote:
> Hello Sergey,
>
> I am using cxf version 2.7.0.redhat-610379, as part of fabric and camel, and
> have followed a similar path, configuring the @Multipart to my json type. I
> also have an attachment as well in the request, but I get the same problem.
> Is there something wrong with version 2.7.0?
>
> ResourceClass{
>
> .....
> @POST
> @Path("/stat/{statId}/status")
> @Consumes(MediaType.MULTIPART_FORM_DATA)
> @Produces(MediaType.APPLICATION_JSON)
> public Response createStatus(@Multipart(value="upload", required = false)
> Attachment upload, @FormParam(value = "update")StatusUpdateType
> statusUpdate){
> return null;
> }
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/JAX-RS-form-reading-I-m-stumped-tp567915p5760543.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>


-- 
Sergey Beryozkin

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