<!--
  ~ Copyright 2005-2007 WSO2, Inc. (http://wso2.com)
  ~
  ~ Licensed under the Apache License, Version 2.0 (the "License");
  ~ you may not use this file except in compliance with the License.
  ~ You may obtain a copy of the License at
  ~
  ~ http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License.
  -->

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
        "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<body>
<h1>JavascriptService Sample Guide</h1>

<h2>INTRODUCTION</h2>

<p>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 <a
        href="http://www.ecma-international.org/publications/standards/Ecma-357.htm">E4X
    (ECMAScript for XML)</a> syntax and deployed on WSO2 WSAS.</p>

<h2>SCENARIO</h2>

<p>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.</p>
<pre>function echo(echoXML){
    return echoXML;
}</pre>

<p>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.</p>

<h2>HOW TO BUILD AND RUN THE SAMPLE</h2>

<p>JavascriptService sample is in WSO2WSAS_HOME|samples|JavascriptService.</p>

<p>To build the samples you need <a href="http://ant.apache.org/">Apache
    Ant</a> build tool.</p>

<h3>Now follow these simple instructions:</h3>
<ol>
    <li>Run WSO2 WSAS. See <a
            href="installation_guide.html">Installation Guide</a> for
        installation details.
    </li>
    <li>Switch to the JavascriptService directory, e.g.</li>
    <pre>   cd WSO2WSAS_HOME\samples\JavascriptService</pre>
    <li>From there simply type</li>
    <pre>   ant</pre>

    <p>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.</p>

    <p>(See <a
            href="user_guide.html">Administrator&#x2019;s
        Guide</a> on how to sign into Management Console and to navigate through
        it.)</p>
</ol>

<h4>Method 1:</h4>
<ul>
    <li>Click on the <strong>JavascriptService</strong> link and go to the
        Service Information page.
    </li>
    <li>From there click on the <strong>Try It</strong> link to go to the
        Select Port page.
    </li>
    <li>You would obtain the following page. Select the operation you want to
        try.    <br/><br/>
        <p><img alt="Select Binding Port for service"
            src="images/js/select_operation.jpg"/></p> <br/><br/>
    </li>
    <li>Then from the <strong>JavascriptServiceStub</strong> generated enter a
        Request Value and click on the Try button. You should be able to see the
        received response as follows. <br/> <br/>
         <p>
        <img alt="Try JavascriptService" src="images/js/try.jpg"/><br/>
        </p>
        <br/><br/>
    </li>
</ul>

<h4>Method 2:</h4>
<ul>
    <li>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.
    </li>
    <li>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.
    </li>
</ul>

<h2>APPENDIX</h2>
<ul>
    <li>WSDL for the Echo JavascriptService - <a
            href="JavascriptService/wsdl/JavascriptService.wsdl">JavascriptService.wsdl</a>
    </li>
</ul>
</body>
</html>
