Re: How to POST data to an external site from an action?

2006-05-03 Thread Michael Jouravlev

On 5/3/06, Martin Kindler <[EMAIL PROTECTED]> wrote:

Thank you all for answering!

But I seem not to have stated my problem clearly: I know how I can POST to
an uri using Java.
My problem is that I want the user to be redirected (or forwarded) to the
page my action has posted the data to.

The easy way to handle this is:
put a button on my page by which the customer selects his preferred payment
service.
creati an action which prepares the values needed by this payment service.
This action forwards to a little jsp-page which contains a form with all the
data.
When the user submits the form, he is transferred to the payment service
with all neccessary information.


When a user is transferred to a payment service right from the
browser, how does your application know about this?


This means two clicks by the user for just selecting a payment service. I do
want to make a one-click procedure from this. A solution found by googling
automates the second submit by javascript. This is what I now have
implemented. The question is: is there a more elegant way?

If I use any of the http client approaches (either using java.net or commons
httpclient) I get the response somewhere in my action, but it should be in
the user's browser.
Probably one could say that I need sort of (transparent) proxy like
behaviour.


Yep, your action behaves as proxy. Also, your application is in the
know of what is happening.

Michael.

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: How to POST data to an external site from an action?

2006-05-02 Thread Nikolaj Berntsen
Frank W. Zammetti wrote:

>Hi Martin,
>
>Have a look at Commons HTTPClient:
>
>http://jakarta.apache.org/commons/httpclient/
>  
>
I did not know that one, I use webconversation from http://httpunit.org
which real powerful but might be be overkill.

Cheers,
/\/


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: How to POST data to an external site from an action?

2006-05-02 Thread David Evans
Here's a quick connect using standard java (not tested):

java.net.HttpURLConnection connection;
java.net.URL url;

try {
   // Create new URL and connect
   url = new URL("http://www.test.com/test.cgi";);
   connection = (HttpURLConnection) url.openConnection();
   // Setup HTTP POST parameters
   connection.setDoOutput(true);
   connection.setDoInput(true);
   connection.setUseCaches(false);

   String queryString = "myParm1=test&myParam2=test2";

   // POST data
   OutputStream out = connection.getOutputStream();
   out.write(queryString);
   out.close();
   }
   catch (Exception e1) {
   System.out.println("Error:" + e1.toString());
   }


n Tue, 2006-05-02 at 18:42 +0200, Martin Kindler wrote:
> Hi all,
> 
> I'm kind of stuck with a little problem. perhaps someone can help!
> 
> I want to include a payment service into my Struts Action 1.2.x based shop.
> The payment service needs the information via http POST. The user (my
> customer) will authorize the transaction on the site of the payment service.
> After finishing he will press a "back"-button which calls my shop again.
> 
> I could put a form containing the necessary data for the payment service on
> my shop site and on submit everything would be fine. But as I will support
> more than one payment service I would like to not include all the data in
> the JSP page where they could be seen in the source.
> I would instead like to have a button "pay by payment service x" which calls
> an action that creates the POST data and sends them to the payment service
> redirecting my customer to its site.
> 
> as a picture:
> 
>  payByPaymentService.do?id=
>   |
>   |  (the product data are stored in the session)
>   v
>  payByPaymentServiceAction.execute()
>   |
>   | (generate the POST data)
>   v
>  http://www.paymentservice.cgi
> 
> How can I do this?
> 
> Martin
> 
> 
> 
> -
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: How to POST data to an external site from an action?

2006-05-02 Thread Frank W. Zammetti
Hi Martin,

Have a look at Commons HTTPClient:

http://jakarta.apache.org/commons/httpclient/

This allows you to make various types of HTTP requests, and its easy
enough to do from an Action.

Frank

-- 
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
AIM: fzammetti
Yahoo: fzammetti
MSN: [EMAIL PROTECTED]
Java Web Parts -
http://javawebparts.sourceforge.net
Supplying the wheel, so you don't have to reinvent it!

On Tue, May 2, 2006 12:42 pm, Martin Kindler said:
> Hi all,
>
> I'm kind of stuck with a little problem. perhaps someone can help!
>
> I want to include a payment service into my Struts Action 1.2.x based
> shop.
> The payment service needs the information via http POST. The user (my
> customer) will authorize the transaction on the site of the payment
> service.
> After finishing he will press a "back"-button which calls my shop again.
>
> I could put a form containing the necessary data for the payment service
> on
> my shop site and on submit everything would be fine. But as I will support
> more than one payment service I would like to not include all the data in
> the JSP page where they could be seen in the source.
> I would instead like to have a button "pay by payment service x" which
> calls
> an action that creates the POST data and sends them to the payment service
> redirecting my customer to its site.
>
> as a picture:
>
>  payByPaymentService.do?id=
>   |
>   |  (the product data are stored in the session)
>   v
>  payByPaymentServiceAction.execute()
>   |
>   | (generate the POST data)
>   v
>  http://www.paymentservice.cgi
>
> How can I do this?
>
> Martin
>
>
>
> -
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]