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

# JavascriptService Sample Guide

## INTRODUCTION

We will use this sample to demonstrate the capabilities of WSO2 WSAS in terms of the flexibility in deploying services. A service could be written entirely in Javascript using the easy to use E4X (ECMAScript for XML) syntax and deployed on WSO2 WSAS.

## SCENARIO

For the sake of simplicity we will illustrate an echo service written in javascript. The javascript source is kept in the WSO2WSAS_HOME/samples/JavascriptService/js and it has the following simple piece of code.

    function echo(echoXML){
        return echoXML;
    }

Advanced services could also be implemented using Javascript functions as in the above example. The only requirement is that the return value from the javascript function should be an XML. The argument to the function is an XML and E4X syntax can be used to easily manipulate the XML to implement the business logic.

## HOW TO BUILD AND RUN THE SAMPLE

JavascriptService sample is in WSO2WSAS_HOME|samples|JavascriptService.

To build the samples you need Apache Ant build tool.

### Now follow these simple instructions:

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

       cd WSO2WSAS_HOME\samples\JavascriptService

3. From there simply type

       ant

The build automatically copies the JavascriptService.aar file containing the service into the repository. If you select the Services page in the Management Console, you should see the JavascriptService deployed. (See Administrator?s Guide on how to sign into Management Console and to navigate through it.)

#### Method 1:

- Click on the JavascriptService link and go to the Service Information page.
- From there click on the Try It link to go to the Select Port page.
- You would obtain the following page. Select the operation you want to try.
- Then from the JavascriptServiceStub generated enter a Request Value and click on the Try button. You should be able to see the received response as follows.

#### Method 2:

- If you are still in the JavascriptService directory, you will find the run-client.bat and run-client.sh files. To see the JavascriptService in action you can run the bat file on Windows or the shell file on Linux platforms.
- After running the bat/shell file, you should see the string of hard-coded XML on the command window which is echoed from the service.

## APPENDIX

- WSDL for the Echo JavascriptService - JavascriptService.wsdl