Hello there,

You are not modelling your resources in a correct way. I see two
resources, minimum:

ContactsResource (the list of all contacts)
ContactResource (a given contact)

ContactsResource is the one that will call ContactDao's findAll()

ContactResource is the one that will call the other 2 methods of ContactDao

and it's those 2 resources the ones that have the @Get annotation,
something like this:

public class ContactDao {
  public List<Contact> findAll() {
     // Do the storage query here and return results
  }

  public Contact findById(long id) {
    // Do the storage query here and return result
  }

  public Contact findByName(String name) {
   // Do the storage query here and return result
  }
}

public class ContactsResource extends ServerResource {
  List<Contact> contacts;

  @Override
  public void doInit() {
     // Get a DAO instance here and store it in dao
     contacts = dao.findAll();
  }

  @Get("xml")
  public Representation getXML() {
    return buildXMLRepresentation(contacts); // This buildXML method
is one you'll define later for this class
  }

  @Get("json")
  public Representation getJSON() {
    return buildJSONRepresentation(contacts); // Same as for XML method above
  }

  // Other methods here
}

public class ContactResource extends ServerResource {
  Contact contact;

  @Override
  public void doInit() {
   // Parse request parameters
   String stringID = ((String)getRequest().getAttributes().get("id"));
   // Get a DAO instance here and store it in dao
   contact = dao,findById(new Long(stringID).longValue());
  }

  @Get("xml")
  public Representation getXML() {
    return new buildXMLRepresentation(contact);
  }

  @Get("json")
  public Representation getJSON() {
    return new buildJSONRepresentation(contact);
  }
}

Also, you need to define the URIs that will be mapped to those
resources, and so on. I think you need to start rethinking some things
from scratch. I strongly suggest you take a look at the FirstResource
restlet tutorial, and if possible get a book about REST, like the
excellent (even if the examples are not in Java), RESTful Web
Services, from O'Reilly.

On Sat, Jun 26, 2010 at 12:37 PM,  <[email protected]> wrote:
> thank you for your answer, but still i cannot manage to run my application
>
> let me reask the question
> imagine the following interface
>
> interface ContactDao {
> �...@get
>  public List<Contact> findAll();
>
> �...@get
>  public Contact findById(long id);
>
> �...@get
>  public Contact findByName(String name);
> }
>
> every time i execute a call, the first function is executed, unless i change 
> the annotation to have three different, @Get @Post @put
>
> how can i make this work with the three @Get annotations ?
>
>
>
>
>> hi,
>>
>> i've an interface with two functions annotated with @get
>>
>> public interface HelloWorld {
>>       @Get("hello")
>>       public String hello();
>>       @Get("test2")
>>       public String test2();
>> }
>>
>> when i execute the client always the first function is executed but never 
>> test2 function.
>> if i change @get annotation on test2 for @put or any other one everything 
>> works nice.
>>
>> any tip to reuse the same annotation ??
>
> ------------------------------------------------------
> http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2626264
>



-- 
Fabián Mandelbaum
IS Engineer

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2626465

Reply via email to