Thursday, September 25, 2008

HTTP Content Negotiation with Apache Axis2

Since the 1.3 release of Axis2, it supports HTTP Content Negotiation. It is not turned on by default but can be done so by adding the following parameter to your axis2.xml.

<parameter name="httpContentNegotiation">true</parameter>

Axis2 does not honor the content-type text/xml when its in the Accept Header. This is because the content-type text/xml is primarily used for SOAP 1.1 but when a request is sent via the browser it has the Accept header as "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 ". If we were to honor text/xml this would result in a SOAP 1.1 response. Not too good for a REST scenario ha! This is the result of the same content-type (text/xml) been used for two message formats (SOAP 1.1 and POX).

Now lets get back to HTTP Content Negotiation with Apache Axis2. Performing a GET request on the version service would result in the following request and response. You could capture them by using TCPMonitor.


Now try editing the Accept header to "application/json/badgerfish". You should have enabled JSON support for this to work. This would result in,


A blog post on how to enable JSON on Axis2 will follow. This configuration can be used to enable HTTP Content Negotiation on WSO2 WSAS as well as the Mashup Server. It should work with Synapse and the WSO2 ESB too but I haven't checked it.

Wednesday, September 24, 2008

Mashup Server as a Teaching Tool

I've been involved in quite a few trainings in the recent past. Both on Axis2 as well as the Mashup Server. The newest on the list was a "Introduction to WSDL 2.0" training that I conducted yesterday. One of the cool tools that I have used in all these trainings is the Mashup Server. The Mashup Server makes it amazingly simple to to create services in a matter of minutes, whats more there is a bunch of resources thats auto-generate for each service.

For e.g I used my RESTDemo mashup extensively to describe how WSDL 2.0 enables REST.

Note : The RESTDemo Mashup does not cover all capabilities of WSDL 2.0. I intend to do a comprehensive write up of this soon.

One might wonder how the Mashup Server helps teach a person Axis2? Well to be frank the Mashup Server is a highly customized version of Axis2. We've used quite a few extension points in Axis2 to make the Mashup Server what it is. Hence its a great case study for the customizability of Axis2.

Saturday, September 20, 2008

WSO2 Data Services 1.0 Released!

The title says it all, after months of hard work the 1.0 version of the WSO2 Data Services Solution is out. This version of Data Services is based on carbon, which is based on OSGI. There were quite a lot of challenges that the Data Services team had to undergo in order to pull of this release.

Some key features of this release are,
  • Built-in Connection pooling support
  • Aggregate data from multiple data sources
  • Support for exposing Stored procedures & functions
  • Built-in caching to enhance performance
  • Throttling to ensure that your database is never overloaded
  • Secured access to data
  • Reliable delivery of messages
It also come with an eclipse IDE plugin.

For those who are not familiar with WSO2 Data Services is, it is a way to expose data locked up in Data Bases, Excel files or CSV files as Web Services in a matter of minutes. And it requires zero code (You could either use the wizard that comes with it or simple use your favorite editor to write your configuration).

Sumedha's blog has quite a few tips on Data Services. From doing basic stuff to more advanced scenarios.

As with all products at WSO2 the Data Services Solution is shipped under the Apache License. Download it and try it out.

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.

#@annotate("returns=int", "operationName=add", var1="integer", var2="integer")
def add(var1,var2):
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.

from org.wso2.wsf.jython.client import WSClient
from org.wso2.wsf.jython.client import WSFault
from org.wso2.wsf.jython.client import WSMessage

req_payload_string = "12"
END_POINT = "http://localhost:8080/axis2/services/simpleService"

try:
client = WSClient({ "to" : END_POINT}, "")
req_message = WSMessage(req_payload_string, {})
print " Sending OM : " , req_payload_string
res_message = client.request(req_message)
print " Response Message: " , res_message

except WSFault, e:
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".

WSF/PHP - Use Cases Discussed

Katie having a discussion with Shankar (Lead developer of WSF/PHP) on what WSF/PHP (Web Services Framework for PHP) can be used for at ZendCon 2008.



WSF/PHP 2.0 was released just a few days ago.

Wednesday, September 17, 2008

Expose and Invoke Mashups over JMS

My article on Exposing and Invoking mashups using SOAP/POX over JMS with the WSO2 Mashup Server has been published on the WSO2 developers portal for SOA. It talks about how you could invoke mashups running on a WSO2 Mashup server over JMS and also how you could send JMS messages using a Mashup running on the server. You would me amazed to see how easy it is. The article contains sample code which help you get going in minutes.

JMS plays an important part in most enterprises and this open the door for enterprise mashups using the Mashup Server.

Get Twitter Friends Time Line Using a Mashup

Milinda has posted how to Get Your Twitter Friends Time Line Using libcurl. I thought of publishing a alternative mechanism to doing it. How about getting your twitter friends time line using the WSO2 Mashup Server? Well is pretty simple and straight forward. Here is the code (Just a few lines of code),

function getTwitterFriendsTimeline(){
var request = new WSRequest();
request.open("GET","http://twitter.com/statuses/friends_timeline.xml?count=5", false, "username","password");
request.send(null);
return request.responseE4X;
}

Pretty simple ha! If you wanted you could have published this on mooshup and have it run for you 24*7 for you. Of course you might want to do something with this data to make it a useful mashup.