0

I am sending request through soap using php curl getting java Exception. When I request for response I am getting error. I tried a lot at my end but problem is not solve.

$soap_request  = "<?xml version=\"1.0\"?>";
  $soap_request .= "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n";
  $soap_request .= "  <soap:Body>\n"; 
  $soap_request .= "    <RevodocLead xmlns='http://localhost/'>\n";
  $soap_request .= "        <inode>\n";
  $soap_request .= "            <version>1.0</version>\n";
  $soap_request .= "            <sourceuserid>[email protected]</sourceuserid>\n";
  $soap_request .= "            <sourceid>18641254455</sourceid>\n";
  $soap_request .= "            <dealercode>1458445284</dealercode>\n";
  $soap_request .= "            <created>18-12-2015 13:45EST</created>\n";
  $soap_request .= "            <browser>Android Browser</browser>\n";
  $soap_request .= "            <os>Macintosh</os>\n";
  $soap_request .= "            <agent>[email protected]</agent>\n";
  $soap_request .= "            <product>mortgage-renewal</product>\n";
  $soap_request .= "            <name>success</name>\n";
  $soap_request .= "            <address>success</address>\n";
  $soap_request .= "            <email>success</email>\n";
  $soap_request .= "            <phone>success</phone>\n";
  $soap_request .= "            <propertyvalue>325000</propertyvalue>\n";
  $soap_request .= "            <mortgage>300000</mortgage>\n";
  $soap_request .= "            <referralcode>F3S2A2</referralcode>\n";
  $soap_request .= "            <note>value</note>\n";
  $soap_request .= "            <futurecontact>yes</futurecontact>\n";
  $soap_request .= "        </inode>\n"; 
  $soap_request .= "    </RevodocLead>\n";
  $soap_request .= "  </soap:Body>\n";
  $soap_request .= "</soap:Envelope>";

$header = array(
    "Content-type: text/xml;charset=\"utf-8\"",
    "Accept: text/xml",
    "Cache-Control: no-cache",
    "Pragma: no-cache",
    "SOAPAction: myactionMethod",
    "Content-length: ".strlen($soap_request),
  );

  $soap_do = curl_init();
  curl_setopt($soap_do, CURLOPT_URL, $url );
  curl_setopt($soap_do, CURLOPT_HEADER, false);
  curl_setopt($soap_do, CURLOPT_CONNECTTIMEOUT, 100);
  curl_setopt($soap_do, CURLOPT_TIMEOUT,        100);
  curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true );
  curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false);
  curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, false);
  curl_setopt($soap_do, CURLOPT_POST,           true );
  curl_setopt($soap_do, CURLOPT_POSTFIELDS,     $soap_request);
  curl_setopt($soap_do, CURLOPT_HTTPHEADER,     $header);


  if(curl_exec($soap_do) === false) {
    $err = 'Curl error: ' . curl_error($soap_do);
    curl_close($soap_do);
    print $err;
  } else {
    $result = curl_exec($soap_do);
    echo '<pre>';
    print_r($result);
    curl_close($soap_do);
    //print 'Operation completed without any errors';
  }

I am getting error

soap:Serverjava.lang.ClassCastException: java.lang.String cannot be cast to javax.xml.bind.JAXBElement

2
  • i reckon you will have to add your $header and $soap_request to your question, since the error states quite clearly that there is some unexpected string where an xml element was expected Commented Apr 17, 2015 at 9:12
  • Hi hexerel i added both $header and $soap_request Commented Apr 17, 2015 at 9:19

1 Answer 1

2

Please check below code. It's working great.

class RevodocLeadSoapClient extends SoapClient {

    function __construct($wsdl, $options) {
        parent::__construct($wsdl, $options);
        $this->server = new SoapServer($wsdl, $options);
    }
    public function __doRequest($request, $location, $action, $version) { 
        $result = parent::__doRequest($request, $location, $action, $version); 
        return $result; 
    } 
    function __anotherRequest($call, $params) {
        $location = 'https://www.t1.revodoc.com/ws/services/RevoLeadWebService';
        $action = 'http://localhost/'.$call;
        $request = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
                    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:typens="https://secure.maventa.com/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
                    <SOAP-ENV:Body>
                    <RevodocLead xmlns="http://localhost/">';
        $request .= $params;
        $request .= '</RevodocLead>
                    </SOAP-ENV:Body>
                    </SOAP-ENV:Envelope>';
        $result =$this->__doRequest($request, $location, $action, '1');
        return $result;
    } 
}

// Create new SOAP client
$wsdl = 'https://www.t1.revodoc.com/ws/services/RevoLeadWebService?wsdl';
$client = new RevodocLeadSoapClient($wsdl, array(
    'cache_wsdl'    => WSDL_CACHE_NONE, 
    'cache_ttl'     => 86400, 
    'trace'         => true,
    'exceptions'    => true,
));

$operations = "RevodocLead";

$soap_request .= "<inode>";
$soap_request .= "<version>1.0</version>";
$soap_request .= "<sourceuserid>[email protected]</sourceuserid>";
$soap_request .= "<sourceid>18641254455</sourceid>";
$soap_request .= "<dealercode>1458445284</dealercode>";
$soap_request .= "<created>18-12-2015 13:45EST</created>";
$soap_request .= "<browser>Android Browser</browser>";
$soap_request .= "<os>Macintosh</os>";
$soap_request .= "<agent>[email protected]</agent>";
$soap_request .= "<product>mortgage-renewal</product>";
$soap_request .= "<name>success</name>";
$soap_request .= "<address>success</address>";
$soap_request .= "<email>success</email>";
$soap_request .= "<phone>success</phone>";
$soap_request .= "<propertyvalue>325000</propertyvalue>";
$soap_request .= "<mortgage>300000</mortgage>";
$soap_request .= "<referralcode>F3S2A2</referralcode>";
$soap_request .= "<note>value</note>";
$soap_request .= "<futurecontact>yes</futurecontact>";
$soap_request .= "</inode>";

// Make the request
try {
    $request = $client->__anotherRequest($operations, $soap_request);
} catch (SoapFault $e ){
    echo "Last request:<pre>" . htmlentities($client->__getLastRequest()) . "</pre>";
    exit();
}
//Print Response. #RevodocLeadResponse
echo '<pre><b>', htmlentities($request), '</b></pre>';
Sign up to request clarification or add additional context in comments.

9 Comments

Hi jayson in my case authenticatoin does not required
you can directly call the __soapCall method without SoapHeader and __setSoapHeaders
"SOAPAction: myactionMethod", defined at you header array.
$wsdl = 'mysite?wsdl'; $client = new SoapClient($wsdl); $soap_request['inode'] = array('version' => '1.0', 'sourceuserid' => '[email protected]', 'sourceid' => '15640435843584', 'dealercode' => '41358-21' ,'created' => '18-04-2015 13:45EST' ,'browser' => 'chrome ,'os' => 'linux' ); $result = $client->__soapCall("RevodocLead", $soap_request); print_r($result); ?>
Fatal error: Uncaught SoapFault exception: [soap:Server] java.lang.NullPointerException in /var/www/html/webservice/04.php:16 Stack trace: #0 /var/www/html/webservice/04.php(16): SoapClient->__soapCall('RevodocLead', Array) #1 {main} thrown in /var/www/html/webservice/04.php on line 16
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.