You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by immutability <de...@bielik.org> on 2008/08/25 21:10:11 UTC

T5: How to implement a simple API servlet?

Guys, I've been trying to search google and nabble for this, but just
couldn't find the answer, perhaps I'm just using the wrong keywords or
something... as I'm sure it will sound trivial to some of you.

Here's what I'm trying to achieve: I'd like to implement a simplistic API in
our webapplication using just a plain old servlet to handle all API method
calls. The idea is to just call this single servlet, passing in the required
set of parameters via GET/POST, and responding with a either an XML data
response (text/xml), or a binary stream (zipped data) depending on the
method called.

Now, I'm lost trying to find the best way how to mix this into the existing
Tapestry5 application. I have tried to just add the servlet/mapping into
web.xml but that doesn't work. I thought about extending TapestryFilter to
ignore the API servlet's path, but the doFilter method is "final" right? I
also thought about just getting the raw http request/response within a
tapestry page using injection, but that just doesn't feel right - it seems
better to bypass tapestry altogether for this purpose, or is it wrong?

Thanks for any ideas in advance!
Rado
-- 
View this message in context: http://www.nabble.com/T5%3A-How-to-implement-a-simple-API-servlet--tp19149751p19149751.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5: How to implement a simple API servlet?

Posted by immutability <de...@bielik.org>.
Thanks a lot for the tip Howard, I'll try it this way then, and see how it
goes! :)


Howard Lewis Ship wrote:
> 
> I did some modest work like this many months back, where I had a page
> as a kind of RESTful service endpoint.  I returned a StreamResponse
> from onActivate().  The "page" didn't even have a template.  This is
> not quite what T5 is intended to do, but you get the benefits of live
> class reloading and IoC integration, so why not?
> 
> On Mon, Aug 25, 2008 at 12:10 PM, immutability <de...@bielik.org>
> wrote:
>>
>> Guys, I've been trying to search google and nabble for this, but just
>> couldn't find the answer, perhaps I'm just using the wrong keywords or
>> something... as I'm sure it will sound trivial to some of you.
>>
>> Here's what I'm trying to achieve: I'd like to implement a simplistic API
>> in
>> our webapplication using just a plain old servlet to handle all API
>> method
>> calls. The idea is to just call this single servlet, passing in the
>> required
>> set of parameters via GET/POST, and responding with a either an XML data
>> response (text/xml), or a binary stream (zipped data) depending on the
>> method called.
>>
>> Now, I'm lost trying to find the best way how to mix this into the
>> existing
>> Tapestry5 application. I have tried to just add the servlet/mapping into
>> web.xml but that doesn't work. I thought about extending TapestryFilter
>> to
>> ignore the API servlet's path, but the doFilter method is "final" right?
>> I
>> also thought about just getting the raw http request/response within a
>> tapestry page using injection, but that just doesn't feel right - it
>> seems
>> better to bypass tapestry altogether for this purpose, or is it wrong?
>>
>> Thanks for any ideas in advance!
>> Rado
>> --
>> View this message in context:
>> http://www.nabble.com/T5%3A-How-to-implement-a-simple-API-servlet--tp19149751p19149751.html
>> Sent from the Tapestry - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
> 
> 
> 
> -- 
> Howard M. Lewis Ship
> 
> Creator Apache Tapestry and Apache HiveMind
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/T5%3A-How-to-implement-a-simple-API-servlet--tp19149751p19149933.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5: How to implement a simple API servlet?

Posted by Howard Lewis Ship <hl...@gmail.com>.
I did some modest work like this many months back, where I had a page
as a kind of RESTful service endpoint.  I returned a StreamResponse
from onActivate().  The "page" didn't even have a template.  This is
not quite what T5 is intended to do, but you get the benefits of live
class reloading and IoC integration, so why not?

On Mon, Aug 25, 2008 at 12:10 PM, immutability <de...@bielik.org> wrote:
>
> Guys, I've been trying to search google and nabble for this, but just
> couldn't find the answer, perhaps I'm just using the wrong keywords or
> something... as I'm sure it will sound trivial to some of you.
>
> Here's what I'm trying to achieve: I'd like to implement a simplistic API in
> our webapplication using just a plain old servlet to handle all API method
> calls. The idea is to just call this single servlet, passing in the required
> set of parameters via GET/POST, and responding with a either an XML data
> response (text/xml), or a binary stream (zipped data) depending on the
> method called.
>
> Now, I'm lost trying to find the best way how to mix this into the existing
> Tapestry5 application. I have tried to just add the servlet/mapping into
> web.xml but that doesn't work. I thought about extending TapestryFilter to
> ignore the API servlet's path, but the doFilter method is "final" right? I
> also thought about just getting the raw http request/response within a
> tapestry page using injection, but that just doesn't feel right - it seems
> better to bypass tapestry altogether for this purpose, or is it wrong?
>
> Thanks for any ideas in advance!
> Rado
> --
> View this message in context: http://www.nabble.com/T5%3A-How-to-implement-a-simple-API-servlet--tp19149751p19149751.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>



-- 
Howard M. Lewis Ship

Creator Apache Tapestry and Apache HiveMind

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5: How to implement a simple API servlet?

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Mon, 25 Aug 2008 16:10:11 -0300, immutability <de...@bielik.org>  
escreveu:

> Here's what I'm trying to achieve: I'd like to implement a simplistic  
> API in our webapplication using just a plain old servlet to handle all  
> API method calls. The idea is to just call this single servlet, passing  
> in the required set of parameters via GET/POST, and responding with a  
> either an XML data
> response (text/xml), or a binary stream (zipped data) depending on the
> method called.

At least with GET, You could do this with a Tapestry page class returning  
a StreamResponse in its onActivate() method. Way easier than writing a  
servlet.
More information here:  
http://tapestry.apache.org/tapestry5/guide/pagenav.html (StreampResponse  
section)
One example here:  
http://wiki.apache.org/tapestry/Tapestry5HowToCreatePieChartsInAPage. The  
example generates images, but it can be used to generate any kind of  
response.

> Now, I'm lost trying to find the best way how to mix this into the  
> existing Tapestry5 application. I have tried to just add the  
> servlet/mapping into
> web.xml but that doesn't work. I thought about extending TapestryFilter  
> to ignore the API servlet's path, but the doFilter method is "final"  
> right?

You don't need to do this. Read the "Ignored paths" section of  
http://tapestry.formos.com/nightly/tapestry5/guide/conf.html. Short  
version: add this method to your AppModule class:

public static void  
contributeIgnoredPathsFilter(UnorderedCollection<String> configuration) {
     configuration.add("/pathToYourServlet/.*");
}

PS: the configuration page in the regular Tapestry site  
(http://tapestry.apache.org/tapestry5/guide/conf.html) is empty.

Thiago

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org