You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by niksami <ni...@fleka.me> on 2010/11/15 15:18:03 UTC

XML requests

Hello everyone.

In my application I need to receive XML requests, and then to send the
response back to the client in XML format too. I tried to find some nice
solution here, but with no success. I hope you can give me some short code
examples.

Best regards,
Niksa
-- 
View this message in context: http://tapestry.1045711.n5.nabble.com/XML-requests-tp3265672p3265672.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: XML requests

Posted by niksami <ni...@fleka.me>.
Thanks, next time I'll ask Google before asking a dumb question :)

-----
Niksa Mijanovic
Java developer, jr.
www.fleka.me
-- 
View this message in context: http://tapestry.1045711.n5.nabble.com/XML-requests-tp3265672p3268918.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: XML requests

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Wed, 17 Nov 2010 09:11:18 -0200, niksami <ni...@fleka.me> wrote:

> I've also tried your code, but I get problem that I can not find  
> SAXBuilder as part of my Tapestry project... I'm using Tapestry 5.2...  
> What can I do in that case? :)

It's part of JDOM, which isn't included automatically by Maven when you  
declare your Tapestry dependency.. ;)

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br

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


Re: XML requests

Posted by niksami <ni...@fleka.me>.
I've also tried your code, but I get problem that I can not find SAXBuilder
as part of my Tapestry project... I'm using Tapestry 5.2... What can I do in
that case? :)


Joost Schouten (mailing lists) wrote:
> 
>   More common is to deal with xml requests though a POST. In that case 
> you can do something like below.
> 
> Cheers,
> Joost
> 
> 
> @Inject
> private RequestGlobals requestGlobals;
> 
> @OnEvent(value = EventConstants.ACTIVATE)
> private Object activate() throws Exception {
> 
>          HttpServletRequest httpServletRequest = 
> requestGlobals.getHTTPServletRequest();
>          ServletInputStream inputStream = 
> httpServletRequest.getInputStream();
> 
>          SAXBuilder builder = new SAXBuilder();
>          Document xmlRequest = builder.build(inputStream);
> 
>          String xmlStringResponse = .... build up your xml response ....
> 
>          final ByteArrayInputStream output = new 
> ByteArrayInputStream(xmlStringResponse);
> 
>          final StreamResponse streamResponse = new StreamResponse() {
> 
>              public String getContentType() {
>                  return "text/xml";
>              }
> 
>              public InputStream getStream() throws IOException {
>                  return output;
>              }
> 
>              public void prepareResponse(Response response) {
>              }
>          };
>          return streamResponse;
> }
> 
> On 15/11/10 4:47 PM, niksami wrote:
>> This will work for me. Basically I need to receive XML as a parameter,
>> for
>> example as a String in onActivate() method. So, I think this will do job
>> for
>> me:
>>
>>   public TextStreamResponse onActivate(String xml) {
>>
>>      //doing something with xml
>>
>>      return new TextStreamResponse("text/xml", xml);
>>
>> }
>>
>> Thank you!
>>
>> Niksa
>>
>>
>> Richard Hill-7 wrote:
>>>
>>> You don't specify where/how you want to receive XML requests from - is
>>> this server-to-server? If so this out of the realm of Tapestry, but
>>> there's plenty of java networking libs to help you do this.
>>>
>>> With respect to sending an xml document/page to a browser client,
>>> tapestry is not really designed for this. Although you could use
>>> TextStreamResponse for this:
>>>
>>> http://tapestry.apache.org/tapestry5/apidocs/org/apache/tapestry5/util/TextStreamResponse.html
>>>
>>>
>>> public TextStreamResponse onActivate() {
>>>
>>>      String xml = getMyXMLFromSomeWhere....
>>>
>>>      return new TextStreamResponse("text/xml", xml);
>>>
>>> }
>>>
>>>
>>> R.
>>>
>>>
>>>
>>> -----Original Message-----
>>> From: niksami<ni...@fleka.me>
>>> Reply-to: "Tapestry users"<us...@tapestry.apache.org>
>>> To: users@tapestry.apache.org
>>> Subject: XML requests
>>> Date: Mon, 15 Nov 2010 06:18:03 -0800 (PST)
>>>
>>> Hello everyone.
>>>
>>> In my application I need to receive XML requests, and then to send the
>>> response back to the client in XML format too. I tried to find some nice
>>> solution here, but with no success. I hope you can give me some short
>>> code
>>> examples.
>>>
>>> Best regards,
>>> Niksa
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> 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://tapestry.1045711.n5.nabble.com/XML-requests-tp3265672p3268904.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: XML requests

