SoapServer/Client now handle binary files correctly & large tests/fixtures update

Soap Server and Client were breaking binary files during transfer due to invalid Mime Message Parser. Now is it working fine with no errors, but the message parser is about to be rewritten into a better form.
This commit is contained in:
Petr Bechyně
2017-04-04 18:36:18 +02:00
parent 311f9e6d08
commit 564005da93
42 changed files with 1135 additions and 250 deletions

View File

@ -0,0 +1,16 @@
<?php
namespace Fixtures\Attachment;
trait MessageWithAttachmentsTrait
{
/**
* @var AttachmentCollection $attachmentCollection
*/
public $attachmentCollection;
public function hasAttachments()
{
return $this->attachmentCollection !== null && $this->attachmentCollection->hasAttachments();
}
}

View File

@ -34,6 +34,10 @@ class DummyService implements AttachmentsHandlerInterface
'DummyServiceResponseWithAttachments' => DummyServiceResponseWithAttachments::class,
'DummyServiceRequest' => DummyServiceRequest::class,
'DummyServiceRequestWithAttachments' => DummyServiceRequestWithAttachments::class,
'DummyServiceMethodWithOutgoingLargeSwaRequest' => DummyServiceMethodWithOutgoingLargeSwaRequest::class,
'DummyServiceMethodWithOutgoingLargeSwaResponse' => DummyServiceMethodWithOutgoingLargeSwaResponse::class,
'DummyServiceMethodWithIncomingLargeSwaRequest' => DummyServiceMethodWithIncomingLargeSwaRequest::class,
'DummyServiceMethodWithIncomingLargeSwaResponse' => DummyServiceMethodWithIncomingLargeSwaResponse::class,
];
}
@ -67,6 +71,54 @@ class DummyService implements AttachmentsHandlerInterface
return $dummyServiceHandler->handle($dummyServiceRequest);
}
/**
* @param DummyServiceMethodWithOutgoingLargeSwaRequest $dummyServiceRequest
* @return DummyServiceMethodWithOutgoingLargeSwaResponse
*/
public function dummyServiceMethodWithOutgoingLargeSwa(DummyServiceMethodWithOutgoingLargeSwaRequest $dummyServiceRequest)
{
$dummyServiceHandler = new DummyServiceHandlerWithOutgoingLargeSwa();
$dummyServiceResponseWithAttachments = $dummyServiceHandler->handle($dummyServiceRequest);
if ($dummyServiceResponseWithAttachments->hasAttachments() === true) {
$soapAttachments = [];
foreach ($dummyServiceResponseWithAttachments->attachmentCollection->attachments as $attachment) {
$soapAttachments[] = new SoapAttachment(
$attachment->fileName,
$attachment->contentType,
$attachment->content
);
}
$this->addAttachmentStorage(new RequestHandlerAttachmentsStorage($soapAttachments));
}
return $dummyServiceResponseWithAttachments;
}
/**
* @param DummyServiceMethodWithIncomingLargeSwaRequest $dummyServiceRequest
* @return DummyServiceMethodWithIncomingLargeSwaResponse
*/
public function dummyServiceMethodWithIncomingLargeSwa(DummyServiceMethodWithIncomingLargeSwaRequest $dummyServiceRequest)
{
$dummyServiceHandler = new DummyServiceHandlerWithIncomingLargeSwa();
$attachmentStorageContents = $this->getAttachmentStorage()->getAttachments();
if (count($attachmentStorageContents) > 0) {
$attachments = [];
foreach ($attachmentStorageContents as $soapAttachment) {
$attachments[] = new Attachment(
$soapAttachment->getId(),
$soapAttachment->getType(),
$soapAttachment->getContent()
);
}
$dummyServiceRequest->attachmentCollection = new AttachmentCollection($attachments);
}
return $dummyServiceHandler->handle($dummyServiceRequest);
}
/**
* @param DummyServiceRequestWithAttachments $dummyServiceRequestWithAttachments
* @return DummyServiceResponseWithAttachments

View File

@ -22,6 +22,26 @@
<xsd:element name="status" type="xsd:boolean" minOccurs="1"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="DummyServiceMethodWithOutgoingLargeSwaRequest">
<xsd:sequence>
<xsd:element name="dummyAttribute" type="xsd:int" minOccurs="1"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="DummyServiceMethodWithOutgoingLargeSwaResponse">
<xsd:sequence>
<xsd:element name="status" type="xsd:boolean" minOccurs="1"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="DummyServiceMethodWithIncomingLargeSwaRequest">
<xsd:sequence>
<xsd:element name="dummyAttribute" type="xsd:int" minOccurs="1"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="DummyServiceMethodWithIncomingLargeSwaResponse">
<xsd:sequence>
<xsd:element name="status" type="xsd:boolean" minOccurs="1"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="DummyServiceRequestWithAttachments">
<xsd:sequence>
<xsd:element name="dummyAttribute" type="xsd:int" minOccurs="1"/>
@ -41,12 +61,24 @@
<message name="DummyServiceRequest">
<part name="request" type="tns:DummyServiceRequest"/>
</message>
<message name="DummyServiceMethodWithOutgoingLargeSwaRequest">
<part name="request" type="tns:DummyServiceMethodWithOutgoingLargeSwaRequest"/>
</message>
<message name="DummyServiceMethodWithIncomingLargeSwaRequest">
<part name="request" type="tns:DummyServiceMethodWithIncomingLargeSwaRequest"/>
</message>
<message name="DummyServiceRequestWithAttachments">
<part name="request" type="tns:DummyServiceRequestWithAttachments"/>
</message>
<message name="DummyServiceResponse">
<part name="dummyServiceReturn" type="tns:DummyServiceResponse"/>
</message>
<message name="DummyServiceMethodWithOutgoingLargeSwaResponse">
<part name="dummyServiceReturn" type="tns:DummyServiceMethodWithOutgoingLargeSwaResponse"/>
</message>
<message name="DummyServiceMethodWithIncomingLargeSwaResponse">
<part name="dummyServiceReturn" type="tns:DummyServiceMethodWithIncomingLargeSwaResponse"/>
</message>
<message name="DummyServiceResponseWithAttachments">
<part name="dummyServiceReturn" type="tns:DummyServiceResponseWithAttachments"/>
</message>
@ -55,6 +87,14 @@
<wsdl:input message="tns:DummyServiceRequest"/>
<wsdl:output message="tns:DummyServiceResponse"/>
</wsdl:operation>
<wsdl:operation name="dummyServiceMethodWithOutgoingLargeSwa">
<wsdl:input message="tns:DummyServiceMethodWithOutgoingLargeSwaRequest"/>
<wsdl:output message="tns:DummyServiceMethodWithOutgoingLargeSwaResponse"/>
</wsdl:operation>
<wsdl:operation name="dummyServiceMethodWithIncomingLargeSwa">
<wsdl:input message="tns:DummyServiceMethodWithIncomingLargeSwaRequest"/>
<wsdl:output message="tns:DummyServiceMethodWithIncomingLargeSwaResponse"/>
</wsdl:operation>
<wsdl:operation name="dummyServiceMethodWithAttachments">
<wsdl:input message="tns:DummyServiceRequestWithAttachments"/>
<wsdl:output message="tns:DummyServiceResponseWithAttachments"/>
@ -72,6 +112,26 @@
<soap:body use="literal" namespace="http://schema.testcase"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="dummyServiceMethodWithIncomingLargeSwa">
<soap:operation soapAction="DummyService.dummyServiceMethodWithIncomingLargeSwa" style="rpc"/>
<wsdl:input>
<soap:header use="literal" message="tns:SoapHeader" part="SoapHeader" namespace="http://schema.testcase"/>
<soap:body use="literal" part="request" namespace="http://schema.testcase"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal" namespace="http://schema.testcase"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="dummyServiceMethodWithOutgoingLargeSwa">
<soap:operation soapAction="DummyService.dummyServiceMethodWithOutgoingLargeSwa" style="rpc"/>
<wsdl:input>
<soap:header use="literal" message="tns:SoapHeader" part="SoapHeader" namespace="http://schema.testcase"/>
<soap:body use="literal" part="request" namespace="http://schema.testcase"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal" namespace="http://schema.testcase"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="dummyServiceMethodWithAttachments">
<soap:operation soapAction="DummyService.dummyServiceMethodWithAttachments" style="rpc"/>
<wsdl:input>

View File

@ -0,0 +1,27 @@
<?php
namespace Fixtures;
class DummyServiceHandlerWithIncomingLargeSwa
{
/**
* @param DummyServiceMethodWithIncomingLargeSwaRequest $request
* @return DummyServiceMethodWithIncomingLargeSwaResponse
*/
public function handle(DummyServiceMethodWithIncomingLargeSwaRequest $request)
{
if ($request->hasAttachments() === true) {
foreach ($request->attachmentCollection->attachments as $attachment) {
file_put_contents(
__DIR__.'/../../cache/attachment-server-request-'.$attachment->fileName,
$attachment->content
);
}
}
$response = new DummyServiceMethodWithIncomingLargeSwaResponse();
$response->status = true;
return $response;
}
}

