soap
The soap plugin provides a convenient approach to transform between RESTful HTTP requests and SOAP requests, as well as their corresponding responses.
With a single URL to the WSDL file, API7 automatically parses the file content and generates conversion logics to allow for the protocol transcoding.
Examples
Prerequisites
The soap plugin depends on soap-proxy, a separate service that handles WSDL parsing and JSON-to-SOAP transcoding. You must start soap-proxy before using this plugin, and configure the gateway with its connection address.
Start SOAP Proxy
- Docker
- Kubernetes
Start the soap-proxy container on the same network as your APISIX instance (adjust accordingly for your environment):
docker run -d \
--name soap-proxy \
--network=apisix-quickstart-net \
-p 5000:5000 \
api7/soap-proxy:1.0.0
Create a Deployment and Service for soap-proxy in the same namespace as your gateway:
apiVersion: apps/v1
kind: Deployment
metadata:
namespace: aic
name: soap-proxy
spec:
replicas: 1
selector:
matchLabels:
app: soap-proxy
template:
metadata:
labels:
app: soap-proxy
spec:
containers:
- name: soap-proxy
image: api7/soap-proxy:1.0.0
ports:
- containerPort: 5000
---
apiVersion: v1
kind: Service
metadata:
namespace: aic
name: soap-proxy
spec:
selector:
app: soap-proxy
ports:
- protocol: TCP
port: 5000
targetPort: 5000
type: ClusterIP
Apply the manifest:
kubectl apply -f soap-proxy.yaml
Configure the Gateway
By default, the soap plugin expects soap-proxy to be available at http://127.0.0.1:5000. Update the plugin_attr in your gateway configuration to point to the correct address.
- Docker
- Kubernetes
Add the following to your config.yaml:
plugin_attr:
soap:
endpoint: http://soap-proxy:5000
timeout: 3000
Reload the gateway for the changes to take effect:
apisix reload
Add the following to your gateway config.yaml ConfigMap:
plugin_attr:
soap:
endpoint: http://soap-proxy:5000
timeout: 3000
Restart the gateway deployment to apply the changes:
kubectl rollout restart deployment/<gateway-deployment> -n aic
Invoke an Operation
The following example demonstrates how you can configure the plugin on a route and invoke an operation available on the upstream server as specified in the WSDL file.
Create a route with the soap plugin:
- Admin API
- ADC
- Ingress Controller
curl 'http://127.0.0.1:9180/apisix/admin/routes' -X PUT \
-H 'X-API-KEY: ${ADMIN_API_KEY}' \
-d '{
"id": "soap-hello",
"uri": "/SayHello",
"methods": ["POST"],
"plugins": {
"soap": {
"wsdl_url": "https://apps.learnwebservices.com/services/hello?wsdl"
}
}
}'
services:
- name: soap-service
routes:
- name: soap-hello
uris:
- /SayHello
methods:
- POST
plugins:
soap:
wsdl_url: "https://apps.learnwebservices.com/services/hello?wsdl"
Synchronize the configuration to the gateway:
adc sync -f adc.yaml
- Gateway API
- APISIX CRD
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
namespace: aic
name: soap-hello
spec:
parentRefs:
- name: apisix
rules:
- matches:
- path:
type: Exact
value: /SayHello
method: POST
filters:
- type: ExtensionRef
extensionRef:
group: apisix.apache.org
kind: PluginConfig
name: soap-plugin-config
---
apiVersion: apisix.apache.org/v1alpha1
kind: PluginConfig
metadata:
namespace: aic
name: soap-plugin-config
spec:
plugins:
- name: soap
config:
wsdl_url: "https://apps.learnwebservices.com/services/hello?wsdl"
apiVersion: apisix.apache.org/v2
kind: ApisixRoute
metadata:
namespace: aic
name: soap-hello
spec:
ingressClassName: apisix
http:
- name: soap-hello
match:
paths:
- /SayHello
methods:
- POST
plugins:
- name: soap
enable: true
config:
wsdl_url: "https://apps.learnwebservices.com/services/hello?wsdl"
Apply the configuration:
kubectl apply -f soap-ic.yaml
❶ Set the URI to the name of the operation in the WSDL file.
❷ Allow only for the POST request method.
❸ Set the URL path to the WSDL file.
Send a request to the route verify:
curl 'http://127.0.0.1:9080/SayHello' -X POST -d '{"Name": "John Doe"}'
You should see an HTTP/1.1 200 OK response with the following:
"Hello John Doe!"