Monday, February 16, 2015

A possible reason and solution for getting 400 Bad Request even when the synapse configuration in WSO2 ESB is correct

Sometimes you might spend lot of time in analyzing the reason for getting 400 bad request when you invoke an up and running backend service through WSO2 ESB.

When you configure and save the synapse configuration of your proxy, you will not see any issue. But sometimes there can a possible reason for this issue.

One good example is explained below :

Look at the below synapse configuration of WSO2 ESB proxy service.

 <proxy name="statuscodeProxy"
          transports="https http"
            <log level="full"/>
                  <address uri=""/>
            <log level="full"/>

By the look of it, this is alright and you are good to configure it in WSO2 ESB. But the endpoint defined as : is not exactly the endpoint the backend service expects.

Sometimes there can be missing parameters etc. But if you exactly know your backend service does not expect any parameters and still it throws a 400 bad reques, can you imagine the reason for this?

After spending hours, I accidently found a possible reason :

 it was due to the backend expects a / at the end of the endpoint. So it expects : except

If you configure a tcpmon in between ESB and the backend, you will see the difference as below : :  GET  HTTP/1.1  - 400 bad Request : GET / HTTP/1.1  - 200 OK

So if you too come across this situation, please try out this option. Sometimes this might save your time! :)