I'm trying to create a mashup in WSO2 AS 5.1.0. I have managed to succesfully create a simple HelloWorld service, however when I try to integrate other service into it, I get an error.
This is my HelloWorld service:
this.documentation = "This is a test Hello World service";
system.include("HelloStub.js");
hello.documentation = "say hello"
hello.inputTypes = {"user": "string"}
hello.outputType = "string";
function hello(user){
try{
var response = services["admin/testmashup"].operations["sayMyName"](user);
}catch(e){
return "Danger, Robinson! " + e.toString()
}
return "Hello, there! " + response;
}
function whoAreYou(){
try{
var response = services["admin/testmashup"].operations["toString"]();
}catch(e){
return "Danger, Robinson! " + e.toString()
}
return "Hello! " + response;
}
And this is the admin/testmashup
service
this.serviceName = "testmashup";
this.documentation = "Test mashup service" ;
toString.documentation = "say something" ;
toString.inputTypes = { /* no arguments */ };
toString.outputType = "string";
function toString()
{
return "Hi, my name is testmashup";
}
sayMyName.documentation = "Make me feel happy";
sayMyName.inputTypes = {"myName":"string"};
sayMyName.outputType = "string";
function sayMyName(myName){
return "Your very beautiful name is " + myName;
}
I must note that when I call the admin/testmashup
service, it works as expected.
The file HelloStub.js
is a Javascript (E4X) stub, generated by the WSO2 Applicanton Server.
When I test the operation whoAreYou
, which has no arguments, I get the following response:
<ws:whoAreYouResponse xmlns:ws="http://services.mashup.wso2.org/helloWorld?xsd">
<return xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:js="http://www.wso2.org/ns/jstype" js:type="string" xsi:type="xs:string">Hello! <ws:toStringResponse xmlns:ws="http://services.mashup.wso2.org/testmashup?xsd"><return>Hi, my name is testmashup</return></ws:toStringResponse></return>
</ws:whoAreYouResponse>
I can see the text Hi, my name is testmashup
within the encoded response. But when I try to call hello
, with the following xml:
<body>
<p:hello xmlns:p="http://services.mashup.wso2.org/helloWorld?xsd">
<!--Exactly 1 occurrence-->
<user>John</user>
</p:hello>
</body>
I get the following error:
<ws:helloResponse xmlns:ws="http://services.mashup.wso2.org/helloWorld?xsd">
<return>Danger, Robinson! org.wso2.carbon.CarbonException: Invalid input for the payload in WSRequest Hostobject : John</return>
</ws:helloResponse>
I have tried to make this work for the last couple of days and have searched all over the place for an answer, but I can't seem to find it. The official documentation does not provide an example using stubs of external webservices that have operations with one or more arguments.
Also, if it is possible, I would like to know how to consume REST-JSON services from a javascript mashup.
Any ideas?