I'm trying to call an APEX REST service from another system. The other system is not capable of JSON, it can pass data in XML only for PUT or POST, or in the querystring for GET.
So far, all of my attempts to retrieve the querystring have failed - containsKey() returns false.
Is there a way to make my REST service work using a querystring, and make the test class prove that it does? I'd rather not have to hack my way through the XML using string functions.
Here is a portion of the REST service...
@RestResource(urlMapping='/SubscriptionEventNew')
global with sharing class SubscriptionEventNew {
global class SubscriptionException extends Exception {}
@HttpGet
global static GatewayLog__c NewSubscription() {
GatewayInfo gwInfo = new GatewayInfo();
GatewayLog__c gwLogResponse = new GatewayLog__c();
try
{
if (!ApexPages.currentPage().getParameters().containsKey('SubscriptionID')) {
System.debug('Hey argument missing');
throw new SubscriptionException('SubscriptionID must be passed in querystring');
}
And here is a testmethod that fails to pass the querystring:
@isTest
public with sharing class SubscriptionEventsTest {
public static testmethod void SubscriptionEventNewTestValid() {
RestRequest req = new RestRequest();
RestResponse res = new RestResponse();
req.requestURI = '/SubscriptionEventNew';
req.addParameter('SubscriptionID','4948C4C7-74EB-4467-BF72-B201A804B800');
req.httpMethod = 'GET';
RestContext.request = req;
RestContext.response = res;
GatewayLog__c log = SubscriptionEventNew.NewSubscription();
// TestProcess.AnalyzeLog(log);
}
params
property of theRestContext.Request
object