Как создать Rest API из SOAP Backend с помощью WSO2 API Manager - PullRequest
0 голосов
/ 02 октября 2019

Я недавно работаю с wso2 api manager, и мне нужно приостановить службу SOAP и перенести ее в REST API, я видел всю документацию, но никто не отвечает на мою проблему, я уже создал последовательность ввода

getProdRequestInSequence.xml

<?xml version="1.0" encoding="UTF-8"?>
<sequence xmlns="http://ws.apache.org/ns/synapse" name="getProdRequestInSequence" ><!-- This is the SOAP action which the backend SOAP operation expects, we set it in a header mediator --><header description="SOAPAction" name="SOAPAction" scope="transport" value="http://localhost:81/soap/products.php/query/getProd"/><!-- We are storing the input values which the end users input for these values into these two properties --><property name="uri.var.categoria" expression="$url:categoria"/>
<!-- Since we do not want the URL pattern we mentioned to be sent to the backend we need to add the below property to remove it --><property name="REST_URL_POSTFIX" scope="axis2" action="remove"/><!-- Now we need to create the actual payload which the backend requires. For that we use the payload factory mediator --><payloadFactory description="transform" media-type="xml">
  <format>
  <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:quer="http://localhost:81/soap/products.php/query/">
  <soapenv:Header/>
  <soapenv:Body>
  <quer:getProd>
    <quer:categoria>$1</quer:categoria>
  </quer:getProd></soapenv:Body>
  </soapenv:Envelope>
  </format>
  <args>
    <arg expression="get-property(‘uri.var.categoria’)"/>
  </args>
</payloadFactory><!-- Here we are setting the content type which the web service expects --><property description="messageProperty" name="messageType" scope="axis2" type="STRING" value="application/soap+xml"/>
</sequence>

xml_to_json_out_message.xml

<?xml version="1.0" encoding="UTF-8"?>
<sequence xmlns="http://ws.apache.org/ns/synapse" name="xml_to_json_out_message" >
<!-- Transforms the response to a JSON -->
    <property description="message" name="messageType" scope="axis2" type="STRING" value="application/json"/>
</sequence>

Теперь, согласно документации, эти файлы, когда-то созданные, я оплачиваю в политике передачи сообщений и должна работать отлично, но это дает мнеэта ошибка

Сбои шлюза

Ошибка публикации рабочих сред и песочницы Ошибка при развертывании последовательности на шлюзе ###

Заранее благодарим за помощь

getProdRequestInSequence.xml

 <?xml version="1.0" encoding="UTF-8"?>
    <sequence xmlns="http://ws.apache.org/ns/synapse" name="getProdRequestInSequence" ><!-- This is the SOAP action which the backend SOAP operation expects, we set it in a header mediator --><header description="SOAPAction" name="SOAPAction" scope="transport" value="http://localhost:81/soap/products.php/query/getProd"/><!-- We are storing the input values which the end users input for these values into these two properties --><property name="uri.var.categoria" expression="$url:categoria"/>
    <!-- Since we do not want the URL pattern we mentioned to be sent to the backend we need to add the below property to remove it --><property name="REST_URL_POSTFIX" scope="axis2" action="remove"/><!-- Now we need to create the actual payload which the backend requires. For that we use the payload factory mediator --><payloadFactory description="transform" media-type="xml">
      <format>
      <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:quer="http://localhost:81/soap/products.php/query/">
      <soapenv:Header/>
      <soapenv:Body>
      <quer:getProd>
        <quer:categoria>$1</quer:categoria>
      </quer:getProd></soapenv:Body>
      </soapenv:Envelope>
      </format>
      <args>
        <arg expression="get-property(‘uri.var.categoria’)"/>
      </args>
    </payloadFactory><!-- Here we are setting the content type which the web service expects --><property description="messageProperty" name="messageType" scope="axis2" type="STRING" value="application/soap+xml"/>
    </sequence>

и выходной последовательности

xml_to_json_out_message.xml

 <?xml version="1.0" encoding="UTF-8"?>
    <sequence xmlns="http://ws.apache.org/ns/synapse" name="xml_to_json_out_message" >
    <!-- Transforms the response to a JSON -->
        <property description="message" name="messageType" scope="axis2" type="STRING" value="application/json"/>
    </sequence>

Теперь, согласнок документации, эти файлы, когда-то созданные, я взимаю в политике передачи сообщений, и должен работать отлично, но это дает мне эту ошибку

Gateway Failures

Failed для публикации сред производства и песочницы Ошибка при развертывании последовательности на шлюзе

Заранее спасибо за помощь

Ответы [ 2 ]

0 голосов
/ 17 октября 2019

Разрешение для вышеупомянутой проблемы:

На данный момент у вашего подхода есть специальный символ "" ", который часто встречается, если вы используете мак-книгу для разработок. Замена одинарных кавычек на правильные символы решит ваши текущие проблемы.


Рекомендуемый подход с WSo2 API Manager:

Менеджер API WSO2 имеет возможность представить Сервис / API SOAP как API REST Из коробки без каких-либо последовательностей или конфигураций уровня синапса.

Чтобы открыть сервис REST с помощью WSO2API Manager, вам просто нужно указать внутренний URL и файл WDSL с этой функцией.

Пожалуйста, обратитесь к документации здесь .

0 голосов
/ 16 октября 2019

Существует несоответствие синтаксиса в предоставленном getProdRequestInSequence.xml файле конфигурации синапса.

uri.var.categoria заключен в специальный символ (') внутри метода get-property()и который не является символом одинарных кавычек ('). Пожалуйста, найдите обновленный файл конфигурации синапса ниже

getProdRequestInSequence.xml

<?xml version="1.0" encoding="UTF-8"?>
    <sequence xmlns="http://ws.apache.org/ns/synapse" name="getProdRequestInSequence" >
    <!-- This is the SOAP action which the backend SOAP operation expects, we set it in a header mediator -->
    <header description="SOAPAction" name="SOAPAction" scope="transport" value="http://localhost:81/soap/products.php/query/getProd"/>
    <!-- We are storing the input values which the end users input for these values into these two properties -->
    <property name="uri.var.categoria" expression="$url:categoria"/>
    <!-- Since we do not want the URL pattern we mentioned to be sent to the backend we need to add the below property to remove it -->
    <property name="REST_URL_POSTFIX" scope="axis2" action="remove"/>
    <!-- Now we need to create the actual payload which the backend requires. For that we use the payload factory mediator -->
    <payloadFactory description="transform" media-type="xml">
        <format>
            <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:quer="http://localhost:81/soap/products.php/query/">
                <soapenv:Header/>
                <soapenv:Body>
                    <quer:getProd>
                        <quer:categoria>$1</quer:categoria>
                    </quer:getProd>
                </soapenv:Body>
            </soapenv:Envelope>
        </format>
        <args>
            <arg expression="get-property('uri.var.categoria')"/>
        </args>
    </payloadFactory>
    <!-- Here we are setting the content type which the web service expects -->
    <property description="messageProperty" name="messageType" scope="axis2" type="STRING" value="application/soap+xml"/>
</sequence>
...