View File

@ -0,0 +1,32 @@
<?php
namespace Fixtures;
use BeSimple\SoapServerAndSoapClientCommunicationTest;
use Fixtures\Attachment\Attachment;
use Fixtures\Attachment\AttachmentCollection;
class DummyServiceHandlerWithOutgoingLargeSwa
{
/**
* @param DummyServiceMethodWithOutgoingLargeSwaRequest $request
* @return DummyServiceMethodWithOutgoingLargeSwaResponse
*/
public function handle(DummyServiceMethodWithOutgoingLargeSwaRequest $request)
{
$response = new DummyServiceMethodWithOutgoingLargeSwaResponse();
$response->status = true;
$response->attachmentCollection = new AttachmentCollection([
new Attachment('filename.txt', 'text/plain', 'plaintext file'),
new Attachment('filename.html', 'text/html', '<html><body>Hello world</body></html>'),
new Attachment(
'filename.docx',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
file_get_contents(SoapServerAndSoapClientCommunicationTest::LARGE_SWA_FILE)
),
]);
return $response;
}
}

View File

@ -0,0 +1,15 @@
<?php
namespace Fixtures;
use Fixtures\Attachment\MessageWithAttachmentsTrait;
class DummyServiceMethodWithIncomingLargeSwaRequest
{
use MessageWithAttachmentsTrait;
/**
* @var int $dummyAttribute
*/
public $dummyAttribute;
}

