Sorry for the late response, I was having some personal emergencies in the past 
two weeks. In REST, one URI must represent one concrete entity or a set of 
concrete entities. So your question is whether or not it is possible to use one 
URI to represent polymorphic entities? Very interesting. Though IMHO I don’t 
think this works. For example, say I have three types for my online book store: 
Book, CD and Item, Book and CD are extended from Item. Both book and CD are 
concrete entities that are persisted in database. The Item on the contrary, is 
only an abstract concept, itself is not a concrete entity in the database. Lets 
exam whether or not the CRUD operations on the Item resource always make sense. 

When you do a HTTP GET to query entities, you can do following:

http://localhost:9000/bookstore/books/123
http://localhost:9000/bookstore/cds/124
http://localhost:9000/bookstore/items/123
http://localhost:9000/bookstore/items/124

The items/123 and items/124 are the tricky ones, items/123 is actually equal to 
books/123, items/124 is equal to cds/124. In this case, we can probably say 
polymorphic URI works. But in the case of POST, I start to see problems:

POST http://localhost:9000/bookstore/items

What does this mean? Create an abstract type "Item"? But entity type Item does 
not really exist, it is only an abstract concept. Create a concrete type? But 
how? Well, if the server is smart enough, we might be able to detect the 
concrete type by examining the content of POST body. If the content of POST 
body is an on-wire representation of Book then we create a Book entity. As you 
can probably agree, this might work in some cases but it is not a generic 
enough solution, it goes too far. Actually, when you sent a HTTP POST to add an 
entity on the client side, surely you already know the concrete type you want 
to create. If you know you want to add a Book, why don’t simply call "POST 
http://localhost:9000/bookstore/book";?

Same thing applies to HTTP PUT and HTTP DELETE.

Cheers,
Jervis

> -----Original Message-----
> From: TonyTheFish [mailto:[EMAIL PROTECTED]
> Sent: 2008年1月18日 2:43
> To: [email protected]
> Subject: Polymorphic dispatch, JAXB REST.
> 
> 
> I have an r&d project on the go and I'm having difficulty getting a rest
> service to dispatch correctly.
> 
> I have these two classes
> @XmlTransient
> public class Transaction implements Serializable { ... }
> 
> @XmlRootElement(name = "transactionType1")
> public class TransactionType1 extends Transaction implements Serializable {
> .. }
> 
> If I try to feed a TransactionType1 instance into this
> 
> @HttpMethod("POST")
>       @ProduceMime("application/xml")
>       @UriTemplate("/transaction/")
>       public Response addTransaction(Transaction transaction) { ... }
> 
> I see
> 
> java.lang.NullPointerException
>         at
> org.apache.cxf.jaxrs.JAXRSUtils.readFromEntityBody(JAXRSUtils.java:224)
>         at
> org.apache.cxf.jaxrs.JAXRSUtils.processParameter(JAXRSUtils.java:199)
> 
> ....
> 
> However if I change the method signature to accept TransactionType1 it
> works
> fine.  What I'm really after, as you probably guessed, is to dispatch
> multiple transaction types through the same endpoint.
> 
> Thanks in advance - TtF
> --
> View this message in context:
> http://www.nabble.com/Polymorphic-dispatch%2C-JAXB-REST.-tp14928185
> p14928185.html
> Sent from the cxf-user mailing list archive at Nabble.com.

----------------------------
IONA Technologies PLC (registered in Ireland)
Registered Number: 171387
Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland

Reply via email to