On Nov 18, 2008, at 7:16 PM, António Mota wrote:
> I remembered why I didn't proceed at that time investigating the
> Jersey IoC. I saw that it was based on the WebApplication and my REST
> infrastructure is to be protocol independent (as Roy Fielding itself
> sugests in his dissertation).
>
The REST style is independent of protocol but the architecture you
apply the style does not have to be. JAX-RS makes no attempts to be
protocol independent (but see later). Being protocol independent is an
architectural decision you should make based on your requirements.
> So I have to have two different layers on the client-side, a
> Connectors layer (which for now is only a HttpConnector) and a
> Resources layer, that is responsible for finding and handle the right
> resource to the connector to populate with the request and send to the
> messaging infrastructure.
>
> Take the example of a FileUpload service. Now I have that service as
> a resource:
>
> @POST
> @Path("/FileUpload")
> void saveFile(@FormParam("filename")String name, @FormParam("file")
> byte[] file);
>
> and I have the HttpConnector that receives the request as a Multi-part
> request, asks the ResourceFactory (let's call it that) to find and
> instantiate the correct Resource, hand it back to the HttpConnector
> that in turns populates the MessageBean and send it to the Messaging
> infrastructure.
>
> But I also want a Email connector, that receives a email with
> "/FileUpload" as a Subject and a file as a attachment, and does the
> same (asks the ResourceFactory, etc...).
>
> So the finding of the correct resource cannot be the HttpConector (or
> Servlet or whatever) but the Resource component that can have several
> connectors connecting to him.
>
> Any thoughts on this?
>
I recommend you support two different Jersey-based containers:
1) Using HTTP; and
2) Using SMTP and mapping the SMTP request/response to Jersey
ContainerRequest and ContainerResponse
that can then be passed to WebApplication.handle.
A WebApplication instance created can be shared between the two. It is
quite easy to support containers, for example look at MuleSource [1].
My guess is the mapping from an SMTP request to a ContainerRequest
should be rather simple for what you require.
You can also look at the code for the ServletContainer and the
GrizzlyContainer for other examples.
Paul.
[1]
http://mule.mulesource.org/display/JERSEY/User%27s+Guide
http://svn.mule-transport-jersey.muleforge.org/