diff --git a/Soap/SoapRequest.php b/Soap/SoapRequest.php index 5be7a4b..bd316fb 100644 --- a/Soap/SoapRequest.php +++ b/Soap/SoapRequest.php @@ -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() diff --git a/Tests/SoapRequestTest.php b/Tests/SoapRequestTest.php new file mode 100644 index 0000000..4f041a7 --- /dev/null +++ b/Tests/SoapRequestTest.php @@ -0,0 +1,45 @@ + + * + * 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 + */ +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="";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); + } +} diff --git a/Tests/fixtures/mtom/simple.txt b/Tests/fixtures/mtom/simple.txt new file mode 100644 index 0000000..a1bf2b1 --- /dev/null +++ b/Tests/fixtures/mtom/simple.txt @@ -0,0 +1,16 @@ + +--uuid:0ca0e16e-feb1-426c-97d8-c4508ada5e82+id=7 +Content-ID: +Content-Transfer-Encoding: 8bit +Content-Type: application/xop+xml;charset=utf-8;type="application/soap+xml" + +http://xmlsoap.org/echoBinaryAsStringurn:uuid:1bf061d6-d532-4b0c-930b-8b8202c38b8ahttp://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymoushttp://131.107.72.15/Mtom/svc/service.svc/Soap12MtomUTF8 + +--uuid:0ca0e16e-feb1-426c-97d8-c4508ada5e82+id=7 +Content-ID: +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-- \ No newline at end of file