You need to sign in to do that
Don't have an account?

Saleforce sites as listener/handler for http POST?
Hi everyone,
Does anyone have any experience/example code with setting a sites page to function as a listener/handler for an http POST?
Thanks!
it's fairly simple. in the visualforce page's controller, you just end up using the
ApexPages.CurrentPage().getParameters().get("param") method for all the params you need. I found that this works for both HTTP GET and POST handling in my testing.
All Answers
it's fairly simple. in the visualforce page's controller, you just end up using the
ApexPages.CurrentPage().getParameters().get("param") method for all the params you need. I found that this works for both HTTP GET and POST handling in my testing.
What paul-lmi suggests will work great when you are looking for name value pairs.
But in my case, where I want to receive an XML POST via HTTPS, is there a way for me to see the whole HTTP POST message?
In other programming languages, there would be a function to get the HTTPRequest content... I can't seem to find a way to get the entire message.
Can anyone provide me with some ideas to try?
Thanks!
Erik
Thanks Paul-lmi,
MAP<String,String> pmtrs= ApexPages.currentPage().getParameters();
For others out there accepting an XML message via post, here's my plan
I will keep you posted.
Update: So close, but this doesn't work: getParameters() appears to only be able to return a Map of name value pairs. And since an XML string is not Name Value, you just get a null string back... bummer
Here is my supporting evidence: debug logs of a CGI post vs an XML post:
CGI/Name-Value pair example:
Here is the debug log for the sendings system:
[03-12-09 13:56:42][DEBUG]: MultiServerMode is off and CategoryMode is off; running ALL scheduled engines
[03-12-09 13:56:42][INFO]: XSL file name: 1259877402.xsl
[03-12-09 13:56:42][WARN]: Required credentials not available for BASIC <any realm>@edy2007-developer-edition.na3.force.com:80
[03-12-09 13:56:42][WARN]: Preemptive authentication requested but no default credentials available
// the part below is a well formatted HTTP POST CGI message
[03-12-09 13:56:42][DEBUG]: >> "POST / HTTP/1.1[\r][\n]"
[03-12-09 13:56:42][DEBUG]: >> "User-Agent: Jakarta Commons-HttpClient/3.0.1[\r][\n]"
[03-12-09 13:56:42][DEBUG]: >> "Host: edy2007-developer-edition.na3.force.com[\r][\n]"
[03-12-09 13:56:42][DEBUG]: >> "Content-Length: 1439[\r][\n]"
[03-12-09 13:56:42][DEBUG]: >> "Content-Type: application/x-www-form-urlencoded[\r][\n]"
[03-12-09 13:56:42][DEBUG]: >> "[\r][\n]"
[03-12-09 13:56:42][DEBUG]: >> "B2_MailCity=&REAgentPhone=&FirstMortgageBalance
…..
And here is what getParameters finds:
ApexPages.currentPage()getParameters() ={AdditionalInformation=, B2_BirthDate=, B2_FirstName=, B2_GrossMonthlyIncome=, B2_LastName=, B2_MailCity=, B2_MailState=, B2_MailStreetAddress=, B2_MailZipCode=, B2_SSN=, ...}
//the values are blank, but at least it finds the data. (the data is returned in a alphabetically
//organized Map, so the A, and Bs come first... there is data in later variables...
XML posting example:
Here is the debug log for the sendings system:
[03-12-09 13:45:18][DEBUG]: MultiServerMode is off and CategoryMode is off; running ALL scheduled engines
[03-12-09 13:45:18][INFO]: XSL file name: 1259876718.xsl
[03-12-09 13:45:19][WARN]: Required credentials not available for BASIC <any realm>@edy2007-developer-edition.na3.force.com:80
[03-12-09 13:45:19][WARN]: Preemptive authentication requested but no default credentials available
// the part below is a well formatted HTTP POST XML message
[03-12-09 13:45:19][DEBUG]: >> "POST / HTTP/1.1[\r][\n]"
[03-12-09 13:45:19][DEBUG]: >> "Content-Type: text/xml[\r][\n]"
[03-12-09 13:45:19][DEBUG]: >> "User-Agent: Jakarta Commons-HttpClient/3.0.1[\r][\n]"
[03-12-09 13:45:19][DEBUG]: >> "Host: edy2007-developer-edition.na3.force.com[\r][\n]"
[03-12-09 13:45:19][DEBUG]: >> "Content-Length: 2304[\r][\n]"
[03-12-09 13:45:19][DEBUG]: >> "[\r][\n]"
[03-12-09 13:45:19][DEBUG]: >> "<?xml version="1.0" encoding="UTF-8"?>[\n]"
[03-12-09 13:45:19][DEBUG]: >> "<Leads xmlns="http://www.<removedtoprotecttheinnocent>.com/hla/2006">[\n]"
[03-12-09 13:45:19][DEBUG]: >> "<Lead>[\n]"
[03-12-09 13:45:19][DEBUG]: >> "<LeadType>1</LeadType>[\n]"
[03-12-09 13:45:19][DEBUG]: >> "<LeadID>222838775</LeadID>[\n]"
...
And here is what getParameters finds:
ApexPages.currentPage()getParameters() ={} <--- LOOK HERE ***** The braces {} are empty!
And I am unable to find the getBody() function apparently we all desire: there is an ideaexchange idea to allow access to Raw XML post data:
http://ideas.salesforce.com/article/show/10093914/Enable_Access_to_Raw_Post_Data_in_Visualforce_Pages
Rock the vote!
Erik
Hello,
We are developing an XML listener (service) as a Sites page.
We are using getContent() to obtain the XML content posted (via HTTP POST) without parameters. To be more specific, this is not through a form POST.
When I call xmlBody.toString() based on the code below, it returns nothing.
VF page Coding
<apex:page controller="InboundProcessor" action="{!init}" showHeader="false" sidebar="false"></apex:page>
ApexClass Coding
public PageReference init() {
PageReference xml = new PageReference(ApexPages.currentPage().GetURL());
Blob xmlBody = xml.getContent();
System.debug('blobcontent::'+xmlBody);
System.debug('xmlStringcontent::'+xmlBody.toString());
}
Is there any issue with getContent()?
Arunraj
How'd you guys go getting this working? That is, a sites page able to receive an xml file and parse it?
Did any one figure this out?
I also need to create a listner to an HTTPPost response.
I used content type 'application/x-www-form-urlencoded' in my HTTP POST (sending from Excel VBA test code) and then did the following to get the body in Salesforce:
string body = '';
MAP<string, string> params = ApexPages.currentPage().getParameters();
for (string paramname : params.keySet() )
body += paramname + '=' + params.get(paramname) + '\n';
if (body.endsWith('=\n')) {
body = body.substring(0,body.length()-2);
}
I do not get any parameters when I set the content-type of the HTTP POST to 'text/xml'. Does anybody know how to get it working with 'text/xml'?
We are trying to do something similar, but need to look at the Parameter and then respond back with a specific XML response based on the type of request. Is this possible?
Here is an example of our VisualForce page:
Or, maybe we can set the HTTP response in the controller?
Thanks,
Jon