What benefit would you gain from Camel in this case? If your only goal is to expose a POJO service through a Restful interface a simple JAX-RS or Spring MVC/REST service would suffice. Or does the implementation of e.g. findPerson(id) involve the use of Camel?
On Wed, May 18, 2011 at 10:19 PM, gonzalo diethelm <[email protected]> wrote: > Seeing as there have been no answers, let me ask my question in a more > open-ended way. I am looking for a way to provide RESTful services with a > Camel endpoint. I will have two objects in my hierarchy: Person and Account. > For each object I will need to support several methods (search, create, > update, delete) with different parameters; these methods are mapped to URLs > with the appropriate HTTP verb and URL path parameters. So, for example, I > will have the following methods for Person: > > findPerson(id) => GET /person/{id}, XML response > findAllPersons() => GET /person, XML response > addPerson(data) => POST /person, XML body with person data > updatePerson(data) => PUT /person, XML body with person data > deletePerson(id) => DELETE /person/{id} > > and the same sort of thing for Account. > > Now, I want to do this by exposing exactly TWO Camel routes, one listening > on "http://.../person" and one listening on "http://.../account". Each > route should then forward the request to a Java class (one class for Person, > one for Account). I would like the class for Person to be written like this > (likewise for Account; annotation syntax was made up): > > @URL("/person") > Class PersonBean { > > @Method("GET") > @URL("/{id}") > Person findPerson(@Param("id") int id) { > Person person = getMeThatPerson(id); > return person; // magically mapped to an XML response body > } > > @Method("GET") > @URL("") > List<Person> findAllPersons() { > List<Person> list = getMeAllPersons(); > return list; // magically mapped to an XML response body > } > > @Method("POST") > @URL("") > Person createPerson(@Body Person person) { > // magically map POST body to a Person object > saveThisPerson(person); > return person; // magically mapped to an XML response body > } > > @Method("PUT") > @URL("") > Person updatePerson(@Body Person person) { > // magically map POST body to a Person object > saveThisPerson(person); > return person; // magically mapped to an XML response body > } > > @Method("DELETE") > @URL("/{id}") > void deletePerson(@Param("id") int id) { > getRidOfThisPerson(id); > return; > } > } > > My questions are: > > 1. What kind of endpoint should I use for this? I would like it to be as > lightweight as possible, so jetty, restlet or servlet seem preferable to > CXF. I have done something similar to this with restlet, but I ended up > configuring the HTTP verb in the route itself, which was not to my liking. > > 2. How do I specify the routes so that I can write my beans the way I > described? I would rather map each method to the correct verb in my Java > code, not in the route specification. > > Thanks in advance and best regards. > > -- > DCV > Gonzalo Diethelm > Gerente Desarrollo de Sistemas / CDO > Apoquindo 4001 piso 12, Santiago, Chile > +56 2 393-9073 > [email protected] / www.dcv.cl > > > > -----Original Message----- > > From: gonzalo diethelm [mailto:[email protected]] > > Sent: Monday, 16 May, 2011 18:46 > > To: [email protected] > > Subject: RE: Service architecture > > > > > So, my question is: is it possible to magically go from the Camel > > from("") > > > route definition to a Spring MVC implementation of the business logic? > > > > Let me clarify my question a bit: I would love to be able to do this: > > > > from("INPUT:http://localhost:9080/account") > > .to("PROCESS://magic"); > > > > The meaning of this route would be: > > > > 1. Register "http://localhost:9080/account/" as the URL for a Camel > > endpoint. I have no idea what "INPUT" could be; I am guessing it might be > > "jetty" or "servlet". > > > > 2. An hits on that URL or anything "hanging" from there should be > > forwarded to "magic", which is a Java class that implements the > > @Controller Spring annotation. I have no idea what "PROCESS" would be... > > > > 3. This class is declared like this: > > > > @Controller > > @RequestMapping("/account") > > public class MagicController > > { > > @RequestMapping(value="/owners/{oid}", method=RequestMethod.GET) > > public String findOwner(@PathVariable("oid") String oid, > > Model model) > > { /*blah*/ } > > > > @RequestMapping(value="/{aid}", method=RequestMethod.POST) > > public String createAccount(@PathVariable("aid") String aid, > > Model model) > > { /*blah*/ } > > } > > > > In other words, I would like to have a single Java class that handles all > > URLs hanging from the one my Camel route is defined for. And this class > > should be allowed to use Spring to access all things related to the > > request (URL path parameters, headers, cookies, body, etc.), using all > the > > Spring goodness that has been created for these purposes. > > > > > If I am talking nonsense, apologies in advance. > > > > Ditto. > > > > -- > > Gonzalo Diethelm > >
