예제 #1
0
 public function testSerialization()
 {
     $msg = new XPSoapMessage();
     $msg->createCall('Test', 'testSerialization');
     $this->assertEquals('Test', $msg->action);
     $this->assertEquals('testSerialization', $msg->method);
     $this->assertEquals('SOAP-ENV:Envelope', $msg->root()->getName());
     $this->assertNotEmpty($msg->root()->getAttributes());
     $msg->setData(array('int' => 1, 'float' => 6.1, 'string' => 'Binford', 'string2' => '"<&>"', 'bool' => true, 'date' => \util\Date::fromString('1977-12-14 11:55AM Europe/Berlin'), 'null' => null, 'array' => array(2, 3), 'hash' => array('class' => 'Test', 'method' => 'testSerialization')));
     // Let's be somewhat forgiving on whitespace
     $src = trim(chop($msg->getSource(0)));
     $this->assertEquals('<SOAP-ENV:Envelope', substr($src, 0, 18));
     $this->assertEquals('</SOAP-ENV:Envelope>', substr($src, -20));
     $this->assertContains($src, '<int xsi:type="xsd:int">1</int>', 'integer');
     $this->assertContains($src, '<float xsi:type="xsd:float">6.1</float>', 'float');
     $this->assertContains($src, '<string xsi:type="xsd:string">Binford</string>', 'string');
     $this->assertContains($src, '<string2 xsi:type="xsd:string">&quot;&lt;&amp;&gt;&quot;</string2>', 'escaping');
     $this->assertContains($src, '<bool xsi:type="xsd:boolean">true</bool>', 'bool');
     $this->assertContains($src, '<date xsi:type="xsd:dateTime">1977-12-14T11:55:00+01:00</date>', 'date');
     $this->assertContains($src, '<null xsi:nil="true"/>', 'null');
     $this->assertContains($src, '<array xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="xsd:anyType[2]">', 'array');
     $this->assertContains($src, '<item xsi:type="xsd:int">2</item>', 'array.inner');
     $this->assertContains($src, '<item xsi:type="xsd:int">3</item>', 'array.inner');
     $this->assertContains($src, '<hash xsi:type="xsd:struct">', 'hash');
     $this->assertContains($src, '<class xsi:type="xsd:string">Test</class>', 'hash.inner');
     $this->assertContains($src, '<method xsi:type="xsd:string">testSerialization</method>', 'hash.inner');
     return $src;
 }
예제 #2
0
 /**
  * Invoke a command
  *
  * @param   webservices.uddi.UDDICommand
  * @return  lang.Object
  * @throws  lang.IllegalArgumentException in case an illegal command was passed
  * @throws  io.IOException in case the HTTP request failed
  * @throws  webservices.soap.SOAPFaultException in case a SOAP fault was returned
  * @throws  xml.XMLFormatException in case the XML returned was not well-formed
  */
 public function invoke($command)
 {
     if (is('webservices.uddi.InquiryCommand', $command)) {
         $c = $this->conn['inquiry'];
     } else {
         if (is('webservices.uddi.PublishCommand', $command)) {
             $c = $this->conn['publish'];
         } else {
             throw new \lang\IllegalArgumentException('Unknown command type "' . \xp::typeOf($command) . '"');
         }
     }
     // Create message
     with($m = new XPSoapMessage());
     $m->encoding = 'utf-8';
     $m->root = new \xml\Node('soap:Envelope', null, ['xmlns:soap' => 'http://schemas.xmlsoap.org/soap/envelope/']);
     $body = $m->root()->addChild(new \xml\Node('soap:Body'));
     $command->marshalTo($body->addChild(new \xml\Node('command', null, ['xmlns' => UDDIConstants::namespaceFor($this->version), 'generic' => UDDIConstants::versionIdFor($this->version)])));
     // Assemble request
     with($r = $c->request->create(new \peer\http\HttpRequest()));
     $r->setMethod(HttpConstants::POST);
     $r->setParameters(new \peer\http\RequestData($m->getDeclaration() . "\n" . $m->getSource(0)));
     $r->setHeader('SOAPAction', '""');
     $r->setHeader('Content-Type', 'text/xml; charset=' . $m->encoding);
     // Send it
     $this->cat && $this->cat->debug('>>>', $r->getRequestString());
     $response = $c->send($r);
     // Read response
     $sc = $response->getStatusCode();
     $this->cat && $this->cat->debug('<<<', $response);
     $xml = '';
     while ($buf = $response->readData()) {
         $xml .= $buf;
     }
     $this->cat && $this->cat->debug('<<<', $xml);
     if ($answer = XPSoapMessage::fromString($xml)) {
         if (null !== ($content_type = $response->getHeader('Content-Type'))) {
             @(list($type, $charset) = explode('; charset=', $content_type));
             if (!empty($charset)) {
                 $answer->setEncoding($charset);
             }
         }
     }
     // Check for faults
     if (null !== ($fault = $answer->getFault())) {
         throw new SOAPFaultException($fault);
     }
     // Unmarshal response
     return $command->unmarshalFrom($answer->root()->nodeAt(0)->nodeAt(0));
 }