Posted by niksami <ni...@fleka.me>.
OK, I added JDOM to Maven, and when I tried this code I got following error:

org.apache.tapestry5.ioc.internal.OperationException
org.jdom.JDOMException: Error on line -1: Premature end of file.

pointing to this line of code:

Document xmlRequest = builder.build(inputStream);

As I sad earlier I use form on another page to get XML. This is the form:

<form  id="xmlForm" method="post" action="http://mypath/testXml">
        <textarea name="xmlarea" />
        <input type="submit" value="submit" />
</form>

and I added your code to the page where I obtain XML, instead of:

public TextStreamResponse onActivate() {

                xmlarea = (String) request.getParameter("xmlarea");

                 //Just returns the same XML
                return new TextStreamResponse("text/xml", xmlarea);

                }

        } 

Do you have some clue?

-----
Niksa Mijanovic
Java developer, jr.
www.fleka.me
-- 
View this message in context: http://tapestry.1045711.n5.nabble.com/XML-requests-tp3265672p3268954.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: XML requests

Posted by niksami <ni...@fleka.me>.
Thanks, but this is the simplest thing that worked for me (thanks to Thiago):

Test page for submitting XML contains only form with textarea (with no Java
code on the back):

<form  id="xmlForm" method="post" action="http://mypath/testXml">
	<textarea name="xmlarea" />
	<input type="submit" value="submit" />
</form>

Then on other page I have this (in the Java code of the page, the tml is
empty HTML page):

        @Inject
	private Request request;

	@Property
	private String xmlarea;

	public TextStreamResponse onActivate() {

		xmlarea = (String) request.getParameter("xmlarea");

                 //Just returns the same XML
		return new TextStreamResponse("text/xml", xmlarea);

		}

	}
-- 
View this message in context: http://tapestry.1045711.n5.nabble.com/XML-requests-tp3265672p3268862.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: XML requests

Posted by "Joost Schouten (ml)" <jo...@jsportal.com>.
  More common is to deal with xml requests though a POST. In that case 
you can do something like below.

Cheers,
Joost


@Inject
private RequestGlobals requestGlobals;

@OnEvent(value = EventConstants.ACTIVATE)
private Object activate() throws Exception {

         HttpServletRequest httpServletRequest = 
requestGlobals.getHTTPServletRequest();
         ServletInputStream inputStream = 
httpServletRequest.getInputStream();

         SAXBuilder builder = new SAXBuilder();
         Document xmlRequest = builder.build(inputStream);

         String xmlStringResponse = .... build up your xml response ....

         final ByteArrayInputStream output = new 
ByteArrayInputStream(xmlStringResponse);

         final StreamResponse streamResponse = new StreamResponse() {

             public String getContentType() {
                 return "text/xml";
             }

             public InputStream getStream() throws IOException {
                 return output;
             }

             public void prepareResponse(Response response) {
             }
         };
         return streamResponse;
}

