Skip to content

How to Switch from UDP to HTTP/S

This example demonstrates how WSO2 Micro Integrator receives SOAP messages over UDP and forwards them over HTTP.

Synapse configuration

Following are the integration artifacts (proxy service) that we can used to implement this scenario. See the instructions on how to build and run this example.

<?xml version="1.0" encoding="UTF-8"?>
<proxy name="StockQuoteProxy" startOnLoad="true" transports="udp" xmlns="http://ws.apache.org/ns/synapse">
    <target>
        <inSequence>
            <log category="INFO" level="full"/>
            <property name="OUT_ONLY" scope="default" type="BOOLEAN" value="true"/>
            <call>
                <endpoint key="SimpleStockEp"/>
            </call>
        </inSequence>
        <faultSequence/>
    </target>
    <publishWSDL key="conf:UDP_WSDL/sample_proxy_1.wsdl" preservePolicy="true">
    </publishWSDL>
    <parameter name="transport.udp.port">9999</parameter>
    <parameter name="transport.udp.contentType">text/xml</parameter>
</proxy>
<?xml version="1.0" encoding="UTF-8"?>
<endpoint name="SimpleStockEp" xmlns="http://ws.apache.org/ns/synapse">
    <address uri="http://localhost:9000/services/SimpleStockQuoteService">
        <suspendOnFailure>
            <initialDuration>-1</initialDuration>
            <progressionFactor>1</progressionFactor>
        </suspendOnFailure>
        <markForSuspension>
            <retriesBeforeSuspension>0</retriesBeforeSuspension>
        </markForSuspension>
    </address>
</endpoint>

Build and run

Create the artifacts:

  1. Launch Visual Studio Code with the Micro Integrator for VS Code extension (MI for VS Code) installed.

    Info

    Follow the Install Micro Integrator for VS Code documentation for a complete installation guide.

  2. Create an integration project.

  3. Add sample_proxy_1.wsdl as a registry resource (change the registry path of the proxy accordingly).
    1. Download sample_proxy_1.wsdl
    2. Add a registry resource. Add registry resource
      1. Click on + sign next to Registry.
      2. Select Import from the file system.
      3. Goto Browse file and select the downloaded file.
      4. Provide artifact name, registry type, and registry path as in the figure.
      5. Create the registry resource.
  4. Create the proxy service with the configurations given above.
  5. Deploy the artifacts in your Micro Integrator.

Set up the back-end service:

  • Download the back-end service.
  • Extract the downloaded zip file.
  • Open a terminal, navigate to the axis2Server/bin/ directory inside the extracted folder.
  • Execute the following command to start the axis2server with the SimpleStockQuote back-end service:

    sh axis2server.sh
    
    axis2server.bat
    

Enable the UDP transport and start the Micro-Integrator.

Send the following message via UDP to the UDP listener port (9999).

<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <soapenv:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
        <wsa:To>udp://localhost:9999/services/StockQuoteProxy</wsa:To>
        <wsa:ReplyTo>
            <wsa:Address>http://www.w3.org/2005/08/addressing/none</wsa:Address>
        </wsa:ReplyTo>
        <wsa:MessageID>urn:uuid:464d2e2a-cd47-4c63-a7c6-550c282a1e3c</wsa:MessageID>
        <wsa:Action>urn:placeOrder</wsa:Action>
    </soapenv:Header>
    <soapenv:Body>
        <m0:placeOrder xmlns:m0="http://services.samples">
            <m0:order>
                <m0:price>172.23182849731984</m0:price>
                <m0:quantity>18398</m0:quantity>
                <m0:symbol>IBM</m0:symbol>
            </m0:order>
        </m0:placeOrder>
    </soapenv:Body>
</soapenv:Envelope>
In Linux, we can save the above request in a request.xml file and use netcat to send the UDP request.

nc -u localhost 9999 < request.xml

You will see the following response in the back-end service's console:

Tue Jul 23 17:30:16 IST 2024 samples.services.SimpleStockQuoteService  :: Accepted order #1 for : 18398 stocks of IBM at $ 172.23182849731984