You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by llonely <at...@gmail.com> on 2007/10/31 12:22:47 UTC

Simple servlet with xml output - to tapestry

Hi all, 

I am currently testing tapestry and trying to convert a simple servlet.

I have a typical servlet that gets parameters and returns xml

for example http://localhost:8080/myapp/method=login&user=test
result:
 <results>
  <status>ok</status> 
  </results>

after that, return results for user stored in session
http://localhost:8080/myapp/method=info

 <results>
  <username>test</username> 
  </results>

so basically I want something similar in tapestry that:

- will accept parameters
- will use xml as templates and will generate xml results
- will persist the user credentials into the session

My biggest concern is '2'  (xml output). Its not clear to me how should I
configured it. Should it be a service or I can just edit the template (can't
make it return xml). I am still trying to become familiar with tapestry so I
can't completely understand some forum results regarding outputs.

I am using version 5.0.5

Any advice would be very much appreciated.

Thanks


-- 
View this message in context: http://www.nabble.com/Simple-servlet-with-xml-output---to-tapestry-tf4724274.html#a13506986
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: Simple servlet with xml output - to tapestry

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Wed, 31 Oct 2007 11:37:43 -0200, llonely <at...@gmail.com> wrote:

> Many thanks Thiago,
> this is surprisingly helpful!

You're welcome. :)

> Is XML output possible on template level? Having a template with the  
> basic structure and update it based on parameter values.

As far as I know, you can generate any XML output you want in Tapestry 5  
templates, but a redirect will be made (following the redirect-after-post  
design pattern) and the HTTP response content type will not be set to  
text/xml.

Other option would be using some template engine like Velocity or  
FreeMarker to generate your XML.

-- 
Thiago H. de Paula Figueiredo
Desenvolvedor, Instrutor e Consultor de Tecnologia
Eteg Tecnologia da Informação Ltda.
http://www.eteg.com.br

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


Re: Simple servlet with xml output - to tapestry

Posted by llonely <at...@gmail.com>.
Thank you very much both.

Fernando, I just voted for on bug. Will try to use the patch as well, as I
need namespaces.
Will keep you posted

regards
thanos



Fernando Padilla wrote:
> 
> Yes you can output XML directly from the template with some caveats.
> 
> 1) By default the contentType is "text/html", if you want to change that 
> you can override it by using this annotation on your page class file:
> @Meta("tapestry.response-content-type=text/xml")
> 
> 2) namespaces are totally ignored and stripped out.
> 
> 3) if you use any of the special html elements, then it uses the old 
> html method of not actually closing the tags ( <br>,  , etc ).  So 
> essentially it outputs invalid xml.  You might have to do some post 
> processing to clean it up..
> 
> 
> possible work around:
> 
> If you need namespaces, or if you need to avoid the "special html tag" 
> handling, you need to look at JIRA issue TAPESTRY-1600.  Go there and 
> vote on the bug, it also has a patch if you're stuck and feeling 
> adventurous.  I have been using the patch for over a month on 
> production, and have gotten response from another person that they are 
> pretty happy with it.
> 
> Go vote for it, for some reason we have gotten zero response from the T5 
> developers on reviewing the patch.  If applying the patch is too much 
> for you and there is still interest, maybe I'll have to maintain a 
> tapestry build with the patch applied..
> 
> 
> 
> 
> 
> llonely wrote:
>> Many thanks Thiago,
>> this is surprisingly helpful!
>> 
>> Is XML output possible on template level? Having a template with the
>> basic
>> structure and update it based on parameter values.
>> 
>> BR
>> 
>> 
>> 
>> 
>> Thiago H de Paula Figueiredo-2 wrote:
>>> On Wed, 31 Oct 2007 09:22:47 -0200, llonely <at...@gmail.com> wrote:
>>>
>>>> Hi all,
>>>>
>>>> I am currently testing tapestry and trying to convert a simple servlet.
>>>>
>>>> I have a typical servlet that gets parameters and returns xml
>>> Generate the XML output using any method you fancy and then return a  
>>> StreamResponse (in this case, a TextStreamResponse) in your onActivate  
>>> method. Tapestry 5 will not issue a redirect as it does with normal
>>> pages.  
>>> One example is in Howard's blog:  
>>> http://tapestryjava.blogspot.com/2007/08/handling-direct-urls-in-tapestry-5.html.  
>>> :)
>>>
>>> In previous versions this kind of situation was hard to implement, but
>>> in  
>>> Tapestry 5 it's a piece of cake. :)
>>>
>>> -- 
>>> Thiago H. de Paula Figueiredo
>>> Desenvolvedor, Instrutor e Consultor de Tecnologia
>>> Eteg Tecnologia da Informação Ltda.
>>> http://www.eteg.com.br
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>>
>>>
>>>
>> 
> 
> ---------------------------------------------------------------------
> 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/Simple-servlet-with-xml-output---to-tapestry-tf4724274.html#a13512908
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: Simple servlet with xml output - to tapestry

