0

In our JSF app(MyFaces Trinidad) we have a link clicking on that will launch a application running using aspx (http://crd-dev:1890/Timeandreviews/Login.aspx). Since we have authenticated user already, we have to pass the user id to the ASPX application. They dont want to receive this s a GET param in URL, they need it as POST data. Is that possible to send it as POST data? If possible how to send in JSF and how to read it in ASPX.

I have tried setting like below in JSF (.XHTML page)

ExternalContext ext = FacesContext.getCurrentInstance().getExternalContext();
    HttpServletRequest httpRequest = (HttpServletRequest) ext.getRequest();
    HttpSession httpSession = (HttpSession) ext.getSession(true);
    httpRequest.setAttribute("USER_HTREQ", "TST_USR");
    httpSession.setAttribute("USER_HTSES", "TST_USR");
    ext.getRequestMap().put("USER_REQMP", "TST_USR");
    try {
        ext.redirect("http://crd-dev:1890/Timeandreviews/Login.aspx");
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

and tried reading in aspx as Method 1:

string[] keys = Request.Form.AllKeys;
for (int i= 0; i < keys.Length; i++) 
{
   Response.Write(keys[i] + ": " + Request.Form[keys[i]] + "<br>");
}

Method 2: var oSR = new StreamReader(Request.InputStream); string sContent = oSR.ReadToEnd();

But both of them dint work. Please help

Pat
  • 535
  • 1
  • 16
  • 41

1 Answers1

1

Since you don't only need to post data, but also need to redirect the user, the Apache HttpClient is not going to help you.

The simplest solution is just create a form with hidden inputs, fill them and post the form.

<form method="post" id="form-id"
      action="http://crd-dev:1890/Timeandreviews/Login.aspx">
  <input type="hidden" name="input-id" id="input-id"/>
  etc.
</form>

You can execute Javascripts from your bean by adding it like this:

String script = "document.getElementById('input-id').value = 'value';"
              + "document.getElementById('form-id').submit();";
FacesContext fctx = FacesContext.getCurrentInstance();  
ExtendedRenderKitService erks =
    Service.getRenderKitService(fctx, ExtendedRenderKitService.class);
erks.addScript(fctx, script);
Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102
  • Thanks @jasper "create a form with hidden inputs, fill them and post the form." Means creating a hidden field at my code (JSF end), fill it as you said above and redirect to aspx page? Any idea how ASP .NET should read this hidden field? – Pat Sep 04 '15 at 05:25
  • There is no need to do anything on the ASP .NET side. Just use the correct action URL and post the form. See also the updated answer. – Jasper de Vries Sep 04 '15 at 07:57