Hi

Please see comments inline.

thanks, Sergey

----- Original Message ----- From: "fahman_dude" <[email protected]>
To: <[email protected]>
Sent: Thursday, February 18, 2010 2:13 PM
Subject: RESTful services without annotations



Hello,

I am trying at the moment to implement a RESTful Service without annotations
(as in using "user model" instead) and using this (for my taste bit
confusing) guide: http://cxf.apache.org/docs/jax-rs.html

S.B : recommendations are welcome. David K. has helped quite a bit - let me know if you'd like certain things be better expanded upon, etc...

Since my implementation does not work I am trying to understand the whole
mechanics in-depth and am stuck at the moment on this example:
http://svn.apache.org/repos/asf/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerUserResourceTest.java

The question I have here, is: Why is it required to programmatically create
UserRessource instances

S.B there's no such requirement. This test just shows that one can 
progarammatically register a user model reference.

<snip>
JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();

...
UserResource ur = new UserResource();
ur.setName(BookStoreNoAnnotations.class.getName());
ur.setPath("/bookstoreNoAnnotations");
...
sf.setModelBeans(ur);
...
</snap>

in addition to setting ModelRef?

<snip>
...
String modelRef =
"classpath:/org/apache/cxf/systest/jaxrs/resources/resources2.xml";
sf.setModelRefWithServiceClass(modelRef,
BookStoreNoAnnotationsInterface.class);
...
</snap>

S.B :

In this particular code snippet two things are happening :

1. User model is created programmatically and the resource class which is beng described is BookStoreNoAnnotations.class which is a concrete class

2. Another user model (resource2.xml) is being linked to, this model describes an interface only (BookStoreNoAnnotationsInterface), hence we also register a concrete class implementing it (BookStoreNoAnnotationsImpl). This latter option is partucularly effective in the OSGI case or when you have a lot of dynamic resources coming in...It also works well on the client proxy side where there's no need to register an actual implementation.

S.B : note that in 2. the test uses sf.setModelRefWithServiceClass(modelref, SomeClass.class) but it could've just used sf.setModelRef(modelref) even with this model describing an interface only. sf.setModelRefWithServiceClass() is used mainly in (D)OSGI where the OSGI runtime has already loaded an interface class.

Isn't it so that the model already describes EVERYTHING UserResource
instances do. When I don't create UserResource instances I get this error:

S.B : do you have an actual requirement to create them programmatically, it should all be hidden if you link to a model from Spring...

ERROR [main] apache.cxf.jaxrs.AvstractJAXRSFactoryBean (231) - No resource
classes found

My code looks like this:

...
JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
sf.setAddress("hhtp:/...");
sf.setModelRef("classpath:/to/my/modelref.xml");
sf.setServiceBeans(new MyWSImplementationNoAnnotations);
sf.create()
...

S.B : If you have a model describing an interface only then you need to call 
setModelRefWithServiceClass as it is done in the test

modelref.xml looks like this:

<model xlmns="http://cxf.apache.org/jaxrs";>
<resource name="MyWSImplementationNoAnnotationsInterface"
path="mywsservice"
produces="application/json" consumes="multipart/form-data">
<operation name="do" verb="POST" path="/do">


</operation>
</resource>
</model>

And the

public class MyWSImplementationNoAnnotations implements
MyWSImplementationNoAnnotationsInterface {
...
public void do(ComplexClass docontext, AnotherComplexClass domoreStuff) {
...
}
}

S.B : All seems fine. Can you please post me the model.ref with these two sample classes ? Actually your model does not descrive the actual parameters docontext and domoreStuff. It's a multipart/form-data that is expected, these parameters, do they have to be mapped to indiv attachment parts ? If so they you'd probably need to mark both in the model as parameters of REQUEST_BODY...

let me know how it goes please, Sergey

cheers
reinis
--
View this message in context: 
http://old.nabble.com/RESTful-services-without-annotations-tp27637811p27637811.html
Sent from the cxf-user mailing list archive at Nabble.com.

Reply via email to