Esempio n. 1
0
 public function testHeader()
 {
     $msg = XPSoapMessage::fromString('
     <SOAP-ENV:Envelope
       xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:xsd="http://www.w3.org/2001/XMLSchema">
     <SOAP-ENV:Header>
       <targetAddress SOAP-ENV:mustUnderstand="1">
         http://tokyo:8004/glue/urn:CorpDataServices
       </targetAddress>
     </SOAP-ENV:Header>
     <SOAP-ENV:Body>
       <ns1:getQuote
        xmlns:ns1="urn:DirectedQuoteProxyService"
        SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
         <stocks xsi:type="xsd:string">AMX</stocks>
       </ns1:getQuote>
     </SOAP-ENV:Body>
     </SOAP-ENV:Envelope>
   ');
     $headers = $msg->getHeaders();
     $this->assertNotEquals(NULL, $msg->getHeaders());
     $this->assertEquals(1, sizeof($headers));
     foreach ($headers as $h) {
         $this->assertSubclass($h, 'webservices.soap.xp.XPSoapHeaderElement');
     }
 }
 /**
  * Retrieve SOAP message from request
  *
  * @return  webservices.soap.xp.XPSoapMessage message object
  */
 public function getMessage()
 {
     $m = XPSoapMessage::fromString($this->getData());
     list($class, $method) = explode('#', str_replace('"', '', $this->getHeader('SOAPAction')));
     $m->setHandlerClass($class);
     $m->setMethod($method);
     $m->setMapping($this->mapping);
     return $m;
 }
    public function multipleParameters()
    {
        $this->router->setMockHeaders(array('SOAPAction' => 'DummyRpcImplementation#checkMultipleParameters', 'Content-Type' => 'text/xml; charset=iso-8859-1'));
        $this->router->setMockData('<?xml version="1.0" encoding="iso-8859-1"?>
<SOAP-ENV:Envelope
 xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
 xmlns:si="http://soapinterop.org/xsd"
 SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
 xmlns:ctl="DummyRpcImplementation"
>
  <SOAP-ENV:Body>  
    <ctl:checkMultipleParameters>    
      <item xsi:type="xsd:string">Lalala</item>
      <item xsi:type="xsd:int">1</item>
      <item xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="xsd:anyType[4]">        
        <item xsi:type="xsd:int">12</item>
        <item xsi:type="xsd:string">Egypt</item>
        <item xsi:type="xsd:boolean">false</item>
        <item xsi:type="xsd:int">-31</item>
      </item>
      <item xsi:type="xsd:struct">        
        <lowerBound xsi:type="xsd:int">18</lowerBound>
        <upperBound xsi:type="xsd:int">139</upperBound>
      </item>
    </ctl:checkMultipleParameters>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
      ');
        $this->router->init();
        $response = $this->router->process();
        $this->assertEquals(200, $response->statusCode);
        $msg = XPSoapMessage::fromString($response->getContent());
        $data = current($msg->getData());
        $this->assertEquals('Lalala', $data[0]) && $this->assertEquals(1, $data[1]) && $this->assertEquals(array(12, 'Egypt', FALSE, -31), $data[2]) && $this->assertEquals(array('lowerBound' => 18, 'upperBound' => 139), $data[3]);
    }
 /**
  * Retrieve the answer
  *
  * @param   peer.http.HttpResponse response
  * @return  webservices.soap.SOAPMessage
  * @throws  io.IOException in case the data cannot be read
  * @throws  xml.XMLFormatException in case the XML is not well-formed
  * @throws  lang.IllegalAccessException in case authorization is required
  * @throws  lang.IllegalStateException in case an unexpected HTTP status code is returned
  */
 public function retrieve($response)
 {
     $this->cat && $this->cat->debug('<<<', $response->toString());
     $code = $response->getStatusCode();
     switch ($code) {
         case HttpConstants::STATUS_OK:
         case HttpConstants::STATUS_INTERNAL_SERVER_ERROR:
             $xml = '';
             while ($buf = $response->readData()) {
                 $xml .= $buf;
             }
             $this->cat && $this->cat->debug('<<<', $xml);
             $answer = XPSoapMessage::fromString($xml);
             $answer->action = $this->_action;
             // Fault?
             if (NULL !== ($fault = $answer->getFault())) {
                 throw new SOAPFaultException($fault);
             }
             return $answer;
         case HttpConstants::STATUS_AUTHORIZATION_REQUIRED:
             throw new IllegalAccessException('Authorization required: ' . $response->getHeader('WWW-Authenticate'));
         default:
             throw new IllegalStateException('Unexpected return code: ' . $response->getStatusCode());
     }
 }
 /**
  * Retrieve the answer
  *
  * @return  &webservices.soap.XPSoapMessage
  */
 public function retrieve($response)
 {
     return XPSoapMessage::fromString($this->answer);
 }
 /**
  * Invoke method call
  *
  * @param   string method name
  * @param   var vars
  * @return  var answer
  * @throws  lang.IllegalArgumentException
  * @throws  webservices.soap.SOAPFaultException
  */
 public function invoke()
 {
     if (!$this->transport instanceof SOAPHTTPTransport) {
         throw new IllegalArgumentException('Transport must be a webservices.soap.transport.SOAPHTTPTransport');
     }
     $args = func_get_args();
     $message = new XPSoapMessage();
     $message->setEncoding($this->encoding);
     $message->createCall($this->action, array_shift($args), $this->targetNamespace, $this->headers);
     $message->setMapping($this->mapping);
     $message->setData($args);
     // Send
     if (FALSE == ($response = $this->transport->send($message))) {
         return FALSE;
     }
     // Response
     if (FALSE == ($answer = $this->transport->retrieve($response))) {
         return FALSE;
     }
     $answer->setMapping($this->mapping);
     $data = $answer->getData();
     if (sizeof($data) == 1) {
         return current($data);
     }
     if (sizeof($data) == 0) {
         return NULL;
     }
     return $data;
 }