From 3ea277b2bd88867f80d9b77d565da21db73fe110 Mon Sep 17 00:00:00 2001 From: Mel McCann Date: Mon, 10 Sep 2018 12:35:03 +0100 Subject: [PATCH 1/5] Adding a temporary fix to deal with serialization of older versions of event messages that had the responseHeaders as a string --- .../Soap/Exceptions/SoapException.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Components/WebService/Soap/Exceptions/SoapException.php b/Components/WebService/Soap/Exceptions/SoapException.php index 04ac1820..f00a7263 100644 --- a/Components/WebService/Soap/Exceptions/SoapException.php +++ b/Components/WebService/Soap/Exceptions/SoapException.php @@ -3,6 +3,7 @@ namespace Smartbox\Integration\FrameworkBundle\Components\WebService\Soap\Exceptions; use JMS\Serializer\Annotation as JMS; +use JMS\Serializer\Annotation\Accessor; use Smartbox\CoreBundle\Type\SerializableInterface; use Smartbox\CoreBundle\Type\Traits\HasInternalType; use Smartbox\Integration\FrameworkBundle\Components\WebService\Exception\ExternalSystemExceptionInterface; @@ -25,6 +26,7 @@ class SoapException extends \Exception implements SerializableInterface, Externa * @JMS\Expose * @JMS\Type("array") * @JMS\SerializedName("requestHeaders") + * @Accessor(getter="getResponseHeaders",setter="setsRequestHeadersTypeUnknown") * @JMS\Groups({"logs"}) */ protected $requestHeaders; @@ -160,6 +162,23 @@ public function setResponseHeaders($responseHeaders) return $this; } + /** + * + * @return SoapException + */ + public function setsRequestHeadersTypeUnknown($responseHeaders) + { + if(is_string($responseHeaders)){ + $this->responseHeaders = array($responseHeaders); + }elseif(is_array($responseHeaders)){ + $this->responseHeaders = $responseHeaders; + }else{ + $this->responseHeaders = array(); + } + return $this; + } + + /** * @return string */ From 611564b2098d995484dcb87b489af0fda72e9fd6 Mon Sep 17 00:00:00 2001 From: Mel McCann Date: Mon, 10 Sep 2018 12:56:52 +0100 Subject: [PATCH 2/5] undo my rookie copy and paste error --- .../WebService/Soap/Exceptions/SoapException.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Components/WebService/Soap/Exceptions/SoapException.php b/Components/WebService/Soap/Exceptions/SoapException.php index f00a7263..72b0caae 100644 --- a/Components/WebService/Soap/Exceptions/SoapException.php +++ b/Components/WebService/Soap/Exceptions/SoapException.php @@ -166,14 +166,14 @@ public function setResponseHeaders($responseHeaders) * * @return SoapException */ - public function setsRequestHeadersTypeUnknown($responseHeaders) + public function setsRequestHeadersTypeUnknown($requestHeaders) { - if(is_string($responseHeaders)){ - $this->responseHeaders = array($responseHeaders); - }elseif(is_array($responseHeaders)){ - $this->responseHeaders = $responseHeaders; + if(is_string($requestHeaders)){ + $this->requestHeaders = array($requestHeaders); + }elseif(is_array($requestHeaders)){ + $this->requestHeaders = $requestHeaders; }else{ - $this->responseHeaders = array(); + $this->requestHeaders = array(); } return $this; } From cd4f0f4152dbfc80eeafd448542c1a4f5551fade Mon Sep 17 00:00:00 2001 From: Mel McCann Date: Mon, 10 Sep 2018 16:53:12 +0100 Subject: [PATCH 3/5] Add new type starray to handle old event deserialization and new event deserialization --- .../Soap/Exceptions/SoapException.php | 22 +-------- Events/StarrayHandler.php | 47 +++++++++++++++++++ Resources/config/services.yml | 6 +++ 3 files changed, 55 insertions(+), 20 deletions(-) create mode 100644 Events/StarrayHandler.php diff --git a/Components/WebService/Soap/Exceptions/SoapException.php b/Components/WebService/Soap/Exceptions/SoapException.php index 72b0caae..d696ab67 100644 --- a/Components/WebService/Soap/Exceptions/SoapException.php +++ b/Components/WebService/Soap/Exceptions/SoapException.php @@ -24,9 +24,8 @@ class SoapException extends \Exception implements SerializableInterface, Externa /** * @var array * @JMS\Expose - * @JMS\Type("array") + * @JMS\Type("starray") * @JMS\SerializedName("requestHeaders") - * @Accessor(getter="getResponseHeaders",setter="setsRequestHeadersTypeUnknown") * @JMS\Groups({"logs"}) */ protected $requestHeaders; @@ -43,7 +42,7 @@ class SoapException extends \Exception implements SerializableInterface, Externa /** * @var array * @JMS\Expose - * @JMS\Type("array") + * @JMS\Type("starray") * @JMS\SerializedName("responseHeaders") * @JMS\Groups({"logs"}) */ @@ -162,23 +161,6 @@ public function setResponseHeaders($responseHeaders) return $this; } - /** - * - * @return SoapException - */ - public function setsRequestHeadersTypeUnknown($requestHeaders) - { - if(is_string($requestHeaders)){ - $this->requestHeaders = array($requestHeaders); - }elseif(is_array($requestHeaders)){ - $this->requestHeaders = $requestHeaders; - }else{ - $this->requestHeaders = array(); - } - return $this; - } - - /** * @return string */ diff --git a/Events/StarrayHandler.php b/Events/StarrayHandler.php new file mode 100644 index 00000000..72ebb842 --- /dev/null +++ b/Events/StarrayHandler.php @@ -0,0 +1,47 @@ + GraphNavigator::DIRECTION_DESERIALIZATION, + 'format' => 'json', + 'type' => 'starray', + 'method' => 'serializeStringOrArrayToArray', + ), + ); + } + + /** + * The de-serialization function, which will return always an array. + * This is a temporary solution to a problem. + * + * @param VisitorInterface $visitor + * @param string|array $data + * @param array $type + * + * @return array + */ + public function serializeStringOrArrayToArray(VisitorInterface $visitor, $data, array $type, Context $context) + { + if (is_string($data)) { + return array($data); + } elseif (is_array($data)) { + return $data; + } else { + return array(); + } + } +} diff --git a/Resources/config/services.yml b/Resources/config/services.yml index e3c3f1c0..9503f164 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -24,6 +24,7 @@ parameters: smartesb.steps_provider.dbal.class: Smartbox\Integration\FrameworkBundle\Components\DB\Dbal\DbalStepsProvider smartesb.steps_provider.nosql.class: Smartbox\Integration\FrameworkBundle\Components\DB\NoSQL\NoSQLStepsProvider smartesb.steps_provider.csv.class: Smartbox\Integration\FrameworkBundle\Components\FileService\Csv\CsvConfigurableStepsProvider + smartesb.serialization.handler.starray.class: Smartbox\Integration\FrameworkBundle\Events\StarrayHandler services: smartesb.serialization.handler.mongodate: @@ -108,3 +109,8 @@ services: smartesb.handlers.async: class: '%smartesb.handlers.message_routing.class%' + + smartesb.serialization.handler.starray: + class: '%smartesb.serialization.handler.starray.class%' + tags: + - { name: jms_serializer.subscribing_handler } From b010c470f808c718434f1293b20352757a31cbb6 Mon Sep 17 00:00:00 2001 From: Mel McCann Date: Wed, 12 Sep 2018 15:25:35 +0100 Subject: [PATCH 4/5] WIP: Testing serialization of starray --- .../Soap/Exceptions/SoapException.php | 4 +- Events/StarrayHandler.php | 42 ++++++++++++++++--- 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/Components/WebService/Soap/Exceptions/SoapException.php b/Components/WebService/Soap/Exceptions/SoapException.php index d696ab67..43049dab 100644 --- a/Components/WebService/Soap/Exceptions/SoapException.php +++ b/Components/WebService/Soap/Exceptions/SoapException.php @@ -116,7 +116,7 @@ public function getRequestHeaders() */ public function setRequestHeaders($requestHeaders) { - $this->requestHeaders = $this->parseHeadersToArray($requestHeaders); + $this->requestHeaders = (object)$this->parseHeadersToArray($requestHeaders); return $this; } @@ -156,7 +156,7 @@ public function getResponseHeaders() */ public function setResponseHeaders($responseHeaders) { - $this->responseHeaders = $this->parseHeadersToArray($responseHeaders); + $this->responseHeaders = (object)$this->parseHeadersToArray($responseHeaders); return $this; } diff --git a/Events/StarrayHandler.php b/Events/StarrayHandler.php index 72ebb842..3b56e806 100644 --- a/Events/StarrayHandler.php +++ b/Events/StarrayHandler.php @@ -2,39 +2,69 @@ namespace Smartbox\Integration\FrameworkBundle\Events; +use Doctrine\Common\Collections\ArrayCollection; use JMS\Serializer\Context; use JMS\Serializer\GraphNavigator; use JMS\Serializer\Handler\SubscribingHandlerInterface; use JMS\Serializer\VisitorInterface; +use JMS\Serializer\Handler\ArrayCollectionHandler; -class StarrayHandler implements SubscribingHandlerInterface +class StarrayHandler extends ArrayCollectionHandler { /** * {@inheritdoc} */ public static function getSubscribingMethods() { + return array( + array( + 'direction' => GraphNavigator::DIRECTION_SERIALIZATION, + 'format' => 'json', + 'type' => 'starray', + 'method' => 'serializeToArray', + ), array( 'direction' => GraphNavigator::DIRECTION_DESERIALIZATION, 'format' => 'json', 'type' => 'starray', - 'method' => 'serializeStringOrArrayToArray', + 'method' => 'deserializeToArray', ), ); } + + + /** + * The de-serialization function, which will return always an array. + * This is a temporary solution to a problem. + * + * @param VisitorInterface $visitor + * @param mixed $data + * @param array $type + * @param Context $context + * + * @return array + */ + public function serializeToArray(VisitorInterface $visitor, $data, array $type, Context $context) + { + $data = new ArrayCollection((array)$data); + + return parent::serializeCollection($visitor, $data, $type, $context); + } + /** * The de-serialization function, which will return always an array. * This is a temporary solution to a problem. * - * @param VisitorInterface $visitor - * @param string|array $data - * @param array $type + * @param VisitorInterface $visitor + * @param mixed $data + * @param array $type + * @param Context $context * * @return array */ - public function serializeStringOrArrayToArray(VisitorInterface $visitor, $data, array $type, Context $context) + public function deserializeToArray(VisitorInterface $visitor, $data, array $type, Context $context) { if (is_string($data)) { return array($data); From ae5f4ac821a57e70b8c6af7e82b9f25389a20c71 Mon Sep 17 00:00:00 2001 From: Mel McCann Date: Wed, 12 Sep 2018 16:24:01 +0100 Subject: [PATCH 5/5] remove unused use --- Components/WebService/Soap/Exceptions/SoapException.php | 1 - 1 file changed, 1 deletion(-) diff --git a/Components/WebService/Soap/Exceptions/SoapException.php b/Components/WebService/Soap/Exceptions/SoapException.php index 43049dab..414ad1a0 100644 --- a/Components/WebService/Soap/Exceptions/SoapException.php +++ b/Components/WebService/Soap/Exceptions/SoapException.php @@ -3,7 +3,6 @@ namespace Smartbox\Integration\FrameworkBundle\Components\WebService\Soap\Exceptions; use JMS\Serializer\Annotation as JMS; -use JMS\Serializer\Annotation\Accessor; use Smartbox\CoreBundle\Type\SerializableInterface; use Smartbox\CoreBundle\Type\Traits\HasInternalType; use Smartbox\Integration\FrameworkBundle\Components\WebService\Exception\ExternalSystemExceptionInterface;