【发布时间】:2015-05-27 23:35:01
【问题描述】:
我制作了一个使用 SOAP 交换从 Web API 获取数据的 Web 应用程序。这最初是以程序方式完成的,我现在正试图将其移入 Laravel 框架。如果 SOAP 响应是“请求被 Throttle 服务器拒绝”,我设置了 view 以向用户显示,但我不知道如何检查该特定错误。这是课程:
<?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');
}
}
}
问题是它在到达if 语句检查 SOAP 请求是否返回值 (SessionID) 之前,会在 $auth_response = $auth_client->authenticate(); 处引发“请求被 Throttle 服务器拒绝”默认 Laravel 错误。由于某种原因,它在以程序方式设置时并没有这样做。
if 语句检查是否已从 authenticate() 方法返回值,如果有,则将其 (SessionID) 分配给搜索客户端的 cookie 以授权搜索。否则会显示自定义错误消息。
我尝试过使用is_soap_fault,但这并没有抓住它,因为它在技术上不是肥皂故障。我还尝试删除导致问题的行并将if 语句更改为:
if (isset($auth_client->authenticate()->return) {...
但这也只会导致默认的 Laravel SoapFault 页面。 return Redirect::route('throttle') 向用户显示自定义错误页面,保存为throttle.blade.php。
有人知道如何测试油门错误吗?
【问题讨论】:
标签: php web-services soap laravel-5 throttling