+ Start a Discussion

I need a simple sites page that returns XML for a querystring -- must I use a controller?

I'm looking around the documentation looking for something similar to a server page (active/java/etc.).  All I need is for the site to respond to a GET request with the objectid for a given email address (not really, but it's the simplest representative example I can think of).


I'm not seeing where I can embed APEX code inside an <apex:page>.  


So if I receive an HTTP GET for mysite.force.com/thing?email=username@gmail.com


I want to return some simple XML






But from the documentation, since I'm not seeing embedded APEX code, do I have to create a controller?


So, must the page be something closer to:


<apex:page controller="EmailLookup">





and create a (controller) class that reads the querystring, does the SOQL query to find the corresponding objectid, and define a method called IdForEmail() that returns the string value?


You cannot run Apex within Visualforce itself, you can only refer to bound variables/functions, formulas, etc.


So right, if it was the other way where your GET was ?id=889766876, you coud use a standardController to deliver {!ObjectName.Email} without needing custom controller.  The reverse, though, would require a controller.


If this access could be done in an authenticated way (not sure what your client is) you might look into the APEX REST developer preview coming in Summer '11.  It would let you do the opposite - have a GET endpoint without the need for Visualforce, and could return either XML or JSON.


I finally got it working.


My biggest frustration was in the debugging of the silly thing.  Everything worked through the unit tests, but there was a null pointer exception when it ran through the webpage.  Instead of knowing what the problem was, the page displayed a security violation which led me to believe there was some kind is silly security issue.


Now it's working much better, but is trying to interpret the XML I've put into the apex:page when I'd really rather it didn't.