+ Start a Discussion
Oldwen AdrianoOldwen Adriano 

RESTful Callout: End of file issue

Hello Dev community,

I have an issue with a RESTful callout I'm attempting to make.  The error I get is End of File from server.  Below is my code and the error message.  I'm placing the items in this order:  Page, Controller, Helper class, Web Service SOAP instructions, Page error, dev console error.  Any help is greatly appreciated.
 
<apex:page id="page" controller="WebServiceCallOut" >
	<apex:form id="form" >
		<apex:sectionHeader title="RESTFUL Callout Viewer" />
		
		<apex:pageBlock >
			<apex:pageBlockButtons >
				<apex:commandButton value="Callout" action="{!callout}" id="btnCallout"/>
			</apex:pageBlockButtons>
		
		
			<apex:pageBlockSection columns="1" title="HttpResponse" collapsible="false" >
				<apex:pageBlockSectionItem >
					<apex:outputLabel value="getBody()" />
					{!responseBody}
				</apex:pageBlockSectionItem>
			</apex:pageBlockSection>
		
		</apex:pageBlock>
	</apex:form>
</apex:page>
public with sharing class WebServiceCallOut 
{
	public String responseBody {get;set;}
	
	public String requestEndpoint {get;set;}
	public String requestMethod {get;set;}
	public String requestBody {get;set;}
	
    public WebServiceCallOut()
    {
    	requestEndpoint = myURL.com;
    	requestMethod = 'POST';
    	
    	requestBody = CreateSoapHeader();
    }
    
    public void callout()
    {
		httpResponse res = VerintAPI.callout(requestMethod, requestEndpoint, requestBody);

		responseBody = res.getBody();
	}
	
	public String CreateSoapHeader()
   	{
   		String myServer = 'variable';
   		String myBackup = 'variable';
   		String myPort = ''variable'';
   		String myDevice = 'variable';
   		String myPBX = ''variable'';
   		String myExt = ''variable'';
   
   		String soap = '<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' +
   		'<soap:Body>' + 
   		'<GetContactId xmlns="http://tempuri.org/">' + 
   		'<request>' +
   		'<Server>' + myServer + '</Server>' + 
        '<BackupServer>' + myBackup + '</BackupServer>' + 
        '<Port>' + myPort + '</Port>' + 
        '<ContactId></ContactId>' +
        '<Extension>' + myExt + '</Extension>' +
        '<AgentPbxId>' + myPBX + '</AgentPbxId>' +
        '<SysDevice>' + myDevice + '</SysDevice>' +
        '<RecordingSource></RecordingSource>' +
        '<Attributes>' +
        '  <AttributeKeyValue>' +
        '    <Key></Key>' +
        '    <Value></Value>' +
        '  </AttributeKeyValue>' +
        '</Attributes>' +
        '</request>' +
        '</GetContactId>' +
        '</soap:Body>' +
        '</soap:Envelope>' ;
        
        return soap;
   	}
}
public with sharing class VerintAPI 
{
    //public static String BASE_URL = '';
    
    
    public static httpResponse callout(String httpMethod, String endpoint, String body)
    {
    	httpRequest req = new httpRequest();
    	
    	req.setMethod(httpMethod);
    	
    	req.setEndpoint(endpoint);
    	
    	req.setHeader('Host', 'verint11-ws.alorica.com');
    	req.setHeader('Content-Type', 'text/xml; charset=utf-8');
    	req.setHeader('Content-Length', string.valueof(body.length()));
    	req.setHeader('SOAPAction', '"http://tempuri.org/GetContactId"');
    	
    	req.setBody(body);
    	    	    	
    	req.setTimeout(120000);
    	
    	httpResponse res = new http().send(req);
    	
    	return res;
    }
}

User-added image
User-added image
User-added image