2 if(!defined('sugarEntry'))define('sugarEntry', true);
3 /*********************************************************************************
4 * SugarCRM is a customer relationship management program developed by
5 * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
7 * This program is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU Affero General Public License version 3 as published by the
9 * Free Software Foundation with the addition of the following permission added
10 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
19 * You should have received a copy of the GNU Affero General Public License along with
20 * this program; if not, see http://www.gnu.org/licenses or write to the Free
21 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
27 * The interactive user interfaces in modified source and object code versions
28 * of this program must display Appropriate Legal Notices, as required under
29 * Section 5 of the GNU Affero General Public License version 3.
31 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32 * these Appropriate Legal Notices must retain the display of the "Powered by
33 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34 * technical reasons, the Appropriate Legal Notices must display the words
35 * "Powered by SugarCRM".
36 ********************************************************************************/
38 require('service/core/SugarSoapService.php');
39 require('include/nusoap/nusoap.php');
42 * This is an abstract class for the soap implementation for using NUSOAP. This class is responsible for making
43 * all NUSOAP call by passing the client's request to NUSOAP server and seding response back to client
46 abstract class NusoapSoap extends SugarSoapService{
48 * This is the constructor. It creates an instance of NUSOAP server.
50 * @param String $url - This is the soap URL
53 public function __construct($url){
54 $GLOBALS['log']->info('Begin: NusoapSoap->__construct');
55 $this->server = new soap_server();
56 $this->soapURL = $url;
57 $this->server->configureWSDL('sugarsoap', $this->getNameSpace(), $url);
58 if(!isset($GLOBALS['HTTP_RAW_POST_DATA']))$GLOBALS['HTTP_RAW_POST_DATA'] = file_get_contents('php://input');
59 parent::__construct();
60 $GLOBALS['log']->info('End: NusoapSoap->__construct');
64 * Fallback function to catch unexpected failure in SOAP
66 public function shutdown()
68 if($this->in_service) {
69 $out = ob_get_contents();
71 $GLOBALS['log']->info('NusoapSoap->shutdown: service died unexpectedly');
72 $this->server->fault(-1, "Unknown error in SOAP call: service died unexpectedly", '', $out);
73 $this->server->send_response();
78 * It passes request data to NUSOAP server and sends response back to client
81 public function serve(){
82 $GLOBALS['log']->info('Begin: NusoapSoap->serve');
84 $this->in_service = true;
85 register_shutdown_function(array($this, "shutdown"));
87 $this->server->service($GLOBALS['HTTP_RAW_POST_DATA']);
88 $this->in_service = false;
91 $GLOBALS['log']->info('End: NusoapSoap->serve');
95 * This method registers all the complex type with NUSOAP server so that proper WSDL can be generated
97 * @param String $name - name of complex type
98 * @param String $typeClass - (complexType|simpleType|attribute)
99 * @param String $phpType - array or struct
100 * @param String $compositor - (all|sequence|choice)
101 * @param String $restrictionBase - SOAP-ENC:Array or empty
102 * @param Array $elements - array ( name => array(name=>'',type=>'') )
103 * @param Array $attrs - array(array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'xsd:string[]'))
104 * @param String $arrayType - arrayType: namespace:name (xsd:string)
107 public function registerType($name, $typeClass, $phpType, $compositor, $restrictionBase, $elements, $attrs=array(), $arrayType=''){
108 $this->server->wsdl->addComplexType($name, $typeClass, $phpType, $compositor, $restrictionBase, $elements, $attrs, $arrayType);
112 * This method registers all the functions you want to expose as services with NUSOAP
114 * @param String $function - name of the function
115 * @param Array $input - assoc array of input values: key = param name, value = param type
116 * @param Array $output - assoc array of output values: key = param name, value = param type
119 function registerFunction($function, $input, $output){
120 if(in_array($function, $this->excludeFunctions))return;
123 if (isset($_REQUEST['use']) && ($_REQUEST['use'] == 'literal')) {
126 if (isset($_REQUEST['style']) && ($_REQUEST['style'] == 'document')) {
129 $this->server->register($function, $input, $output, $this->getNameSpace(), '',$style, $use);
133 * This function registers implementation class name with NUSOAP so when NUSOAP makes a call to a funciton,
134 * it will be made on this class object
136 * @param String $implementationClass
139 function registerImplClass($implementationClass){
140 $GLOBALS['log']->info('Begin: NusoapSoap->registerImplClass');
141 if (empty($implementationClass)) {
142 $implementationClass = $this->implementationClass;
144 $this->server->register_class($implementationClass);
145 $GLOBALS['log']->info('End: NusoapSoap->registerImplClass');
149 * Sets the name of the registry class
151 * @param String $registryClass
154 function registerClass($registryClass){
155 $GLOBALS['log']->info('Begin: NusoapSoap->registerClass');
156 $this->registryClass = $registryClass;
157 $GLOBALS['log']->info('End: NusoapSoap->registerClass');
161 * This function sets the fault object on the NUSOAP
163 * @param SoapError $errorObject - This is an object of type SoapError
166 public function error($errorObject){
167 $GLOBALS['log']->info('Begin: NusoapSoap->error');
168 $this->server->fault($errorObject->getFaultCode(), $errorObject->getName(), '', $errorObject->getDescription());
169 $GLOBALS['log']->info('Begin: NusoapSoap->error');