Posted by thanos <at...@gmail.com>.
Turns out the patch is too big to apply.
Fernando, is it possible to share a build with the patch applied? I am sure
other people will have the save need and would surely appreciated it

thanks
Thanos


Fernando Padilla wrote:
> 
> Yes you can output XML directly from the template with some caveats.
> 
> 1) By default the contentType is "text/html", if you want to change that 
> you can override it by using this annotation on your page class file:
> @Meta("tapestry.response-content-type=text/xml")
> 
> 2) namespaces are totally ignored and stripped out.
> 
> 3) if you use any of the special html elements, then it uses the old 
> html method of not actually closing the tags ( <br>,  , etc ).  So 
> essentially it outputs invalid xml.  You might have to do some post 
> processing to clean it up..
> 
> 
> possible work around:
> 
> If you need namespaces, or if you need to avoid the "special html tag" 
> handling, you need to look at JIRA issue TAPESTRY-1600.  Go there and 
> vote on the bug, it also has a patch if you're stuck and feeling 
> adventurous.  I have been using the patch for over a month on 
> production, and have gotten response from another person that they are 
> pretty happy with it.
> 
> Go vote for it, for some reason we have gotten zero response from the T5 
> developers on reviewing the patch.  If applying the patch is too much 
> for you and there is still interest, maybe I'll have to maintain a 
> tapestry build with the patch applied..
> 
> 
> 
> 
> 
> llonely wrote:
>> Many thanks Thiago,
>> this is surprisingly helpful!
>> 
>> Is XML output possible on template level? Having a template with the
>> basic
>> structure and update it based on parameter values.
>> 
>> BR
>> 
>> 
>> 
>> 
>> Thiago H de Paula Figueiredo-2 wrote:
>>> On Wed, 31 Oct 2007 09:22:47 -0200, llonely <at...@gmail.com> wrote:
>>>
>>>> Hi all,
>>>>
>>>> I am currently testing tapestry and trying to convert a simple servlet.
>>>>
>>>> I have a typical servlet that gets parameters and returns xml
>>> Generate the XML output using any method you fancy and then return a  
>>> StreamResponse (in this case, a TextStreamResponse) in your onActivate  
>>> method. Tapestry 5 will not issue a redirect as it does with normal
>>> pages.  
>>> One example is in Howard's blog:  
>>> http://tapestryjava.blogspot.com/2007/08/handling-direct-urls-in-tapestry-5.html.  
>>> :)
>>>
>>> In previous versions this kind of situation was hard to implement, but
>>> in  
>>> Tapestry 5 it's a piece of cake. :)
>>>
>>> -- 
>>> Thiago H. de Paula Figueiredo
>>> Desenvolvedor, Instrutor e Consultor de Tecnologia
>>> Eteg Tecnologia da Informação Ltda.
>>> http://www.eteg.com.br
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>>
>>>
>>>
>> 
> 
> ---------------------------------------------------------------------
> 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/Simple-servlet-with-xml-output---to-tapestry-tf4724274.html#a13625882
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: Simple servlet with xml output - to tapestry

Posted by Fernando Padilla <fe...@alum.mit.edu>.
Yes you can output XML directly from the template with some caveats.

1) By default the contentType is "text/html", if you want to change that 
you can override it by using this annotation on your page class file:
@Meta("tapestry.response-content-type=text/xml")

2) namespaces are totally ignored and stripped out.

3) if you use any of the special html elements, then it uses the old 
html method of not actually closing the tags ( <br>, <img>, etc ).  So 
essentially it outputs invalid xml.  You might have to do some post 
processing to clean it up..


