Hi,
I tried the HelloWorld example at http://wso2.org/project/mashup/0.1/docs/index.html
When I tried modifying the mashup client to manipulate the returned XML using E4X, I found that the returned object was a DOM Element object, not an XML object, so E4X operations were not possible.
var response = helloworld.hello("<test/>");
Any idea how I can get it to a form that I can perform E4X operations on it?
Thanks and regards,
Ganesh
Use the E4X stub
Hi Ganesh,
This can be performed easily by using the E4X stub. In order to get the E4X stub all you need to do is inport the stub as <script type="text/javascript;e4x=1" src="?stub&lang=e4x"></script>
You can take a look at a details explanation on how stubs can be used in the 0.2 documentation available at http://wso2.org/project/mashup/0.2/docs/index.html (The using stubs section). I noticed you used the 0.1 version of the documentation please use the 0.2 version as its uptp date (You may even want to work with the 0.2 version of the mashup server).
Please let us know if you have any more concerns.
Thanks,
keith.
The problem isn't lack of E4X support, it's the returned object
Keith,
Thanks for the quick reply. I forgot to mention that E4X is available and working within the script. The problem is when I make the Web Service call and receive an XML object from it, I can't directly manipulate that object using E4X, because it's not of type "XML" but rather of type "Element".
I'm attaching the relevant files "groceryList.js" and "groceryPrices.js", which go directly under the scripts directory, and "index.html", which goes under "groceryList.resources/www".
I'm trying to do a mashup to enhance a simple grocery list (items and required quantities) with prices taken from another service, so that the individual rows as well as the overall list have dollar amounts included.
If you comment out the two web service calls from index.html and uncomment the direct setting of the two variables gList and gPrices, you can see it working in Firefox by just reading it off the filesystem (no need for a server).
Regards,
Ganesh
Hi Ganesh, I noted that you
Hi Ganesh,
I noted that you have use the default stub. The default stub we genarate uses dom as it needs to be compatible with both IE and firefox if you need the E4X stub you should include this as follows,
<script type="text/javascript;e4x=1" src="../groceryList?stub&lang=e4x"></script>
<script type="text/javascript;e4x=1" src="../groceryPrices?stub&lang=e4x"></script>
Also I noticed a bug in the E4X stub and fixed it. Your mashup works fine now, you can try this with the nightly build at http://ww2.wso2.org/~builder/mashup/
Thanks,
Keith.
Thanks!
Thanks, it works now. Of course, the XML document is now an inner element, without the surrounding <response> tags, which changed one of my E4X expressions. But that's not a major problem.
Let me play with this for a while :-).
Ganesh
You can use annotations to make better use of the stub
Hi Ganesh,
Nice to hear that its working for you now. You can make better use of the stubs by using .inputTypes and .outputType annotations (These are used to customize the inputs and outputs of your JS function, these type details are then taken into the genarated WSDL and hence the stubs get these information). Please let us now if you need any help.
Thanks,
Keith.
Even more fixed ;-)
As I was reviewing Keith's fix I also encountered the inappropriate stripping of the <response> element. I checked in a fix for that as well.
While testing my fixes I also created an async client version of your mashup, which I'll paste in here in case it proves useful. You'll also notice the new stubs don't require you to rewrite the address in order to use the service from localhost - that is now built into the stub itself.
Thanks for trying out the Mashup Server and let us know if you encounter anything else that you like, dislike, or causes problems for you.
<script type="text/javascript">
var gList = "", gPrices = "";
function listDone(response) {
gList = response;
if (gPrices != "") complete();
}
function pricesDone(response) {
gPrices = response;
if (gList != "") complete();
}
groceryList.getList.callback = listDone;
groceryList.getList();
groceryPrices.getPrices.callback = pricesDone;
groceryPrices.getPrices();
function complete() {
alert ( gPrices );
alert ( gList );
var total = 0.0;
for each ( i in gList.descendants("line-item") )
{
i.@amount = i.@qty * gPrices..prod.(@id==i.@prod)["@unit-price"];
total += Number( i.@amount );
}
gList..order["total-amt"] = total;
alert( gList );
}
</script>
P.S. getting the fix
P.S. if you don't want to wait until tomorrow's nightly build to use the fixed stub, just download a copy from http://wso2.org/repos/wso2/trunk/commons/dynamic-codegen/src/jsstub.xslt and place it in {wso2-mashup}/lib folder. Simply refresh the browser and you'll get the corrected stub.