HTTP request consumer in XPages
December 18th, 2010Chris Toohey recently posted an example of a simple HTTP request consumer using a traditional (classic) Lotus Notes/Domino agent. I had a need for a similar solution in XPages - and since Chris never posted his follow-up post on the XPages version I had to do it myself 🙂
The HTTP request consumer is used by a 3rd party callback service to report back the status of (in my case) a HTTP form post submitted earlier by my app to that service.
The XPages solution is a simple XPage that uses the afterRenderResponse event to gather fields returned and display a related response to the user - including displaying a useful error message to the user in case the callback service misses important fields. The HTTP request parameters (form fields) are retrieved using param.get('<field>'). The HTTP request parameters can be GET parameters (e.g. http://hostname.com?p1=v1&p2=v2) or POST parameters.
Basic code example for the afterRenderResponse event:
try {
var exCon = facesContext.getExternalContext();
var writer = facesContext.getResponseWriter();
var response = exCon.getResponse();
response.setContentType("text/html");
writer.write("" + "\n");
writer.write("" + "\n");
writer.write("" + "\n");
writer.write("" + "\n");// Read the HTTP request parameters
var _param1 = param.get( 'test1' );
var _param2 = param.get( 'test2' );// then do whatever is needed with the HTTP request parameters - e.g. print the contents of the parameters in the response.
writer.write("<p>Parameter 1: " + _param1 + "</p>\n");
writer.write("<p>Parameter 2: " + _param2 + "</p>\n");writer.write("" + "\n");
writer.write("" + "\n");
writer.endDocument();
facesContext.responseComplete();} catch(e) {
_dump(e);
}
Tags: HTTP request consumer, XPages
April 15th, 2012 at 14:29
You do want to add some sort of replacement, filtering, ... for "" to prevent XSS attacks, if you use the values of the HTTP request parameters directly.