On 15/11/10 4:47 PM, niksami wrote:
> This will work for me. Basically I need to receive XML as a parameter, for
> example as a String in onActivate() method. So, I think this will do job for
> me:
>
>   public TextStreamResponse onActivate(String xml) {
>
>      //doing something with xml
>
>      return new TextStreamResponse("text/xml", xml);
>
> }
>
> Thank you!
>
> Niksa
>
>
> Richard Hill-7 wrote:
>>
>> You don't specify where/how you want to receive XML requests from - is
>> this server-to-server? If so this out of the realm of Tapestry, but
>> there's plenty of java networking libs to help you do this.
>>
>> With respect to sending an xml document/page to a browser client,
>> tapestry is not really designed for this. Although you could use
>> TextStreamResponse for this:
>>
>> http://tapestry.apache.org/tapestry5/apidocs/org/apache/tapestry5/util/TextStreamResponse.html
>>
>>
>> public TextStreamResponse onActivate() {
>>
>>      String xml = getMyXMLFromSomeWhere....
>>
>>      return new TextStreamResponse("text/xml", xml);
>>
>> }
>>
>>
>> R.
>>
>>
>>
>> -----Original Message-----
>> From: niksami<ni...@fleka.me>
>> Reply-to: "Tapestry users"<us...@tapestry.apache.org>
>> To: users@tapestry.apache.org
>> Subject: XML requests
>> Date: Mon, 15 Nov 2010 06:18:03 -0800 (PST)
>>
>> Hello everyone.
>>
>> In my application I need to receive XML requests, and then to send the
>> response back to the client in XML format too. I tried to find some nice
>> solution here, but with no success. I hope you can give me some short code
>> examples.
>>
>> Best regards,
>> Niksa
>>
>>
>>
>> ---------------------------------------------------------------------
>> 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: XML requests

Posted by niksami <ni...@fleka.me>.
This will work for me. Basically I need to receive XML as a parameter, for
example as a String in onActivate() method. So, I think this will do job for
me:

 public TextStreamResponse onActivate(String xml) {

    //doing something with xml

    return new TextStreamResponse("text/xml", xml);

}

Thank you!

Niksa


Richard Hill-7 wrote:
> 
> 
> You don't specify where/how you want to receive XML requests from - is
> this server-to-server? If so this out of the realm of Tapestry, but
> there's plenty of java networking libs to help you do this.
> 
> With respect to sending an xml document/page to a browser client,
> tapestry is not really designed for this. Although you could use
> TextStreamResponse for this:
> 
> http://tapestry.apache.org/tapestry5/apidocs/org/apache/tapestry5/util/TextStreamResponse.html
> 
> 
> public TextStreamResponse onActivate() {
> 
>     String xml = getMyXMLFromSomeWhere....
> 
>     return new TextStreamResponse("text/xml", xml);
> 
> }
> 
> 
> R.
> 
> 
> 
> -----Original Message-----
> From: niksami <ni...@fleka.me>
> Reply-to: "Tapestry users" <us...@tapestry.apache.org>
> To: users@tapestry.apache.org
> Subject: XML requests
> Date: Mon, 15 Nov 2010 06:18:03 -0800 (PST)
> 
> Hello everyone.
> 
> In my application I need to receive XML requests, and then to send the
> response back to the client in XML format too. I tried to find some nice
> solution here, but with no success. I hope you can give me some short code
> examples.
> 
> Best regards,
> Niksa
> 
> 
> 
> ---------------------------------------------------------------------
> 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://tapestry.1045711.n5.nabble.com/XML-requests-tp3265672p3265893.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: XML requests

Posted by Richard Hill <ri...@su3analytics.com>.
You don't specify where/how you want to receive XML requests from - is
this server-to-server? If so this out of the realm of Tapestry, but
there's plenty of java networking libs to help you do this.

With respect to sending an xml document/page to a browser client,
tapestry is not really designed for this. Although you could use
TextStreamResponse for this:

http://tapestry.apache.org/tapestry5/apidocs/org/apache/tapestry5/util/TextStreamResponse.html


public TextStreamResponse onActivate() {

    String xml = getMyXMLFromSomeWhere....

    return new TextStreamResponse("text/xml", xml);

}


R.



-----Original Message-----
From: niksami <ni...@fleka.me>
Reply-to: "Tapestry users" <us...@tapestry.apache.org>
To: users@tapestry.apache.org
Subject: XML requests
Date: Mon, 15 Nov 2010 06:18:03 -0800 (PST)

Hello everyone.

In my application I need to receive XML requests, and then to send the
response back to the client in XML format too. I tried to find some nice
solution here, but with no success. I hope you can give me some short code
examples.

Best regards,
Niksa



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


Re: XML requests

