Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

Support for MTOM

Anonymous
2010-10-28
2013-06-06

  • Anonymous
    2010-10-28

    I there planned support for MTOM in future releases?

     
  • Kervala
    Kervala
    2011-06-10

    Hi,

    I just implemented basic MTOM attachments for compatibility with gSOAP.

    This patch is created against lats version from CVS.

    --- D:/nusoap/nusoap.php    Fri Jun 10 14:27:31 2011
    +++ D:/nusoap/nusoap_fixed.php  Fri Jun 10 14:34:29 2011
    @@ -38,7 +38,7 @@
     */
    
     /*
    - * Some of the standards implmented in whole or part by NuSOAP:
    + * Some of the standards implemented in whole or part by NuSOAP:
      *
      * SOAP 1.1 (http://www.w3.org/TR/2000/NOTE-SOAP-20000508/)
      * WSDL 1.1 (http://www.w3.org/TR/2001/NOTE-wsdl-20010315)
    @@ -2187,6 +2187,7 @@
        var $request_method = 'POST';
        var $protocol_version = '1.0';
        var $encoding = '';
    +   var $attachments = array();
        var $outgoing_headers = array();
        var $incoming_headers = array();
        var $incoming_cookies = array();
    @@ -3346,6 +3347,54 @@
                return false;
            }
    
    +       if (isset($this->incoming_headers['content-type'])) {
    +           $content_type = $this->incoming_headers['content-type'];
    +           // check if Content-Type is multipart/related
    +           if (preg_match("#multipart/related#", $content_type)) {
    +               // check and get used boundary for multipart
    +               if (preg_match("#boundary=\"([^\"]+)\";#", $content_type, $regs)) {
    +                   $boundary = $regs[1];
    +                   // split each part
    +                   $parts = explode("--$boundary", $data);
    +                   // process each part
    +                   if (count($parts)) foreach($parts as $part) if ($part) {
    +                       $part = trim($part);
    +                       // search for real data position
    +                       $pos = strpos($part,"$lb$lb");
    +                       $header_data = trim(substr($part,0,$pos));
    +                       $header_array = explode($lb,$header_data);
    +                       $part = ltrim(substr($part,$pos));
    +                       $content_id = '';
    +                       $content_type = '';
    +                       // check headers
    +                       foreach ($header_array as $header_line) {
    +                           $arr = explode(':',$header_line,2);
    +                           if(count($arr) > 1){
    +                               $header_name = strtolower(trim($arr[0]));
    +                               $header_value = trim($arr[1]);
    +                               if ($header_name == 'content-type') {
    +                                   $content_type = $header_value;
    +                               } elseif ($header_name == 'content-id') {
    +                                   $content_id = 'id:'.substr($header_value, 1, strlen($header_value)-2);
    +                               }
    +                           }
    +                       }
    +                       // real data uses SOAP-ENV:Envelope
    +                       if ($content_id == 'id:SOAP-ENV:Envelope')
    +                       {
    +                           // overwrite Content-Type
    +                           $this->incoming_headers['content-type'] = $content_type;
    +                           $data = $part;
    +                       }
    +                       else
    +                       {
    +                           $this->attachments[] = array('content-id' => $content_id, 'content-type' => $content_type, 'data' => $part);
    +                       }
    +                   }
    +               }
    +           }
    +       }
    +
            return $data;
        }
    
    @@ -6785,13 +6834,22 @@
        * @param    string $decode_utf8 whether to decode UTF-8 to ISO-8859-1
        * @access   public
        */
    -   function nusoap_parser($xml,$encoding='UTF-8',$method='',$decode_utf8=true){
    +   function nusoap_parser($xml,$encoding='UTF-8',$method='',$decode_utf8=true,$attachments=''){
            parent::nusoap_base();
            $this->xml = $xml;
            $this->xml_encoding = $encoding;
            $this->method = $method;
            $this->decode_utf8 = $decode_utf8;
    
    +       // virtual position to be sure we are not overwriting real positions
    +       $attachment_position = 1000;
    +       // add attachements in $this->ids and $this->message
    +       if ($attachments) foreach($attachments as $attachment) {
    +           $this->ids[$attachment['content-id']] = $attachment_position;
    +           $this->message[$attachment_position] = array('cdata' => $attachment['data'], 'name' => $attachment['content-id'], 'type' => $attachment['content-type'], 'children' => '');
    +           ++$attachment_id;
    +       }
    +
            // Check whether content has been read.
            if(!empty($xml)){
                // Check XML encoding
    @@ -7847,7 +7905,7 @@
                        return false;
                    } else {
                        $this->debug('got response, length='. strlen($this->responseData).' type='.$http->incoming_headers['content-type']);
    -                   return $this->parseResponse($http->incoming_headers, $this->responseData);
    +                   return $this->parseResponse($http->incoming_headers, $this->responseData, $http->attachments);
                    }
                break;
                default:
    @@ -7865,7 +7923,7 @@
        * @return   mixed   value of the message, decoded into a PHP type
        * @access   private
        */
    -    function parseResponse($headers, $data) {
    +    function parseResponse($headers, $data, $attachments='') {
            $this->debug('Entering parseResponse() for data of length ' . strlen($data) . ' headers:');
            $this->appendDebug($this->varDump($headers));
            if (!isset($headers['content-type'])) {
    @@ -7881,8 +7939,9 @@
            if (strpos($headers['content-type'], '=')) {
                $enc = str_replace('"', '', substr(strstr($headers["content-type"], '='), 1));
                $this->debug('Got response encoding: ' . $enc);
    -           if(preg_match('/^(ISO-8859-1|US-ASCII|UTF-8)$/i',$enc)){
    -               $this->xml_encoding = strtoupper($enc);
    +           // line could have extra characters after encoding
    +           if(preg_match('/^(ISO-8859-1|US-ASCII|UTF-8)/i',$enc,$regs)){
    +               $this->xml_encoding = strtoupper($regs[1]);
                } else {
                    $this->xml_encoding = 'US-ASCII';
                }
    @@ -7891,7 +7950,7 @@
                $this->xml_encoding = 'ISO-8859-1';
            }
            $this->debug('Use encoding: ' . $this->xml_encoding . ' when creating nusoap_parser');
    -       $parser = new nusoap_parser($data,$this->xml_encoding,$this->operation,$this->decode_utf8);
    +       $parser = new nusoap_parser($data,$this->xml_encoding,$this->operation,$this->decode_utf8,$attachments);
            // add parser debug data to our debug
            $this->appendDebug($parser->getDebug());
            // if parse errors