added unit test for SoapRequest's mtom handling;
fixed bugs;
This commit is contained in:
parent
c7f173456b
commit
6ff34b8db9
@ -145,15 +145,15 @@ class SoapRequest extends Request
|
||||
$mimeMessage = Message::createFromMessage($content, $contentTypeHeader['boundary']);
|
||||
$mimeParts = $mimeMessage->getParts();
|
||||
|
||||
$soapMimePartId = $contentTypeHeader['start'];
|
||||
$soapMimePartType = $this->splitContentTypeHeader($contentTypeHeader['start-info']);
|
||||
$soapMimePartId = trim($contentTypeHeader['start'], '<>');
|
||||
$soapMimePartType = $contentTypeHeader['start-info'];
|
||||
|
||||
$rootPart = array_shift($mimeParts);
|
||||
$rootPartType = $this->splitContentTypeHeader($rootPart->type);
|
||||
|
||||
// TODO: add more checks to achieve full compatibility to MTOM spec
|
||||
// http://www.w3.org/TR/soap12-mtom/
|
||||
if($rootPart->id != $soapMimePartId || $rootPartType['_type'] != 'application/xop+xml' || $rootPartType['type'] != $soapMimePartType['type'])
|
||||
if($rootPart->id != $soapMimePartId || $rootPartType['_type'] != 'application/xop+xml' || $rootPartType['type'] != $soapMimePartType)
|
||||
{
|
||||
throw new \InvalidArgumentException();
|
||||
}
|
||||
@ -161,7 +161,7 @@ class SoapRequest extends Request
|
||||
foreach($mimeParts as $mimePart)
|
||||
{
|
||||
$this->soapAttachments->add(new SoapAttachment(
|
||||
trim($mimePart->id, '<>'),
|
||||
$mimePart->id,
|
||||
$mimePart->type,
|
||||
// handle content decoding / prevent encoding
|
||||
$mimePart->getContent()
|
||||
|
45
Tests/SoapRequestTest.php
Normal file
45
Tests/SoapRequestTest.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of the WebServiceBundle.
|
||||
*
|
||||
* (c) Christian Kerl <christian-kerl@web.de>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace Bundle\WebServiceBundle\Tests;
|
||||
|
||||
use Bundle\WebServiceBundle\Soap\SoapRequest;
|
||||
|
||||
/**
|
||||
* UnitTest for \Bundle\WebServiceBundle\Soap\SoapRequest.
|
||||
*
|
||||
* @author Christian Kerl <christian-kerl@web.de>
|
||||
*/
|
||||
class SoapRequestTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testMtomMessage()
|
||||
{
|
||||
$content = $this->loadRequestContentFixture('mtom/simple.txt');
|
||||
|
||||
$request = new SoapRequest($content);
|
||||
$request->server->set('CONTENT_TYPE', 'multipart/related; type="application/xop+xml";start="<http://tempuri.org/0>";boundary="uuid:0ca0e16e-feb1-426c-97d8-c4508ada5e82+id=7";start-info="application/soap+xml"');
|
||||
|
||||
$message = $request->getSoapMessage();
|
||||
|
||||
$this->assertEquals(735, strlen(trim($message)));
|
||||
$this->assertEquals(1, count($request->getSoapAttachments()));
|
||||
|
||||
$attachment = $request->getSoapAttachments()->get('http://tempuri.org/1/632618206527087310');
|
||||
|
||||
$this->assertNotNull($attachment);
|
||||
$this->assertEquals('application/octet-stream', $attachment->getType());
|
||||
$this->assertEquals(767, strlen(trim($attachment->getContent())));
|
||||
}
|
||||
|
||||
private function loadRequestContentFixture($name)
|
||||
{
|
||||
return file_get_contents(__DIR__ . '/fixtures/' . $name);
|
||||
}
|
||||
}
|
16
Tests/fixtures/mtom/simple.txt
vendored
Normal file
16
Tests/fixtures/mtom/simple.txt
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
|
||||
--uuid:0ca0e16e-feb1-426c-97d8-c4508ada5e82+id=7
|
||||
Content-ID: <http://tempuri.org/0>
|
||||
Content-Transfer-Encoding: 8bit
|
||||
Content-Type: application/xop+xml;charset=utf-8;type="application/soap+xml"
|
||||
|
||||
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://schemas.xmlsoap.org/ws/2004/08/addressing"><s:Header><a:Action s:mustUnderstand="1">http://xmlsoap.org/echoBinaryAsString</a:Action><a:MessageID>urn:uuid:1bf061d6-d532-4b0c-930b-8b8202c38b8a</a:MessageID><a:ReplyTo><a:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</a:Address></a:ReplyTo><a:To s:mustUnderstand="1">http://131.107.72.15/Mtom/svc/service.svc/Soap12MtomUTF8</a:To></s:Header><s:Body><EchoBinaryAsString xmlns="http://xmlsoap.org/Ping"><array><xop:Include href="cid:http%3A%2F%2Ftempuri.org%2F1%2F632618206527087310" xmlns:xop="http://www.w3.org/2004/08/xop/include"/></array></EchoBinaryAsString></s:Body></s:Envelope>
|
||||
|
||||
--uuid:0ca0e16e-feb1-426c-97d8-c4508ada5e82+id=7
|
||||
Content-ID: <http://tempuri.org/1/632618206527087310>
|
||||
Content-Transfer-Encoding: binary
|
||||
Content-Type: application/octet-stream
|
||||
|
||||
H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d ! H e l l o W o r l d !
|
||||
|
||||
--uuid:0ca0e16e-feb1-426c-97d8-c4508ada5e82+id=7--
|
Loading…
Reference in New Issue
Block a user