You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by David Karlsen <da...@gmail.com> on 2015/02/13 11:06:36 UTC
Problem marshalling responses when using LocalTransport for
intgration testing
Hi.
I'm using the localtransport to do integration testing of my JAX-RS
resources.
I setup the server like this:
private <T> void setupResource( T resource )
{
try
{
PropertyUtils.setProperty( resource, "contextHolder", contextHolder );
}
catch ( Exception e ) {
logger.warn( "No property for setting contextHolder", e );
}
JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
List<Object> providers = new ArrayList<>();
providers.add( new JacksonJaxbJsonProvider() );
providers.add( new ServiceExceptionMapper() );
//providers.add( new ContextHolder() ); //?
sf.setProviders( providers );
sf.setResourceClasses( resource.getClass() );
sf.setResourceProvider( resource.getClass(),
new SingletonResourceProvider( resource, true ));
sf.setAddress( ENDPOINT_ADDRESS );
server = sf.create();
}
And get my client like this:
protected <T> T getClientProxy( Class<T> resourceClass ) {
T client = JAXRSClientFactory.create( ENDPOINT_ADDRESS,resourceClass );
WebClient.getConfig( client )
.getRequestContext().put( LocalConduit.DIRECT_DISPATCH, Boolean.TRUE);
return client;
}
Invocation is OK on the server side, but when it's about to marshal
the response it says:
No message body reader has been found for class <myPojo>, ContentType:
application/json
even though I've set the JacksonJaxbJsonProvider in the provider list.
When running a standalone server in a servlet-container it works just
fine. What am I missing?
--
--
David J. M. Karlsen - http://www.linkedin.com/in/davidkarlsen
Re: Problem marshalling responses when using LocalTransport for intgration
testing
Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
Looks like it is actually a client side error, pass a
Collections.singetonList(new JacksonJaxbJsonProvider()) to
JAXRSClientFactory and the test should pass
HTH, Sergey
On 15/02/15 20:08, David Karlsen wrote:
> Yes they are (it's the same classpath as when running as a standalone .war
> in a container). The problem only arises when testing under localtransport.
>
> 2015-02-13 17:54 GMT+01:00 Andrei Shakirin <as...@talend.com>:
>
>> Hi,
>>
>> Could you double check that Jackson provider jars are on the classpath?
>>
>> Regards,
>> Andrei.
>>
>>> -----Original Message-----
>>> From: David Karlsen [mailto:davidkarlsen@gmail.com]
>>> Sent: Freitag, 13. Februar 2015 11:07
>>> To: users@cxf.apache.org
>>> Subject: Problem marshalling responses when using LocalTransport for
>>> intgration testing
>>>
>>> Hi.
>>>
>>> I'm using the localtransport to do integration testing of my JAX-RS
>> resources.
>>>
>>> I setup the server like this:
>>>
>>> private <T> void setupResource( T resource ) {
>>> try
>>> {
>>> PropertyUtils.setProperty( resource, "contextHolder",
>> contextHolder );
>>> }
>>> catch ( Exception e ) {
>>> logger.warn( "No property for setting contextHolder", e );
>>> }
>>>
>>> JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
>>>
>>> List<Object> providers = new ArrayList<>();
>>> providers.add( new JacksonJaxbJsonProvider() );
>>> providers.add( new ServiceExceptionMapper() );
>>> //providers.add( new ContextHolder() ); //?
>>> sf.setProviders( providers );
>>>
>>> sf.setResourceClasses( resource.getClass() );
>>> sf.setResourceProvider( resource.getClass(),
>>> new SingletonResourceProvider( resource, true ));
>>> sf.setAddress( ENDPOINT_ADDRESS );
>>>
>>> server = sf.create();
>>> }
>>>
>>>
>>> And get my client like this:
>>>
>>> protected <T> T getClientProxy( Class<T> resourceClass ) {
>>> T client = JAXRSClientFactory.create( ENDPOINT_ADDRESS,resourceClass
>> );
>>> WebClient.getConfig( client )
>>> .getRequestContext().put( LocalConduit.DIRECT_DISPATCH,
>>> Boolean.TRUE);
>>>
>>> return client;
>>> }
>>>
>>>
>>> Invocation is OK on the server side, but when it's about to marshal the
>> response
>>> it says:
>>>
>>> No message body reader has been found for class <myPojo>, ContentType:
>>> application/json
>>>
>>>
>>> even though I've set the JacksonJaxbJsonProvider in the provider list.
>>>
>>> When running a standalone server in a servlet-container it works just
>> fine.
>>> What am I missing?
>>>
>>>
>>>
>>> --
>>> --
>>> David J. M. Karlsen - http://www.linkedin.com/in/davidkarlsen
>>
>
>
>
Re: Problem marshalling responses when using LocalTransport for
intgration testing
Posted by David Karlsen <da...@gmail.com>.
Yes they are (it's the same classpath as when running as a standalone .war
in a container). The problem only arises when testing under localtransport.
2015-02-13 17:54 GMT+01:00 Andrei Shakirin <as...@talend.com>:
> Hi,
>
> Could you double check that Jackson provider jars are on the classpath?
>
> Regards,
> Andrei.
>
> > -----Original Message-----
> > From: David Karlsen [mailto:davidkarlsen@gmail.com]
> > Sent: Freitag, 13. Februar 2015 11:07
> > To: users@cxf.apache.org
> > Subject: Problem marshalling responses when using LocalTransport for
> > intgration testing
> >
> > Hi.
> >
> > I'm using the localtransport to do integration testing of my JAX-RS
> resources.
> >
> > I setup the server like this:
> >
> > private <T> void setupResource( T resource ) {
> > try
> > {
> > PropertyUtils.setProperty( resource, "contextHolder",
> contextHolder );
> > }
> > catch ( Exception e ) {
> > logger.warn( "No property for setting contextHolder", e );
> > }
> >
> > JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
> >
> > List<Object> providers = new ArrayList<>();
> > providers.add( new JacksonJaxbJsonProvider() );
> > providers.add( new ServiceExceptionMapper() );
> > //providers.add( new ContextHolder() ); //?
> > sf.setProviders( providers );
> >
> > sf.setResourceClasses( resource.getClass() );
> > sf.setResourceProvider( resource.getClass(),
> > new SingletonResourceProvider( resource, true ));
> > sf.setAddress( ENDPOINT_ADDRESS );
> >
> > server = sf.create();
> > }
> >
> >
> > And get my client like this:
> >
> > protected <T> T getClientProxy( Class<T> resourceClass ) {
> > T client = JAXRSClientFactory.create( ENDPOINT_ADDRESS,resourceClass
> );
> > WebClient.getConfig( client )
> > .getRequestContext().put( LocalConduit.DIRECT_DISPATCH,
> > Boolean.TRUE);
> >
> > return client;
> > }
> >
> >
> > Invocation is OK on the server side, but when it's about to marshal the
> response
> > it says:
> >
> > No message body reader has been found for class <myPojo>, ContentType:
> > application/json
> >
> >
> > even though I've set the JacksonJaxbJsonProvider in the provider list.
> >
> > When running a standalone server in a servlet-container it works just
> fine.
> > What am I missing?
> >
> >
> >
> > --
> > --
> > David J. M. Karlsen - http://www.linkedin.com/in/davidkarlsen
>
--
--
David J. M. Karlsen - http://www.linkedin.com/in/davidkarlsen
RE: Problem marshalling responses when using LocalTransport for
intgration testing
Posted by Andrei Shakirin <as...@talend.com>.
Hi,
Could you double check that Jackson provider jars are on the classpath?
Regards,
Andrei.
> -----Original Message-----
> From: David Karlsen [mailto:davidkarlsen@gmail.com]
> Sent: Freitag, 13. Februar 2015 11:07
> To: users@cxf.apache.org
> Subject: Problem marshalling responses when using LocalTransport for
> intgration testing
>
> Hi.
>
> I'm using the localtransport to do integration testing of my JAX-RS resources.
>
> I setup the server like this:
>
> private <T> void setupResource( T resource ) {
> try
> {
> PropertyUtils.setProperty( resource, "contextHolder", contextHolder );
> }
> catch ( Exception e ) {
> logger.warn( "No property for setting contextHolder", e );
> }
>
> JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
>
> List<Object> providers = new ArrayList<>();
> providers.add( new JacksonJaxbJsonProvider() );
> providers.add( new ServiceExceptionMapper() );
> //providers.add( new ContextHolder() ); //?
> sf.setProviders( providers );
>
> sf.setResourceClasses( resource.getClass() );
> sf.setResourceProvider( resource.getClass(),
> new SingletonResourceProvider( resource, true ));
> sf.setAddress( ENDPOINT_ADDRESS );
>
> server = sf.create();
> }
>
>
> And get my client like this:
>
> protected <T> T getClientProxy( Class<T> resourceClass ) {
> T client = JAXRSClientFactory.create( ENDPOINT_ADDRESS,resourceClass );
> WebClient.getConfig( client )
> .getRequestContext().put( LocalConduit.DIRECT_DISPATCH,
> Boolean.TRUE);
>
> return client;
> }
>
>
> Invocation is OK on the server side, but when it's about to marshal the response
> it says:
>
> No message body reader has been found for class <myPojo>, ContentType:
> application/json
>
>
> even though I've set the JacksonJaxbJsonProvider in the provider list.
>
> When running a standalone server in a servlet-container it works just fine.
> What am I missing?
>
>
>
> --
> --
> David J. M. Karlsen - http://www.linkedin.com/in/davidkarlsen