Posted by niksami <ni...@fleka.me>.
Thanks, I'll try this.
-- 
View this message in context: http://tapestry.1045711.n5.nabble.com/XML-requests-tp3265672p3265787.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: Re: XML requests

Posted by niksami <ni...@fleka.me>.
Thank you. I'll try that, and then I'll inform you about success.

Kind regards,
Niksa
-- 
View this message in context: http://tapestry.1045711.n5.nabble.com/XML-requests-tp3265672p3267210.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: Re: XML requests

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Tue, 16 Nov 2010 09:55:06 -0200, niksami <ni...@fleka.me> wrote:

> And parameter name should be? Name of textarea from which is sent XML  
> POST request?

Yes. It's just an ordinary text area.

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br

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


Re: Re: XML requests

Posted by niksami <ni...@fleka.me>.
And parameter name should be? Name of textarea from which is sent XML POST
request?
-- 
View this message in context: http://tapestry.1045711.n5.nabble.com/XML-requests-tp3265672p3267201.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: Re: XML requests

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Tue, 16 Nov 2010 09:48:33 -0200, niksami <ni...@fleka.me> wrote:

> So my problem is how I can exchange that XML between that 2  
> applications. I can return it by TextStreamResponse, but how can I  
> receive it from that
> other app? That other app will send the XML POST request.

Just @Inject Request and use the getParameter(String name) method.

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br

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


Re: Re: XML requests

Posted by niksami <ni...@fleka.me>.
Ok... This is simplified situation... Another application needs to
communicate with my Tapestry application (to get some data). That
application will send XML to my page. On my page I will get that XML, add
some data to it, and then return the XML back to that application.

So my problem is how I can exchange that XML between that 2 applications. I
can return it by TextStreamResponse, but how can I receive it from that
other app? That other app will send the XML POST request.
-- 
View this message in context: http://tapestry.1045711.n5.nabble.com/XML-requests-tp3265672p3267193.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: Re: XML requests

Posted by Richard Hill <ri...@su3analytics.com>.
You need to be a little clearer about the flow of your XML - where it
originates, what you need to do with it and where it needs to go. 


 

-----Original Message-----
From: niksami <ni...@fleka.me>
Reply-to: "Tapestry users" <us...@tapestry.apache.org>
To: users@tapestry.apache.org
Subject: Re: Re: XML requests
Date: Tue, 16 Nov 2010 03:37:49 -0800 (PST)

Thank you again for your answer. But I don't understand you completely. Form
with TextArea can be used to obtain XML from another page that is sent to my
page with POST, or just to send POST? How can I access that XML that other
page sent me? Do I need to use Request, and then access it from parameter?

Please, write a line or two of code if you can.



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


Re: Re: XML requests

Posted by niksami <ni...@fleka.me>.
Thank you again for your answer. But I don't understand you completely. Form
with TextArea can be used to obtain XML from another page that is sent to my
page with POST, or just to send POST? How can I access that XML that other
page sent me? Do I need to use Request, and then access it from parameter?

Please, write a line or two of code if you can.
-- 
View this message in context: http://tapestry.1045711.n5.nabble.com/XML-requests-tp3265672p3267178.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: Re: XML requests

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Tue, 16 Nov 2010 06:56:34 -0200, niksami <ni...@fleka.me> wrote:

> Yes, I need POST to receive XML and then GET to return the new XML back  
> to that app. TextStreamResponse works well to return the XML back, but  
> can
> someone show me some example with POST. Just something like "Hello World"
> example to show me how this method works (getting XML from POST).

Just use a Form with a TextArea for your XML. ;)

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br

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


Re: Re: XML requests

Posted by niksami <ni...@fleka.me>.
Thank you for your answers.

Yes, I forgot about special signs, but also I found that activation context
would not supply my needs (because that other app can not access my page
with added arguments to URL).

Yes, I need POST to receive XML and then GET to return the new XML back to
that app. TextStreamResponse works well to return the XML back, but can
someone show me some example with POST. Just something like "Hello World"
example to show me how this method works (getting XML from POST).


I'm stuck on that 
-- 
View this message in context: http://tapestry.1045711.n5.nabble.com/XML-requests-tp3265672p3266999.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