Documentation

##### WSO2 WSAS 2.2-RC1

- Release Notes
- Contents
- Home

##### Downloads

- Releases

##### Documentation

- User Guide
- FAQs
- Installation Guide
- Source
- Running Behind a Proxy
- Data Services Guide
  - RDBMS Data Source
  - CSV Data Source
  - Excel Data Source
  - JNDI Data Source
- EJB Guide
- Clustering Guide
- JMX Guide
- XKMS Guide
- Changing Keys

##### Samples

- Chad
- Commodity Quote
- Data Services
- Flickr
- Javascript
- Jaxws
- JiBX
- Mtom
- STS
- Trader
- Tiny URL
- Metadata Exchange
- WS-Transfer
- XML Key Managment Specification
- Cluster Management

##### API Documentation

- Java Docs

##### Tools

- Code Generation
- Change Password
- Eclipse IDE Integration
- TCP Monitor
- WSDL2Code
- WSDL View
- Try It
- AAR Validation
- MAR Validation

##### Resources

- News

##### Get Involved

- Mailing Lists
- Integration

##### Project Information

- Project Team
- Issue Tracking
- License

# TinyURL Sample Guide

## INTRODUCTION

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

## SCENARIO

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.

## HOW TO BUILD AND RUN THE SAMPLE

TUrl-Rest sample is in WSO2WSAS_HOME|samples|TinyURL folder.

To build the samples you need the Apache Ant build tool.

### Now Follow The Simple Instructions:

1. Run WSO2 WSAS. See Installation Guide for installation details.
2. Switch to the TinyURL directory, e.g.

         cd WSO2WSAS_HOME/samples/TinyURL

3.     From there simply type
         ant

#### You should see messages like this:

    Buildfile: build.xml

    clean:
       [delete] Deleting directory /home/user/wso2wsas-2.0/samples/TinyURL/temp
       [delete] Deleting directory /home/user/wso2wsas-2.0/samples/TinyURL/services

    init:
        [mkdir] Created dir: /home/user/wso2wsas-2.0/samples/TinyURL/temp/TinyUrl/META-INF
        [mkdir] Created dir: /home/user/wso2wsas-2.0/samples/TinyURL/temp/classes
        [mkdir] Created dir: /home/user/wso2wsas-2.0/samples/TinyURL/services
        [mkdir] Created dir: /home/user/wso2wsas-2.0/samples/TinyURL/temp/TinyUrl/www/extensions/core

    compile-all:
        [javac] Compiling 4 source files to /home/user/wso2wsas-2.0/samples/TinyURL/temp/TinyUrl

    build-service:
         [copy] Copying 1 file to /home/user/wso2wsas-2.0/samples/TinyURL/temp/TinyUrl/META-INF
         [copy] Copying 2 files to /home/user/wso2wsas-2.0/samples/TinyURL/temp/TinyUrl/www/extensions/core
         [copy] Copying 1 file to /home/user/wso2wsas-2.0/samples/TinyURL/temp/TinyUrl/www
          [jar] Building jar: /home/user/wso2wsas-2.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/wso2wsas-2.0/repository/services

    BUILD SUCCESSFUL
    Total time: 2 seconds

The build automatically copies the .aar file containing the service into the repository.
1. If you select the Services page in the Management Console, you should now see the TinyUrl service deployed. If you don't see it, try clicking the 'Services' menu on the right column of the Management Console.

   (See Administrator’s Guide on how to sign into Management Console and to navigate through it.)

### Let’s illustrate the above options using an example:

For example, if the URL we need to submit is http://www.wso2.com 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:9762/rest/TinyURL/addUrl with the "URL" parameter holding the longer URL.

http://localhost:9762/rest/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:

https://127.0.0.1:9443/rest/TinyURL/go?id=1340973355

Click the above URL to access http://www.wso2.com.