I have made a web application that uses SOAP exchanges to get data from a Web API. This was initially done in a procedural way and I'm now trying to move it into a Laravel framework. I have a view
set up to display to the user if the SOAP Response is "Request denied by Throttle server" but I don't know how to check for that particular error. Here is the Class:
<?php namespace App\Models;
use SoapClient;
use Illuminate\Http\RedirectResponse;
class SoapWrapper {
public function soapExchange() {
// set WSDL for authentication and create new SOAP client
$auth_url = "http://search.webofknowledge.com/esti/wokmws/ws/WOKMWSAuthenticate?wsdl";
// set WSDL for search and create new SOAP client
$search_url = "http://search.webofknowledge.com/esti/wokmws/ws/WokSearch?wsdl";
// array options are temporary and used to track request & response data
$auth_client = @new SoapClient($auth_url);
// array options are temporary and used to track request & response data
$search_client = @new SoapClient($search_url);
// run 'authenticate' method and store as variable
$auth_response = $auth_client->authenticate();
// call 'setCookie' method on '$search_client' storing SID (Session ID) as the response (value) given from the 'authenticate' method
// check if an SID has been set, if not it means Throttle server has stopped the query, therefore display error message
if (isset($auth_response->return)) {
$search_client->__setCookie('SID',$auth_response->return);
} else {
return Redirect::route('throttle');
}
}
}
The problem is that it throws the "Request denied by Throttle server" default Laravel error at $auth_response = $auth_client->authenticate();
before it gets to the if
statement that checks if a value (SessionID) has been returned by the SOAP Request. It didn't do this when it was set up in a procedural way for some reason.
The if
statement checks if a value has been returned from the authenticate()
method and if it has, assigns it (SessionID) to the cookie of the search client to authorise searches. Otherwise it displays a custom error message.
I have tried using is_soap_fault
but that doesn't catch it because it isn't technically a soap fault. I've also tried removing the line causing the problem and changing the if
statement to:
if (isset($auth_client->authenticate()->return) {...
But that just causes the default Laravel SoapFault page too. The return Redirect::route('throttle')
displays a custom error page to the user, saved as throttle.blade.php
.
Anyone know how I can test for the throttle error?
Never mind, found answer here: Catching an exception when creating a new SoapClient properly .
I'll post my amended code anyway just in case it's of any use to anyone else in future:
<?php namespace App\Models;
use SoapClient;
use Illuminate\Http\RedirectResponse;
class SoapWrapper {
public function soapExchange() {
try {
// set WSDL for authentication and create new SOAP client
$auth_url = "http://search.webofknowledge.com/esti/wokmws/ws/WOKMWSAuthenticate?wsdl";
// set WSDL for search and create new SOAP client
$search_url = "http://search.webofknowledge.com/esti/wokmws/ws/WokSearch?wsdl";
// array options are temporary and used to track request & response data
$auth_client = @new SoapClient($auth_url);
// array options are temporary and used to track request & response data
$search_client = @new SoapClient($search_url);
// run 'authenticate' method and store as variable
$auth_response = $auth_client->authenticate();
// add SID (SessionID) returned from authenticate() to cookie of search client
$search_client->__setCookie('SID', $auth_response->return);
} catch (\SoapFault $e) {
return Redirect::route('throttle');
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.