public function filterResponse(SoapResponse $response)
 {
     if ($response->getContentType() === self::CONTENT_TYPE) {
         $decoded = $this->decoder->decode($response->getContent());
         $response->setContent($decoded);
         $response->setContentType(self::DECODED_CONTENT_TYPE);
     }
 }
Exemplo n.º 2
0
 /**
  * Modify the given response XML.
  *
  * @param \BeSimple\SoapCommon\SoapResponse $response SOAP response
  *
  * @return void
  */
 public function filterResponse(SoapResponse $response)
 {
     // get attachments from request object
     $attachmentsToSend = $response->getAttachments();
     // build mime message if we have attachments
     if (count($attachmentsToSend) > 0) {
         $multipart = new MimeMultiPart();
         $soapPart = new MimePart($response->getContent(), 'text/xml', 'utf-8', MimePart::ENCODING_EIGHT_BIT);
         $soapVersion = $response->getVersion();
         // change content type headers for MTOM with SOAP 1.1
         if ($soapVersion == SOAP_1_1 && $this->attachmentType & Helper::ATTACHMENTS_TYPE_MTOM) {
             $multipart->setHeader('Content-Type', 'type', 'application/xop+xml');
             $multipart->setHeader('Content-Type', 'start-info', 'text/xml');
             $soapPart->setHeader('Content-Type', 'application/xop+xml');
             $soapPart->setHeader('Content-Type', 'type', 'text/xml');
         } elseif ($soapVersion == SOAP_1_2) {
             $multipart->setHeader('Content-Type', 'type', 'application/soap+xml');
             $soapPart->setHeader('Content-Type', 'application/soap+xml');
         }
         $multipart->addPart($soapPart, true);
         foreach ($attachmentsToSend as $cid => $attachment) {
             $multipart->addPart($attachment, false);
         }
         $response->setContent($multipart->getMimeMessage());
         // TODO
         $headers = $multipart->getHeadersForHttp();
         list($name, $contentType) = explode(': ', $headers[0]);
         $response->setContentType($contentType);
     }
 }
Exemplo n.º 3
0
 /**
  * Modify the given response XML.
  *
  * @param \BeSimple\SoapCommon\SoapResponse $response SOAP response
  *
  * @return void
  */
 public function filterResponse(SoapResponse $response)
 {
     // array to store attachments
     $attachmentsRecieved = array();
     // check content type if it is a multipart mime message
     $responseContentType = $response->getContentType();
     if (false !== stripos($responseContentType, 'multipart/related')) {
         // parse mime message
         $headers = array('Content-Type' => trim($responseContentType));
         $multipart = MimeParser::parseMimeMessage($response->getContent(), $headers);
         // get soap payload and update SoapResponse object
         $soapPart = $multipart->getPart();
         // convert href -> myhref for external references as PHP throws exception in this case
         // http://svn.php.net/viewvc/php/php-src/branches/PHP_5_4/ext/soap/php_encoding.c?view=markup#l3436
         $content = preg_replace('/href=(?!#)/', 'myhref=', $soapPart->getContent());
         $response->setContent($content);
         $response->setContentType($soapPart->getHeader('Content-Type'));
         // store attachments
         $attachments = $multipart->getParts(false);
         foreach ($attachments as $cid => $attachment) {
             $attachmentsRecieved[$cid] = $attachment;
         }
     }
     // add attachments to response object
     if (count($attachmentsRecieved) > 0) {
         $response->setAttachments($attachmentsRecieved);
     }
 }