• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to send data to another site, get response, redirect and get new response

 
Enrico Morelli
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear all,
I've to write a Java EE application that have to become an interface to a payment platform. The protocol require to send a POST string containing some information (including an error and response page) to an external host, get the response and redirect the user to another host using the previous response. When the user ends the transaction the host redirect the user to my error or response page.

For the moment my user access to my application using glassfish REALM authentication. After that I write the following code:



The previous code works fine. I receive the response. But now I don't know how to continue. How can redirect the user to another site, and when the payment is finished, receive the response? Another question is, the user authenticate himself to access to the application. When the user will redirect to an external site, the glassfish session permits to get the response from the other host without require a new authentication?

Thanks
 
Dieter Quickfend
Bartender
Posts: 543
4
Java Netbeans IDE Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it completely depends on the implementation on the other site. What we've done before is send a redirect with a parameter called "returnUrl" containing the return url, and this is kept in the request until the other site is ready to return to that specified parameter. As for the redirection, you can just check the response for some content and according to that content perform a sendRedirect() call to the url you need to 301 to.
 
Enrico Morelli
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dieter Quickfend wrote:it completely depends on the implementation on the other site. What we've done before is send a redirect with a parameter called "returnUrl" containing the return url, and this is kept in the request until the other site is ready to return to that specified parameter. As for the redirection, you can just check the response for some content and according to that content perform a sendRedirect() call to the url you need to 301 to.


I don't know the implementation of the other side. I know only the protocol to use. So the code that I posted works for the first step. When I obtain the first response, I receive the address where I've to redirect the user. For that have I to use sendRedirect() ?

When the user has finish to pay, the remote site redirect the user to my site using one of the two pages I specified (response.xhtml or error.xhtml) passing them some reponse parameters.
Is it correct the following code to obtain these response parameters?



response.xhtml


 
Enrico Morelli
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm able to redirect the user to another site:



Now the problem is when the other site redirect the user to my platform sending them GET data. How can grab its to display in a JSF page?
 
Dieter Quickfend
Bartender
Posts: 543
4
Java Netbeans IDE Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It'll be in the request. Just display the request and you'll see which data they're sending you to use.
 
Enrico Morelli
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dieter Quickfend wrote:It'll be in the request. Just display the request and you'll see which data they're sending you to use.


Ok, but please can you be more explicit? I'm a bit confused. The remote site redirect the user on a JSF page (I cannot redirect to a Bean), so how can grab the GET response from the JSF page?
It's correct the code I posted?

 
Dieter Quickfend
Bartender
Posts: 543
4
Java Netbeans IDE Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To get your request in the JSF page, you get the relevant data from FacesContext using ExternalContext.getRequestHeaderMap, getRequestParameterMap etc... in a bean or you use stuff like : '<hutputText value="#{param['dataOtherSiteReturnedAndStuff']}" />' if you know it's in the parameters. You can always make a quick JSP/servlet that displays the entire request and redirect there to see where to find your required data, and only after that make a jsf page and a backing bean that gets your request... It's entirely your choice.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!