Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement MTOM SOAP (multipart MIME) #43

Open
simevo opened this issue Oct 28, 2018 · 4 comments
Open

implement MTOM SOAP (multipart MIME) #43

simevo opened this issue Oct 28, 2018 · 4 comments
Labels
help wanted Extra attention is needed
Milestone

Comments

@simevo
Copy link
Collaborator

simevo commented Oct 28, 2018

https://en.wikipedia.org/wiki/Message_Transmission_Optimization_Mechanism:

MTOM is the W3C Message Transmission Optimization Mechanism, a method of efficiently sending binary data to and from Web services.

@simevo simevo added this to the 0.2 milestone Oct 28, 2018
@simevo simevo added the help wanted Extra attention is needed label Oct 28, 2018
@cesco69
Copy link

cesco69 commented Nov 9, 2018

@simevo PHP SoapClient doesn't support anymore MTOM. A simple implementation is:

class MTOMSoapClient extends SoapClient
{
    public function __doRequest($request, $location, $action, $version, $one_way = 0)
    {
        $response = parent::__doRequest($request, $location, $action, $version, $one_way);

        $xml_response = null;

        preg_match('/<soap[\s\S]*nvelope>/', $response, $xml_response);

        if (!is_array($xml_response) || !count($xml_response)) {
            throw new Exception('No XML has been found.');
        }

        $xml_response = reset($xml_response);

        $xop_elements = null;
        preg_match_all('/<xop[\s\S]*?\/>/', $response, $xop_elements);
        $xop_elements = reset($xop_elements);

        if (is_array($xop_elements) && count($xop_elements)) {
            foreach ($xop_elements as $xop_element) {
                
                $cid = null;
                preg_match('/cid:([0-9a-zA-Z-]+)@/', $xop_element, $cid);
                $cid = $cid[1];

                $binary = null;
                preg_match('/Content-ID:[\s\S].+?'.$cid.'[\s\S].+?>([\s\S]*?)--uuid/', $response, $binary);
                $binary = trim($binary[1]);

                $binary = base64_encode($binary);

                $xml_response = preg_replace('/<xop:Include[\s\S]*cid:'.$cid.'@[\s\S]*?\/>/', $binary, $xml_response);
            }
        }

        return $xml_response;
    }
}

@simevo
Copy link
Collaborator Author

simevo commented Nov 13, 2018

Hi and thanks !
Have you tested that this works with the official SdI ?
Can we include this code in this repo and licence it AGPL-3.0 ? A PR would be even better !

@cesco69
Copy link

cesco69 commented Nov 13, 2018

Have you tested that this works with the official SdI ?

yes, it is the same code from https://forum.italia.it/t/sdicoop-configurazione-php-soapclient-per-invio-di-test/5528/5?u=simevo without the ssl implementation.

Can we include this code in this repo and licence it AGPL-3.0 ?

no problem.

@cesco69
Copy link

cesco69 commented Nov 14, 2018

Ho fatto una PR #56

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants