SOAP error after changing php from 5.3 to 5.5

Asked

Viewed 3,918 times

0

Good afternoon, I did a php upgrade on my server and one of my scripts stopped working. Error shown is this:

  thrown in /home/brewhead/public_html/catalog/model/shipping/jadlog5.php on line 65
[07-Dec-2016 21:13:08 America/Sao_Paulo] PHP Fatal error:  SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://jadlog.com.br/JadlogEdiWs/services/ValorFreteBean?wsdl' : failed to load external entity "http://jadlog.com.br/JadlogEdiWs/services/ValorFreteBean?wsdl"
 in /home/brewhead/public_html/catalog/model/shipping/jadlog5.php on line 65
[07-Dec-2016 21:13:08 America/Sao_Paulo] PHP Fatal error:  Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://jadlog.com.br/JadlogEdiWs/services/ValorFreteBean?wsdl' : failed to load external entity "http://jadlog.com.br/JadlogEdiWs/services/ValorFreteBean?wsdl"
 in /home/brewhead/public_html/catalog/model/shipping/jadlog5.php:65
Stack trace:
#0 /home/brewhead/public_html/catalog/model/shipping/jadlog5.php(65): SoapClient->SoapClient('http://jadlog.c...')
#1 /home/brewhead/public_html/catalog/controller/checkout/shipping.php(143): ModelShippingJadlog5->getQuote(Array)
#2 [internal function]: ControllerCheckoutShipping->quote(Array)
#3 /home/brewhead/public_html/system/modification/system/engine/action.php(65): call_user_func(Array, Array)
#4 /home/brewhead/public_html/system/engine/front.php(34): Action->execute(Object(Registry))
#5 /home/brewhead/public_html/system/engine/front.php(29): Front->execute(Object(Action))
#6 /home/brewhead/public_html/index.php(265): Front->dispatch(Object(Action), Object(Action))
#7 {main}
  thrown in /home/brewhead/public_html/catalog/model/shipping/jadlog5.php on line 65

I tried to change the script several times but could not solve the problem.

