Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 09b6e03

Browse files
author
Vasiliev.A
committed
fix for support schema request CommunicationConfig::TOPIC_REQUEST_TYPE_METHOD, added new attribute is_synchronous for topic to communication.xsd schema
1 parent aa9f2af commit 09b6e03

File tree

5 files changed

+35
-57
lines changed

5 files changed

+35
-57
lines changed

app/code/Magento/WebapiAsync/Plugin/Communication/Config/CompositeReader.php

Lines changed: 0 additions & 46 deletions
This file was deleted.

app/code/Magento/WebapiAsync/etc/di.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@
4242
<argument name="processorPath" xsi:type="const">Magento\WebapiAsync\Controller\Rest\AsynchronousSchemaRequestProcessor::BULK_PROCESSOR_PATH</argument>
4343
</arguments>
4444
</virtualType>
45-
<type name="Magento\Framework\Communication\Config\CompositeReader">
46-
<plugin name="forceTopicsTypeToAsync" type="Magento\WebapiAsync\Plugin\Communication\Config\CompositeReader" />
47-
</type>
4845
<type name="Magento\Webapi\Controller\Rest">
4946
<plugin name="webapiContorllerRestAsync" type="Magento\WebapiAsync\Plugin\ControllerRest" />
5047
</type>

lib/internal/Magento/Framework/Communication/Config/Reader/XmlReader/Converter.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ protected function extractTopics($config)
124124
$requestSchema,
125125
$responseSchema
126126
);
127+
$isSynchronous = $this->extractTopicIsSynchronous($topicNode) ?? null;
127128
if ($serviceMethod) {
128129
$output[$topicName] = $this->reflectionGenerator->generateTopicConfigForServiceMethod(
129130
$topicName,
@@ -134,7 +135,7 @@ protected function extractTopics($config)
134135
} elseif ($requestSchema && $responseSchema) {
135136
$output[$topicName] = [
136137
Config::TOPIC_NAME => $topicName,
137-
Config::TOPIC_IS_SYNCHRONOUS => true,
138+
Config::TOPIC_IS_SYNCHRONOUS => $isSynchronous ?? true,
138139
Config::TOPIC_REQUEST => $requestSchema,
139140
Config::TOPIC_REQUEST_TYPE => Config::TOPIC_REQUEST_TYPE_CLASS,
140141
Config::TOPIC_RESPONSE => $responseSchema,
@@ -143,7 +144,7 @@ protected function extractTopics($config)
143144
} elseif ($requestSchema) {
144145
$output[$topicName] = [
145146
Config::TOPIC_NAME => $topicName,
146-
Config::TOPIC_IS_SYNCHRONOUS => false,
147+
Config::TOPIC_IS_SYNCHRONOUS => $isSynchronous ?? false,
147148
Config::TOPIC_REQUEST => $requestSchema,
148149
Config::TOPIC_REQUEST_TYPE => Config::TOPIC_REQUEST_TYPE_CLASS,
149150
Config::TOPIC_RESPONSE => null,
@@ -258,4 +259,22 @@ protected function parseServiceMethod($serviceMethod, $topicName)
258259
);
259260
return $parsedServiceMethod;
260261
}
262+
263+
/**
264+
* Extract is_synchronous topic value.
265+
*
266+
* @param \DOMNode $topicNode
267+
* @return boolean|null
268+
*/
269+
protected function extractTopicIsSynchronous($topicNode)
270+
{
271+
$attributeName = Config::TOPIC_IS_SYNCHRONOUS;
272+
$topicAttributes = $topicNode->attributes;
273+
if (!$topicAttributes->getNamedItem($attributeName)) {
274+
return null;
275+
}
276+
$value = $topicAttributes->getNamedItem($attributeName)->nodeValue;
277+
$isSynchronous = filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
278+
return $isSynchronous;
279+
}
261280
}

lib/internal/Magento/Framework/Communication/Config/ReflectionGenerator.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ public function extractMethodMetadata($className, $methodName)
4242
$result = [
4343
Config::SCHEMA_METHOD_PARAMS => [],
4444
Config::SCHEMA_METHOD_RETURN_TYPE => $this->methodsMap->getMethodReturnType($className, $methodName),
45-
Config::SCHEMA_METHOD_HANDLER => [Config::HANDLER_TYPE => $className, Config::HANDLER_METHOD => $methodName]
45+
Config::SCHEMA_METHOD_HANDLER => [
46+
Config::HANDLER_TYPE => $className,
47+
Config::HANDLER_METHOD => $methodName
48+
]
4649
];
4750
$paramsMeta = $this->methodsMap->getMethodParams($className, $methodName);
4851
foreach ($paramsMeta as $paramPosition => $paramMeta) {
@@ -63,29 +66,33 @@ public function extractMethodMetadata($className, $methodName)
6366
* @param string $serviceType
6467
* @param string $serviceMethod
6568
* @param array|null $handlers
69+
* @param bool|null $isSynchronous
6670
* @return array
6771
*/
68-
public function generateTopicConfigForServiceMethod($topicName, $serviceType, $serviceMethod, $handlers = [])
72+
public function generateTopicConfigForServiceMethod($topicName, $serviceType, $serviceMethod, $handlers = [], $isSynchronous = null)
6973
{
7074
$methodMetadata = $this->extractMethodMetadata($serviceType, $serviceMethod);
7175
$returnType = $methodMetadata[Config::SCHEMA_METHOD_RETURN_TYPE];
7276
$returnType = ($returnType != 'void' && $returnType != 'null') ? $returnType : null;
77+
if (!isset($isSynchronous)) {
78+
$isSynchronous = $returnType ? true : false;
79+
}
7380
return [
7481
Config::TOPIC_NAME => $topicName,
75-
Config::TOPIC_IS_SYNCHRONOUS => $returnType ? true : false,
82+
Config::TOPIC_IS_SYNCHRONOUS => $isSynchronous,
7683
Config::TOPIC_REQUEST => $methodMetadata[Config::SCHEMA_METHOD_PARAMS],
7784
Config::TOPIC_REQUEST_TYPE => Config::TOPIC_REQUEST_TYPE_METHOD,
7885
Config::TOPIC_RESPONSE => $returnType,
7986
Config::TOPIC_HANDLERS => $handlers
80-
?: [self::DEFAULT_HANDLER => $methodMetadata[Config::SCHEMA_METHOD_HANDLER]]
87+
? : [self::DEFAULT_HANDLER => $methodMetadata[Config::SCHEMA_METHOD_HANDLER]]
8188
];
8289
}
8390

8491
/**
8592
* Generate topic name based on service type and method name.
86-
*
8793
* Perform the following conversion:
88-
* \Magento\Customer\Api\RepositoryInterface + getById => magento.customer.api.repositoryInterface.getById
94+
* \Magento\Customer\Api\RepositoryInterface + getById =>
95+
* magento.customer.api.repositoryInterface.getById
8996
*
9097
* @param string $typeName
9198
* @param string $methodName

lib/internal/Magento/Framework/Communication/etc/communication.xsd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
<xs:attribute type="schemaType" name="schema" use="optional"/>
4141
<xs:attribute type="xs:string" name="request" use="optional"/>
4242
<xs:attribute type="xs:string" name="response" use="optional"/>
43+
<xs:attribute type="xs:boolean" name="is_synchronous" use="optional"/>
4344
</xs:complexType>
4445
<xs:complexType name="handlerType">
4546
<xs:attribute type="xs:string" name="name" use="required"/>

0 commit comments

Comments
 (0)