wso2wso2-esbwso2-enterprise-integrator

Unexpected character '{' (code 123) in prolog; expected '<' in wso2 esb


I'm making a API call to an http endpoint via API in WSO2 EI and my error is:

 Unexpected character '{' (code 123) in prolog; expected '<'

Attempting to call endpoint directly and the result is:

*   Trying IP:PORT...
* TCP_NODELAY set
* Connected to ...
> POST /source.html HTTP/1.1
> Host: IP:PORT
> User-Agent: curl/7.68.0
> Accept: */*
> Content-Type: application/x-www-form-urlencoded
> Content-Length: 63
>
* upload completely sent off: 63 out of 63 bytes
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Server: Mule EE Core Extensions/3.9.5-20230823
< Set-Cookie: Stick=R2583989947; Domain=trionline.iic.local; Path=/
< Transfer-Encoding: chunked
< Content-Type: text/json; charset=utf-8
< Date: Mon, 01 Jan 2024 10:19:52 GMT
< Keep-Alive: false
< http.version: HTTP/1.1

< X-Powered-By: Servlet/2.5 JSP/2.1
< http.status: 200
< http.request: .../resource.html
< http.headers: {Transfer-Encoding=chunked, Keep-Alive=false, Connection=false, Set-Cookie= 
[Lorg.apache.commons.httpclient.Cookie;@1f6ae621, Date=Mon, 01 Jan 2024 10:19:52 GMT, X- 
Powered-By=Servlet/2.5 JSP/2.1, Content-Type=text/json; charset=utf-8}
< http.method: POST
< http.query.params: {}
< http.query.string:
< Connection: close
<
* Closing connection 0{"token":"..."}

It seems that EI can not transfer response to text/json. how I should handle different content types in WSO2?


Solution

  • Assuming you are on Micro Integrator and the response you are getting is a valid JSON, you can add the following configuration to the deployment.toml so WSO2 will parse the content as a JSON payload.

    [[custom_message_builders]]
    content_type = "text/json"
    class="org.wso2.micro.integrator.core.json.JsonStreamBuilder"
    

    For EI add the following to the <messageBuilders> section in axis2.xml

    <messageBuilder contentType="text/json" class="org.wso2.carbon.integrator.core.json.JsonStreamBuilder"/>