Error consuming json service

preben's picture
im not able to use a json response in mashup. Error: org.apache.axis2.AxisFault: com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character '{' (code 123) in prolog; expected '<' at [row,col {unknown-source}]: [2,2] example getNowNext.safe = true; getNowNext.httpMethod = "GET"; getNowNext.outputType = "xml"; function getNowNext() { var nownext = new WSRequest(); var options = new Array(); options.useSOAP = false; options.HTTPMethod = "GET"; options.HTTPInputSerialization = "application/json" nownext.open(options, "http://somejsonresponseurl",false); var request = null; nownext.send(request); return nownext.responseXML; } axis2.xml has been set to use messageformatters : and messagebuilders I have created a jira MASHUP-1354 for this. As it seems to be an error. Are there any workarounds? Thanks Preben
tyrell's picture

Hi, You can use the new

Hi, You can use the new HTTPClient Host Object (http://wso2.org/project/mashup/2.1.0/docs/httpclienthostobject.html) for these types of services. The above problem with WSRequest HS occurs due it sending every response through the XML parser. If the end-point you are invoking is RESTy and might return non-xml, HTTPClient HS is the best alternative. Tyrell
preben's picture

I have been looking at that

I have been looking at that at it works. Now I only need a nifty way of converting json back to xml, so I can expose it as a composite mashup xml service. HttpClient doesnt't support something like responseXML. Do you have any other suggestions on how to convert from json to xml in a mashup ? Thanks Preben
tyrell's picture

Here's a sample javascript

Here's a sample javascript code that converts a string to E4X. var my-variable = new XML('xml-string-here'); Also have a look at http://wso2.org/project/mashup/2.0.2/docs/e4xquickstart.html for more E4X tips and tricks :) Tyrell
preben's picture

Yes well the problem is that

Yes well the problem is that json needs to be converted back to xml before I can use it as a XML var for further mashup. So the task is to have a function jsonToXML. Preben
library project main code
Learn Cloud
Learn
Cloud

The WSO2 Application Server is a reliable application server that can host your enterprise web applications. The WSO2 Application Server as a Service is offered in StratosLive, the WSO2 Platform as a Service. This article explains how a simple web application can be developed and deployed from Carbon Studio to the WSO2 Application Server...

Latest Webinar
Different groups within an organization need to monitor different Key Performance Indicators (KPIs) - An operations team will be interested in the response times of business services and loads of each service,..
Thursday, February 9th 2012, 09.00 AM (PST)

Thursday, February 9th 2012, 10.00 AM (GMT)