wso2esbapache-synapse

REST Proxy Server with Apache Synapse


Iam new to the ESB's and Apache Synapse. I have a simple REST API that takes a GET method and returns a simple json response. I tried to create a proxy with Apache Synapse.

The configuration is given below.

    <proxy name="SampeJsonProxy">
        <target>
            <endpoint>
                <address uri="http://localhost:8081/kafka/publish/hello" format="json"  methods="GET"/>
            </endpoint>
            <inSequence>
                <log level="full"/>
            </inSequence>
            <outSequence>
                <send/>
            </outSequence>
        </target>
    </proxy>

When I do a curl on the REST API I get response as

curl -v http://127.0.0.1:8081/kafka/publish/hello
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to 127.0.0.1 (127.0.0.1) port 8081 (#0)
> GET /kafka/publish/hello HTTP/1.1
> Host: 127.0.0.1:8081
> User-Agent: curl/7.55.1
> Accept: */*
>
< HTTP/1.1 200
< Content-Type: text/plain;charset=UTF-8
< Content-Length: 48
< Date: Wed, 10 Feb 2021 13:48:27 GMT
<
 {"name": "John", "age": 31, "city": "New York"}* Connection #0 to host 127.0.0.1 left intact

When I do a curl on the synapse server I get as below without response.

curl -v http://127.0.0.1:8280/kafka/publish/hello
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to 127.0.0.1 (127.0.0.1) port 8280 (#0)
> GET /kafka/publish/hello HTTP/1.1
> Host: 127.0.0.1:8280
> User-Agent: curl/7.55.1
> Accept: */*
>
< HTTP/1.1 202 Accepted
< Date: Wed, 10 Feb 2021 13:48:18 GMT
< Server: Synapse-PT-HttpComponents-NIO
< Transfer-Encoding: chunked
<
* Connection #0 to host 127.0.0.1 left intact

The log on synapse server is shown below.

INFO LogMediator To: /kafka/publish/hello, MessageID: urn:uuid:46af1619-6bbb-4fe9-b00f-2ec1e7e938a3, Direction: request

I ran the configuration by editing the synapse_sample_150.xml and replacing content with above proxy and run it as synapse.bat -sample 150.

I don't understand why this is not working. Can someone help me understand the problem. I refered the second example in the here.


Solution

  • I found the problem. I was hitting at the wrong proxy.Giving a curl at http://127.0.0.1:8280/services/SampeJsonProxy solves the gives the right output.