Thursday, October 30, 2008

WSO2 Mashup Server ScreenCast #3 - Service Composition

The third of Jonathan's screen cast on the Mashup Server is now out. This edition focuses on Service Composition using the WSO2 Mashup Server. It shows how easy it is to compose services as well as demonstrates the use of E4X constructs when writing mashups.



The first edition was a helloworld followed by how the mashup server could be used to do web scraping. You could have a look at the high-res version on the WSO2 Oxygentank at,
ScreenCast - Hello World
ScreenCast - Scraping
ScreenCast - Service Composition

Tuesday, October 28, 2008

Speaking at IITC 2008 - Server-Side Mashups for enterprise SOA

I will be conducting a half-day tutorial titled "Server-Side Mashups for enterprise SOA" at the 9th International Information Technology Conference (IITC 2008) on the 30th at the University of Colombo School of Computing. This will be a beginner level tutorial where I will talk of how the WSO2 Mashup Server can be used as an enterprise integration tool.

Monday, October 27, 2008

WSO2 Mashup Server Screencast #2 - How to Scrape a Web Page

In the previous screencast Jonathan explained how you could get started with the Mashup Server with a simple Hello World Mashup. Now the second in this series of Screencast is out.



In this screencast Jonathan explains how you could scrape a web page and make that information available to tour mashup. There is a whole load of information available on the web that is not accessible via an API and screen scraping can be used to get that information into your mashups.

You could view the Hi-Resolution version of this if you have good bandwidth.

Wednesday, October 22, 2008

Is Identity a Problem in your SOA? How about Identity as a Service

SOA promises unlimited agility and organizational flexibility with a new layer of services breaking out all existing application silos. As many businesses move ahead with SOA, identity management needs to be made available as a service in the architecture in a consistent and reusable way across all applications.

Prabath Siriwardena who leads the WSO2 Identity Solution team talks about how Identity can be thought of as a Service.

Tuesday, October 21, 2008

Book on RESTfull Web Services with PHP by Samisa

Samisa Abeysinghe's book "RESTful PHP Web Services" is now available for Purchase. Learn the basic architectural concepts and step through examples of consuming and creating RESTful web services in PHP.


What you will learn from this book:
  • Basic concepts of REST architecture
  • Consuming public REST-style services from your PHP applications
  • Consuming RESTful web services, such as those from leading APIs such as Flickr, and Yahoo Web Search
  • Making your own PHP applications accessible to other applications through a RESTful API
  • REST support in the popular Zend framework
  • Debugging RESTful services and clients
  • A case study of designing a RESTful PHP service from the ground up, and designing clients to consume the service
Approach:
The book explains the basic concepts associated with the REST architectural style, but the emphasis is on creating PHP code for consuming and creating RESTful services in PHP. There is plenty of example PHP code to illustrate the concepts, with careful explanations of how the code works.
Who this book is written for:
This book targets PHP developers who want to build or make use of RESTful web services, or explore the options available to them in PHP. You will need to know the basics of PHP development, but no knowledge of REST is assumed, nor any knowledge of creating web services generally.
The book also contains a dedicated appendix chapter on using WSO2 WSF/PHP.

Sleeping on a Problem Provides Better Solutions

How true this is. I'm sure even you would have experienced this at some time or another.

"Sleep seems to nail down the information we have and reorganize the way it is stored in the brain," Prof Stickgold added. Which perhaps explains why sleeping on a problem often provides the best solution.

Read the full story here

WSO2 Mashup Server - Quick Start Guide

Channa has composed a nice little Quick Start Guide for the Mashup Server. It shows how you could get started by installing it and provisioning it and the later section cover how you could get data from a external web page using the scraper tool, how you could access a external web service using a generated stub and how you could read in a feed using the FeedReader.

Its a nice little pack that gets you started off pretty quick.

Will India's victory over Australia mark the end for Anil Kumble