possible work around:

If you need namespaces, or if you need to avoid the "special html tag" 
handling, you need to look at JIRA issue TAPESTRY-1600.  Go there and 
vote on the bug, it also has a patch if you're stuck and feeling 
adventurous.  I have been using the patch for over a month on 
production, and have gotten response from another person that they are 
pretty happy with it.

Go vote for it, for some reason we have gotten zero response from the T5 
developers on reviewing the patch.  If applying the patch is too much 
for you and there is still interest, maybe I'll have to maintain a 
tapestry build with the patch applied..





llonely wrote:
> Many thanks Thiago,
> this is surprisingly helpful!
> 
> Is XML output possible on template level? Having a template with the basic
> structure and update it based on parameter values.
> 
> BR
> 
> 
> 
> 
> Thiago H de Paula Figueiredo-2 wrote:
>> On Wed, 31 Oct 2007 09:22:47 -0200, llonely <at...@gmail.com> wrote:
>>
>>> Hi all,
>>>
>>> I am currently testing tapestry and trying to convert a simple servlet.
>>>
>>> I have a typical servlet that gets parameters and returns xml
>> Generate the XML output using any method you fancy and then return a  
>> StreamResponse (in this case, a TextStreamResponse) in your onActivate  
>> method. Tapestry 5 will not issue a redirect as it does with normal pages.  
>> One example is in Howard's blog:  
>> http://tapestryjava.blogspot.com/2007/08/handling-direct-urls-in-tapestry-5.html.  
>> :)
>>
>> In previous versions this kind of situation was hard to implement, but in  
>> Tapestry 5 it's a piece of cake. :)
>>
>> -- 
>> Thiago H. de Paula Figueiredo
>> Desenvolvedor, Instrutor e Consultor de Tecnologia
>> Eteg Tecnologia da Informação Ltda.
>> http://www.eteg.com.br
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>>
> 

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


Re: Simple servlet with xml output - to tapestry

Posted by llonely <at...@gmail.com>.
Many thanks Thiago,
this is surprisingly helpful!

Is XML output possible on template level? Having a template with the basic
structure and update it based on parameter values.

BR




Thiago H de Paula Figueiredo-2 wrote:
> 
> On Wed, 31 Oct 2007 09:22:47 -0200, llonely <at...@gmail.com> wrote:
> 
>>
>> Hi all,
>>
>> I am currently testing tapestry and trying to convert a simple servlet.
>>
>> I have a typical servlet that gets parameters and returns xml
> 
> Generate the XML output using any method you fancy and then return a  
> StreamResponse (in this case, a TextStreamResponse) in your onActivate  
> method. Tapestry 5 will not issue a redirect as it does with normal pages.  
> One example is in Howard's blog:  
> http://tapestryjava.blogspot.com/2007/08/handling-direct-urls-in-tapestry-5.html.  
> :)
> 
> In previous versions this kind of situation was hard to implement, but in  
> Tapestry 5 it's a piece of cake. :)
> 
> -- 
> Thiago H. de Paula Figueiredo
> Desenvolvedor, Instrutor e Consultor de Tecnologia
> Eteg Tecnologia da Informação Ltda.
> http://www.eteg.com.br
> 
> ---------------------------------------------------------------------
> 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/Simple-servlet-with-xml-output---to-tapestry-tf4724274.html#a13509247
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: Simple servlet with xml output - to tapestry

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Wed, 31 Oct 2007 09:22:47 -0200, llonely <at...@gmail.com> wrote:

>
> Hi all,
>
> I am currently testing tapestry and trying to convert a simple servlet.
>
> I have a typical servlet that gets parameters and returns xml

Generate the XML output using any method you fancy and then return a  
StreamResponse (in this case, a TextStreamResponse) in your onActivate  
method. Tapestry 5 will not issue a redirect as it does with normal pages.  
One example is in Howard's blog:  
http://tapestryjava.blogspot.com/2007/08/handling-direct-urls-in-tapestry-5.html.  
:)

In previous versions this kind of situation was hard to implement, but in  
Tapestry 5 it's a piece of cake. :)

-- 
Thiago H. de Paula Figueiredo
Desenvolvedor, Instrutor e Consultor de Tecnologia
Eteg Tecnologia da Informação Ltda.
http://www.eteg.com.br

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