In this sample the capabilities of WSO2 WSAS to handle both SOAP and Representational State Transfer (REST) will be demonstrated. These capabilities are demonstrated with the help of a web service form which a shorter URL can be obtained by submitting a longer URL
As many of you probably know we can submit a long URL and obtain a shorter URL from www.tinyurl.com.
We can simply develop a web service that provides the same functionality. The beauty of this web service is that the same service can be used by a desktop client or a web browser to obtain a URL and by a browser to go to the web page represented by the URL obtained without any additional Servlet or JSP logic or any shared database instance.
We can identify two main requirements at this point:
Any user of the service should be able to obtain a URL from the service by submitting any URL, Any user should be able to use a URL provided by the service to access the original web page.
The service will have to have two operations to support the above two scenarios.
addUrl - Allows a URL to be added to the service and provides a new URL which can be used to access the page of the original URL.go - When this operation is invoked with a URL obtained from the service it will return HTML text to that will contain the original URL in an iframe.
TUrl-Rest sample is in CARBON_HOME|samples|TinyURL folder.
To build the samples you need the Apache Ant build tool.
From there simply type ant
Buildfile: build.xml clean: [delete] Deleting directory /home/user/wso2wsas-3.1.2/samples/TinyURL/temp [delete] Deleting directory /home/user/wso2wsas-3.1.2/samples/TinyURL/services init: [mkdir] Created dir: /home/user/wso2wsas-3.1.2/samples/TinyURL/temp/TinyUrl/META-INF [mkdir] Created dir: /home/user/wso2wsas-3.1.2/samples/TinyURL/temp/classes [mkdir] Created dir: /home/user/wso2wsas-3.1.2/samples/TinyURL/services [mkdir] Created dir: /home/user/wso2wsas-3.1.2/samples/TinyURL/temp/TinyUrl/www/extensions/core compile-all: [javac] Compiling 4 source files to /home/user/wso2wsas-3.1.2/samples/TinyURL/temp/TinyUrl build-service: [copy] Copying 1 file to /home/user/wso2wsas-3.1.2/samples/TinyURL/temp/TinyUrl/META-INF [copy] Copying 2 files to /home/user/wso2wsas-3.1.2/samples/TinyURL/temp/TinyUrl/www/extensions/core [copy] Copying 1 file to /home/user/wso2wsas-3.1.2/samples/TinyURL/temp/TinyUrl/www [jar] Building jar: /home/user/wso2wsas-3.1.2/samples/TinyURL/services/TinyURL.aar build-all: [echo] Copying the created aar files in to the repository [copy] Copying 1 file to /home/user/wso2wsas-3.1.2/repository/services BUILD SUCCESSFUL Total time: 2 seconds
(See Administrator's Guide on how to sign into Management Console and to navigate through it.)
For example, if the URL we need to submit is http://wso2.org/ then, type the longer URL in the text box and submit it.
When you submit the shorter URL a HTTP GET request is sent to http://127.0.0.1:9763/services/TinyURL/addUrl with the "URL" parameter holding the longer URL.
http://localhost:9763/services/TinyURL/addUrl?url=http://www.google.com is REST call to TinyURL web service
Then you should see an URL similar to the following one:
Click the above URL to access http://www.wso2.com.