Earlier today India completed a crushing victory against Australia in the second Test. India dominated this test match from day 1 and did not let the Aussies have a sniff. Notably Anil Kumble (India's Test captain) did not take the field in the second test due to injury and it was Mahendra Singh Dhoni who led India in his place.

Kumble's replacement in this test was Amit Mishra who infact made his debut in this test. The young mans performance was outstanding and he was a key reason for Australia's first innings failure. In contrast the man he replaced went wicketless in the first Test, and the media was calling for his retirement.

In my view Mishra's success in the second test plus Kumble's failure in the first could mean curtains for the international career of Kumble. Let me make no mistake Kumble had his times and in fact he is India's most successful spinner. with a test best of 10/74 Kumble has taken over 600 test sticks. But every good thing has got to come to an end and I feel that Kumbles good times are drawing to a end.

It will be interesting to see how Kumble will react to the media in the dawn of India's victory. I'm sure the media have plenty to say tomorrow...

Monday, October 20, 2008

India and Sri Lankas War agaisnt LTTE

Sanjiva has written an excellent blog asking India to stay away from interfering with Sri Lankas war against the LTTE.

Let me add a bit more to what Sanjiva had to say. If the politicians in Tamil Nadu are so worried about the innocent Tamils that are been trapped by the LTTE, why don't they pressurize the LTTE asking them to let go of the innocent civilians? The truth of the matter is that the LTTE is holding civilians in the north as a battle shield. What that would do is just delay the inevitable rather than stop it from happening.

Why is the so called INTERNATIONAL COMMUNITY keeping there eyes shut on this? Why don't they come forward and pressurize the LTTE to let go of innocent Tamil civilians? Are they just worried about the LTTE and not the innocent Tamils?

Some thoughts to ponder about....

Thursday, October 16, 2008

WSO2 Mashup Server Screencast - Getting started with a HelloWorld

The WSO2 Mashup Server is a platform for hosting mashups written in JavaScript with the E4X extension. These mashups can consume data from various sources such as feeds, HTML pages, external Web services, databases (via Data Services), Excel files (via Data Services) etc. These newly created mashups are then exposed as Web services in return.



In this Screencast, Jonathan Marsh, Director of Mashup Technologies for WSO2, demonstrates how to create a simple hello-world Web service using only the WSO2 Mashup Server and Notepad. A simple Javascript function is deployed as a Web service, WSDL and other metadata is automatically generated, and then the service is tested using the Mashup Servers try-it page. The service also shows how to quickly construct XML using the E4X Javascript extensions, and how to apply simple annotations documenting the operations and declaring parameter types.

Wednesday, October 15, 2008

Apache Synapse/WSO2 ESB calling a REST Endpoint

One of the features of Apache Synapse and the WSO2 ESB (Which is Apache Synapse + Monitoring + Management + WSO2 Registry Integration) is that it can change message formats.

There was a question on the ESB-USER mailing list recently asking how you could receive a SOAP message and send out a REST message (HTTP POST serialized as application/x-www-form-urlencoded) to another service. In order to do this you simply need to set two properties on the message. The HTTP_Method to be used and the messageType to be used. The following is a complete synapse.xml

<syn:definitions xmlns:syn="http://ws.apache.org/ns/synapse">

<syn:registry provider="org.wso2.esb.registry.ESBRegistry">

<syn:parameter name="root">file:registry/</syn:parameter>

</syn:registry>

<syn:proxy name="RESTProxy" startOnLoad="true">

<syn:target>

<syn:endpoint name="RESTEndpoint">

<syn:address uri="http://localhost:7763/services/keith/test/foo"/>

</syn:endpoint>

<syn:inSequence>

<syn:property name="messageType" value="application/x-www-form-urlencoded" scope="axis2"/>

<syn:property name="HTTP_METHOD" value="post" scope="axis2"/>

</syn:inSequence>

</syn:target>

</syn:proxy>

<syn:sequence name="main">

<syn:send/>

</syn:sequence>

<syn:sequence name="fault">

<syn:log/>

</syn:sequence>

</syn:definitions>


Here is the request sent into the ESB:

POST /soap/RESTProxy/mediate HTTP/1.1

Content-Type: application/soap+xml; charset=UTF-8; action="urn:anonOutInOp"

User-Agent: WSO2 Mashup Server - Version 1.5.1

Host: 127.0.0.1

Content-Length: 191



<?xml version='1.0' encoding='UTF-8'?>

<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">

<soapenv:Body>

<foo>

<param>keith</param>

</foo>

</soapenv:Body>

</soapenv:Envelope>


Here is its response (or Request sent out to the REST service):

POST http://localhost:7763/services/keith/test/foo HTTP/1.1
Host: 127.0.0.1
Content-Type: application/x-www-form-urlencoded; charset=UTF-8;action="urn:anonOutInOp";
Transfer-Encoding: chunked
Connection: Keep-Alive
User-Agent: Synapse-HttpComponents-NIO

b
param=keith
0

Tuesday, October 14, 2008

How to Embed Axis2 into a Existing Web Application

This article by Deepal explains how you could embed Axis2 into a Existing Web Application. Its pretty straight forward and simple. Its a good resource for anyone who is trying to expose web services out of an existing web app.

How to Create a Mock Web Service using the WSO2 ESB

One of the key features of the WSO2 ESB (Enterprise Service Bus) are Proxy Services. This post explains how you could use the proxy services feature in the WSO2 ESB to create Mock Services. These services could offer a REST interface as well as a SOAP interface.

Customer uses WSO2 products to Increase Productivity

This article shows how Concur used the WSO2 Enterprise Service Bus (WSO2 ESB) and the WSO2 Web Services Application Server (WSO2 WSAS) to increase there productivity. It also states that the solution was build in a mere 3 hours whereas it took 3 weeks to build it with pure Java. The following is a quote from the article,

"In the initial deployment, the WSO2 data services technology was able to access the database and convert data into a SOAP message in "literally two minutes," according to Svee. During a training session with WSO2, the Concur team used the "WSO2 ESB to replicate a data synchronization system in three hours that the group had previously taken three weeks to build in Java.""

Wednesday, October 8, 2008

Apache Axis2 Tips and Tricks

Recently I've been blogging extensively on some tips and tricks related to Apache Axis2. Here's a summary of them,

Axis2 - Setting the HTTP Method when sending request

Apache Axis2 supports sending (and receiving) requests over GET, POST, PUT and DELETE. This can be done by setting the "Constants.Configuration.HTTP_METHOD" property on the options object. If the HTTP Method is not set explicitly then it defaults to POST.

Most often that not when changing the HTTP Method you may want to change the serialization format as well. This can be done by setting the "Constants.Configuration.MESSAGE_TYPE" property on the options object (You can change the Serialization format even without changing the HTTP Method. For e.g Send a POX message via POST).

The following code Snippet shows how to send a message as "application/x-www-form-urlencoded" over GET.

options.setProperty(Constants.Configuration.HTTP_METHOD,HTTPConstants.HTTP_METHOD_GET);
options.setProperty(Constants.Configuration.MESSAGE_TYPE,HTTPConstants.MEDIA_TYPE_X_WWW_FORM);

Tuesday, October 7, 2008

Axis2 - Adding custom SOAP Headers to a request using ServiceClient

The Axis2 ServiceClient API provides three main ways of adding SOAP Headers to a request. Lets take a look at how this could be done,

  • Add a simple header which contains a String to the request


serviceClient.addStringHeader(new QName("http://wso2.org", "ThirdHeader"), "This is a sample Header");

This is the simplest method of adding a header. But this method restricts you to simple String headers.

  • Creating a header as a OMElement and adding it to the request


OMElement firstHeader = AXIOMUtil.stringToOM(
"This is a sample Header");
serviceClient.addHeader(firstHeader);

Users are expected to create the complete header themselves using Axiom's OMElement APIs.

  • Creating a header as a SOAPHeaderBlock and adding it to the request


OMNamespace omNamespace =
OMAbstractFactory.getOMFactory().createOMNamespace("http://wso2.com", "ws");
SOAPHeaderBlock secondHeader = OMAbstractFactory.getSOAP12Factory().createSOAPHeaderBlock("SecondHeader", omNamespace);
secondHeader.addChild(AXIOMUtil.stringToOM("This is a sample Header"));
//secondHeader.setMustUnderstand(true);
serviceClient.addHeader(secondHeader);

Users are expected to create the header using Axiom's SOAP APIs. Users could use the API to set various options on the header such as the MustUnderstand Attribute.

Monday, October 6, 2008

Axiom - How to create a OMElement from a String

If someone is using Axis2's ServiceClient to send a request to a service they will have to deal with OMElements. That is because ServiceClient accepts the payload as a OMElement. Using Axiom API's to create this OMElement could be time consuming and may take several lines of code. Alternatively users could create this OMElement from a String as follows,

OMElement payload = AXIOMUtil.stringToOM("Hi! This is a sample Request.");

This utility method that comes with Axiom takes in a String as the argument and returns an OMElement.

Axis2 - Setting custom HTTP Headers on a response

There may be instances where users would want to add a custom HTTP header to the response message in Apache Axis2. The following shows how this could be achieved,

MessageContext responseMessageContext =
MessageContext.getCurrentMessageContext().getOperationContext().getMessageContext(
WSDLConstants.MESSAGE_LABEL_OUT_VALUE);
List headers = new ArrayList();
headers.add(new Header(HTTPConstants.HEADER_CONTENT_ENCODING, "identity"));
responseMessageContext.setProperty(HTTPConstants.HTTP_HEADERS, headers);

This method could be used to add multiple headers to the response message. This also should how a service could get hold of the response message context.

Sunday, October 5, 2008

Panoramas of Beautiful Sigiriya

Sigiriya (which means Lions Rock) which is a ancient rock fortress built by King Kasyapa (477 – 495 AD) is located in the central part of Sri Lanka. Some people even call it the Eigth Wonder of the World, its that amazing. If you are traveling to Sri Lanka its a place that you must visit.

Ruwan Janapriya (A colleague of mine at WSO2) who is a great photographer has created some stunning Panoramas of of Sigiriya. There are several of them taken at various locations, some cover the beautiful paintings (frescos) of Sigiriya as well.

One of Ruwan Janapriyas Panoramas has been selected for the World Wide Panorama event 2008. Thats how good he is in Panography.

Friday, October 3, 2008

How to run Axis2 behind a proxy and Bypass the Proxy for some Domains

I'm sure some of you might already know how to set proxy details in Axis2. Even nandana had blogged about it some time ago. For those who are not familiar with it here is how you could do it. You need to add the following parameter into your clients axis2.xml,

<parameter name="Proxy">

<Configuration>

<ProxyHost>proxy.wso2.org</ProxyHost>

<ProxyPort>5678</ProxyPort>

<ProxyUser>EXAMPLE\keith</ProxyUser>

<ProxyPassword>keithsPassword</ProxyPassword>

</Configuration>

</parameter>

There may be instances where you do not want some request to go through the proxy. For e.g lets imaging you do not want to go through the proxy on a localhost call or when you are calling foo.com. Is it possible to do this? Of course and you could do it by adding the following system property "http.nonProxyHosts",

-Dhttp.nonProxyHosts=localhost|foo.com

The http.nonProxyHosts can be set to specify the hosts which should be connected to directly (not through the proxy server). The value of the http.nonProxyHosts property can be a list of hosts, each separated by | (the pipe character). It can also take a regular expression for matches for example: *.sfbay.sun.com would match any fully qualified hostname in the sfbay domain.

For more information you could refer http://java.sun.com/features/2002/11/hilevel_network.html.

Thursday, October 2, 2008

Axis2 - Calling a Service which is Protected by HTTP Basic Authentication

If you need to call a service which is protected using HTTP Basic Authentication with Apache Axis2, then you could do so by setting the following property on the options object.

HttpTransportProperties.Authenticator authenticator = new HttpTransportProperties.Authenticator();
authenticator.setUsername("keith");
authenticator.setPassword("keith");
authenticator.setPreemptiveAuthentication(true);
options.setProperty(HTTPConstants.AUTHENTICATE, authenticator);

If you are using a generated stub you could get hold of the options object as,

stub._serviceClient.getOptions();

Axis2 wsdl2java - Generate Better Code with -uw

This is a question asked regularly on the axis-user list. "Code generated by the wsdl2java tool is hard to use. Is there any better way that I can generate code?".

The answer to this is that you could actually use wsdl2java to generate better code. Lets take an example scenario. For this I will be using a Service that I have deployed on Mooshup.com. This simple service has a operation called demo which accepts three parameters (firstParam, secondParam and thirdParam). I will be using the wsdl of this service for explanation. Lets first try to use wsdl2java on this wsdl and see what happens and how -uw can help.

If i was to generate a stub for this using the following command,

sh wsdl2java.sh -uri http://mooshup.com/services/keith/DemoService?wsdl -o /home/keith/projects/demo

I would have to use this stub as follows,

DemoServiceStub stub = new DemoServiceStub();
DemoServiceStub.Demo demo = new DemoServiceStub.Demo();
DemoServiceStub.DemoType demoType = new DemoServiceStub.DemoType();
demo.setDemo(demoType);
demoType.setFirstParam("firstParam");
demoType.setSecondParam(10.0);
demoType.setThirdParam(true);
stub.demo(demo);

Now this does not look too elegant, but if I were to generate code using the -uw option with the following command,

sh wsdl2java.sh -uri http://mooshup.com/services/keith/DemoService?wsdl -o /home/keith/projects/demo -uw

I would be able to use the stub as,

DemoServiceStub stub = new DemoServiceStub();
stub.demo("firstParam", 20.0, true);

Now what is more elegant and easier? Its a easy answer.

The secret to this lies in the schema. You wont be able to generate easy to use stubs such as this all the time. What gets unwrapped (when -uw is used) is the sequence within the complex type. In our case the schema was as follows,


<xs:complexType name="demoType">

<xs:sequence>

<xs:element name="firstParam" type="xs:string" />

<xs:element name="secondParam" type="xs:double" />

<xs:element name="thirdParam" type="xs:boolean" />

</xs:sequence>

</xs:complexType>

<xs:element name="demo" type="ws:demoType" />



So the bottom line is use the -uw option when generating code with wsdl2java, this would generate code that is easy to use. (This should have been the default in wsdl2java ;))

Most users are not aware of the set of options that wsdl2java offer (Will cover that in another post).