Re: Do a POST with Tapestry and "Link"
It's not really clear what you want to do. With Tapestry you really don't need to fiddling with URLEncoder or connections. Which Tapestry Version are you targeting (3, 4 or 5)? If you use 5 - take a look at the LinkSubmit component (http://tapestry.apache.org/tapestry5.1/tapestry-core/ref/org/apache/tapestry5/corelib/components/LinkSubmit.html). Simple form example with LinkSubmit: # Submit me -- View this message in context: http://tapestry-users.832.n2.nabble.com/Do-a-POST-with-Tapestry-and-Link-tp5717358p5724205.html Sent from the Tapestry Users mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Do a POST with Tapestry and "Link"
Hi, I need to do POST in Tapestry for example : When I try : String data = URLEncoder.encode("*FirstParam*", "UTF-8") + "=" + URLEncoder.encode("*FirstParam*", "UTF-8"); data += "&" + URLEncoder.encode("*SndParam*", "UTF-8") + "=" + URLEncoder.encode("*SndParam"*, "UTF-8"); // Send data URL url = new URL(*MyURL*); URLConnection conn = url.openConnection(); conn.setDoOutput(true); OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream()); wr.write(data); wr.flush(); But Tapestry tell me that I must use : java.net.URL, org.apache.tapestry5.Link, org.apache.tapestry5.StreamResponse Any one know how to do ? Thanks in advance *Khalid.*
Re: Do a post with Tapestry and Link
Thank you I'll try that.
Re: Do a post with Tapestry and Link
On Mon, 08 Nov 2010 11:01:31 -0200, Khalid EL BOUKHARI wrote: Thank you Joost and Thiago, :) May be may question wasn't clear. So what I need that a method return an object that make a post with the previous params. My interpretation was correct. Tapestry (and any other web framwork) don't do POST requests, they handle them. You'll need to use HttpClient to do that or rethink the logic you're trying to implement. -- 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-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: Do a post with Tapestry and Link
Thank you Joost and Thiago, May be may question wasn't clear. So what I need that a method return an object that make a post with the previous params. I hope that is more clear now. Cheers, Khalid.
Re: Do a post with Tapestry and Link
If I read this correctly you are using an external java program to post to a tapestry page. Correct? The error you are refering to is usually associated with the required return type from an event method which you have not shown in your post. Can you post the page code handeling the POST request? For refference, below you will find the onActivate code of a page I use to handle external XML POST requests. Cheers, Joost -- a POST handling page -- @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 response = ... build the response xml Document final ByteArrayInputStream output = new ByteArrayInputStream(response.getBytes()); 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 8/11/10 11:36 AM, Khalid EL BOUKHARI wrote: Hi, I need to do POST in Tapestry for example : When I try : String data = URLEncoder.encode("*FirstParam*", "UTF-8") + "=" + URLEncoder.encode("*FirstParam*", "UTF-8"); data += "&" + URLEncoder.encode("*SndParam*", "UTF-8") + "=" + URLEncoder.encode("*SndParam"*, "UTF-8"); // Send data URL url = new URL(*MyURL*); URLConnection conn = url.openConnection(); conn.setDoOutput(true); OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream()); wr.write(data); wr.flush(); But Tapestry tell me that I must use : java.net.URL, org.apache.tapestry5.Link, org.apache.tapestry5. StreamResponse Any one know how to do ? Thanks in advance *Khalid.* - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: Do a post with Tapestry and Link
On Mon, 08 Nov 2010 08:36:46 -0200, Khalid EL BOUKHARI wrote: Hi, Hi! I need to do POST in Tapestry for example : Tapestry handles request, doesn't makes them. Use HttpClient for that. -- 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-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Do a post with Tapestry and Link
Hi, I need to do POST in Tapestry for example : When I try : String data = URLEncoder.encode("*FirstParam*", "UTF-8") + "=" + URLEncoder.encode("*FirstParam*", "UTF-8"); data += "&" + URLEncoder.encode("*SndParam*", "UTF-8") + "=" + URLEncoder.encode("*SndParam"*, "UTF-8"); // Send data URL url = new URL(*MyURL*); URLConnection conn = url.openConnection(); conn.setDoOutput(true); OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream()); wr.write(data); wr.flush(); But Tapestry tell me that I must use : java.net.URL, org.apache.tapestry5.Link, org.apache.tapestry5. StreamResponse Any one know how to do ? Thanks in advance *Khalid.*