Thursday, September 18, 2008

Web Services Framework for Jython Released!

WSF/Jython (Web Services Framework for Jython) is the latest addition to the impressive SOA stack at WSO2. It provides an amazingly simple approach to write web services as well as consume web services using Jython. As with all other products at WSO2, it is released under the Apache License hence you can download it and give it a try.

There are two packages that comes with this release, the server side and the client side.

Client Side Features

  • Support for invoking Web Services in a simple clean manner

  • Ability to use WS-Addressing when invoking services

  • Ability to invoke services which require WS-Security

  • Ability to send binary attachments using MTOM

Server side Features

  • Support for exposing services written in Jython

  • DataBinding support using a simple annotation mechanism

  • Automated WSDL generation

  • Ability to expose all enterprise features of Axis2 to services written in Jython
Here is one of the simplest services you could write. It contains a add method which would add two integers and return the result as an integer. The annotations are used to describe the actual data types that flow in and out of a function.
  1. #@annotate("returns=int", "operationName=add", var1="integer", var2="integer")  
  2. def add(var1,var2):  
  3.   return var1+var2  

You could refer the article Deploying Python Services for more details.

Now lets see how easy it is to write a client for the service that we just wrote.
  1. from org.wso2.wsf.jython.client import WSClient  
  2. from org.wso2.wsf.jython.client import WSFault  
  3. from org.wso2.wsf.jython.client import WSMessage  
  4.   
  5. req_payload_string = "<add><var1>1</var1><var2>2</var2></add>"  
  6. END_POINT = "http://localhost:8080/axis2/services/simpleService"  
  7.   
  8. try:  
  9.   client = WSClient({  "to" : END_POINT}, "")  
  10.   req_message = WSMessage(req_payload_string, {})  
  11.   print " Sending OM      : " , req_payload_string  
  12.   res_message = client.request(req_message)  
  13.   print " Response Message: " , res_message  
  14.   
  15. except WSFault, e:  
  16.   e.printStackTrace();  

You could execute this client by simple running the "wsfjython" shell script as follows,

sh wsfjython.sh /opt/software/wsf-jython-client-1.0-alpla/samples/myClient.py

For more details on writing clients and usage of advanced features please refer the article "Invoking Enterprise Web Services using Jython".

2 comments:

AJ said...

I have a question on the payload, our webservice - takes in username, pwd and token.
Signature:
login(username, pwd, string token)

ENDPOINT : https://sdfdsf:9300/LoginService

Now how do I know what is the payload xml ?

Thanks

Priyanka said...

need to integrate Jython web app with spring middle layer & hibernate for as backend.
is it feasible.?