You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Bruno Dusausoy <br...@yp5.be> on 2011/06/01 08:40:26 UTC
Object is not an instance of declaring class
Hi,
I have a problem with JAXRSServerFactoryBean.
I have a tiny RESTful webservice :
@POST
@Path("/computation")
@Consumes(MediaType.TEXT_XML)
@Produces(MediaType.TEXT_XML)
@Override
public Response compute(Request request) {
// do stuff and then respond
}
It works perfectly well when I use Spring (and CXFServlet within a
Tomcat container), like this :
<jaxrs:server id="computationRESTService" address="/">
<jaxrs:features>
<cxf:logging/>
</jaxrs:features>
<jaxrs:serviceBeans>
<ref bean="computationService"/>
</jaxrs:serviceBeans>
<jaxrs:schemaLocations>
<jaxrs:schemaLocation>classpath:schemas/webservice-request.xsd</jaxrs:schemaLocation>
</jaxrs:schemaLocations>
</jaxrs:server>
There's no problem at all with this configuration.
But when I try to launch the server programmatically without Spring,
like this :
JAXRSServerFactoryBean sfb = new JAXRSServerFactoryBean();
sfb.setResourceClasses(RestComputationService.class);
sfb.setResourceProvider(RestComputationService.class,
new
SingletonResourceProvider(RestComputationService.class));
sfb.setAddress(BASE_URL);
BindingFactoryManager manager =
sfb.getBus().getExtension(BindingFactoryManager.class);
JAXRSBindingFactory factory = new JAXRSBindingFactory();
factory.setBus(sfb.getBus());
manager.registerBindingFactory(JAXRSBindingFactory.JAXRS_BINDING_ID,
factory);
Server server = sfb.create();
server.start();
Each time I try an POST method - that is the same I use to do with my
Spring/Tomcat configuration - I get this error :
org.apache.cxf.interceptor.Fault: object is not an instance of declaring
class while invoking public server.webservice.model.response.Response
server.RestComputationService.compute(server.webservice.model.request.Request)
with params [server.webservice.model.request.Request@413fc6].
I'm sure I'm missing something in my code.
Can anyone tell me what I'm missing/doing wrong ?
Regards.
--
Pensez environnement : limitez l'impression de ce mail.
Please don't print this e-mail unless you really need to.
Re: Object is not an instance of declaring class
Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi Bruno
>>
>> I didn't have a chance to test yet, just would like to clarify one
>> thing, It appears the test server uses createServerFromSpring(). Can
>> you confirm you are seeing this issue with createServer() ?
>>
> Hi Sergey,
>
> Yes, I confirm. The createServerFromSpring() method was there onlye to see
> if I had the same issue with or without Spring, which is the case.
>
> Regards.
> --
Moving JAX-RS annotations from RestComputationService to
ComputationService should get it fixed. It appears that Spring or
aspectj classes are interfering somehow, so it does look like it's
AOP-related issue. Usually having an interface annotated with JAX-RS
annotations and root resource classes implementing it helps.
Give it a try please
Cheers, Sergey
> Bruno Dusausoy
> YP5 Software
> --
> Pensez environnement : limitez l'impression de ce mail.
> Please don't print this e-mail unless you really need to.
>
Re: Object is not an instance of declaring class
Posted by Bruno Dusausoy <br...@yp5.be>.
On 06/01/2011 11:46 PM, Sergey Beryozkin wrote:
> Hi Bruno,
>
> I didn't have a chance to test yet, just would like to clarify one
> thing, It appears the test server uses createServerFromSpring(). Can
> you confirm you are seeing this issue with createServer() ?
>
Hi Sergey,
Yes, I confirm. The createServerFromSpring() method was there onlye to
see if I had the same issue with or without Spring, which is the case.
Regards.
--
Bruno Dusausoy
YP5 Software
--
Pensez environnement : limitez l'impression de ce mail.
Please don't print this e-mail unless you really need to.
Re: Object is not an instance of declaring class
Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi Bruno,
I didn't have a chance to test yet, just would like to clarify one
thing, It appears the test server uses createServerFromSpring(). Can
you confirm you are seeing this issue with createServer() ?
thanks, Sergey
2011/6/1 Bruno Dusausoy <br...@yp5.be>:
> On 06/01/2011 11:07 AM, Sergey Beryozkin wrote:
>>
>> Hi
>>
>> That is unusual that you get this kind of error when starting a simple
>> server without any explicit Spring configuration.
>>
>> I believe you had something working so I'm wondering what may've
>> caused this sideeffect.
>> It appears you have some inheritance in the code. Can you please send
>> me either a sample maven project or
>> some code showing how RestComputationService has been implemented. Do
>> you have JAX-RS annotations both in RestComputationService and in
>> interface or abstract class it implements/extends ? That may cause
>> some 'confusion'
>>
>
> Hi Sergey,
>
> Here's a piece of the project I develop. I've turned it into a simple
> standalone project which you can use (maybe you'll have to add extras repos
> to the POM because I'm using the company's repo manager which includes what
> I need).
>
> I really think the problem lies in the fact I didn't understand how to
> correctly launch a standalone server programmatically since it works when
> deploying in Tomcat.
>
> So, can you look at it and tell me what I'm doing wrong ?
>
> You'll find the project as well as an XML input sample attached.
>
> Thanks a lot.
>
> Regards, Bruno.
>
> --
> Pensez environnement : limitez l'impression de ce mail.
> Please don't print this e-mail unless you really need to.
>
Re: Object is not an instance of declaring class
Posted by Bruno Dusausoy <br...@yp5.be>.
On 06/01/2011 11:07 AM, Sergey Beryozkin wrote:
> Hi
>
> That is unusual that you get this kind of error when starting a simple
> server without any explicit Spring configuration.
>
> I believe you had something working so I'm wondering what may've
> caused this sideeffect.
> It appears you have some inheritance in the code. Can you please send
> me either a sample maven project or
> some code showing how RestComputationService has been implemented. Do
> you have JAX-RS annotations both in RestComputationService and in
> interface or abstract class it implements/extends ? That may cause
> some 'confusion'
>
Hi Sergey,
Here's a piece of the project I develop. I've turned it into a simple
standalone project which you can use (maybe you'll have to add extras
repos to the POM because I'm using the company's repo manager which
includes what I need).
I really think the problem lies in the fact I didn't understand how to
correctly launch a standalone server programmatically since it works
when deploying in Tomcat.
So, can you look at it and tell me what I'm doing wrong ?
You'll find the project as well as an XML input sample attached.
Thanks a lot.
Regards, Bruno.
--
Pensez environnement : limitez l'impression de ce mail.
Please don't print this e-mail unless you really need to.
Re: Object is not an instance of declaring class
Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
That is unusual that you get this kind of error when starting a simple
server without any explicit Spring configuration.
I believe you had something working so I'm wondering what may've
caused this sideeffect.
It appears you have some inheritance in the code. Can you please send
me either a sample maven project or
some code showing how RestComputationService has been implemented. Do
you have JAX-RS annotations both in RestComputationService and in
interface or abstract class it implements/extends ? That may cause
some 'confusion'
Cheers, Sergey
On Wed, Jun 1, 2011 at 7:40 AM, Bruno Dusausoy <br...@yp5.be> wrote:
> Hi,
>
> I have a problem with JAXRSServerFactoryBean.
>
> I have a tiny RESTful webservice :
>
> @POST
> @Path("/computation")
> @Consumes(MediaType.TEXT_XML)
> @Produces(MediaType.TEXT_XML)
> @Override
> public Response compute(Request request) {
> // do stuff and then respond
> }
>
> It works perfectly well when I use Spring (and CXFServlet within a Tomcat
> container), like this :
>
> <jaxrs:server id="computationRESTService" address="/">
> <jaxrs:features>
> <cxf:logging/>
> </jaxrs:features>
> <jaxrs:serviceBeans>
> <ref bean="computationService"/>
> </jaxrs:serviceBeans>
> <jaxrs:schemaLocations>
>
> <jaxrs:schemaLocation>classpath:schemas/webservice-request.xsd</jaxrs:schemaLocation>
> </jaxrs:schemaLocations>
> </jaxrs:server>
>
> There's no problem at all with this configuration.
> But when I try to launch the server programmatically without Spring, like
> this :
>
> JAXRSServerFactoryBean sfb = new JAXRSServerFactoryBean();
> sfb.setResourceClasses(RestComputationService.class);
> sfb.setResourceProvider(RestComputationService.class,
> new SingletonResourceProvider(RestComputationService.class));
> sfb.setAddress(BASE_URL);
>
> BindingFactoryManager manager =
> sfb.getBus().getExtension(BindingFactoryManager.class);
> JAXRSBindingFactory factory = new JAXRSBindingFactory();
> factory.setBus(sfb.getBus());
>
> manager.registerBindingFactory(JAXRSBindingFactory.JAXRS_BINDING_ID,
> factory);
>
> Server server = sfb.create();
> server.start();
>
> Each time I try an POST method - that is the same I use to do with my
> Spring/Tomcat configuration - I get this error :
>
> org.apache.cxf.interceptor.Fault: object is not an instance of declaring
> class while invoking public server.webservice.model.response.Response
> server.RestComputationService.compute(server.webservice.model.request.Request)
> with params [server.webservice.model.request.Request@413fc6].
>
> I'm sure I'm missing something in my code.
> Can anyone tell me what I'm missing/doing wrong ?
>
> Regards.
> --
> Pensez environnement : limitez l'impression de ce mail.
> Please don't print this e-mail unless you really need to.
>