I hope the reader of this blog has got an
idea about WSO2 ESB and the pass-through transport and the different
type of content types support for the product.
For more information read on,
http://wso2.com/products/enterprise-service-bus/
To test Multipart/form data, we need
the below things ready.
- A backend service.
- tcpmon to view the pass through
- A form to submit data
- Attachments – text files, json file, an image
- WSO2 ESB with the correct synapse configuration of the proxy
Backend Service
- As the backend service, I will be setting the offset to 2 and run a WSO2 App Server, which can also be downloaded from http://wso2.com/products/application-server/. I am using 5.1.0.
- I will be using the HelloService in unsecured mode.
- I assume now that I have the HelloService up and runninn in, http://localhost:9765/services/HelloService
Set up tcp mon
1. Start the tcpmon in the
<ESB_Home>/bin - sh tcpmon.sh
2. Create 2 listeners as below.
1. Listen Port 8281, Target host –
localhost, Target port – 8280 – Before hits the ESB/
HelloProxyService proxy
2. Listen Port 9766, target host –
localhost, target port – 9765 – After passing through ESB and
Before hits the backend
A form to submit data
form action="http://localhost:8281/services/HelloProxyService/greet"
<html>
<head><title>multipart/form-data - Client</title></head>
<body>
<form action="http://localhost:8281/services/HelloProxyService/greet" method="POST" enctype="multipart/form-data">
User Name: <input type="text" name="name">
User id: <input type="text" name="id">
User Address: <input type="text" name="add">
AGE: <input type="text" name="age">
<br>
Upload :
<input type="file" name="datafile" size="40" multiple>
</p>
<input type="submit" value="Submit">
</form>
</body>
</html>
Attachments
- As attachments, I have just a text file with some texts in it
- A jpeg image
- A Json file with a json object.
{
"name":"John Johnson",
"street":"Oslo West 555",
"age":33,
"phone":"555 1234567"
}
Synapse configurations
- The below proxy will allow the user to view the data that has been sent.
<Port> = 9766 or a different port you provide
<proxy name="HelloProxyService"
transports="https http"
startOnLoad="true"
trace="disable">
<description/>
<target>
<endpoint>
<address uri="http://localhost:<port>/services/HelloService"/>
</endpoint>
<outSequence>
<property name="OUT_ONLY" value="true"/>
<send/>
</outSequence>
</target>
</proxy>
2. If you want to test whether this form data saved in to a file correctly, you can enable VFS transport in axis2.xml and use the following synapse accordingly. We will be saving it in to a file in the given location.
<proxy name="HelloProxyService"
transports="https http"
startOnLoad="true"
trace="disable">
<description/>
<target>
<endpoint>
<address uri="vfs:file:///home/ushani/Downloads/out"/>
</endpoint>
<inSequence>
<property name="OUT_ONLY" value="true"/>
</inSequence>
<outSequence>
<send/>
</outSequence>
</target>
</proxy>
To Test :
(Listen Port 8281, Target host – localhost, Target port – 8280 – Before hits the ESB/ HelloProxyService proxy)
(Listen Port 9766 or a different port, target host – localhost, target port – 9765 or different port which the backend service is run – After passing through ESB and Before hits the backend)
No comments:
Post a Comment