Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using PostMethod to post from a servlet without capturing the response body

 
William Farrugia
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Is there a way to avoid capturing a post reply response body?



The only output i get is if i do


But it need the output to be on https://www.somehost.com/Pay and not as output of my own servlet.

Any help appreciated.

William.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65229
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
William Farrugia wrote:But it need the output to be on https://www.somehost.com/Pay and not as output of my own servlet.

I do not know what you mean by this.
 
William Farrugia
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello and thanks for your reply.

Well posting from a form by



and doing it via PostMethod


yields a different result. By PostMethod the response is sort of captured and I can output it with out.print, but instead I would like to open the response page on the source server rather than printing it out from my servlet. I know it's kinda strange sorry.






 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65229
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
William Farrugia wrote:but instead I would like to open the response page on the source server rather than printing it out from my servlet.

Still lost. Are you expecting to cause a browser window to open up somewhere else and display a response? Isn't going to happen. No where. No how.

What are you actually trying to accomplish?
 
William Farrugia
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's a payment gateway. They require that I post hashed XML to a web service, and the response is a secure form (with text fields for the credit card, cvv etc) that I should be able to place in an iFrame. When I output the response body as a String (from the PostMethod) I get the form properly but it doesn't submit cause the action is set to a web service that obviously doesn't exist on my server.

Should I maybe use the regular HTML form instead and just generate the XML from a JSP?

Re your question yes, I would like the response to popup in an iFrame. Sorry for the mess but I think I should probably change payment gateway provider :/
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
William Farrugia wrote:Re your question yes, I would like the response to popup in an iFrame. Sorry for the mess but I think I should probably change payment gateway provider :/


And like Bear suggested, you can only send the response back to the place where the request came from. So if you want the response to appear in an iframe, then you have to send the request from that iframe.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65229
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
William Farrugia wrote:and the response is a secure form (with text fields for the credit card, cvv etc) that I should be able to place in an iFrame.

Sounds fine. Are you displaying the form in the iframe ok? If the response is a full HTML page you should have no problems. Just make sure that the request is issued from the iframe as that its the target of the response (as Paul posted).

When I output the response body as a String (from the PostMethod) I get the form properly but it doesn't submit cause the action is set to a web service that obviously doesn't exist on my server.

So when they return the form to you, the form action is not set correctly to point to a URL on their site? Are you sure that you are using their service properly?

Should I maybe use the regular HTML form instead and just generate the XML from a JSP?
You should never do anything in a JSP. JSPs are for view generation, not processing.

 
Tim McGuire
Ranch Hand
Posts: 820
IntelliJ IDE Tomcat Server VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A while ago, I had this same question and it nearly cost me my mind.

I posted a question on javaranch (http://www.coderanch.com/t/363380/Servlets/java/forward-HttpUrlConnection)
and eventually solved it.

The initial server side post returned an HTML form that I pasted back into the browser with response.getWriter().write(theReturnedHTML) and it worked!

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65229
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, that's what we've been saying, but the point is that the request needs to come from the iframe for the response to be shown there. And it's not going to help him much if the form action isn't correct.

Still waiting for the OP to respond.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic