Laravel测试与SOAP WDSL的连接和异常处理 [英] Laravel test connection to SOAP WDSL and exception handling

查看:139
本文介绍了Laravel测试与SOAP WDSL的连接和异常处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用laravel框架,我想检查与Soap服务器的连接是否成功,而应用程序不会因致命错误而死.

I use the laravel framework and I want to check if a connection to Soap server was successful or not, without the app dying with fatal error.

这两者:

$this->client = @new SoapClient("http://some.url/test.wsdl");
                $this->session = $this->client->login("username", "password");
                if (is_soap_fault($this->session)) {
                   return "Error";
                }

这:

try {
 $this->client = @new SoapClient("http://some.url/test.wsdl");
 $this->session = $this->client->login("username", "password");
} catch (SoapFault $e) {
    return "Error";
}

导致致命错误:

Symfony \ Component \ Debug \ Exception \ FatalErrorException

SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://some.url/test.wsdl' : failed to load external entity "http://some.url/test.wsdl"

谢谢

推荐答案

我今天也在这个问题上苦苦挣扎.问题在于Laravel错误处理程序将这个可捕获的错误解释为致命错误,并因此中止了程序.

I struggled with this issue today as well. The problem is the Laravel error handler is interpreting this catchable error as a fatal error, and aborting the program as a result.

要解决此问题,您需要在Laravel的内部错误处理程序之前拦截错误.此方法取决于您的Laravel版本:

To counter this, you need to intercept the error prior to Laravel's internal error handler. This method varies depending on your Laravel version:

Laravel 4.*

  1. 转到您的globals.php文件.这应该在您的app\start\文件夹中.
  2. 添加以下代码(感谢dmgfjaved ):

  1. Go to your globals.php file. This should be in your app\start\ folder.
  2. Add the following code (Thanks dmgfjaved):

App::fatal(function($exception)
{   //If SOAP Error is found, we don't want to FATALLY crash but catch it instead
   if(strpos($exception->getMessage(), 'SOAP-ERROR') !== FALSE)
   {
     return '';
   }
});

Laravel 5.*

  1. 没有globals.php文件.所有IoC呼叫均通过ServiceProviders处理.转到app\Providers\AppServiceProvider.php.
  2. 找到render()函数.
  3. return parent::render($request, $e);

  1. There is no globals.php file. All IoC calls are handled via ServiceProviders. Go to app\Providers\AppServiceProvider.php.
  2. Find the render() function.
  3. Add the following code before the return parent::render($request, $e);

if(strpos($e->getMessage(), 'SOAP-ERROR') !== false)
{
    return false;
}

这将从您的错误处理程序中删除SoapFault错误类型.记住要抓住SoapFault,因为Laravel不会!

This will remove the SoapFault error type from your error handler. Remember to catch the SoapFault as Laravel won't!

这篇关于Laravel测试与SOAP WDSL的连接和异常处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