You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by "razuro (via GitHub)" <gi...@apache.org> on 2023/03/13 06:40:32 UTC

[GitHub] [apisix-docker] razuro opened a new issue, #443: No body-transformer plugin

razuro opened a new issue, #443:
URL: https://github.com/apache/apisix-docker/issues/443

   Body-transformer plugin should be available in 3.2.0. But this Apisix docker version does not seem to have the plugin.Apologies if this plugin is actually available and kindly help me to enable them. Thanks


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix-docker] razuro commented on issue #443: No body-transformer plugin

Posted by "razuro (via GitHub)" <gi...@apache.org>.
razuro commented on issue #443:
URL: https://github.com/apache/apisix-docker/issues/443#issuecomment-1490300785

   Awesome! It actually works. Thanks for your help @DebbyMiressa!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix-docker] DebbyMiressa commented on issue #443: No body-transformer plugin

Posted by "DebbyMiressa (via GitHub)" <gi...@apache.org>.
DebbyMiressa commented on issue #443:
URL: https://github.com/apache/apisix-docker/issues/443#issuecomment-1477494203

   The Body-Transformer plugin exists in APISIX V3.2.0 if you check the [schema.json](http://localhost:9092/v1/schema) file. There is currently a bug in which the plugin schema is not synchronized with the plugins listed in the [dashboard](http://localhost:9000/plugin/market). Until they push a bug-fix on their next release, maybe try using the command line to enable and configure the plugin. 
   Here is a code snippet that transforms the request body from JSON to XML and transforms the response body from XML to JSON. Before using the code below, change the req_template and res_template to your needs and make sure it applies to your requirements.
   ```sh
   req_template=$(cat <<EOF | awk '{gsub(/"/,"\\\"");};1' | awk '{$1=$1};1' | tr -d '\r\n'
   <?xml version="1.0"?>
   <soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
    <soap-env:Body>
     <ns0:getCountryRequest xmlns:ns0="http://spring.io/guides/gs-producing-web-service">
      <ns0:name>{{_escape_xml(name)}}</ns0:name>
     </ns0:getCountryRequest>
    </soap-env:Body>
   </soap-env:Envelope>
   EOF
   )
   
   rsp_template=$(cat <<EOF | awk '{gsub(/"/,"\\\"");};1' | awk '{$1=$1};1' | tr -d '\r\n'
   {% if Envelope.Body.Fault == nil then %}
   {
      "status":"{{_ctx.var.status}}",
      "currency":"{{Envelope.Body.getCountryResponse.country.currency}}",
      "population":{{Envelope.Body.getCountryResponse.country.population}},
      "capital":"{{Envelope.Body.getCountryResponse.country.capital}}",
      "name":"{{Envelope.Body.getCountryResponse.country.name}}"
   }
   {% else %}
   {
      "message":{*_escape_json(Envelope.Body.Fault.faultstring[1])*},
      "code":"{{Envelope.Body.Fault.faultcode}}"
      {% if Envelope.Body.Fault.faultactor ~= nil then %}
      , "actor":"{{Envelope.Body.Fault.faultactor}}"
      {% end %}
   }
   {% end %}
   EOF
   )
   
   curl http://127.0.0.1:9180/apisix/admin/routes/test_ws \
       -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
   {
       "methods": ["POST"],
       "uri": "/ws",
       "plugins": {
           "proxy-rewrite": {
               "headers": {
                   "set": {
                       "Accept-Encoding": "identity",
                       "Content-Type": "text/xml"
                   }
               }
           },
           "response-rewrite": {
               "headers": {
                   "set": {
                       "Content-Type": "application/json"
                   }
               }
           },
           "body-transformer": {
               "request": {
                   "template": "'"$req_template"'"
               },
               "response": {
                   "template": "'"$rsp_template"'"
               }
           }
       },
       "upstream": {
           "type": "roundrobin",
           "nodes": {
               "localhost:8080": 1
           }
       }
   }'
   
   curl -s http://127.0.0.1:9080/ws -H 'content-type: application/json' -X POST -d '{"name": "Spain"}' | jq
   {
     "status": "200",
     "currency": "EUR",
     "population": 46704314,
     "capital": "Madrid",
     "name": "Spain"
   }
   
   # Fault response
   curl -s http://127.0.0.1:9080/ws -H 'content-type: application/json' -X POST -d '{"name": "Spain"}' | jq
   {
     "message": "Your name is required.",
     "code": "SOAP-ENV:Server"
   }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix-docker] DebbyMiressa commented on issue #443: No body-transformer plugin

Posted by "DebbyMiressa (via GitHub)" <gi...@apache.org>.
DebbyMiressa commented on issue #443:
URL: https://github.com/apache/apisix-docker/issues/443#issuecomment-1482439251

   In order to synchronize the dashboard plugin list with the [schema.json](http://localhost:9092/v1/schema) file, you need to manually copy everything in the [schema.json](http://localhost:9092/v1/schema) file and paste it into /usr/local/apisix-dahsboard/conf/schema.json file. Here is additional Info regarding [adding a custom plugin to your dashboard](https://github.com/apache/apisix-dashboard/issues/646) and [FAQ #4 on apisix.apache.org site regarding dashboard plugin list synchronization after modifying existing or adding custom plugin to apisix](https://apisix.apache.org/docs/dashboard/2.10/FAQ/)
   
   In order for you to find this file and edit it, you can execute the following commands in your **apisix-dashboard-1 docker container terminal**: 
   ```sh
   cd /usr/local/apisix-dahsboard/conf
   ls
   cat schema.js
   ```
   Now you should see a long JSON file for plugin configuration. In order to edit this schema.json file, we can use vi text editor. Use the following command to open schema.json with vi text editor:
   ```sh
   vi /usr/local/apisix-dashboard/conf/schema.json
   ```
   After you open the file, delete all the text in the file using the command: 
   ```sh
   :%d
   ```
   Now, manually copy everything in the [schema.json](http://localhost:9092/v1/schema) file and paste it into /usr/local/apisix-dahsboard/conf/schema.json file. You can do this simply by pressing right-click inside the terminal or by using the following command: 
   ```sh
   &quot;+p
   ```
   Finally, you can save and exit the file using the command:
   ```sh
   :wq
   ```
   
   After you refresh the Manager API (or restarting the container will also do just to be sure), as you can see, the body-transform plugin is now added to the dashboard.
   ![plugin list](https://user-images.githubusercontent.com/101793279/227465364-9c1d945f-38d1-4545-ab40-ca6e44b94640.PNG)
   
   Hope this helps! Please give this comment a like if it helps you in any way!
   Best of luck!
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix-docker] razuro closed issue #443: No body-transformer plugin

Posted by "razuro (via GitHub)" <gi...@apache.org>.
razuro closed issue #443: No body-transformer plugin
URL: https://github.com/apache/apisix-docker/issues/443


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix-docker] Abdellah35 commented on issue #443: No body-transformer plugin

Posted by "Abdellah35 (via GitHub)" <gi...@apache.org>.
Abdellah35 commented on issue #443:
URL: https://github.com/apache/apisix-docker/issues/443#issuecomment-1483760750

   Thanks @DebbyMiressa, this solution worked form me.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org