2

An external site redirect the user to my platform passing some POST data. How can grab this information from my Bean and display its in a JSF page?

I've try a lot of solution but no one works. The following is a JSF testing page.

 <f:metadata>
  <f:viewParam name="auth" value="#{getResponse2.auth}" required="true"/>
 </f:metadata>

<ui:define name="content">
    <center>
       An error occurred during  transaction
        #{getResponse2.auth}<br />
        #{getResponse2.responsecode}
    </center>

Here some attempt to grab POST data:

@ManagedBean
@RequestScoped
public class getResponse extends HttpServlet {
   private String paymentId;
   private String result;
   private String auth;
   private String ref;
   private String traind;
   private String trackid;
   private String udf1;
   private String responsecode;
   private String host;
   @Override
   public void doPost(HttpServletRequest request, HttpServletResponse response) {
      paymentId = request.getParameter("paymentid");
      result = request.getParameter("result");
      auth = request.getParameter("auth");
      ref = request.getParameter("ref");
      traind = request.getParameter("tranid");
      trackid = request.getParameter("trackid");
      udf1 = request.getParameter("udf1");
      responsecode = request.getParameter("responsecode");
      System.out.println("response code: " + responsecode);
  }

Another one:

   public void getResponse() {

    paymentId = ((HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest()).getParameter("paymentId");
    result = ((HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest()).getParameter("result");
    auth = ((HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest()).getParameter("auth");
    ref = ((HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest()).getParameter("ref");
    traind = ((HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest()).getParameter("traind");
    trackid = ((HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest()).getParameter("trakid");
    udf1 = ((HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest()).getParameter("udf1");
    responsecode = ((HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest()).getParameter("responsecode");

}
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Enrico Morelli
  • 185
  • 3
  • 16
  • 1
    Redirect and "POST data"? A redirect is always GET. Are you absolutely positive that the incoming HTTP request is a POST request and not a GET? By the way, letting your managed bean class extend `HttpServlet` really doesn't make any sense. The "another one" approach should theoretically work, provided that it's invoked the right way (that is, by a GET request). – BalusC Nov 13 '13 at 12:20
  • Will it even work with extending HttpServlet and declaring it as @RequestScoped? – Artem Moskalev Nov 13 '13 at 12:22
  • @BalusC I think you are ready, it's possible that the data are GET. I've only this example in the documentation: String result = request.getParameter("result"); In the GET case how can grab the parameters? – Enrico Morelli Nov 13 '13 at 12:54
  • @BalusC I'm not able to find examples how to grab GET data. Is it so complicated? – Enrico Morelli Nov 14 '13 at 08:58
  • @BalusC In my searches I found your tutorials http://balusc.blogspot.it/2011/09/communication-in-jsf-20.html#ProcessingGETRequestParameters but I don't find a solution for my problem. – Enrico Morelli Nov 14 '13 at 09:09
  • This question is not answerable without detailed information about the incoming HTTP request. If you have no clue, use a HTTP traffic monitor like Fiddler. – BalusC Nov 14 '13 at 14:27
  • Now the bank staff tell me that the data are transmitted using POST. – Enrico Morelli Nov 14 '13 at 15:33
  • From the bank documentation I have: Protocol: HTTP, Method: POST, Content-Type: URL Encoded (legacy): application/www-form-urlencoded or application/x-www-form-urlencoded – Enrico Morelli Nov 14 '13 at 15:34
  • There is also an example of a page that grab the response: <% long paymentID = Long.parseLong(request.getParameter("paymentid")); String result = request.getParameter("result"); String auth = request.getParameter("auth"); long ref = Long.parseLong(request.getParameter("ref")); %> – Enrico Morelli Nov 14 '13 at 15:39
  • Nothing to do, the response has to be read by a JSP page that must to redirect to another page. Now I've other problems. Thanks – Enrico Morelli Nov 18 '13 at 16:16

0 Answers0