follows my script making the Soap request:

    $cost = 0;

    //dados do carrinho e calcula as medidas
    $pais = $address['iso_code_2'];

    $tiposFrete = array('Expresso'=>0,'Package'=>3,'Rodoviario'=>4,'Economico'=>5,'DOC'=>6,'Corporate'=>7,'.COM'=>9,'Cargo'=>12);

    $soapClient = new SoapClient("http://jadlog.com.br/JadlogEdiWs/services/ValorFreteBean?wsdl");

    foreach($tiposFrete AS $k=>$v){
        $tipos = $this->config->get('jadlog5_tipos');
        if((!empty($tipos) && in_array($v,$tipos))){

            $peso_cubado = $this->pesoCubado($v);
            $fator_cubagem = $this->vCubagem[$v];
            if($fator_cubagem=='6000'){
                $prazo = $this->config->get('jadlog5_prazoa');
            }else{
                $prazo = $this->config->get('jadlog5_prazo');
            }

        //regra do maior peso
            $weight = number_format($this->cart->getWeight()/1000, 2, '.', '');
        //echo $peso_cubado." | ".$weight;
            if($weight>$peso_cubado){
                $peso_cubado=$weight;
            }

        //if($weight>$peso_cubado){
            //$peso_cubado = $weight/1000;
        //}
        //print("$peso_cubado | $weight");

            $default = array('cep_origem' => preg_replace('/\D/', '', $this->config->get('jadlog5_cep')),
                'cep_destino' => preg_replace('/\D/', '', $address['postcode']),
                'peso' => number_format($peso_cubado, 2, ',', ''),
                'valor' => number_format($this->cart->getSubTotal(), 2, ',', ''),
                'modalidade' => $v,
                'cnpj' => trim($this->config->get('jadlog5_user')),
                'password' => trim($this->config->get('jadlog5_senha')),
                'seguro' => 'S',
                'coleta' => number_format($this->config->get('jadlog5_coleta'), 2, ',', ''),
                'acobrar' => ($this->config->get('jadlog5_frete')==0?'N':'S'),
                'entrega' => ($this->config->get('jadlog5_entrega')==0?'D':'R'));

            $consulta['vModalidade']          =    $default['modalidade'];
            $consulta['Password']             =    $default['password'];
            $consulta['vSeguro']              =    $default['seguro'];
            $consulta['vVlDec']               =    $default['valor'];
            $consulta['vVlColeta']            =    $default['coleta'];
            $consulta['vCepOrig']             =    $default['cep_origem'];
            $consulta['vCepDest']             =    $default['cep_destino'];
            $consulta['vPeso']                =    $default['peso'];
            $consulta['vFrap']                =    $default['acobrar'];
            $consulta['vEntrega']             =    $default['entrega'];
            $consulta['vCnpj']                =    $default['cnpj'];
        //echo "<pre>";
        //print_r($consulta);
        //echo "</pre>";
            try { 
                $info = $soapClient->__call("valorar", array($consulta)); 
                $calculo = json_decode(json_encode(@simplexml_load_string($info->valorarReturn)),true); 
                if(isset($calculo['Jadlog_Valor_Frete']['Retorno'])){
                    if($calculo['Jadlog_Valor_Frete']['Retorno']<=0){
                        $this->log->write("Erro jadlog ".$k.": " . $calculo['Jadlog_Valor_Frete']['Mensagem']); 
                    }else{

                        $cost = str_replace('.','',$calculo['Jadlog_Valor_Frete']['Retorno']);
                        $cost = str_replace(',','.',$cost);
                        $cost = ($cost+$this->config->get('jadlog5_taxa'));

                        $code = $v;
                        $quote_data[$code] = array(
                            'code'         => 'jadlog5.' . $code,
                            'title'        => '<img src="https://brewheadshop.com.br/img_pagamento/jadlog.png"> '.$k.' '.$prazo.'<br>Entregas para todo o Brasil com prazos aproximados para cada Região a seguir:<br>Região Sul: de 4 à 7 dias úteis<br>Região Sudeste: de 3 à 5 dias úteis<br>Região Centro-Oeste: de 4 à 10 dias úteis<br>Região Nordeste: de 8 à 19 dias úteis<br>Região Norte: de 20 à 25 dias úteis<br><span style="font-size:16px;font-weight:bold">Valor de Entrega</span>',
                            'cost'         => $this->tax->calculate($cost, $this->config->get('jadlog5_tax_class_id'), $this->config->get('config_tax')),
                            'tax_class_id' => $this->config->get('jadlog5_tax_class_id'),
                            'text'         => $this->formatar($this->tax->calculate($cost, $this->config->get('jadlog5_tax_class_id'), $this->config->get('config_tax')))
                            );

                    }
                }
            } catch (SoapFault $fault) { 
            //print_r($fault->faultstring); 
                $this->log->write("Erro de acesso a api jadlog, verificar se o mesmo esta online e o firewall esta com a porta 8080 liberada!");    
            }

        }

someone would be kind enough to tell me how to solve this problem?

thank you very much

  • Are you sure the problem is on your side? can you test in the old version? the error message is SOAP-ERROR: Parsing WSDL: Couldn't load from ...

  • in the old version works ok. I am testing what our colleague posted below.

2 answers

1

Check whether the SoapClient is sending the user-agent, the error from what I read is PARSE and not of connection, see:

SOAP-ERROR: Parsing WSDL: Couldn’t load

So try this:

$opts = array(
        'http' => array( 'user_agent' => 'PHPSoapClient' )
    );

$context = stream_context_create($opts);
$soapContext = array(
                  'stream_context' => $context,
                  'cache_wsdl' => WSDL_CACHE_NONE
               );

$soapClient = new SoapClient("http://jadlog.com.br/JadlogEdiWs/services/ValorFreteBean?wsdl", $soapContext);

You can try changing the PHPSoapClient by the desired user-agent

If you fail you can try 'trace' => true:

$opts = array(
        'trace' => true,
        'http' => array( 'user_agent' => 'PHPSoapClient' )
    );

$context = stream_context_create($opts);
$soapContext = array(
                  'trace' => true,
                  'stream_context' => $context,
                  'cache_wsdl' => WSDL_CACHE_NONE
               );

$soapClient = new SoapClient("http://jadlog.com.br/JadlogEdiWs/services/ValorFreteBean?wsdl", $soapContext);

It may also be lack of header called Accepets, can send him like this:

$opts = array(
        'trace' => true,
        'http' => "User-agent: PHPSoapClient\r\n" .
                  "Accept: application/xhtml+xml,application/xml"
    );

This is because since version 5.5 some things have started to change in how PHP makes HTTP access and in 5.6 HTTPS has also changed, many things must be used stream_ to adjust.

Note: i had a similar problem while migrating to php5.6

  • didn’t work :(

  • @Jasarorion the trace returned nothing?

  • it gives the error before trace #0 /home/brewhead/public_html/catalog/model/shipping/jadlog5.php(75): SoapClient->SoapClient('http://jadlog.c...', Array)&#xA;#1 /home/brewhead/public_html/catalog/controller/checkout/shipping.php(143): ModelShippingJadlog5->getQuote(Array)

  • @Jasarorion may be some kind of firewall or block, please try this (create a white and paste file and run it): <?php&#xA;$opts = array(&#xA; 'http' => array( 'user_agent' => 'PHPSoapClient' )&#xA; );&#xA;&#xA;$context = stream_context_create($opts);&#xA;&#xA;$op = fopen("http://jadlog.com.br/JadlogEdiWs/services/ValorFreteBean?wsdl", 'r', false, $context);&#xA;&#xA;var_dump(fread($op, 2000));, If you return Xml then problem is not firewall

  • http://brewheadshop.com.br/testejad.php returned false

  • @Jasarorion I’m going to download php5.5 (use 5.6) to test, but it’s probably Firewall or php.ini, by the way, you can copy php.ini and send me by Pastebin.com?

  • http://pastebin.com/PciRaRAH

  • @Jasarorion seems to be something in PHP itself, in version 5.5 must be missing some header, I will try to adjust here.

  • thank you very much thank you very much help I am already a few days comeste problem and do not know what else to do.

Show 4 more comments

0

Boy, do the following:

Modifies the line:

$soapClient = new SoapClient("http://jadlog.com.br/JadlogEdiWs/services/ValorFreteBean?wsdl");

To:

// options for ssl in php 5.6.5
$opts = array(
    'ssl' => array('ciphers'=>'RC4-SHA', 'verify_peer'=>false, 'verify_peer_name'=>false)
);

// SOAP 1.2 client
$params = array ('encoding' => 'UTF-8', 'verifypeer' => false, 'verifyhost' => false, 'soap_version' => SOAP_1_2, 'trace' => 1, 'exceptions' => 1, "connection_timeout" => 180, 'stream_context' => stream_context_create($opts) );

$url_webservice="http://jadlog.com.br/JadlogEdiWs/services/ValorFreteBean";
$soapClient = new SoapClient($url_webservice."?wsdl",$params );    

//var_dump($soapClient);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.