Author: chintana Date: Mon Aug 31 11:35:43 2009 New Revision: 809543 URL: http://svn.apache.org/viewvc?rev=809543&view=rev Log: New PHP config service. * Adding operations defined in the .Net config service WSDL. * Removing previously defined operations which are no longer used. * Removing config_svc_processor.php file, now the business logic in is the config_svc.php file itself. * Removing old class info and adding new classes (codegened using the .Net config service WSDL).
Removed: incubator/stonehenge/trunk/stocktrader/php/config_service/config_svc_processor.php Modified: incubator/stonehenge/trunk/stocktrader/php/config_service/class_info.php incubator/stonehenge/trunk/stocktrader/php/config_service/config_svc.php Modified: incubator/stonehenge/trunk/stocktrader/php/config_service/class_info.php URL: http://svn.apache.org/viewvc/incubator/stonehenge/trunk/stocktrader/php/config_service/class_info.php?rev=809543&r1=809542&r2=809543&view=diff ============================================================================== --- incubator/stonehenge/trunk/stocktrader/php/config_service/class_info.php (original) +++ incubator/stonehenge/trunk/stocktrader/php/config_service/class_info.php Mon Aug 31 11:35:43 2009 @@ -1,290 +1,247 @@ -<?php -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/** - * @namespace http://apache.org/stonehenge/stocktrader/xsd - */ -class DBConfig -{ - /** - * @var string $DBName Name of the database server. - * (maps to the xs:string XML schema type ) - */ - public $DBName; - - /** - * @var string $DBHostName host name of the database server - * (maps to the xs:anyURI XML schema type) - */ - public $DBHostName; - - /** - * @var int $DBPort port of the database server - * (maps to the xs:unsignedInt XML schema type ) - */ - public $DBPort; -} - -/** - * @namespace http://apache.org/stonehenge/stocktrader/xsd - */ -class GetDBConfigs -{ -} - -/** - * @namespace http://apache.org/stonehenge/stocktrader/xsd - */ -class DBConfigs -{ - /** - * @var array of object DBConfig $DBConfig - */ - public $DBConfig; -} -/** - * @namespace http://apache.org/stonehenge/stocktrader/xsd - */ -class ActiveDB -{ - /** - * @var string $DBName Name of the database server. - * (maps to the xs:string XML schema type ) - */ - public $DBName; -} - -/** - * @namespace http://apache.org/stonehenge/stocktrader/xsd - */ -class GetActiveDB -{ -} - -/** - * @namespace http://apache.org/stonehenge/stocktrader/xsd - */ -class ServiceLocation -{ - /** - * @var string $ServiceName Name of the service - * (maps to the xs:string XML schema type ) - */ - public $ServiceName; - - /** - * @var string $ServiceURL end point url of the service - * (maps to the xs:anyURI XML schema type) - */ - public $ServiceURL; -} - -/** - * @namespace http://apache.org/stonehenge/stocktrader/xsd - */ -class GetServiceLocations -{ -} - -/** - * @namespace http://apache.org/stonehenge/stocktrader/xsd - */ -class ServiceLocations -{ - /** - * @var array of object ServiceLocation $ServiceLocation - */ - public $ServiceLocation; -} - -/** - * @namespace http://apache.org/stonehenge/stocktrader/xsd - */ -class ClientToBS -{ - /** - * @var string $Client Name of the client - * (maps to the xs:string XML schema type ) - */ - public $Client; - - /** - * @var string $BS Name of the business service - * (maps to the xs:string XML schema type) - */ - public $BS; -} - -/** - * @namespace http://apache.org/stonehenge/stocktrader/xsd - */ -class GetClientToBSConnections -{ -} - -/** - * @namespace http://apache.org/stonehenge/stocktrader/xsd - */ -class ClientToBSConnections -{ - /** - * @var array of object ClientToBS $ClientToBS - */ - public $ClientToBS; -} - -/** - * @namespace http://apache.org/stonehenge/stocktrader/xsd - */ -class BSToOPS -{ - /** - * @var string $BS Name of the business service - * (maps to the xs:string XML schema type ) - */ - public $BS; - - /** - * @var string $OPS Name of the order processor service - * (maps to the xs:string XML schema type) - */ - public $OPS; -} - -/** - * @namespace http://apache.org/stonehenge/stocktrader/xsd - */ -class GetBSToOPSConnections -{ -} - -/** - * @namespace http://apache.org/stonehenge/stocktrader/xsd - */ -class BSToOPSConnections -{ - /** - * @var array of object BSToOPS $BSToOPS - */ - public $BSToOPS; -} - -/** - * @namespace http://apache.org/stonehenge/stocktrader/xsd - */ -class ClientConfigRequest -{ - /** - * @var string $Client Name of the client - * (maps to the xs:string XML schema type ) - */ - public $Client; -} - -/** - * @namespace http://apache.org/stonehenge/stocktrader/xsd - */ -class ClientConfigResponse -{ - /** - * @var string $BS end point url of business service - * (maps to the xs:anyURI XML schema type ) - */ - public $BS; -} - -/** - * @namespace http://apache.org/stonehenge/stocktrader/xsd - */ -class BSConfigRequest -{ - /** - * @var string $BS Name of the business service - * (maps to the xs:unsignedInt XML schema type ) - */ - public $BS; -} - -/** - * @namespace http://apache.org/stonehenge/stocktrader/xsd - */ -class BSConfigResponse -{ - /** - * @var string $DBName name of the database - * (maps to the xs:string XML schema type ) - */ - public $DBName; - - /** - * @var string $DBHostName host name of database server - * (maps to the xs:anyURI XML schema type ) - */ - public $DBHostName; - - /** - * @var int $DBPort port of the database server - * (maps to the xs:unsignedInt XML schema type ) - */ - public $DBPort; - - /** - * @var string $OPS end point url of order processor service - * (maps to the xs:anyURI XML schema type ) - */ - public $OPS; - - /** - * @var boolean $Sec denotes whether secure version of order processor - */ - public $Sec; - -} - -/** - * @namespace http://apache.org/stonehenge/stocktrader/xsd - */ -class OPSConfigRequest -{ -} - -/** - * @namespace http://apache.org/stonehenge/stocktrader/xsd - */ -class OPSConfigResponse -{ - /** - * @var string $DBName name of the database - * (maps to the xs:string XML schema type ) - */ - public $DBName; - - /** - * @var string $DBhostName host name of database server - * (maps to the xs:anyURI XML schema type ) - */ - public $DBHostName; - - /** - * @var int $DBport port of the database server - * (maps to the xs:unsignedInt XML schema type ) - */ - public $DBPort; -} -?> +<?php +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +// PHP classes corresponding to the data types in defined in WSDL + +class GetClientConfig { + + /** + * @var (object)ClientConfigRequest + */ + public $client; + +} + +class ClientConfigRequest { + +} + +class GetClientConfigResponse { + + /** + * @var (object)ClientConfigResponse + */ + public $GetClientConfigResult; + +} + +class ClientConfigResponse { + + /** + * @var string $BS Business service endpoint URL + */ + public $BS; + + /** + * @var string $BSName Business service name + */ + public $BSName; + + /** + * @var boolean $Sec Whether service is secured or not + */ + public $Sec; + +} + +class GetBSConfig { + + /** + * @var (object)BSConfigRequest + */ + public $bs; + +} + +class BSConfigRequest { + /** + * @var string $BSName BS Name + */ + public $BSName; +} + +class GetBSConfigResponse { + + /** + * @var (object)BSConfigResponse + */ + public $GetBSConfigResult; + +} + +class BSConfigResponse { + + /** + * @var string $DBHost Database host + */ + public $DBHostName; + + /** + * @var string $DBName Database name + */ + public $DBName; + + /** + * @var string $DBPort Database port + */ + public $DBPort; + + /** + * @var string $OPS OPS endpoint URL + */ + public $OPS; + + /** + * @var string $OPSName OPS Name + */ + public $OPSName; + + /** + * @var boolean $Sec Service is secured or not + */ + public $Sec; + +} + +class GetOPSConfig { + + /** + * @var (object)OPSConfigRequest + */ + public $ops; + +} + +class OPSConfigRequest { + +} + +class GetOPSConfigResponse { + + /** + * @var (object)OPSConfigResponse + */ + public $GetOPSConfigResult; + +} + +class OPSConfigResponse { + +} + +class SetClientToBS { + + /** + * @var (object)ClientToBS + */ + public $clientConfig; + +} + +class ClientToBS { + +} + +class SetClientToBSResponse { + +} + +class SetBSToOPS { + + /** + * @var (object)BSToOPS + */ + public $bsConfig; + +} + +class BSToOPS { + +} + +class SetBSToOPSResponse { + +} + +class GetBSLocations { + +} + +class GetBSLocationsResponse { + + /** + * @var (object)ArrayOfServiceLocation + */ + public $GetBSLocationsResult; + +} + +class ArrayOfServiceLocation { + + /** + * @var array[0, unbounded] of (object)ServiceLocation + */ + public $ServiceLocation; + +} + +class ServiceLocation { + /** + * @var boolean $Sec Whether service is secured or not + */ + public $Sec; + + /** + * @var string $ServiceName Name of the service + */ + public $ServiceName; + + /** + * @var string $ServiceURL Endpoint URL of the service + */ + public $ServiceURL; +} + +class GetOPSLocations { + +} + +class GetOPSLocationsResponse { + + /** + * @var (object)ArrayOfServiceLocation + */ + public $GetOPSLocationsResult; + +} + +class SetServiceLocation { + + /** + * @var (object)ServiceLocation + */ + public $location; + +} + +class SetServiceLocationResponse { + +} + +?> Modified: incubator/stonehenge/trunk/stocktrader/php/config_service/config_svc.php URL: http://svn.apache.org/viewvc/incubator/stonehenge/trunk/stocktrader/php/config_service/config_svc.php?rev=809543&r1=809542&r2=809543&view=diff ============================================================================== --- incubator/stonehenge/trunk/stocktrader/php/config_service/config_svc.php (original) +++ incubator/stonehenge/trunk/stocktrader/php/config_service/config_svc.php Mon Aug 31 11:35:43 2009 @@ -1,660 +1,333 @@ -<?php -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -require_once ("config_svc_processor.php"); - -/** Set database configurations of a DB - * @namespace http://apache.org/stonehenge/stocktrader - * @param object DBConfig $DBConfig - */ -function storeDBConfig($DBConfig) -{ - if($DBConfig) - { - /* we support MSSQL and MySQL only. If DBName is something else, we should not process anything */ - if(($DBConfig->DBName == DBNAME_MSSQL) || ($DBConfig->DBName == DBNAME_MYSQL)) - { - $db = GetDatabase(); - - /* "BEGIN TRAN" initialize a transaction; which privides control so that later we can cancel - * the transaction, if something goes wrong. */ - if($db->ExecuteQuery("BEGIN TRAN")) - { - $result = getDBConfig($DBConfig->DBName, $db); - if($result) - { - /* this detail is already available. So we should update the records */ - $query = "UPDATE dbconfig WITH (ROWLOCK) SET hostname='$DBConfig->DBHostName', ". - "PORT='$DBConfig->DBPort' WHERE dbname = '$DBConfig->DBName'"; - $status = $db->ExecuteQuery($query); - } - else - { - /* details related to this database is not stored. So we have to insert a new record */ - $query = "INSERT INTO dbconfig (dbname, hostname, port, active) VALUES (". - "'$DBConfig->DBName', '$DBConfig->DBHostName', '$DBConfig->DBPort', 'N');"; - $status = $db->ExecuteQuery($query); - } - - if($status) - { - /* Transaction is successfull, we can safely commit the transaction into the database. */ - $db->ExecuteQuery("COMMIT TRAN"); - } - else - { - /* Transaction is not successfull, we have to rollback the transaction */ - $db->ExecuteQuery("ROLLBACK TRAN"); - error_log("Storing DBConfig failed. \n"); - } - } - else - { - error_log("Cannot initialise a transaction using BEGIN TRAN. \n"); - } - - $db->CloseDatabase(); - } - else - { - error_log("Cannot support database $DBConfig->DBName. Supported databases are ". - DBNAME_MSSQL." and ".DBNAME_MYSQL.".\n"); - } - } -} - -/** Get database configuration for all DBs - * @namespace http://apache.org/stonehenge/stocktrader - * @param object GetDBConfigs $GetDBConfigs - * @return object DBConfigs $DBConfigs - */ -function getDBConfigs($GetDBConfigs) -{ - $db = GetDatabase(); - - $query = "Set NOCOUNT ON; SELECT dbname, hostname, port FROM dbconfig"; - - $result = $db->ExecuteQuery($query); - if ($result) - { - $rowNum = 0; - $DBConfigs = new DBConfigs(); - while($DBName = $db->GetSQLValue($result, $rowNum, 0)) - { - $config = new DBConfig(); - $config->DBName = $DBName; //Get the DB Name - $config->DBHostName = $db->GetSQLValue($result, $rowNum, 1); //Get the host name. - $config->DBPort = $db->GetSQLValue($result, $rowNum, 2); //Get the port - $DBConfigs->DBConfig[$rowNum] = $config; - $rowNum = $rowNum + 1; - } - } - - $db->CloseDatabase(); - return $DBConfigs; -} - -/** Sets active database. - * @namespace http://apache.org/stonehenge/stocktrader - * @param object ActiveDB $ActiveDB Name of the active database - */ -function setActiveDB($ActiveDB) -{ - if($ActiveDB) - { - $DBName = $ActiveDB->DBName; - /* we support MSSQL and MySQL only. If DBName is something else, we should not process anything */ - if(($DBName == DBNAME_MSSQL) || ($DBName == DBNAME_MYSQL)) - { - - $db = GetDatabase(); - - /* check whether DBConfig related to this database is already there. If not there, we can't - * set it as active */ - if(getDBConfig($DBName, $db)) - { - /* "BEGIN TRAN" initialize a transaction; which privides control so that later we can cancel - * the transaction, if something goes wrong. */ - if($db->ExecuteQuery("BEGIN TRAN")) - { - $query = "UPDATE dbconfig WITH (ROWLOCK) SET active='Y' WHERE dbname='$DBName'"; - $status = $db->ExecuteQuery($query); - - if($status) - { - /* Transaction is successfull, we can safely commit the transaction into the database. */ - $db->ExecuteQuery("COMMIT TRAN"); - } - else - { - /* Transaction is not successfull, we have to rollback the transaction */ - $db->ExecuteQuery("ROLLBACK TRAN"); - error_log("Storing Active DB failed. \n"); - } - } - else - { - error_log("Cannot initialise a transaction using BEGIN TRAN. \n"); - } - } - else - { - error_log("Cannot find DBConfig related to $DBName. Could not be able to set active \n"); - } - $db->CloseDatabase(); - } - else - { - error_log("Cannot set database $DBName as active. Supported databases are ". - DBNAME_MSSQL." and ".DBNAME_MYSQL.".\n"); - } - } -} - -/** Get active database. - * @namespace http://apache.org/stonehenge/stocktrader - * @param object GetActiveDB $GetActiveDB - * @return object ActiveDB $CurrentActiveDB Name of the active database - */ -function getActiveDB($GetActiveDB) -{ - $db = GetDatabase(); - - $DBConfig = getActiveDBConfig($db); - if($DBConfig) - { - $config = new ActiveDB(); - $config->DBName = $DBConfig->DBName; - } - else - { - error_log("Cannot find details about active database \n"); - } - - $db->CloseDatabase(); - return $config; -} - -/** Sets service location (End point URL) of a given service. - * @namespace http://apache.org/stonehenge/stocktrader - * @param object ServiceLocation $ServiceLocation - */ -function setServiceLocation($ServiceLocation) -{ - if($ServiceLocation) - { - if(isBusinessServiceDefined($ServiceLocation->ServiceName) - || isOrderProcessorServiceDefined($ServiceLocation->ServiceName) - || isOrderProcessorSecDefined($ServiceLocation->ServiceName)) - { - $db = GetDatabase(); - - /* "BEGIN TRAN" initialize a transaction; which privides control so that later we can cancel - * the transaction, if something goes wrong. */ - if($db->ExecuteQuery("BEGIN TRAN")) - { - $result = getServiceLocation($ServiceLocation->ServiceName, $db); - if($result) - { - /* this detail is already available. So we should update the records */ - $query = "UPDATE service WITH (ROWLOCK) SET url='$ServiceLocation->ServiceURL' ". - "WHERE SERVICENAME = '$ServiceLocation->ServiceName'"; - $status = $db->ExecuteQuery($query); - } - else - { - /* details related to this database is not stored. So we have to insert a new record */ - $query = "INSERT INTO service (servicename, url) VALUES (". - "'$ServiceLocation->ServiceName', '$ServiceLocation->ServiceURL')"; - $status = $db->ExecuteQuery($query); - } - - - if($status) - { - /* Transaction is successfull, we can safely commit the transaction into the database. */ - $db->ExecuteQuery("COMMIT TRAN"); - } - else - { - /* Transaction is not successfull, we have to rollback the transaction */ - $db->ExecuteQuery("ROLLBACK TRAN"); - error_log("Storing service location configuration failed. \n"); - } - } - else - { - error_log("Cannot initialise a transaction using BEGIN TRAN. \n"); - } - - $db->CloseDatabase(); - } - else - { - error_log("Service name $ServiceLocation->ServiceName is not supported by the system.\n"); - } - } -} - -/** Gets all service locations - * @namespace http://apache.org/stonehenge/stocktrader - * @param object GetServiceLocations $GetServiceLocations - * @return object ServiceLocations $ServiceLocations - */ -function getServiceLocations($GetServiceLocations) -{ - $db = GetDatabase(); - - $query = "SET NOCOUNT ON; SELECT servicename, url FROM service"; - - $result = $db->ExecuteQuery($query); - if ($result) - { - $rowNum = 0; - $ServiceLocations = new ServiceLocations(); - while($ServiceName = $db->GetSQLValue($result, $rowNum, 0)) - { - $config = new ServiceLocation(); - $config->ServiceName = $ServiceName; //Get the service name - $config->ServiceURL = $db->GetSQLValue($result, $rowNum, 1); //Get the URL - $ServiceLocations->ServiceLocation[$rowNum] = $config; - $rowNum = $rowNum + 1; - } - } - - $db->CloseDatabase(); - return $ServiceLocations; -} - -/** Sets connection from client to business service - * @namespace http://apache.org/stonehenge/stocktrader - * @param object ClientToBS $ClientToBS - */ -function setConnectionFromClientToBS($ClientToBS) -{ - if($ClientToBS) - { - /* check whether given business service and client name are valid */ - if(isBusinessServiceDefined($ClientToBS->BS)) - { - if(isClientDefined($ClientToBS->Client)) - { - /* both client name and business service are valid. we can store it */ - $db = GetDatabase(); - - /* "BEGIN TRAN" initialize a transaction; which privides control so that later we can cancel - * the transaction, if something goes wrong. */ - if($db->ExecuteQuery("BEGIN TRAN")) - { - $result = getClientToBS($ClientToBS->Client, $db); - if($result) - { - /* this detail is already available. So we should update the records */ - $query = "UPDATE clienttobs WITH (ROWLOCK) SET bs='$ClientToBS->BS' ". - "WHERE client = '$ClientToBS->Client'"; - $status = $db->ExecuteQuery($query); - } - else - { - /* details related to this database is not stored. So we have to insert a new record */ - $query = "INSERT INTO clienttobs (client, bs) VALUES (". - "'$ClientToBS->Client', '$ClientToBS->BS')"; - $status = $db->ExecuteQuery($query); - } - - if($status) - { - /* Transaction is successfull, we can safely commit the transaction into the database. */ - $db->ExecuteQuery("COMMIT TRAN"); - } - else - { - /* Transaction is not successfull, we have to rollback the transaction */ - $db->ExecuteQuery("ROLLBACK TRAN"); - error_log("Storing service location configuration failed. \n"); - } - } - else - { - error_log("Cannot initialise a transaction using BEGIN TRAN. \n"); - } - - $db->CloseDatabase(); - } - else - { - error_log("Client with name $ClientToBS->Client is not supported by the system. \n"); - } - } - else - { - error_log("Business service with name $ClientToBS->BS is not supported by the system. \n"); - } - } -} - -/** Get all connections from client to business service - * @namespace http://apache.org/stonehenge/stocktrader - * @param object GetClientToBSConnections $GetClientToBSConnections - * @return object ClientToBSConnections $ClientToBSConnections - */ -function getClientToBSConnections($GetClientToBSConnections) -{ - $db = GetDatabase(); - - $query = "SET NOCOUNT ON; SELECT client, bs FROM clienttobs"; - - $result = $db->ExecuteQuery($query); - if ($result) - { - $rowNum = 0; - $ClientToBSConnections = new ClientToBSConnections(); - while($ClientName = $db->GetSQLValue($result, $rowNum, 0)) - { - $config = new ClientToBS(); - $config->Client = $ClientName; //Get the client name - $config->BS = $db->GetSQLValue($result, $rowNum, 1); //Get the BS Name - $ClientToBSConnections->ClientToBS[$rowNum] = $config; - $rowNum = $rowNum + 1; - } - } - - $db->CloseDatabase(); - return $ClientToBSConnections; -} - -/** Sets connection from business service to order processor service - * @namespace http://apache.org/stonehenge/stocktrader - * @param object BSToOPS $BSToOPS - */ -function setConnectionFromBSToOPS($BSToOPS) -{ - if($BSToOPS) - { - /* check whether given business service and order processor service are valid */ - if(isBusinessServiceDefined($BSToOPS->BS)) - { - if(isOrderProcessorServiceDefined($BSToOPS->OPS) || isOrderProcessorSecDefined($BSToOPS->OPS)) - { - /* both order processor and business service are valid. we can store it */ - $db = GetDatabase(); - - /* "BEGIN TRAN" initialize a transaction; which privides control so that later we can cancel - * the transaction, if something goes wrong. */ - if($db->ExecuteQuery("BEGIN TRAN")) - { - $result = getBSToOPS($BSToOPS->BS, $db); - if($result) - { - /* this detail is already available. So we should update the records */ - $query = "UPDATE bstoops WITH (ROWLOCK) SET ops='$BSToOPS->OPS' ". - "WHERE bs = '$BSToOPS->BS'"; - $status = $db->ExecuteQuery($query); - } - else - { - /* details related to this database is not stored. So we have to insert a new record */ - $query = "INSERT INTO bstoops (bs, ops) VALUES ('$BSToOPS->BS', '$BSToOPS->OPS')"; - $status = $db->ExecuteQuery($query); - } - - if($status) - { - /* Transaction is successfull, we can safely commit the transaction into the database. */ - $db->ExecuteQuery("COMMIT TRAN"); - } - else - { - /* Transaction is not successfull, we have to rollback the transaction */ - $db->ExecuteQuery("ROLLBACK TRAN"); - error_log("Storing service location configuration failed. \n"); - } - } - else - { - error_log("Cannot initialise a transaction using BEGIN TRAN. \n"); - } - - $db->CloseDatabase(); - } - else - { - error_log("Order processor with name $BSToOPS->OPS is not supported by the system. \n"); - } - } - else - { - error_log("Business service with name $BSToOPS->BS is not supported by the system. \n"); - } - } -} - -/** Get all connections from business service to order processor service - * @namespace http://apache.org/stonehenge/stocktrader - * @param object GetBSToOPSConnections $GetBSToOPSConnections - * @return object BSToOPSConnections $BSToOPSConnections - */ -function getBSToOPSConnections($GetBSToOPSConnections) -{ - $db = GetDatabase(); - - $query = "SET NOCOUNT ON; SELECT bs, ops FROM bstoops"; - - $result = $db->ExecuteQuery($query); - if ($result) - { - $rowNum = 0; - $BSToOPSConnections = new BSToOPSConnections(); - while($BSName = $db->GetSQLValue($result, $rowNum, 0)) - { - $config = new BSToOPS(); - $config->BS = $BSName; //Get the BS name - $config->OPS = $db->GetSQLValue($result, $rowNum, 1); //Get the OPS Name - $BSToOPSConnections->BSToOPS[$rowNum] = $config; - $rowNum = $rowNum + 1; - } - } - - $db->CloseDatabase(); - return $BSToOPSConnections; -} - -/** Get configurations of a client - * @namespace http://apache.org/stonehenge/stocktrader - * @param object ClientConfigRequest $ClientConfigRequest - * @return object ClientConfigResponse $ClientConfigResponse End point url of business service - */ -function getClientConfig($ClientConfigRequest) -{ - if($ClientConfigRequest) - { - $db = GetDatabase(); - - $ClientToBS = getClientToBS($ClientConfigRequest->Client, $db); - if($ClientToBS) - { - $serviceLocation = getServiceLocation($ClientToBS->BS, $db); - if($serviceLocation) - { - $config = new ClientConfigResponse(); - $config->BS = $serviceLocation->ServiceURL; - } - else - { - error_log("Cannot find service location for business service $ClientToBS->BS \n"); - } - } - else - { - error_log("Cannot find details about business service connected to clinet ". - "[$ClientConfigRequest->Client]. \n"); - } - - $db->CloseDatabase(); - } - - return $config; -} - -/** Get configurations of a business service - * @namespace http://apache.org/stonehenge/stocktrader - * @param object BSConfigRequest $BSConfigRequest Name of the business service - * @return object BSConfigResponse $BSConfigResponse - */ -function getBSConfig($BSConfigRequest) -{ - if($BSConfigRequest) - { - $db = GetDatabase(); - - $BSToOPS = getBSToOPS($BSConfigRequest->BS, $db); - if($BSToOPS) - { - $serviceLocation = getServiceLocation($BSToOPS->OPS, $db); - if($serviceLocation) - { - /* found the end point url of order processor service. Now check for active database settings */ - $DBConfig = getActiveDBConfig($db); - if($DBConfig) - { - $config = new BSConfigResponse(); - $config->DBName = $DBConfig->DBName; - $config->DBHostName = $DBConfig->DBHostName; - $config->DBPort = $DBConfig->DBPort; - $config->OPS = $serviceLocation->ServiceURL; - if(isOrderProcessorSecDefined($BSToOPS->OPS)) - { - $config->Sec = true; - } - else - { - $config->Sec = false; - } - } - else - { - error_log("Cannot find details about active database \n"); - } - } - else - { - error_log("Cannot find service location for order processor service $BSToOPS->OPS \n"); - } - } - else - { - error_log("Cannot find details about order processor service connected to business service ". - " [$BSConfigRequest->BS]. \n"); - } - - $db->CloseDatabase(); - } - return $config; -} - -/** Get configurations of a order processor service - * @namespace http://apache.org/stonehenge/stocktrader - * @param object OPSConfigRequest $OPSConfigRequest - * @return object OPSConfigResponse $OPSConfigResponse - */ -function getOPSConfig($OPS) -{ - $db = GetDatabase(); - - $DBConfig = getActiveDBConfig($db); - if($DBConfig) - { - $config = new OPSConfigResponse(); - $config->DBName = $DBConfig->DBName; - $config->DBHostName = $DBConfig->DBHostName; - $config->DBPort = $DBConfig->DBPort; - } - else - { - error_log("Cannot find details about active database \n"); - } - - $db->CloseDatabase(); - return $config; -} - -$operations = array( - "DBConfig"=>"storeDBConfig", - "GetDBConfigs" => "getDBConfigs", - "ActiveDB" => "setActiveDB", - "GetActiveDB" => "getActiveDB", - "ServiceLocation" => "setServiceLocation", - "GetServiceLocations" => "getServiceLocations", - "ClientToBS" => "setConnectionFromClientToBS", - "GetClientToBSConnections" => "getClientToBSConnections", - "BSToOPS" => "setConnectionFromBSToOPS", - "GetBSToOPSConnections" => "getBSToOPSConnections", - "ClientConfigRequest" => "getClientConfig", - "BSConfigRequest" => "getBSConfig", - "OPSConfigRequest" => "getOPSConfig" -); - -$opParams = array( - "storeDBConfig"=>"MIXED", - "getDBConfigs" => "MIXED", - "setActiveDB" => "MIXED", - "getActiveDB" => "MIXED", - "setServiceLocation" => "MIXED", - "getServiceLocations" => "MIXED", - "setConnectionFromClientToBS" => "MIXED", - "getClientToBSConnections" => "MIXED", - "setConnectionFromBSToOPS" => "MIXED", - "getBSToOPSConnections" => "MIXED", - "getClientConfig" => "MIXED", - "getBSConfig" => "MIXED", - "getOPSConfig" => "MIXED" -); - -$classmap = array( - "DBConfig" => "DBConfig", - "GetDBConfigs" => "GetDBConfigs", - "DBConfigs" => "DBConfigs", - "ActiveDB" => "ActiveDB", - "GetActiveDB" => "GetActiveDB", - "ServiceLocation" => "ServiceLocation", - "GetServiceLocations" => "GetServiceLocations", - "ServiceLocations" => "ServiceLocations", - "ClientToBS" => "ClientToBS", - "GetClientToBSConnections" => "GetClientToBSConnections", - "BSToOPS" => "BSToOPS", - "GetBSToOPSConnections" => "GetBSToOPSConnections", - "ClientConfigRequest" => "ClientConfigRequest", - "ClientConfigResponse" => "ClientConfigResponse", - "BSConfigRequest" => "BSConfigRequest", - "BSConfigResponse" => "BSConfigResponse", - "OPSConfigRequest" => "OPSConfigRequest", - "OPSConfigResponse" => "OPSConfigResponse"); - -$svr = new WSService(array( - "operations"=>$operations, - "bindingStyle"=>"doclit", - "opParams" => $opParams, - "serviceName" => "config_svc", - "wsdl" => "../resources/wsdl/config_svc.wsdl", - "classmap" => $classmap)); - - -$svr->reply(); - - -?> +<?php +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +require_once ("../data_layer/data_access_layer.php"); +require_once ("class_info.php"); + +// define the class map +$class_map = array( + "GetClientConfig" => "GetClientConfig", + "ClientConfigRequest" => "ClientConfigRequest", + "GetClientConfigResponse" => "GetClientConfigResponse", + "ClientConfigResponse" => "ClientConfigResponse", + "GetBSConfig" => "GetBSConfig", + "BSConfigRequest" => "BSConfigRequest", + "GetBSConfigResponse" => "GetBSConfigResponse", + "BSConfigResponse" => "BSConfigResponse", + "GetOPSConfig" => "GetOPSConfig", + "OPSConfigRequest" => "OPSConfigRequest", + "GetOPSConfigResponse" => "GetOPSConfigResponse", + "OPSConfigResponse" => "OPSConfigResponse", + "SetClientToBS" => "SetClientToBS", + "ClientToBS" => "ClientToBS", + "SetClientToBSResponse" => "SetClientToBSResponse", + "SetBSToOPS" => "SetBSToOPS", + "BSToOPS" => "BSToOPS", + "SetBSToOPSResponse" => "SetBSToOPSResponse", + "GetBSLocations" => "GetBSLocations", + "GetBSLocationsResponse" => "GetBSLocationsResponse", + "ArrayOfServiceLocation" => "ArrayOfServiceLocation", + "ServiceLocation" => "ServiceLocation", + "GetOPSLocations" => "GetOPSLocations", + "GetOPSLocationsResponse" => "GetOPSLocationsResponse", + "SetServiceLocation" => "SetServiceLocation", + "SetServiceLocationResponse" => "SetServiceLocationResponse"); + +// define PHP functions that maps to WSDL operations +/** + * Service function GetClientConfig + * @param object of GetClientConfig $input + * @return object of GetClientConfigResponse + */ +function GetClientConfig($input) { + // NOTE: $input is of type GetClientConfig + // NOTE: should return an object of type GetClientConfigResponse + + $db = GetDatabase(); + + $client = addslashes($input->client->ClientName); + + $client_config = new GetClientConfigResponse(); + + // getting the BS configured for the client + $query = "SELECT bs FROM clienttobs WHERE client = '" . $client . "'"; + $result = $db->ExecuteQuery($query); + + $bs = ''; // hold the BS corresponding to the input CLIENT + + if ($result) { + $bs = $db->GetSQLValue($result, 0, 0); + } + + if ($bs) { + $query = "SELECT sec, servicename, url FROM service WHERE servicename = '$bs'"; + $result = $db->ExecuteQuery($query); + + if ($result) { + $client_config->GetClientConfigResult = new ClientConfigResponse(); + $client_config->GetClientConfigResult->Sec = $db->GetSQLValue($result, 0, 0) ? "true" : "false"; + $client_config->GetClientConfigResult->BSName = $db->GetSQLValue($result, 0, 1); + $client_config->GetClientConfigResult->BS = $db->GetSQLValue($result, 0, 2); + } + } + + return $client_config; +} + + +/** + * Service function GetBSConfig + * @param object of GetBSConfig $input + * @return object of GetBSConfigResponse + */ +function GetBSConfig($input) { + // NOTE: $input is of type GetBSConfig + // NOTE: should return an object of type GetBSConfigResponse + + $db = GetDatabase(); + + $bs = addslashes($input->bs->BSName); + + $bs_config = new GetBSConfigResponse(); + + if ($bs) { + + $query = "SELECT ops FROM bstoops WHERE bs = '" . $bs . "'"; + $result = $db->ExecuteQuery ( $query ); + + $ops = ''; // hold the OPS corresponding to the input BS + + + if ($result) { + $ops = $db->GetSQLValue ( $result, 0, 0 ); + } + + if ($ops) { + $query = "SELECT sec, servicename, url FROM service WHERE servicename = '$ops'"; + $result = $db->ExecuteQuery ( $query ); + + if ($result) { + $bs_config->GetBSConfigResult = new BSConfigResponse ( ); + $bs_config->GetBSConfigResult->Sec = $db->GetSQLValue ( $result, 0, 0 ) ? "true" : "false"; + $bs_config->GetBSConfigResult->OPSName = $db->GetSQLValue ( $result, 0, 1 ); + $bs_config->GetBSConfigResult->OPS = $db->GetSQLValue ( $result, 0, 2 ); + + $host = ''; + + if (preg_match ( "/mssql/i", $db->connectionInfo->type )) { + $host = preg_split ( "/,/", $db->connectionInfo->server ); + } else if (preg_match ( "/mysql/i", $db->connectionInfo->type )) { + $host = preg_split ( "/:/", $db->connectionInfo->server ); + } + + $bs_config->GetBSConfigResult->DBHostName = $host [0]; + $bs_config->GetBSConfigResult->DBName = $db->connectionInfo->database; + $bs_config->GetBSConfigResult->DBPort = $host [1]; + } + } + + } + + return $bs_config; +} + + +/** + * Service function GetOPSConfig + * @param object of GetOPSConfig $input + * @return object of GetOPSConfigResponse + */ +function GetOPSConfig($input) { + // TODO: fill in the business logic + // NOTE: $input is of type GetOPSConfig + // NOTE: should return an object of type GetOPSConfigResponse + +} + + +/** + * Service function SetClientToBS + * @param object of SetClientToBS $input + * @return object of SetClientToBSResponse + */ +function SetClientToBS($input) { + // NOTE: $input is of type SetClientToBS + // NOTE: should return an object of type SetClientToBSResponse + + $db = GetDatabase(); + + $client = addslashes($input->clientConfig->Client); + $bs = addslashes($input->clientConfig->Bs); + + $query = "UPDATE clienttobs SET bs = '$bs' WHERE client = '$client'"; + + $result = $db->ExecuteQuery($query); + + return new SetClientToBSResponse(); +} + + +/** + * Service function SetBSToOPS + * @param object of SetBSToOPS $input + * @return object of SetBSToOPSResponse + */ +function SetBSToOPS($input) { + // NOTE: $input is of type SetBSToOPS + // NOTE: should return an object of type SetBSToOPSResponse + + $db = GetDatabase(); + + $bs = addslashes($input->bsConfig->Bs); + $ops = addslashes($input->bsConfig->Ops); + + $query = "UPDATE bstoops SET ops = '$ops' WHERE bs = '$bs'"; + + $result = $db->ExecuteQuery($query); + + return new SetBSToOPSResponse(); +} + + +/** + * Service function GetBSLocations + * @param object of GetBSLocations $input + * @return object of GetBSLocationsResponse + */ +function GetBSLocations($input) { + // NOTE: $input is of type GetBSLocations + // NOTE: should return an object of type GetBSLocationsResponse + + $db = GetDatabase(); + + $query = "SELECT sec, servicename, url FROM service WHERE servicename LIKE '%_BS'"; + + $result = $db->ExecuteQuery($query); + + $locations = new GetBSLocationsResponse(); + $locations->GetBSLocationsResult = new ArrayOfServiceLocation(); + + if ($result) { + for ($i = 0; $db->GetSQLValue($result, $i, 1); $i++) { + $locations->GetBSLocationsResult->ServiceLocation[$i] = new ServiceLocation(); + $locations->GetBSLocationsResult->ServiceLocation[$i]->Sec = $db->GetSQLValue($result, $i, 0) ? "true" : "false"; + $locations->GetBSLocationsResult->ServiceLocation[$i]->ServiceName = $db->GetSQLValue($result, $i, 1); + $locations->GetBSLocationsResult->ServiceLocation[$i]->ServiceURL = $db->GetSQLValue($result, $i, 2); + } + } + + return $locations; +} + + +/** + * Service function GetOPSLocations + * @param object of GetOPSLocations $input + * @return object of GetOPSLocationsResponse + */ +function GetOPSLocations($input) { + // NOTE: $input is of type GetOPSLocations + // NOTE: should return an object of type GetOPSLocationsResponse + + $db = GetDatabase(); + + $query = "SELECT sec, servicename, url FROM service WHERE servicename LIKE '%_OPS'"; + + $result = $db->ExecuteQuery($query); + + $locations = new GetOPSLocationsResponse(); + $locations->GetOPSLocationsResult = new ArrayOfServiceLocation(); + + if ($result) { + for ($i = 0; $db->GetSQLValue($result, $i, 1); $i++) { + $locations->GetOPSLocationsResult->ServiceLocation[$i] = new ServiceLocation(); + $locations->GetOPSLocationsResult->ServiceLocation[$i]->Sec = $db->GetSQLValue($result, $i, 0) ? "true" : "false"; + $locations->GetOPSLocationsResult->ServiceLocation[$i]->ServiceName = $db->GetSQLValue($result, $i, 1); + $locations->GetOPSLocationsResult->ServiceLocation[$i]->ServiceURL = $db->GetSQLValue($result, $i, 2); + } + } + + return $locations; +} + + +/** + * Service function SetServiceLocation + * @param object of SetServiceLocation $input + * @return object of SetServiceLocationResponse + */ +function SetServiceLocation($input) { + // NOTE: $input is of type SetServiceLocation + // NOTE: should return an object of type SetServiceLocationResponse + + $db = GetDatabase(); + + $sec = ($input->location->Sec == "true") ? 1 : 0; + $sname = addslashes($input->location->ServiceName); + $surl = addslashes($input->location->ServiceURL); + + $query = "SELECT servicename FROM service WHERE servicename = '$sname'"; + $result = $db->ExecuteQuery($query); + $q2 = ''; + + if ($result && $db->GetSQLValue($result, 0, 0)) { + // update + $q2 = "UPDATE service SET url = '$surl', sec = $sec WHERE servicename = '$sname'"; + } else { + $q2 = "INSERT INTO service(servicename, url, sec) VALUES ('$sname', '$surl', $sec)"; + } + + $r2 = $db->ExecuteQuery($q2); + + return new SetServiceLocationResponse(); +} + + +// define the operations map +$operations = array( + "GetClientConfig" => "GetClientConfig", + "GetBSConfig" => "GetBSConfig", + "GetOPSConfig" => "GetOPSConfig", + "SetClientToBS" => "SetClientToBS", + "SetBSToOPS" => "SetBSToOPS", + "GetBSLocations" => "GetBSLocations", + "GetOPSLocations" => "GetOPSLocations", + "SetServiceLocation" => "SetServiceLocation"); + +// define the actions => operations map +$actions = array( + "http://apache.org/stonehenge/stocktrader/ConfigServiceService/GetClientConfig" => "GetClientConfig", + "http://apache.org/stonehenge/stocktrader/ConfigServiceService/GetBSConfig" => "GetBSConfig", + "http://apache.org/stonehenge/stocktrader/ConfigServiceService/GetOPSConfig" => "GetOPSConfig", + "ClientToBS" => "SetClientToBS", + "BSToOPS" => "SetBSToOPS", + "http://apache.org/stonehenge/stocktrader/ConfigServiceService/GetBSLocations" => "GetBSLocations", + "http://apache.org/stonehenge/stocktrader/ConfigServiceService/GetOPSLocations" => "GetOPSLocations", + "ServiceLocation" => "SetServiceLocation"); + +// create service in WSDL mode +$service = new WSService(array ("wsdl" =>"../resources/wsdl/config_svc.wsdl", + "actions" => $actions, + "classmap" => $class_map, + "operations" => $operations)); + +// process client requests and reply +$service->reply(); + + +?>