View File

@ -0,0 +1,11 @@
<?php
namespace Fixtures;
class DummyServiceMethodWithIncomingLargeSwaResponse
{
/**
* @var bool $status
*/
public $status;
}

View File

@ -0,0 +1,11 @@
<?php
namespace Fixtures;
class DummyServiceMethodWithOutgoingLargeSwaRequest
{
/**
* @var int $dummyAttribute
*/
public $dummyAttribute;
}

View File

@ -0,0 +1,15 @@
<?php
namespace Fixtures;
use Fixtures\Attachment\MessageWithAttachmentsTrait;
class DummyServiceMethodWithOutgoingLargeSwaResponse
{
use MessageWithAttachmentsTrait;
/**
* @var bool $status
*/
public $status;
}

View File

@ -2,10 +2,12 @@
namespace Fixtures;
use Fixtures\Attachment\AttachmentCollection;
use Fixtures\Attachment\MessageWithAttachmentsTrait;
class DummyServiceRequestWithAttachments
{
use MessageWithAttachmentsTrait;
/**
* @var int $dummyAttribute
*/
@ -15,14 +17,4 @@ class DummyServiceRequestWithAttachments
* @var bool $includeAttachments
*/
public $includeAttachments;
/**
* @var AttachmentCollection $attachmentCollection
*/
public $attachmentCollection;
public function hasAttachments()
{
return $this->attachmentCollection !== null && $this->attachmentCollection->hasAttachments();
}
}

View File

@ -2,22 +2,14 @@
namespace Fixtures;
use Fixtures\Attachment\AttachmentCollection;
use Fixtures\Attachment\MessageWithAttachmentsTrait;
class DummyServiceResponseWithAttachments
{
use MessageWithAttachmentsTrait;
/**
* @var bool $status
*/
public $status;
/**
* @var AttachmentCollection $attachmentCollection
*/
public $attachmentCollection;
public function hasAttachments()
{
return $this->attachmentCollection !== null && $this->attachmentCollection->hasAttachments();
}
}

View File

@ -0,0 +1 @@
multipart/related; type="application/soap+xml"; charset=utf-8; boundary="urn:uuid:340c4456-d650-4ddb-ae83-b13cf6077326"; start="<urn:uuid:c0d48506-8780-410c-b06a-52b6bbbefa5b>"; action="DummyService.dummyServiceMethodWithIncomingLargeSwa"

View File

@ -0,0 +1,14 @@
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sch="http://schema.testcase">
<soapenv:Header>
<sch:SoapHeader>
<user>admin</user>
</sch:SoapHeader>
</soapenv:Header>
<soapenv:Body>
<sch:dummyServiceMethodWithOutgoingLargeSwa>
<request>
<dummyAttribute>1</dummyAttribute>
</request>
</sch:dummyServiceMethodWithOutgoingLargeSwa>
</soapenv:Body>
</soapenv:Envelope>

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://schema.testcase">
<SOAP-ENV:Body>
<ns1:dummyServiceMethodWithIncomingLargeSwaRequest>
<dummyServiceReturn>
<status>true</status>
</dummyServiceReturn>
</ns1:dummyServiceMethodWithIncomingLargeSwaRequest>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Binary file not shown.