Merge pull request #5 from aschamberger/master
XML Mime contentType support
This commit is contained in:
commit
e02ca6ca9c
|
@ -277,6 +277,8 @@ class SoapClient extends \SoapClient
|
||||||
$converter = new SwaTypeConverter();
|
$converter = new SwaTypeConverter();
|
||||||
$converter->setKernel($this->soapKernel);
|
$converter->setKernel($this->soapKernel);
|
||||||
} elseif (Helper::ATTACHMENTS_TYPE_MTOM === $options['attachment_type']) {
|
} elseif (Helper::ATTACHMENTS_TYPE_MTOM === $options['attachment_type']) {
|
||||||
|
$xmlMimeFilter = new XmlMimeFilter($options['attachment_type']);
|
||||||
|
$this->soapKernel->registerFilter($xmlMimeFilter);
|
||||||
$converter = new MtomTypeConverter();
|
$converter = new MtomTypeConverter();
|
||||||
$converter->setKernel($this->soapKernel);
|
$converter->setKernel($this->soapKernel);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,75 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the BeSimpleSoapClient.
|
||||||
|
*
|
||||||
|
* (c) Christian Kerl <christian-kerl@web.de>
|
||||||
|
* (c) Francis Besset <francis.besset@gmail.com>
|
||||||
|
*
|
||||||
|
* This source file is subject to the MIT license that is bundled
|
||||||
|
* with this source code in the file LICENSE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace BeSimple\SoapClient;
|
||||||
|
|
||||||
|
use BeSimple\SoapCommon\FilterHelper;
|
||||||
|
use BeSimple\SoapCommon\Helper;
|
||||||
|
use BeSimple\SoapCommon\Mime\MultiPart as MimeMultiPart;
|
||||||
|
use BeSimple\SoapCommon\Mime\Parser as MimeParser;
|
||||||
|
use BeSimple\SoapCommon\Mime\Part as MimePart;
|
||||||
|
use BeSimple\SoapCommon\SoapRequest;
|
||||||
|
use BeSimple\SoapCommon\SoapRequestFilter;
|
||||||
|
use BeSimple\SoapCommon\SoapResponse;
|
||||||
|
use BeSimple\SoapCommon\SoapResponseFilter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* XML MIME filter that fixes the namespace of xmime:contentType attribute.
|
||||||
|
*
|
||||||
|
* @author Andreas Schamberger <mail@andreass.net>
|
||||||
|
*/
|
||||||
|
class XmlMimeFilter implements SoapRequestFilter
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Reset all properties to default values.
|
||||||
|
*/
|
||||||
|
public function resetFilter()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Modify the given request XML.
|
||||||
|
*
|
||||||
|
* @param \BeSimple\SoapCommon\SoapRequest $request SOAP request
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function filterRequest(SoapRequest $request)
|
||||||
|
{
|
||||||
|
// get \DOMDocument from SOAP request
|
||||||
|
$dom = $request->getContentDocument();
|
||||||
|
|
||||||
|
// create FilterHelper
|
||||||
|
$filterHelper = new FilterHelper($dom);
|
||||||
|
|
||||||
|
// add the neccessary namespaces
|
||||||
|
$filterHelper->addNamespace(Helper::PFX_XMLMIME, Helper::NS_XMLMIME);
|
||||||
|
|
||||||
|
// get xsd:base64binary elements
|
||||||
|
$xpath = new \DOMXPath($dom);
|
||||||
|
$xpath->registerNamespace('XOP', Helper::NS_XOP);
|
||||||
|
$query = '//XOP:Include/..';
|
||||||
|
$nodes = $xpath->query($query);
|
||||||
|
|
||||||
|
// exchange attributes
|
||||||
|
if ($nodes->length > 0) {
|
||||||
|
foreach ($nodes as $node) {
|
||||||
|
if ($node->hasAttribute('contentType')) {
|
||||||
|
$contentType = $node->getAttribute('contentType');
|
||||||
|
$node->removeAttribute('contentType');
|
||||||
|
$filterHelper->setAttribute($node, Helper::NS_XMLMIME, 'contentType', $contentType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,12 +7,32 @@ require '../bootstrap.php';
|
||||||
|
|
||||||
echo '<pre>';
|
echo '<pre>';
|
||||||
|
|
||||||
|
class base64Binary
|
||||||
|
{
|
||||||
|
public $_;
|
||||||
|
public $contentType;
|
||||||
|
}
|
||||||
|
|
||||||
|
class AttachmentType
|
||||||
|
{
|
||||||
|
public $fileName;
|
||||||
|
public $binaryData;
|
||||||
|
}
|
||||||
|
|
||||||
|
class AttachmentRequest extends AttachmentType
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
$options = array(
|
$options = array(
|
||||||
'soap_version' => SOAP_1_1,
|
'soap_version' => SOAP_1_1,
|
||||||
'features' => SOAP_SINGLE_ELEMENT_ARRAYS, // make sure that result is array for size=1
|
'features' => SOAP_SINGLE_ELEMENT_ARRAYS, // make sure that result is array for size=1
|
||||||
'trace' => true, // enables use of the methods SoapClient->__getLastRequest, SoapClient->__getLastRequestHeaders, SoapClient->__getLastResponse and SoapClient->__getLastResponseHeaders
|
'trace' => true, // enables use of the methods SoapClient->__getLastRequest, SoapClient->__getLastRequestHeaders, SoapClient->__getLastResponse and SoapClient->__getLastResponseHeaders
|
||||||
'attachment_type' => BeSimpleSoapHelper::ATTACHMENTS_TYPE_MTOM,
|
'attachment_type' => BeSimpleSoapHelper::ATTACHMENTS_TYPE_MTOM,
|
||||||
'cache_wsdl' => WSDL_CACHE_NONE,
|
'cache_wsdl' => WSDL_CACHE_NONE,
|
||||||
|
'classmap' => array(
|
||||||
|
'base64Binary' => 'base64Binary',
|
||||||
|
'AttachmentRequest' => 'AttachmentRequest',
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -28,10 +48,13 @@ $sc = new BeSimpleSoapClient('MTOM.wsdl', $options);
|
||||||
//var_dump($sc->__getTypes());
|
//var_dump($sc->__getTypes());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
$b64 = new base64Binary();
|
||||||
|
$b64->_ = 'This is a test. :)';
|
||||||
|
$b64->contentType = 'text/plain';
|
||||||
|
|
||||||
$attachment = new stdClass();
|
$attachment = new AttachmentRequest();
|
||||||
$attachment->fileName = 'test123.txt';
|
$attachment->fileName = 'test123.txt';
|
||||||
$attachment->binaryData = 'This is a test.';
|
$attachment->binaryData = $b64;
|
||||||
|
|
||||||
var_dump($sc->attachment($attachment));
|
var_dump($sc->attachment($attachment));
|
||||||
|
|
||||||
|
|
|
@ -80,10 +80,10 @@
|
||||||
</binding>
|
</binding>
|
||||||
<service name="MTOMSample">
|
<service name="MTOMSample">
|
||||||
<port name="MTOMSampleSOAP12port_http" binding="tns:MTOMServiceSOAP12Binding">
|
<port name="MTOMSampleSOAP12port_http" binding="tns:MTOMServiceSOAP12Binding">
|
||||||
<soap12:address location="http://192.168.0.104:8080/axis2/services/MTOMSample.MTOMSampleSOAP12port_http/"/>
|
<soap12:address location="http://localhost:8080/axis2/services/MTOMSample.MTOMSampleSOAP12port_http/"/>
|
||||||
</port>
|
</port>
|
||||||
<port name="MTOMSampleSOAP11port_http" binding="tns:MTOMServiceSOAP11Binding">
|
<port name="MTOMSampleSOAP11port_http" binding="tns:MTOMServiceSOAP11Binding">
|
||||||
<soap:address location="http://192.168.0.104:8080/axis2/services/MTOMSample.MTOMSampleSOAP11port_http/"/>
|
<soap:address location="http://localhost:8080/axis2/services/MTOMSample.MTOMSampleSOAP11port_http/"/>
|
||||||
</port>
|
</port>
|
||||||
</service>
|
</service>
|
||||||
</definitions>
|
</definitions>
|
||||||
|
|
|
@ -23,11 +23,12 @@ class CurlTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
protected function startPhpWebserver()
|
protected function startPhpWebserver()
|
||||||
{
|
{
|
||||||
|
$dir = __DIR__.DIRECTORY_SEPARATOR.'Fixtures';
|
||||||
if ('Windows' == substr(php_uname('s'), 0, 7)) {
|
if ('Windows' == substr(php_uname('s'), 0, 7)) {
|
||||||
$powershellCommand = "\$app = start-process php.exe -ArgumentList '-S localhost:8000 -t ".__DIR__.DIRECTORY_SEPARATOR."Fixtures' -WindowStyle 'Hidden' -passthru; Echo \$app.Id;";
|
$powershellCommand = "\$app = start-process php.exe -ArgumentList '-S localhost:8000 -t ".$dir."' -WindowStyle 'Hidden' -passthru; Echo \$app.Id;";
|
||||||
$shellCommand = 'powershell -command "& {'.$powershellCommand.'}"';
|
$shellCommand = 'powershell -command "& {'.$powershellCommand.'}"';
|
||||||
} else {
|
} else {
|
||||||
$shellCommand = "nohup php -S localhost:8000 -t ".__DIR__.DIRECTORY_SEPARATOR."Fixtures &";
|
$shellCommand = "nohup php -S localhost:8000 -t ".$dir." &";
|
||||||
}
|
}
|
||||||
$output = array();
|
$output = array();
|
||||||
exec($shellCommand, $output);
|
exec($shellCommand, $output);
|
||||||
|
|
|
@ -24,11 +24,12 @@ class WsdlDownloaderTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
protected function startPhpWebserver()
|
protected function startPhpWebserver()
|
||||||
{
|
{
|
||||||
|
$dir = __DIR__.DIRECTORY_SEPARATOR.'Fixtures';
|
||||||
if ('Windows' == substr(php_uname('s'), 0, 7)) {
|
if ('Windows' == substr(php_uname('s'), 0, 7)) {
|
||||||
$powershellCommand = "\$app = start-process php.exe -ArgumentList '-S localhost:8000 -t ".__DIR__.DIRECTORY_SEPARATOR."Fixtures' -WindowStyle 'Hidden' -passthru; Echo \$app.Id;";
|
$powershellCommand = "\$app = start-process php.exe -ArgumentList '-S localhost:8000 -t ".$dir."' -WindowStyle 'Hidden' -passthru; Echo \$app.Id;";
|
||||||
$shellCommand = 'powershell -command "& {'.$powershellCommand.'}"';
|
$shellCommand = 'powershell -command "& {'.$powershellCommand.'}"';
|
||||||
} else {
|
} else {
|
||||||
$shellCommand = "nohup php -S localhost:8000 -t ".__DIR__.DIRECTORY_SEPARATOR."Fixtures &";
|
$shellCommand = "nohup php -S localhost:8000 -t ".$dir." &";
|
||||||
}
|
}
|
||||||
$output = array();
|
$output = array();
|
||||||
exec($shellCommand, $output);
|
exec($shellCommand, $output);
|
||||||
|
|
Loading…
Reference in New Issue