[mashup-dev] Annotating JavaScript to make JavaScript Web services
Deployment easy
Sameera Madushan Jayasoma
sameera at wso2.com
Thu Mar 1 21:21:51 PST 2007
Hi all,
Deploying a JavaScript Web services can be as simple as just deploying
the JavaScript source file without a services.xml. In this instance we
need a way to declare, what functions in the js source file, should be
exposed as Web methods. As an example, consider the following js source.
//@WebMethod
function getCurrencyCode(ipAddress){
var code = getCountry(ipAddress);
....
return currencyCode;
}
function getCountry(ipAddress){
.......
return countryName;
}
Only the function getCurrencyCode() is to be exposed as a WebMethod.
I have developed a small patch for Rhino which enable parsing the above
special comments and mark the function as a WebMethod. Then it is
possible to modify the JSDeployer written by Thilina in the following
manner to identify WebMethods.
Object[] ids = engine.getIds();
for (int i = 0; i < ids.length; i++) {
String method = (String) ids[i];
Object object = engine.get(method, engine);
- if(object instanceof Function){
+ if(object instanceof BaseFunction && ((BaseFunction)object).isWebMethod()){
AxisOperation axisOp = new InOutAxisOperation(new QName(method));
axisOp.setMessageReceiver(new JavaScriptReceiver());
axisOp.setStyle(WSDLConstants.STYLE_DOC);
axisService.addOperation(axisOp);
}
}
This patch can be extended to support the required annotations defined
in JSR-181.
Sameera
More information about the Mashup-dev
mailing list