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]); }
/** * 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)); }
/** * 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 = \webservices\soap\xp\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 \lang\IllegalAccessException('Authorization required: ' . $response->getHeader('WWW-Authenticate')); default: throw new \lang\IllegalStateException('Unexpected return code: ' . $response->getStatusCode()); } }
/** * 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 \lang\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; }
/** * Retrieve the answer * * @return &webservices.soap.XPSoapMessage */ public function retrieve($response) { return XPSoapMessage::fromString($this->answer); }