Walkthrough So you understand the power of adapters in Worklight and you've used the techniques from Andy's post to consume JSON services. What do you do if the endpoint you are accessing (in my case Sterling Commerce) returns XML? The good news is that Worklight has very a sensible default behaviour of converting XML to JSON for you f you simply change the returnedContentType parameter of the input object to WL.Server.invokeHttp as follows:
When working with XML results, Worklight gives you the ability to transform the results using an XSL (extensible Stylesheet Language) file to give you full control of how to convert the XML returned by your service into JSON. XSL syntax is beyond the scope of this post, but setting up the transformation is easy. Within your adapter folder, simply create a new XSL file and then develop your stylesheet. Here's mine (lastOrder.xsl):
Debugging Whilst working on this blog post, I had a few issues with connectivity between Worklight and my backend service. Here's a few tricks I learned along the way:
Use nc -l <port> and set the Adapter to connect to localhost:<port> to see the headers Worklight is sending to your server.
Worklight always appends the port to the host HTTP header, even when the port is 80. If your backend service won't tolerate that, you can override the Host header by passing a headers object in your input object.
You can enable Adapter trace in Worklight Studio by editing <Eclipse workspace location>/<project>/server/conf/development.logging.properties - uncomment two lines and add a third:
com.worklight.level = FINE java.util.logging.FileHandler.level = FINE com.worklight.adapters = FINE