|
From: Ryan J. M. <ry...@da...> - 2008-07-16 01:04:56
|
On Jul 15, 2008, at 9:22 AM, Bill Burke wrote:
> I don't see why you need a change to Resteasy to do this when the
> JAX-RS spec allows you to return any arbitrary object from a
> subresource locator. For example:
>
> @Path("/")
> public class CustomerDatabase {
>
> @Path("customers/{id}")
> public Object getCustomer() {
>
> Customer cust = jpa.find(...);
> return cust;
> }
> }
>
> public class Customer {
>
> @GET
> public String get() {...}
>
> @Path("/address")
> public String getAddress() {...}
> }
>
> So
>
> GET /customers/1
> GET /customer/1/address
>
> Would eventually route to Customer.
I've tried that, and it does not work. You can certainly get the
Contact entity, but any @Path annotations on the entity are not
processed. We don't have any unit tests which cover this sort of
behavior, so it maybe that we don't support this yet? (Or support this
with EJB's?) I was also taking a look at the Jersey "Bookmark" example
app, and they have created separate resource classes for child
entities. Ideally, I don't want to do this. You've got similar
patterns being repeated and we've got a lot of meta data on the entity
that we can use.
>
> ResourceFactory is used to instantiate an endpoint and also to
> preprocess the class file looking for annotations and create Path
> bindings in the registry. I don't understand what you want to use
> it for or the change you want.
Understood, and most likely ResourceFactory isn't the best choice.
what I am looking at is take the case where a Contact has a one-to-
many association with a EmailAddress entity. If you just annotate the
entity as such:
@Entity
@Table(name = "contact")
public class Contact
{
...
@GET
@Path("/emailAddresses")
public Set<EmailAddress> getEmailAddresses()
{
return emailAddresses;
}
@GET
@Path("/emailAddresses/{emailAddressId}")
public EmailAddress
getEmailAddressById(@PathParam("emailAddressId") Long id) {
for(EmailAddress emailAddress : this.emailAddresses) {
if(id.equals(emailAddress.getId())) {
return emailAddress;
}
}
return null;
}...
It'd work, but not the most efficient way of doing things. I'm
probably thinking more in terms of Christian's 4th point on Seam
integration and potentially free-associating a bit as well ;). But
another thing to consider is that you may not always get back a
concrete class as it could be a proxy. In which case, the proxy won't
contain the annotation data and therefore won't work.
Ryan-
>
> Ryan J. McDonough wrote:
>> I've been working on an example (most of which I have committed)
>> which uses EJB3 + JPA + Seam. The contact entity is an object graph
>> with multiple child elements. Ideally what I'd like to be able to
>> do is to have the Contact entity that is returned become a sub-
>> resource. However, we don't have a ResourceFactory that can handle
>> that. So I was thinking about an EntityResourceFactory, but I see
>> some challenges:
>> * Introducing JPA (or Hibernate) would create another dependency
>> * The ResourceMethodRegistry does not dynamically load
>> ResourceFactory instances. For example, if we could have a
>> another
>> project load a custom ResourceFactory, how is it located and how
>> does it get utilized?
>> * There doesn't appear to be a clear way of
>> having ResourceMethodRegistry choose a particular
>> ResourceFactory
>> instance
>> I don't know if I'm missing anything, but I see this as an issue
>> and something that the Seam folks might run into some issues?
>> Ryan-
>> ------------------------------------------------------------------------
>> -------------------------------------------------------------------------
>> This SF.Net email is sponsored by the Moblin Your Move Developer's
>> challenge
>> Build the coolest Linux based applications with Moblin SDK & win
>> great prizes
>> Grand prize is a trip for two to an Open Source event anywhere in
>> the world
>> http://moblin-contest.org/redirect.php?banner_id=100&url=/
>> ------------------------------------------------------------------------
>> _______________________________________________
>> Resteasy-developers mailing list
>> Res...@li...
>> https://lists.sourceforge.net/lists/listinfo/resteasy-developers
>
> --
> Bill Burke
> JBoss, a division of Red Hat
> http://bill.burkecentral.com
|