This sample demonstrates the capabilities of the WSO2 Application Server to handle both SOAP and Representational State Transfer (REST) with the help of a Web service form which a shorter URL can be obtained by submitting a longer URL. The sample can be found in <AS_HOME>\samples\TinyURL directory.
You can submit a long URL and obtain a shorter URL from www.tinyurl.com. You 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. It can be used 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 instances.
Two basic requirements can be identified at this point.
The service should have two operations to fulfill the two requirements above.
To build the samples you need the Apache Ant build tool.
The steps are as follows:
2. In a command prompt, switch to the sample directory: cd <AS_HOME>\samples\TinyURL
3. From there, type ant.
The following should be displayed:
Buildfile: build.xml clean: delete Deleting directory /home/user/wso2appserver-4.1.0/samples/TinyURL/temp delete Deleting directory /home/user/wso2appserver-4.1.0/samples/TinyURL/services init: mkdir Created dir: /home/user/wso2appserver-4.1.0/samples/TinyURL/temp/TinyUrl/META-INF mkdir Created dir: /home/user/wso2appserver-4.1.0/samples/TinyURL/temp/classes mkdir Created dir: /home/user/wso2appserver-4.1.0/samples/TinyURL/services mkdir Created dir: /home/user/wso2appserver-4.1.0/samples/TinyURL/temp/TinyUrl/www/extensions/core compile-all: javac Compiling 4 source files to /home/user/wso2appserver-4.1.0/samples/TinyURL/temp/TinyUrl build-service: copy Copying 1 file to /home/user/wso2appserver-4.1.0/samples/TinyURL/temp/TinyUrl/META-INF copy Copying 2 files to /home/user/wso2appserver-4.1.0/samples/TinyURL/temp/TinyUrl/www/extensions/core copy Copying 1 file to /home/user/wso2appserver-4.1.0/samples/TinyURL/temp/TinyUrl/www jar Building jar: /home/user/wso2appserver-4.1.0/samples/TinyURL/services/TinyURL.aar build-all: echo Copying the created aar files in to the repository copy Copying 1 file to /home/user/wso2appserver-4.1.0/repository/deployment/server/axis2services BUILD SUCCESSFUL Total time: 2 seconds
The build automatically copies the .aar file containing the service into the repository.If you go to "Deployed Services" (Manage -> Services -> List) in the Application Server Management Console, you will see the "TinyUrl" service deployed.
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.wso2.com is a REST call to the "TinyURL" Web service.
Then you should see a URL similar to this: https://127.0.0.1:9443/services/TinyURL/go?id=1340973355
Click the above URL to access http://www.wso2.com.