<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-5735449966988481504</id><updated>2012-01-08T23:20:44.256-08:00</updated><category term='XML'/><category term='JavaScript'/><category term='JSON'/><category term='Badgerfish'/><title type='text'>BACKED UP MEMORIES</title><subtitle type='html'>It's me, it's all about ....? better you decide yourselves</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://ruchirawageesha.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5735449966988481504/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://ruchirawageesha.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>wageesha</name><uri>http://www.blogger.com/profile/06227183882522305231</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/_FBxc7ILPVV8/SsW6Hduf6XI/AAAAAAAAACE/l9GDzujJIHg/S220/img_4008.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>31</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-5735449966988481504.post-6450211407108163315</id><published>2011-12-02T06:20:00.000-08:00</published><updated>2011-12-02T07:07:44.208-08:00</updated><title type='text'>Invoking secured web services with WSO2 Mashup Server</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;WSO2 Mashup Server is based on WSO2 Carbon Platform which is then built on top of Apache Axis2 engine. Apache Rampart is the security module of Axis2. It secures SOAP messages according to specifications in the WS-Security stack. When you create a complex mashup which invokes many enterprise level web services, then WS* security will be a key concern.&lt;br /&gt;&lt;br /&gt;Using WSRequest hostobject of the Mashup Server, you can easily access web services secured with many security scenarios. You can either dynamically pick the policy from the service wsdl or set it manually.&lt;br /&gt;&lt;br /&gt;In both cases, you can set all the rampart related configurations using a simple json object notation. In this post, I have described how you can use WSO2 Mashup Server to invoke secured services from a mashup.&lt;br /&gt;&lt;br /&gt;All the samples described here can be deployed on WSO2 Mashup Server 2.3.3 or above which can be downloaded from &lt;a href="http://wso2.org/downloads/mashup-server/"&gt;here&lt;/a&gt;. &lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;&lt;b&gt;Structure of the Keystores&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Lets consider an encryption scenario as below.&lt;br /&gt;&lt;br /&gt;&lt;i&gt;&lt;b&gt;Request Flow&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;When, client invokes the service, it encrypt the payload using client’s private key. Then at the server, it should have client’s public key certificate in order to decrypt the payload.&lt;br /&gt;&lt;br /&gt;&lt;i&gt;&lt;b&gt;Response Flow&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;When server sends back the response to the client, server uses its private key to encrypt the response. Then the client who invoked the secured service should have the public key certificate of the server to decrypt the response.&lt;br /&gt;&lt;br /&gt;Likewise, depending on the security policies being used between client and server, it will need to have client’s public key certificate in at the server and server’s public key certificate at the client. But for several other scenarios, a trusted third party certificate might be used.&lt;br /&gt;&lt;br /&gt;Anyway, we are going to have the following structure in our client and server keystore as it will be used to test all the scenarios available via Mashup Server’s management console.&lt;br /&gt;&lt;br /&gt;&lt;h3 id="client"&gt;&lt;span style="font-size: small;"&gt;&lt;i&gt;client.jks (password - &lt;b&gt;client&lt;/b&gt;)&lt;/i&gt;&lt;/span&gt;&lt;/h3&gt;&lt;table border="1"&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;alias&lt;/th&gt;     &lt;th&gt;key&lt;/th&gt;     &lt;/tr&gt;&lt;/thead&gt;     &lt;tbody&gt;&lt;tr&gt;         &lt;td&gt;client&lt;/td&gt;         &lt;td&gt;client's private key (password - client)&lt;/td&gt;     &lt;/tr&gt;&lt;tr&gt;         &lt;td&gt;server&lt;/td&gt;         &lt;td&gt;server's public key&lt;/td&gt;     &lt;/tr&gt;&lt;/tbody&gt; &lt;/table&gt;&lt;h3 id="server"&gt;&lt;span style="font-size: small;"&gt;&lt;i&gt;&amp;nbsp;&lt;/i&gt;&lt;/span&gt;&lt;/h3&gt;&lt;h3 id="server"&gt;&lt;span style="font-size: small;"&gt;&lt;i&gt;server.jks (password - &lt;b&gt;server&lt;/b&gt;)&lt;/i&gt;&lt;/span&gt;&lt;/h3&gt;&lt;table border="1"&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;alias&lt;/th&gt;     &lt;th&gt;key&lt;/th&gt;     &lt;/tr&gt;&lt;/thead&gt;     &lt;tbody&gt;&lt;tr&gt;         &lt;td&gt;server&lt;/td&gt;         &lt;td&gt;server's private key (password - server)&lt;/td&gt;     &lt;/tr&gt;&lt;tr&gt;         &lt;td&gt;client&lt;/td&gt;         &lt;td&gt;client's public key&lt;/td&gt;     &lt;/tr&gt;&lt;/tbody&gt; &lt;/table&gt;&lt;br /&gt;&lt;b&gt;Generating keystores&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Please follow &lt;a href="http://ruchirawageesha.blogspot.com/2010/07/how-to-create-clientserver-keystores.html"&gt;this post&lt;/a&gt; and create &lt;b&gt;client.jks&lt;/b&gt; and &lt;b&gt;server.jks&lt;/b&gt; with the structure&lt;br /&gt;described above.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;&lt;b&gt;Creating a sample mashup to be used as the service&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;In this tutorial, I will use a simple mashup as the secured service. i.e A mashup which takes a string name as the input and responds a greeting for that name, will be created and deployed in WSO2 Mashup Server. Once we deployed any mashup in WSO2 Mashup Server, it will behave as any other Axis2 service. Then, we can easily do most of the administrative tasks we want using management console.&lt;br /&gt;&lt;br /&gt;So, please create a mashup with the content below. &lt;br /&gt;&lt;pre class="prettyprint lang-js"&gt;this.serviceName = "helloService";&lt;br /&gt;    function sayHello(name) {&lt;br /&gt;    return "Hello " + name "!";&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;span style="font-size: large;"&gt;&lt;b&gt;Creating mashup client&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;i&gt;Introduction to WSRequest Hostobject&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;The WSRequest object is similar to the XMLHTTPRequest object. Its usage typically involves specifying the endpoint address and setting up options on how to frame the message, invoking the operation with a specific XML payload, and then checking and extracting information from the result.&lt;br /&gt;&lt;br /&gt;It can also be considered as the Javascript wrapper for Axis2 ServiceClient which allows to do web service invocation. So, in WSO2 Mashup Server, the Web Service client is WSRequest. You can invoke services either synchronously or asynchronous, send custom HTTP/SOAP headers and even secure services invocation from a mashup with the help of WSRequest Hostobject.&lt;br /&gt;&lt;br /&gt;Following is the Javascript interface of the WSRequest Hostobject. For more information please refer &lt;a href="http://wso2.org/project/mashup/2.3.0/docs/wsrequesthostobject.html"&gt;this&lt;/a&gt;.&lt;br /&gt;&lt;pre class="prettyprint lang-js"&gt;{&lt;br /&gt;    property EventListener onreadystatechange;&lt;br /&gt;    property unsigned short readyState;&lt;br /&gt;    function void open ( object options | String httpMethod, String url [, boolean async [, String username[, String password]]]);&lt;br /&gt;    function void send ( XML payload | XMLString payload ); // To be used when the open method of WSRequest is used&lt;br /&gt;    function void openWSDL ( String wsdlURL, ?boolean async, [Object options,[QName serviceName, [String endpointName]]]);&lt;br /&gt;    function void send ( String operationName | QName operationName, XML payload | XMLString payload ); //To be used when the openWSDL method of WSRequest is used&lt;br /&gt;    readonly property String responseText;&lt;br /&gt;    readonly property Document responseXML;&lt;br /&gt;    readonly property XML responseE4X;&lt;br /&gt;    readonly property WebServiceError error;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;i&gt;&lt;b&gt;Invoking the sample Service&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;Here I will describe how you can use WSRequest Hostobject to invoke a web service. You can find more information about service invocation using WSRequest Hostobject at Mashup Server’s documentation pages. But it would be better to write the client mashup to work with a normal service before extending it to access a secured service.&lt;br /&gt;&lt;br /&gt;Following code fragment will invoke the above deployed HelloService and return the response. In the following client, the payload has been hard coded for the simplicity.&lt;br /&gt;&lt;pre class="prettyprint lang-js"&gt;function invokeService(){&lt;br /&gt;    var client = new WSRequest();&lt;br /&gt;    var options = new Array();&lt;br /&gt;    options["useSOAP"] = 1.2;&lt;br /&gt;    options["action"] = "urn:sayHello";&lt;br /&gt;&lt;br /&gt;    var payload =&lt;br /&gt;    &amp;lt;sayHello&amp;gt;&lt;br /&gt;        &amp;lt;name&amp;gt;Ruchira&amp;lt;/name&amp;gt;&lt;br /&gt;    &amp;lt;/sayHello&amp;gt;;&lt;br /&gt;&lt;br /&gt;    var result;&lt;br /&gt;&lt;br /&gt;    try {&lt;br /&gt;        client.open(options,"http://localhost:9763/services/admin/helloService", false);&lt;br /&gt;        client.send(payload);&lt;br /&gt;        result = client.responseE4X;&lt;br /&gt;    } catch (e) {&lt;br /&gt;        system.log(e.toString(),"error");&lt;br /&gt;        return e.toString();&lt;br /&gt;    }&lt;br /&gt;    return result;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;Create a file named helloClient.js in repository/deployment/server/jsservice/admin directory and add the above code fragment. Once you invoke the "Tryit" page of the newly created service, you should get the "Hello Ruchira!" greeting from the service.&lt;br /&gt;&lt;br /&gt;Once you succeed with the above step, you can move to the next step which secures the helloService and modifies helloClient to invoke the secured service.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;&lt;b&gt;Secure Services&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Secured Web services can be categorized into following forms depending on the method they used.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: small;"&gt;&lt;b&gt;&lt;i&gt;HTTP Basic Auth&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Your service might have been secured using HTTP Basic Authentication. In that case, you can simply pass the username and password into the open() method of WSRequest Hostobject and invoke the service.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;i&gt;WS-Security&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;In most of the Enterprise level use-cases, HTTP Basic Authentication might not be a good solution, then WS-Security comes into the picture. Using WS-Security, you can have a greater flexibility with your service security. So, most of the today’s services are based on WS-Security.&lt;br /&gt;&lt;br /&gt;Likewise, a web service can be secured either with HTTP Basic Authentication or using WS-Security. WSRequest hostobject can be used to invoke services secured with any of the above methods.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;&lt;b&gt;Securing the mashup service&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Uploading Keystore into WSO2 Mashup Server&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Go to Configure &amp;gt; Keystores&lt;/li&gt;&lt;li&gt;Go through "Add New Key store" wizard and add the server.jks created above&lt;/li&gt;&lt;/ol&gt;&lt;/li&gt;&lt;li&gt;Apply a security scenario using Management Console&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Go to Main &amp;gt; Manage &amp;gt; Web Services &amp;gt; List&lt;/li&gt;&lt;li&gt;Select the above created service i.e. "helloService" and click on "Unsecured" link on the service listing&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Go through the security engaging wizard and engage one of the scenarios listed there&lt;/li&gt;&lt;/ol&gt;&lt;/li&gt;&lt;li&gt;View the WSDL&lt;br /&gt;&lt;ol&gt;&lt;li&gt;If you view the WSDL 1.0 or 2.0 of the service now, you will be able to see the newly applied policy in&lt;br /&gt;the WSDL.&lt;br /&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/li&gt;&lt;/ul&gt;&lt;span style="font-size: large;"&gt;&lt;b&gt;Invoking secured service&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;WSRequest Hostobject offers two methods to deal with security. If you know the policy being used in the service, then you can use open() method and set the policy manually. If you don’t, then you can use openWSDL() method which will then extract the policy definition from the given WSDL and invoke the service. But performance wise, open() method is more better than openWSDL() as openWSDL method always read the WSDL before invoking the service.&lt;br /&gt;&lt;br /&gt;&lt;i&gt;&lt;b&gt;open() method&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;Method signature is as bellow. &lt;br /&gt;&lt;pre class="prettyprint lang-js"&gt;function void open ( object options | String httpMethod, String url [, boolean async [, String username[, String password]]])&lt;br /&gt;&lt;/pre&gt;When you use this method to invoke a secured service, then you have two options as below.&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Specify policy definition with rampart configuration as an E4X XML object in the options object using "policy" property. You can also use ${resources.dir} to specify the path of the resources folder in keystore paths. i.e. Assume your keystore named client.jks is in *.resources folder, then you can use&lt;b&gt; ${resources.dir}/client.jks&lt;/b&gt; as the keystore path in your rampart configuration.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Specify policy definition using "policy" property and rampart configuration as a JSON object using "rampart" property. The structure of the rampart configuration JSON has been described under the section named "Rampart&lt;br /&gt;Configuration" below. Here, you don’t need to specify rampart configuration in policy definition.&lt;br /&gt;&lt;/li&gt;&lt;/ol&gt;In both cases, you can also keep the policy definition as a separate XML file within your resources folder and set it to "policy" property by creating an XML object with the help of File Hostobject.&lt;br /&gt;&lt;br /&gt;If you are invoking an HTTP Basic Authentication enabled service, then just passing the username and password as method parameters would be sufficient and "policy" and "rampart" properties won’t need to be specified.&lt;br /&gt;&lt;pre class="prettyprint lang-js"&gt;var options = new Object();&lt;br /&gt;…..&lt;br /&gt;options["policy"] =&lt;br /&gt;&amp;lt;Policy&amp;gt;.....&amp;lt;/Policy&amp;gt;;&lt;br /&gt;options["rampart"] = { ….. };&lt;br /&gt;…..&lt;br /&gt;wsRequest.open(options, serviceUrl, false);&lt;br /&gt;&lt;/pre&gt;Please refer WSRequest documentation at [2] for more information about other input parameters and properties of the options object.&lt;br /&gt;&lt;br /&gt;&lt;i&gt;&lt;b&gt;openWSDL() method &lt;/b&gt;&lt;/i&gt;&lt;br /&gt;&lt;pre class="prettyprint lang-js"&gt;function void openWSDL ( String wsdlURL, ?boolean async, [Object options,[QName serviceName, [String endpointName]]]);&lt;br /&gt;&lt;/pre&gt;When openWSDL() method is used, you need to specify the URL of the secured service WSDL. Then it will read the WSDL and find the attached policy definitions from it. In this case, you only need to specify the "rampart" property in your options object.&lt;br /&gt;&lt;br /&gt;Specifying "policy" property too, will override the policy definition extracted from the WSDL.&lt;br /&gt;&lt;br /&gt;&lt;i&gt;&lt;b&gt;Rampart Configuration&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;Following is the format of the rampart configuration JSON. Dummy values and comments have been added to explain it more precisely.&lt;br /&gt;&lt;br /&gt;&lt;pre class="prettyprint lang-js"&gt;{&amp;nbsp;&lt;br /&gt;    user : "admin", //username for to use UT and other scenarios&lt;br /&gt;    userPassword : "admin", //in UT, this is the user password&lt;br /&gt;    keyPassword : "client", //private key password&lt;br /&gt;    userCertAlias : "client",&lt;br /&gt;    stsAlias : "sts",&lt;br /&gt;    encryptionUser : "server",&lt;br /&gt;    timestampTTL : "10000",&lt;br /&gt;    timestampMaxSkew : "10",&lt;br /&gt;    timestampPrecisionInMilliseconds : "100",&lt;br /&gt;    signatureCrypto : {&lt;br /&gt;        type : "jks", //keystore type&lt;br /&gt;        file : "client.jks", //keystore file relative to resource folder&lt;br /&gt;        password : "client", //keystore password&lt;br /&gt;        enableCryptoCaching : true,&lt;br /&gt;        cacheRefreshInterval : 3000&lt;br /&gt;    },&lt;br /&gt;    encryptionCrypto : {&lt;br /&gt;        type : "jks", //keystore type&lt;br /&gt;        file : "client.jks", //keystore file relative to resource folder&lt;br /&gt;        password : "client", //keystore password&lt;br /&gt;        enableCryptoCaching : true,&lt;br /&gt;        cacheRefreshInterval : 3000&lt;br /&gt;    },&lt;br /&gt;    decryptionCrypto : {&lt;br /&gt;        type : "jks", //keystore type&lt;br /&gt;        file : "client.jks", //keystore file relative to resource folder&lt;br /&gt;        password : "client" //keystore password&lt;br /&gt;    },&lt;br /&gt;    stsCrypto : {&lt;br /&gt;        type : "jks", //keystore type&lt;br /&gt;        file : "client.jks", //keystore file relative to resource folder&lt;br /&gt;        password : "client" //keystore password&lt;br /&gt;    },&lt;br /&gt;    kerberosConfig : {&lt;br /&gt;        /**&lt;br /&gt;        "key" : "value" properties, you can also use ${resources.dir}&lt;br /&gt;        in property values&lt;br /&gt;        */&lt;br /&gt;        "client.principal.name" : "client",&lt;br /&gt;        "client.principal.password" : "client",&lt;br /&gt;        "service.principal.name" : "service",&lt;br /&gt;        "java.security.auth.login.config" : "jassconfig",&lt;br /&gt;        "javax.security.auth.useSubjectCredsOnly" : "true",&lt;br /&gt;        "kdc.des.aes.factor" : "4",&lt;br /&gt;        "java.security.krb5.conf" : "/home/ruchira/wso2/conf"&lt;br /&gt;    }&lt;br /&gt;}&amp;nbsp;&lt;/pre&gt;&lt;span style="font-size: large;"&gt;&lt;b&gt;Secure Client using Open() method&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;(you need to set the correct scenario xml there in the line number 6)&lt;br /&gt;&lt;pre class="prettyprint lang-js"&gt;function invokeSecureServiceOpen() {&lt;br /&gt;    /**&lt;br /&gt;    * Reads the policy.xml from resources folder and creates&lt;br /&gt;    * E4X XML object from it&lt;br /&gt;    */&lt;br /&gt;    var policyFile = new File("scenarios/scenario2-policy.xml");&lt;br /&gt;    policyFile.openForReading();&lt;br /&gt;    var policy = new XML(policyFile.readAll());&lt;br /&gt;&lt;br /&gt;    var client = new WSRequest();&lt;br /&gt;    var options = new Array();&lt;br /&gt;    options["useSOAP"] = 1.2;&lt;br /&gt;    options["action"] = "urn:sayHello";&lt;br /&gt;    options["policy"] = policy;&lt;br /&gt;    options["rampart"] = {&lt;br /&gt;        user : "admin", //username for to use UT and other scenarios&lt;br /&gt;        userPassword : "admin", //in UT, this is the user password&lt;br /&gt;        keyPassword : "client", //private key password&lt;br /&gt;        userCertAlias : "client",&lt;br /&gt;        encryptionUser : "server",&lt;br /&gt;        signatureCrypto : {&lt;br /&gt;            type : "jks", //keystore type&lt;br /&gt;            file : "client.jks", //keystore file relative to resource folder&lt;br /&gt;            password : "client", //keystore password&lt;br /&gt;            enableCryptoCaching : true,&lt;br /&gt;            cacheRefreshInterval : 3000&lt;br /&gt;        },&lt;br /&gt;        encryptionCrypto : {&lt;br /&gt;            type : "jks", //keystore type&lt;br /&gt;            file : "client.jks", //keystore file relative to resource folder&lt;br /&gt;            password : "client", //keystore password&lt;br /&gt;            enableCryptoCaching : true,&lt;br /&gt;            cacheRefreshInterval : 3000&lt;br /&gt;        },&lt;br /&gt;        decryptionCrypto : {&lt;br /&gt;            type : "jks", //keystore type&lt;br /&gt;            file : "client.jks", //keystore file relative to resource folder&lt;br /&gt;            password : "client" //keystore password&lt;br /&gt;        },&lt;br /&gt;        stsCrypto : {&lt;br /&gt;            type : "jks", //keystore type&lt;br /&gt;            file : "client.jks", //keystore file relative to resource folder&lt;br /&gt;            password : "client" //keystore password&lt;br /&gt;        }&lt;br /&gt;    };&lt;br /&gt;&lt;br /&gt;    var payload =&lt;br /&gt;    &amp;lt;sayHello&amp;gt;&lt;br /&gt;        &amp;lt;name&amp;gt;Ruchira&amp;lt;/name&amp;gt;&lt;br /&gt;    &amp;lt;/sayHello&amp;gt;;&lt;br /&gt;&lt;br /&gt;    var result;&lt;br /&gt;&lt;br /&gt;    try {&lt;br /&gt;        client.open(options,"http://localhost:9763/services/admin/helloService", false);&lt;br /&gt;        client.send(payload);&lt;br /&gt;        result = version.responseE4X;&lt;br /&gt;    } catch (e) {&lt;br /&gt;        system.log(e.toString(),"error");&lt;br /&gt;        return e.toString();&lt;br /&gt;    }&lt;br /&gt;    return result;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;span style="font-size: large;"&gt;&lt;b&gt;Secure Client using openWSDL() method&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;pre class="prettyprint lang-js"&gt;function invokeSecureServiceOpenWSDL() {&lt;br /&gt;    var client = new WSRequest();&lt;br /&gt;    var options = new Array();&lt;br /&gt;    options["useSOAP"] = 1.2;&lt;br /&gt;    options["action"] = "urn:sayHello";&lt;br /&gt;    options["rampart"] = {&lt;br /&gt;    user : "admin", //username for to use UT and other scenarios&lt;br /&gt;    userPassword : "admin", //in UT, this is the user password, else private key&lt;br /&gt;    keyPassword : "client", //private key password&lt;br /&gt;    userCertAlias : "client",&lt;br /&gt;    encryptionUser : "server",&lt;br /&gt;    signatureCrypto : {&lt;br /&gt;            type : "jks", //keystore type&lt;br /&gt;            file : "client.jks", //keystore file relative to resource folder&lt;br /&gt;            password : "client", //keystore password&lt;br /&gt;            enableCryptoCaching : true,&lt;br /&gt;            cacheRefreshInterval : 3000&lt;br /&gt;        },&lt;br /&gt;        encryptionCrypto : {&lt;br /&gt;            type : "jks", //keystore type&lt;br /&gt;            file : "client.jks", //keystore file relative to resource folder&lt;br /&gt;            password : "client", //keystore password&lt;br /&gt;            enableCryptoCaching : true,&lt;br /&gt;            cacheRefreshInterval : 3000&lt;br /&gt;        },&lt;br /&gt;        decryptionCrypto : {&lt;br /&gt;            type : "jks", //keystore type&lt;br /&gt;            file : "client.jks", //keystore file relative to resource folder&lt;br /&gt;            password : "client" //keystore password&lt;br /&gt;        },&lt;br /&gt;        stsCrypto : {&lt;br /&gt;            type : "jks", //keystore type&lt;br /&gt;            file : "client.jks", //keystore file relative to resource folder&lt;br /&gt;            password : "client" //keystore password&lt;br /&gt;        }&lt;br /&gt;    };&lt;br /&gt;&lt;br /&gt;    var payload =&lt;br /&gt;    &amp;lt;sayHello&amp;gt;&lt;br /&gt;        &amp;lt;name&amp;gt;Ruchira&amp;lt;/name&amp;gt;&lt;br /&gt;    &amp;lt;/sayHello&amp;gt;;&lt;br /&gt;&lt;br /&gt;    var result;&lt;br /&gt;&lt;br /&gt;    try {&lt;br /&gt;        var service = new QName("http://services.mashup.wso2.org/helloService","helloService");&lt;br /&gt;        request.openWSDL("http://localhost:9763/services/admin/helloService?wsdl", false, options, service, "SOAP12Endpoint");&lt;br /&gt;        request.send("sayHello", payload);&lt;br /&gt;        result = version.responseE4X;&lt;br /&gt;    } catch (e) {&lt;br /&gt;        system.log(e.toString(),"error");&lt;br /&gt;        return e.toString();&lt;br /&gt;    }&lt;br /&gt;    return result;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;span style="font-size: large;"&gt;&lt;b&gt;Testing the service&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;After successfully created the two operations with open and openWSDL methods, now you can invoke the client service using it’s tryit page which will then invoke the secured "helloService".&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5735449966988481504-6450211407108163315?l=ruchirawageesha.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ruchirawageesha.blogspot.com/feeds/6450211407108163315/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ruchirawageesha.blogspot.com/2011/12/blog-post.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5735449966988481504/posts/default/6450211407108163315'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5735449966988481504/posts/default/6450211407108163315'/><link rel='alternate' type='text/html' href='http://ruchirawageesha.blogspot.com/2011/12/blog-post.html' title='Invoking secured web services with WSO2 Mashup Server'/><author><name>wageesha</name><uri>http://www.blogger.com/profile/06227183882522305231</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/_FBxc7ILPVV8/SsW6Hduf6XI/AAAAAAAAACE/l9GDzujJIHg/S220/img_4008.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5735449966988481504.post-1038994448041546774</id><published>2011-06-16T03:19:00.000-07:00</published><updated>2011-08-05T02:00:23.130-07:00</updated><title type='text'>XML to JSON and JSON to XML Conversion in Javascript</title><content type='html'>When we deal with today's highly ajax based web application developments, dealing with XMLs within your page might be a little bit tedious task. As all of us know, JavaScript doesn't have a proper way to deal with XMLs(although recent specs supports E4X, it hasn't implemented in all browsers). If we can convert the XML into a JSON format, then it will be a great relief for web developers.&lt;br /&gt;&lt;br /&gt;Although there are many XML to JSON notations available, all of them tends to ignore xml namespaces, but Badgerfish. So, I thought of writing a JavaScript code which does the XML to JSON conversion and wise-versa. If you want to get the Javascript code for XML to JSON, then go though my blog post &lt;a href="http://ruchirawageesha.blogspot.com/2011/01/xml-to-badgerfish-converter-in.html"&gt;XML to BadgerFish Conversion in Javascript&lt;/a&gt;. In this post, I will give you the function which converts JSON back to it's original XML.&lt;br /&gt;&lt;br /&gt;Using these &lt;a href="http://ruchirawageesha.blogspot.com/2011/01/xml-to-badgerfish-converter-in.html"&gt;xml2bf&lt;/a&gt; and bf2xml functions, you will get the most flexibility with XML in your web developments.&lt;br /&gt;&lt;pre class="prettyprint lang-js"&gt;function bf2xml(json) {&lt;br /&gt;    if (typeof json !== "object") return null;&lt;br /&gt;    var cloneNS = function(ns) {&lt;br /&gt;        var nns = {};&lt;br /&gt;        for (var n in ns) {&lt;br /&gt;            if (ns.hasOwnProperty(n)) {&lt;br /&gt;                nns[n] = ns[n];&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;        return nns;&lt;br /&gt;    };&lt;br /&gt;    var processLeaf = function(lname, child, ns) {&lt;br /&gt;        var body = "";&lt;br /&gt;        if (child instanceof Array) {&lt;br /&gt;            for (var i = 0; i &lt; child.length; i++) {&lt;br /&gt;                body += processLeaf(lname, child[i], cloneNS(ns));&lt;br /&gt;            }&lt;br /&gt;            return body;&lt;br /&gt;        } else if (typeof child === "object") {&lt;br /&gt;            var el = "&amp;lt;" + lname;&lt;br /&gt;            var attributes = "";&lt;br /&gt;            var text = "";&lt;br /&gt;            if (child["@xmlns"]) {&lt;br /&gt;                var xmlns = child["@xmlns"];&lt;br /&gt;                for (var prefix in xmlns) {&lt;br /&gt;                    if (xmlns.hasOwnProperty(prefix)) {&lt;br /&gt;                        if (prefix === "$") {&lt;br /&gt;                            if (ns[prefix] !== xmlns[prefix]) {&lt;br /&gt;                                attributes += " " + "xmlns=\"" + xmlns[prefix] + "\"";&lt;br /&gt;                                ns[prefix] = xmlns[prefix];&lt;br /&gt;                            }&lt;br /&gt;                        } else if (!ns[prefix] || (ns[prefix] !== xmlns[prefix])) {&lt;br /&gt;                            attributes += " xmlns:" + prefix + "=\"" + xmlns[prefix] + "\"";&lt;br /&gt;                            ns[prefix] = xmlns[prefix];&lt;br /&gt;                        }&lt;br /&gt;                    }&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;            for (var key in child) {&lt;br /&gt;                if (child.hasOwnProperty(key) &amp;&amp; key !== "@xmlns") {&lt;br /&gt;                    var obj = child[key];&lt;br /&gt;                    if (key === "$") {&lt;br /&gt;                        text += obj;&lt;br /&gt;                    } else if (key.indexOf("@") === 0) {&lt;br /&gt;                        attributes += " " + key.substring(1) + "=\"" + obj + "\"";&lt;br /&gt;                    } else {&lt;br /&gt;                        body += processLeaf(key, obj, cloneNS(ns));&lt;br /&gt;                    }&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;            body = text + body;&lt;br /&gt;            return (body !== "") ? el + attributes + "&amp;gt;" + body + "&amp;lt;/" + lname + "&amp;gt;" : el + attributes + "/&amp;gt;"&lt;br /&gt;        }&lt;br /&gt;    };&lt;br /&gt;    for (var lname in json) {&lt;br /&gt;        if (json.hasOwnProperty(lname) &amp;&amp; lname.indexOf("@") == -1) {&lt;br /&gt;            return processLeaf(lname, json[lname], {});&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    return null;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5735449966988481504-1038994448041546774?l=ruchirawageesha.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ruchirawageesha.blogspot.com/feeds/1038994448041546774/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ruchirawageesha.blogspot.com/2011/06/xml-to-json-and-json-to-xml-conversion.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5735449966988481504/posts/default/1038994448041546774'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5735449966988481504/posts/default/1038994448041546774'/><link rel='alternate' type='text/html' href='http://ruchirawageesha.blogspot.com/2011/06/xml-to-json-and-json-to-xml-conversion.html' title='XML to JSON and JSON to XML Conversion in Javascript'/><author><name>wageesha</name><uri>http://www.blogger.com/profile/06227183882522305231</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/_FBxc7ILPVV8/SsW6Hduf6XI/AAAAAAAAACE/l9GDzujJIHg/S220/img_4008.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5735449966988481504.post-2849379519663952199</id><published>2011-04-28T06:35:00.000-07:00</published><updated>2011-06-17T05:38:11.782-07:00</updated><title type='text'>How to increase JVM Heap Size and Perm Gen space</title><content type='html'>If you are dealing with applications which have large code bases, then you might quickly run out of Java memory. Probably you might get either java.lang.OutOfMemoryError: PermGen or java.lang.OutOfMemoryError: Java heap space. In order to fix that, just having sufficient memory in your machine is not sufficient. So you need to increase the JVM Heap size and Permanent Generation space.&lt;br /&gt;&lt;br /&gt;Setting the following environment variable before starting your application, you can increase them easily.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Unix&lt;/span&gt;&lt;br /&gt;&lt;pre class="prettyprint lang-sh"&gt;export JAVA_OPTS="-Xms512m -Xmx1024m -XX:MaxPermSize=1024m"&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Windows&lt;/span&gt;&lt;br /&gt;&lt;pre class="prettyprint lang-sh"&gt;set JAVA_OPTS="-Xms512m -Xmx1024m -XX:MaxPermSize=1024m"&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5735449966988481504-2849379519663952199?l=ruchirawageesha.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ruchirawageesha.blogspot.com/feeds/2849379519663952199/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ruchirawageesha.blogspot.com/2011/04/how-to-increase-jvm-heap-size-and-perm.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5735449966988481504/posts/default/2849379519663952199'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5735449966988481504/posts/default/2849379519663952199'/><link rel='alternate' type='text/html' href='http://ruchirawageesha.blogspot.com/2011/04/how-to-increase-jvm-heap-size-and-perm.html' title='How to increase JVM Heap Size and Perm Gen space'/><author><name>wageesha</name><uri>http://www.blogger.com/profile/06227183882522305231</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/_FBxc7ILPVV8/SsW6Hduf6XI/AAAAAAAAACE/l9GDzujJIHg/S220/img_4008.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5735449966988481504.post-4214764881970892591</id><published>2011-04-28T06:28:00.000-07:00</published><updated>2011-06-17T05:41:49.156-07:00</updated><title type='text'>How to Remote Debug on Apache Tomcat</title><content type='html'>If you want to debug on your application on Apache Tomcat, then you might need to set the following environment variables and start Tomcat using the command below where 8000 is the port that you are going to connect from your IDE.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Windows&lt;/span&gt;&lt;br /&gt;&lt;pre class="prettyprint lang-sh"&gt;set JPDA_ADDRESS=8000&lt;br /&gt;set JPDA_TRANSPORT=dt_socket&lt;br /&gt;&lt;br /&gt;bin/catalina.bat jpda start&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Unix&lt;/span&gt;&lt;br /&gt;&lt;pre class="prettyprint lang-sh"&gt;export JPDA_ADDRESS=8000&lt;br /&gt;export JPDA_TRANSPORT=dt_socket&lt;br /&gt;&lt;br /&gt;bin/catalina.sh jpda start&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5735449966988481504-4214764881970892591?l=ruchirawageesha.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ruchirawageesha.blogspot.com/feeds/4214764881970892591/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ruchirawageesha.blogspot.com/2011/04/how-to-remote-debug-on-apache-tomcat.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5735449966988481504/posts/default/4214764881970892591'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5735449966988481504/posts/default/4214764881970892591'/><link rel='alternate' type='text/html' href='http://ruchirawageesha.blogspot.com/2011/04/how-to-remote-debug-on-apache-tomcat.html' title='How to Remote Debug on Apache Tomcat'/><author><name>wageesha</name><uri>http://www.blogger.com/profile/06227183882522305231</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/_FBxc7ILPVV8/SsW6Hduf6XI/AAAAAAAAACE/l9GDzujJIHg/S220/img_4008.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5735449966988481504.post-7579998652375976359</id><published>2011-02-22T05:07:00.000-08:00</published><updated>2011-06-17T05:43:31.427-07:00</updated><title type='text'>Parse XML String into DOM with Javascript</title><content type='html'>You can use following function to convert any XML string into a DOM object from a browser.&lt;br /&gt;&lt;pre  class="prettyprint lang-js"&gt;function parseXML(xml) {&lt;br /&gt;    xml = xml.replace(/^[\s\n\r\t]*[&lt;][\?][xml][^&lt;^&gt;]*[\?][&gt;]/, "");&lt;br /&gt;    var doc;&lt;br /&gt;    if (window.ActiveXObject) {&lt;br /&gt;        doc = new ActiveXObject("Microsoft.XMLDOM");&lt;br /&gt;        doc.async = false;&lt;br /&gt;        doc.loadXML(xml);&lt;br /&gt;    } else&lt;br /&gt;        doc = (new DOMParser()).parseFromString(xml, "application/xml");&lt;br /&gt;    return doc;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5735449966988481504-7579998652375976359?l=ruchirawageesha.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ruchirawageesha.blogspot.com/feeds/7579998652375976359/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ruchirawageesha.blogspot.com/2011/02/parse-xml-string-into-dom-with.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5735449966988481504/posts/default/7579998652375976359'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5735449966988481504/posts/default/7579998652375976359'/><link rel='alternate' type='text/html' href='http://ruchirawageesha.blogspot.com/2011/02/parse-xml-string-into-dom-with.html' title='Parse XML String into DOM with Javascript'/><author><name>wageesha</name><uri>http://www.blogger.com/profile/06227183882522305231</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/_FBxc7ILPVV8/SsW6Hduf6XI/AAAAAAAAACE/l9GDzujJIHg/S220/img_4008.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5735449966988481504.post-7185887963601651388</id><published>2011-02-22T04:47:00.000-08:00</published><updated>2011-02-22T04:52:25.571-08:00</updated><title type='text'>Online XML to JSON Converter using Badgerfish Notation</title><content type='html'>I have hosted an online XML to JSON converter at &lt;a href="http://gogooog.com"&gt;http://gogooog.com&lt;/a&gt;. It has been implemented purely with Javascript. You can read about the xml to &lt;a href="http://www.sklar.com/badgerfish/"&gt;badgerfish&lt;/a&gt; conversion at &lt;a href="http://ruchirawageesha.blogspot.com/2011/01/xml-to-badgerfish-converter-in.html"&gt;http://ruchirawageesha.blogspot.com/2011/01/xml-to-badgerfish-converter-in.html&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5735449966988481504-7185887963601651388?l=ruchirawageesha.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ruchirawageesha.blogspot.com/feeds/7185887963601651388/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ruchirawageesha.blogspot.com/2011/02/online-xml-to-json-converter-using.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5735449966988481504/posts/default/7185887963601651388'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5735449966988481504/posts/default/7185887963601651388'/><link rel='alternate' type='text/html' href='http://ruchirawageesha.blogspot.com/2011/02/online-xml-to-json-converter-using.html' title='Online XML to JSON Converter using Badgerfish Notation'/><author><name>wageesha</name><uri>http://www.blogger.com/profile/06227183882522305231</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/_FBxc7ILPVV8/SsW6Hduf6XI/AAAAAAAAACE/l9GDzujJIHg/S220/img_4008.jpg'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5735449966988481504.post-6300235955028972947</id><published>2011-01-28T02:52:00.000-08:00</published><updated>2011-06-20T03:03:27.441-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JavaScript'/><category scheme='http://www.blogger.com/atom/ns#' term='Badgerfish'/><category scheme='http://www.blogger.com/atom/ns#' term='JSON'/><category scheme='http://www.blogger.com/atom/ns#' term='XML'/><title type='text'>XML to BadgerFish Conversion in Javascript</title><content type='html'>Recently I came across the need of converting an xml into a JSON format. There I used &lt;a href="http://www.sklar.com/badgerfish/"&gt;BadgerFish&lt;/a&gt; notation to transform the xml into JSON.&lt;br /&gt;&lt;br /&gt;You can use following Javascript function to convert any DOM node into the relevant BadgerFish notation. You can convert any XML string into a DOM object using method described at &lt;a href="http://ruchirawageesha.blogspot.com/2011/02/parse-xml-string-into-dom-with.html"&gt;Parse XML String into DOM with Javascript&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Please find the hosted version of XML to Badgerfish converter at &lt;a href="http://gogooog.com"&gt;gogooog.com&lt;/a&gt;&lt;br /&gt;&lt;pre class="prettyprint lang-js"&gt;function xml2bf(node) {&lt;br /&gt;    var json = {};&lt;br /&gt;    var cloneNS = function(ns) {&lt;br /&gt;        var nns = {};&lt;br /&gt;        for (var n in ns) {&lt;br /&gt;            if (ns.hasOwnProperty(n)) {&lt;br /&gt;                nns[n] = ns[n];&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;        return nns;&lt;br /&gt;    };&lt;br /&gt;    var process = function (node, obj, ns) {&lt;br /&gt;        if (node.nodeType === 3) {&lt;br /&gt;            if (!node.nodeValue.match(/[\S]+/)) return;&lt;br /&gt;            if (obj["$"] instanceof Array) {&lt;br /&gt;                obj["$"].push(node.nodeValue);&lt;br /&gt;            } else if (obj["$"] instanceof Object) {&lt;br /&gt;                obj["$"] = [obj["$"], node.nodeValue];&lt;br /&gt;            } else {&lt;br /&gt;                obj["$"] = node.nodeValue;&lt;br /&gt;            }&lt;br /&gt;        } else if (node.nodeType === 1) {&lt;br /&gt;            var p = {};&lt;br /&gt;            var nodeName = node.nodeName;&lt;br /&gt;            for (var i = 0; node.attributes &amp;&amp; i &lt; node.attributes.length; i++) {&lt;br /&gt;                var attr = node.attributes[i];&lt;br /&gt;                var name = attr.nodeName;&lt;br /&gt;                var value = attr.nodeValue;&lt;br /&gt;                if (name === "xmlns") {&lt;br /&gt;                    ns["$"] = value;&lt;br /&gt;                } else if (name.indexOf("xmlns:") === 0) {&lt;br /&gt;                    ns[name.substr(name.indexOf(":") + 1)] = value;&lt;br /&gt;                } else {&lt;br /&gt;                    p["@" + name] = value;&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;            for (var prefix in ns) {&lt;br /&gt;                if (ns.hasOwnProperty(prefix)) {&lt;br /&gt;                    p["@xmlns"] = p["@xmlns"] || {};&lt;br /&gt;                    p["@xmlns"][prefix] = ns[prefix];&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;            if (obj[nodeName] instanceof Array) {&lt;br /&gt;                obj[nodeName].push(p);&lt;br /&gt;            } else if (obj[nodeName] instanceof Object) {&lt;br /&gt;                obj[nodeName] = [obj[nodeName], p];&lt;br /&gt;            } else {&lt;br /&gt;                obj[nodeName] = p;&lt;br /&gt;            }&lt;br /&gt;            for (var j = 0; j &lt; node.childNodes.length; j++) {&lt;br /&gt;                process(node.childNodes[j], p, cloneNS(ns));&lt;br /&gt;            }&lt;br /&gt;        } else if (node.nodeType === 9) {&lt;br /&gt;            for (var k = 0; k &lt; node.childNodes.length; k++) {&lt;br /&gt;                process(node.childNodes[k], obj, cloneNS(ns));&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    };&lt;br /&gt;    process(node, json, {});&lt;br /&gt;    return json;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5735449966988481504-6300235955028972947?l=ruchirawageesha.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ruchirawageesha.blogspot.com/feeds/6300235955028972947/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ruchirawageesha.blogspot.com/2011/01/xml-to-badgerfish-converter-in.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5735449966988481504/posts/default/6300235955028972947'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5735449966988481504/posts/default/6300235955028972947'/><link rel='alternate' type='text/html' href='http://ruchirawageesha.blogspot.com/2011/01/xml-to-badgerfish-converter-in.html' title='XML to BadgerFish Conversion in Javascript'/><author><name>wageesha</name><uri>http://www.blogger.com/profile/06227183882522305231</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/_FBxc7ILPVV8/SsW6Hduf6XI/AAAAAAAAACE/l9GDzujJIHg/S220/img_4008.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5735449966988481504.post-2300614120231446856</id><published>2011-01-26T22:00:00.000-08:00</published><updated>2011-01-26T22:06:22.620-08:00</updated><title type='text'>All about Javascript Functions</title><content type='html'>If you're a Javascript fan, it's worth reading &lt;a href="http://devlicio.us/blogs/sergio_pereira/archive/2009/02/09/javascript-5-ways-to-call-a-function.aspx"&gt;JavaScript, 5 ways to call a function&lt;/a&gt; which nicely explains must to know concepts behind Javascript functions.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5735449966988481504-2300614120231446856?l=ruchirawageesha.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ruchirawageesha.blogspot.com/feeds/2300614120231446856/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ruchirawageesha.blogspot.com/2011/01/all-about-javascript-functions.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5735449966988481504/posts/default/2300614120231446856'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5735449966988481504/posts/default/2300614120231446856'/><link rel='alternate' type='text/html' href='http://ruchirawageesha.blogspot.com/2011/01/all-about-javascript-functions.html' title='All about Javascript Functions'/><author><name>wageesha</name><uri>http://www.blogger.com/profile/06227183882522305231</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/_FBxc7ILPVV8/SsW6Hduf6XI/AAAAAAAAACE/l9GDzujJIHg/S220/img_4008.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5735449966988481504.post-7237754548914158564</id><published>2010-10-02T21:32:00.000-07:00</published><updated>2011-06-17T05:59:26.500-07:00</updated><title type='text'>How to build mod_v8 in Ubuntu</title><content type='html'>&lt;a href="http://journal.paul.querna.org/articles/2008/12/23/mod_v8/"&gt;mod_v8&lt;/a&gt; is a simple Apache module which enable Server Side JavaScript(SSJS) support in Apache Server. It uses Google V8 engine for the JavaScript execution. What this module basically does is, it adds a Handler for a particular file extension(.v8) and then, those files are treated as SSJS files which then get executed via V8 engine.&lt;br /&gt;&lt;br /&gt;While I was building this amazing mod_v8 module, I had to do small modification to the process. So I though it might be worth to have a post with the steps I followed.&lt;br /&gt;&lt;br /&gt;1. Checkout V8 development branch&lt;br /&gt;&lt;pre class="prettyprint lang-sh"&gt;svn checkout http://v8.googlecode.com/svn/branches/bleeding_edge/ v8&lt;/pre&gt;&lt;br /&gt;2. Build V8 using &lt;span style="font-style:italic;"&gt;scons&lt;/span&gt; with the &lt;span style="font-style:italic;"&gt;library=shared&lt;/span&gt; option. Optionally you might need to add arch option too. You can find more info about it at &lt;a href="http://ruchirawageesha.blogspot.com/2010/10/building-v8-in-ubuntu-64-bit.html"&gt;Building V8 in Ubuntu 64 bit&lt;/a&gt;&lt;br /&gt;&lt;pre class="prettyprint lang-sh"&gt;scons library=shared arch=x64&lt;/pre&gt;&lt;br /&gt;3. Assuming your v8 checkout is at &lt;span style="font-style:italic;"&gt;/home/wageesha/v8&lt;/span&gt;, building process will create following obj, libv8.so etc.. directories and files within v8 directory. You need to copy this libv8.so into /usr/lib.&lt;br /&gt;&lt;pre class="prettyprint lang-sh"&gt;cp ~/wageesha/v8/libv8.so /usr/lib&lt;/pre&gt;&lt;br /&gt;4. Checkout mod_v8 code&lt;br /&gt;&lt;pre class="prettyprint lang-sh"&gt;svn checkout https://svn.i-want-a-pony.com/repos/mod_v8/trunk/ mod_v8&lt;/pre&gt;&lt;br /&gt;5. Build mod_v8 using &lt;span style="font-weight:bold;"&gt;scons&lt;/span&gt;. Depending on your scons version, you might need to change&lt;br /&gt;&lt;pre class="prettyprint lang-sh"&gt;opts = Options('build.py') into opts = Variables('build.py')&lt;/pre&gt;and&lt;br /&gt;&lt;pre class="prettyprint lang-sh"&gt;opts.Add(PathOption(....)) into opts.Add(PathVariable(....))&lt;/pre&gt;&lt;br /&gt;in the SConstruct. Further, if you haven't copied libv8.so into the &lt;span style="font-style:italic;"&gt;/usr/lib&lt;/span&gt; directory as in step 3, build process will fail saying&lt;br /&gt;&lt;pre class="prettyprint lang-sh"&gt;/usr/bin/ld: cannot find -lv8&lt;/pre&gt;&lt;br /&gt;6. Then open &lt;span style="font-style:italic;"&gt;/etc/apache2/apache2.conf&lt;/span&gt; and add following lines, with the correct path to libmod_v8.so&lt;br /&gt;&lt;pre class="prettyprint lang-sh"&gt;LoadModule v8_module /home/wageesha/mod_v8/trunk/libmod_v8.so&lt;br /&gt;&lt;br /&gt;&amp;lt;IfModule mod_v8.cpp&amp;gt;&lt;br /&gt;#Adds the v8 handler&lt;br /&gt;AddHandler v8-script .v8&lt;br /&gt;&amp;lt;/IfModule&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;7. Copy &lt;span style="font-style:italic;"&gt;/home/wageesha/mod_v8/trunk/test.v8&lt;/span&gt; into &lt;span style="font-style:italic;"&gt;/var/www&lt;/span&gt; folder.&lt;br /&gt;&lt;br /&gt;8. Restart apache and access test.v8&lt;br /&gt;&lt;pre class="prettyprint"&gt;http://localhost/test.v8&lt;/pre&gt;&lt;br /&gt;which will then print&lt;br /&gt;&lt;pre class="prettyprint"&gt;Hello World!&lt;/pre&gt;&lt;br /&gt;in the browser.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5735449966988481504-7237754548914158564?l=ruchirawageesha.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ruchirawageesha.blogspot.com/feeds/7237754548914158564/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ruchirawageesha.blogspot.com/2010/10/how-to-build-modv8-in-ubuntu.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5735449966988481504/posts/default/7237754548914158564'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5735449966988481504/posts/default/7237754548914158564'/><link rel='alternate' type='text/html' href='http://ruchirawageesha.blogspot.com/2010/10/how-to-build-modv8-in-ubuntu.html' title='How to build mod_v8 in Ubuntu'/><author><name>wageesha</name><uri>http://www.blogger.com/profile/06227183882522305231</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/_FBxc7ILPVV8/SsW6Hduf6XI/AAAAAAAAACE/l9GDzujJIHg/S220/img_4008.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5735449966988481504.post-919403462267727531</id><published>2010-10-01T00:11:00.000-07:00</published><updated>2011-06-17T06:01:52.101-07:00</updated><title type='text'>Building V8 in Ubuntu 64 bit</title><content type='html'>If you are trying to build Google V8 in a Ubuntu 64bit machine you might get &lt;br /&gt;&lt;pre class="prettyprint lang-sh"&gt;/usr/include/gnu/stubs.h:7:27: error: gnu/stubs-32.h: No such file or directory&lt;/pre&gt;error when you ran scons with default arguments. When default arguments are used, it tries to guess the OS. In my case it failed to detect the correct architecture (i.e. x64). So you can specify &lt;span style="font-weight:bold;"&gt;arch&lt;/span&gt; argument when you run the &lt;span style="font-weight:bold;"&gt;scons&lt;/span&gt; to manually set the architecture. i.e.&lt;br /&gt;&lt;pre class="prettyprint lang-sh"&gt;scons arch=x64&lt;/pre&gt;&lt;span style="font-weight:bold;"&gt;arch&lt;/span&gt; argument accepts any of &lt;span style="font-weight:bold;"&gt;arm&lt;/span&gt;, &lt;span style="font-weight:bold;"&gt;ia32&lt;/span&gt;, &lt;span style="font-weight:bold;"&gt;x64&lt;/span&gt; or &lt;span style="font-weight:bold;"&gt;mips&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5735449966988481504-919403462267727531?l=ruchirawageesha.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ruchirawageesha.blogspot.com/feeds/919403462267727531/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ruchirawageesha.blogspot.com/2010/10/building-v8-in-ubuntu-64-bit.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5735449966988481504/posts/default/919403462267727531'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5735449966988481504/posts/default/919403462267727531'/><link rel='alternate' type='text/html' href='http://ruchirawageesha.blogspot.com/2010/10/building-v8-in-ubuntu-64-bit.html' title='Building V8 in Ubuntu 64 bit'/><author><name>wageesha</name><uri>http://www.blogger.com/profile/06227183882522305231</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/_FBxc7ILPVV8/SsW6Hduf6XI/AAAAAAAAACE/l9GDzujJIHg/S220/img_4008.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5735449966988481504.post-2090713455880786619</id><published>2010-07-30T00:18:00.000-07:00</published><updated>2010-07-30T00:23:12.821-07:00</updated><title type='text'>JSON to XML and XML to JSON convertion using Javascript</title><content type='html'>Following link will provide you a better implementation to convert JSON data into XML and vice versa just using Javascript.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://goessner.net/download/prj/jsonxml/"&gt;http://goessner.net/download/prj/jsonxml/&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5735449966988481504-2090713455880786619?l=ruchirawageesha.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ruchirawageesha.blogspot.com/feeds/2090713455880786619/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ruchirawageesha.blogspot.com/2010/07/json-to-xml-and-xml-to-json-convertion.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5735449966988481504/posts/default/2090713455880786619'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5735449966988481504/posts/default/2090713455880786619'/><link rel='alternate' type='text/html' href='http://ruchirawageesha.blogspot.com/2010/07/json-to-xml-and-xml-to-json-convertion.html' title='JSON to XML and XML to JSON convertion using Javascript'/><author><name>wageesha</name><uri>http://www.blogger.com/profile/06227183882522305231</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/_FBxc7ILPVV8/SsW6Hduf6XI/AAAAAAAAACE/l9GDzujJIHg/S220/img_4008.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5735449966988481504.post-259207121932675204</id><published>2010-07-29T22:42:00.000-07:00</published><updated>2010-07-29T22:45:44.155-07:00</updated><title type='text'>Regular Expressions with Javascript</title><content type='html'>Here is an excellent demonstration of Regular Expression usage in Javascript.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://lawrence.ecorp.net/inet/samples/regexp-format.php"&gt;http://lawrence.ecorp.net/inet/samples/regexp-format.php&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5735449966988481504-259207121932675204?l=ruchirawageesha.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ruchirawageesha.blogspot.com/feeds/259207121932675204/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ruchirawageesha.blogspot.com/2010/07/regular-expressions-with-javascript.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5735449966988481504/posts/default/259207121932675204'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5735449966988481504/posts/default/259207121932675204'/><link rel='alternate' type='text/html' href='http://ruchirawageesha.blogspot.com/2010/07/regular-expressions-with-javascript.html' title='Regular Expressions with Javascript'/><author><name>wageesha</name><uri>http://www.blogger.com/profile/06227183882522305231</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/_FBxc7ILPVV8/SsW6Hduf6XI/AAAAAAAAACE/l9GDzujJIHg/S220/img_4008.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5735449966988481504.post-367234171679193844</id><published>2010-07-08T00:15:00.000-07:00</published><updated>2011-06-17T06:11:42.642-07:00</updated><title type='text'>How to Create Client/Server Keystores using Java Keytool</title><content type='html'>Here I have described how to create client/server keystores which can be used to secure Axsi2 webservices and invoke Axis2 secured webservices. i.e. It can be easily used with any &lt;a href="http://wso2.com/products"&gt;WSO2 Product&lt;/a&gt; to experience security scenarios.More detailed explanation on creating client/server keystores using openssl including Certificate Authority(CA) Requests, can be found at &lt;a href="http://wso2.org/library/174"&gt;http://wso2.org/library/174&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Java keytool stores the keys and certificates in a keystore, protected by a keystore password. Further, it protects private key again with another password. A Java keystore contains private-public key pair and multiple trusted certificate entries. All entries in a keystore are referred by aliases. Both private key and self signed public key is referred by one alias while any other trusted certificates are referred by different individual aliases.&lt;br /&gt;&lt;br /&gt;As the first step, let's create a keystore for server. In order to do it, execute following command in a terminal. "server" in the following command corresponds to the private key/self signed public key certificate alias in the keystore while "server.jks" is the name of the creating keystore file.&lt;br /&gt;&lt;pre class="prettyprint"&gt;keytool -genkey -alias server -keyalg RSA -keystore server.jks&lt;br /&gt;&lt;/pre&gt;when you execute the above command it will first prompt you to specify a password which is corresponded to the keystore password. Then it will prompt several questions. You can give answers that you wish. At the end it will ask for a password again, which will be used to secure the generated private key.&lt;br /&gt;&lt;pre class="prettyprint"&gt;Enter keystore password:  &lt;br /&gt;Re-enter new password: &lt;br /&gt;What is your first and last name?&lt;br /&gt;[Unknown]:  Ruchira Wageesha&lt;br /&gt;What is the name of your organizational unit?&lt;br /&gt;[Unknown]:  Mashup Server&lt;br /&gt;What is the name of your organization?&lt;br /&gt;[Unknown]:  WSO2&lt;br /&gt;What is the name of your City or Locality?&lt;br /&gt;[Unknown]:  Ahangama&lt;br /&gt;What is the name of your State or Province?&lt;br /&gt;[Unknown]:  Southern&lt;br /&gt;What is the two-letter country code for this unit?&lt;br /&gt;[Unknown]:  LK&lt;br /&gt;Is CN=Ruchira Wageesha, OU=Mashup Server, O=WSO2, L=Ahangama, ST=Southern, C=LK correct?&lt;br /&gt;[no]: yes&lt;br /&gt;Enter key password for &lt;server&gt;&lt;br /&gt;(RETURN if same as keystore password):&lt;br /&gt;&lt;/pre&gt;Once you successfully completed this, java keytool will create a file named "server.jks". In the same way, you can create a client keystore named "client.jks" with the alias "client" using following command.&lt;br /&gt;&lt;pre class="prettyprint"&gt;keytool -genkey -alias client -keyalg RSA -keystore client.jks&lt;br /&gt;&lt;/pre&gt;Now, you have two files named client.jks and server.jks. You can view the content of these keystore files using the following command. Replacess "ruchira" with the keystore password you entered while creating the keystore.&lt;br /&gt;&lt;pre class="prettyprint"&gt;keytool -list -v -keystore server.jks -storepass ruchira&lt;br /&gt;&lt;/pre&gt;This will list something like this.&lt;br /&gt;&lt;pre class="prettyprint"&gt;Keystore type: JKS&lt;br /&gt;Keystore provider: SUN&lt;br /&gt;&lt;br /&gt;Your keystore contains 1 entry&lt;br /&gt;&lt;br /&gt;Alias name: server&lt;br /&gt;Creation date: Jul 8, 2010&lt;br /&gt;Entry type: PrivateKeyEntry&lt;br /&gt;Certificate chain length: 1&lt;br /&gt;Certificate[1]:&lt;br /&gt;Owner: CN=Ruchira Wageesha, OU=Mashup Server, O=WSO2, L=Ahangama, ST=Southern, C=LK&lt;br /&gt;Issuer: CN=Ruchira Wageesha, OU=Mashup Server, O=WSO2, L=Ahangama, ST=Southern, C=LK&lt;br /&gt;Serial number: 4c356225&lt;br /&gt;Valid from: Thu Jul 08 10:59:09 IST 2010 until: Wed Oct 06 10:59:09 IST 2010&lt;br /&gt;Certificate fingerprints:&lt;br /&gt;MD5:  60:0B:48:0D:DB:56:8C:68:8C:2D:94:4A:D6:DA:04:B8&lt;br /&gt;SHA1: A7:CE:57:10:70:87:C1:2C:C0:9D:1D:90:8C:BB:69:B6:66:26:97:13&lt;br /&gt;Signature algorithm name: SHA1withRSA&lt;br /&gt;Version: 3&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;*******************************************&lt;br /&gt;*******************************************&lt;br /&gt;&lt;/pre&gt;The next step is, getting server's self signed public key certificate and storing it in client's keystore. And getting and storing client's self signed public key certificate in server's keystore. In order to do that, first we need to export both server and client public key certificates into files. Using the following command, you can export server's public key certificate into server.cert file and client's public key certificate into client.cert file.&lt;br /&gt;&lt;pre class="prettyprint"&gt;keytool -export -file server.cert -keystore server.jks -storepass ruchira -alias server&lt;br /&gt;keytool -export -file client.cert -keystore client.jks -storepass ruchira -alias client&lt;br /&gt;&lt;/pre&gt;Now you have server.cert and client.cert. You can use following commands to view certificate contents.&lt;br /&gt;&lt;pre class="prettyprint"&gt;keytool -printcert -v -file server.cert&lt;br /&gt;keytool -printcert -v -file client.cert&lt;br /&gt;&lt;/pre&gt;As the last step, we need to import server.cert into client keystore and client.cert into server keystore. As I mentioned earlier, each entry of a Java Keystore is stored against an alias. So, we need to specify aliases here, which will be used to refer the certificates that we are going to store.&lt;br /&gt;&lt;pre class="prettyprint"&gt;keytool -import -file client.cert -keystore server.jks -storepass ruchira -alias client&lt;br /&gt;&lt;/pre&gt;Above command will store client's self signed public key certificate(client.cert) in server.jks against the alias "client". So, using "client" alias on server.jks, we can refer client's certificate anytime. Likewise, following command will store server.cert within client.jks against the alias "server".&lt;br /&gt;&lt;pre class="prettyprint"&gt;keytool -import -file server.cert -keystore client.jks -storepass ruchira -alias server&lt;br /&gt;&lt;/pre&gt;After all, please view the content of both keystore again using following commands.&lt;br /&gt;&lt;pre class="prettyprint"&gt;keytool -list -v -keystore server.jks -storepass ruchira&lt;br /&gt;keytool -list -v -keystore client.jks -storepass ruchira&lt;br /&gt;&lt;/pre&gt;It will give you something like bellow for server.jks&lt;br /&gt;&lt;pre class="prettyprint"&gt;Keystore type: JKS&lt;br /&gt;Keystore provider: SUN&lt;br /&gt;&lt;br /&gt;Your keystore contains 2 entries&lt;br /&gt;&lt;br /&gt;Alias name: server&lt;br /&gt;Creation date: Jul 8, 2010&lt;br /&gt;Entry type: PrivateKeyEntry&lt;br /&gt;Certificate chain length: 1&lt;br /&gt;Certificate[1]:&lt;br /&gt;Owner: CN=Ruchira Wageesha, OU=Mashup Server, O=WSO2, L=Ahangama, ST=Southern, C=LK&lt;br /&gt;Issuer: CN=Ruchira Wageesha, OU=Mashup Server, O=WSO2, L=Ahangama, ST=Southern, C=LK&lt;br /&gt;Serial number: 4c3562a0&lt;br /&gt;Valid from: Thu Jul 08 11:01:12 IST 2010 until: Wed Oct 06 11:01:12 IST 2010&lt;br /&gt;Certificate fingerprints:&lt;br /&gt;MD5:  AB:77:72:F1:0D:09:55:E3:B6:D3:DC:A6:4D:D4:39:36&lt;br /&gt;SHA1: D7:C1:60:5C:7E:34:40:A9:0B:E4:2C:65:6C:E0:79:7C:EE:37:A7:19&lt;br /&gt;Signature algorithm name: SHA1withRSA&lt;br /&gt;Version: 3&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;*******************************************&lt;br /&gt;*******************************************&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Alias name: client&lt;br /&gt;Creation date: Jul 8, 2010&lt;br /&gt;Entry type: trustedCertEntry&lt;br /&gt;&lt;br /&gt;Owner: CN=Ruchira Wageesha, OU=Mashup Server, O=WSO2, L=Ahangama, ST=Southern, C=LK&lt;br /&gt;Issuer: CN=Ruchira Wageesha, OU=Mashup Server, O=WSO2, L=Ahangama, ST=Southern, C=LK&lt;br /&gt;Serial number: 4c356225&lt;br /&gt;Valid from: Thu Jul 08 10:59:09 IST 2010 until: Wed Oct 06 10:59:09 IST 2010&lt;br /&gt;Certificate fingerprints:&lt;br /&gt;MD5:  60:0B:48:0D:DB:56:8C:68:8C:2D:94:4A:D6:DA:04:B8&lt;br /&gt;SHA1: A7:CE:57:10:70:87:C1:2C:C0:9D:1D:90:8C:BB:69:B6:66:26:97:13&lt;br /&gt;Signature algorithm name: SHA1withRSA&lt;br /&gt;Version: 3&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;*******************************************&lt;br /&gt;*******************************************&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;something like below for client.jks&lt;br /&gt;&lt;pre class="prettyprint"&gt;Keystore type: JKS&lt;br /&gt;Keystore provider: SUN&lt;br /&gt;&lt;br /&gt;Your keystore contains 2 entries&lt;br /&gt;&lt;br /&gt;Alias name: server&lt;br /&gt;Creation date: Jul 8, 2010&lt;br /&gt;Entry type: trustedCertEntry&lt;br /&gt;&lt;br /&gt;Owner: CN=Ruchira Wageesha, OU=Mashup Server, O=WSO2, L=Ahangama, ST=Southern, C=LK&lt;br /&gt;Issuer: CN=Ruchira Wageesha, OU=Mashup Server, O=WSO2, L=Ahangama, ST=Southern, C=LK&lt;br /&gt;Serial number: 4c3562a0&lt;br /&gt;Valid from: Thu Jul 08 11:01:12 IST 2010 until: Wed Oct 06 11:01:12 IST 2010&lt;br /&gt;Certificate fingerprints:&lt;br /&gt;MD5:  AB:77:72:F1:0D:09:55:E3:B6:D3:DC:A6:4D:D4:39:36&lt;br /&gt;SHA1: D7:C1:60:5C:7E:34:40:A9:0B:E4:2C:65:6C:E0:79:7C:EE:37:A7:19&lt;br /&gt;Signature algorithm name: SHA1withRSA&lt;br /&gt;Version: 3&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;*******************************************&lt;br /&gt;*******************************************&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Alias name: client&lt;br /&gt;Creation date: Jul 8, 2010&lt;br /&gt;Entry type: PrivateKeyEntry&lt;br /&gt;Certificate chain length: 1&lt;br /&gt;Certificate[1]:&lt;br /&gt;Owner: CN=Ruchira Wageesha, OU=Mashup Server, O=WSO2, L=Ahangama, ST=Southern, C=LK&lt;br /&gt;Issuer: CN=Ruchira Wageesha, OU=Mashup Server, O=WSO2, L=Ahangama, ST=Southern, C=LK&lt;br /&gt;Serial number: 4c356225&lt;br /&gt;Valid from: Thu Jul 08 10:59:09 IST 2010 until: Wed Oct 06 10:59:09 IST 2010&lt;br /&gt;Certificate fingerprints:&lt;br /&gt;MD5:  60:0B:48:0D:DB:56:8C:68:8C:2D:94:4A:D6:DA:04:B8&lt;br /&gt;SHA1: A7:CE:57:10:70:87:C1:2C:C0:9D:1D:90:8C:BB:69:B6:66:26:97:13&lt;br /&gt;Signature algorithm name: SHA1withRSA&lt;br /&gt;Version: 3&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;*******************************************&lt;br /&gt;*******************************************&lt;br /&gt;&lt;/pre&gt;If everything went well, you might have successfully created server.jks and client.jks which can be used to secure Axis2 Services and access those secured services.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5735449966988481504-367234171679193844?l=ruchirawageesha.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ruchirawageesha.blogspot.com/feeds/367234171679193844/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ruchirawageesha.blogspot.com/2010/07/how-to-create-clientserver-keystores.html#comment-form' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5735449966988481504/posts/default/367234171679193844'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5735449966988481504/posts/default/367234171679193844'/><link rel='alternate' type='text/html' href='http://ruchirawageesha.blogspot.com/2010/07/how-to-create-clientserver-keystores.html' title='How to Create Client/Server Keystores using Java Keytool'/><author><name>wageesha</name><uri>http://www.blogger.com/profile/06227183882522305231</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/_FBxc7ILPVV8/SsW6Hduf6XI/AAAAAAAAACE/l9GDzujJIHg/S220/img_4008.jpg'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5735449966988481504.post-6096962523539240740</id><published>2010-07-07T22:50:00.000-07:00</published><updated>2011-06-17T06:06:41.254-07:00</updated><title type='text'>Java Keytool Keystore Commands</title><content type='html'>&lt;span style="font-weight:bold;"&gt;Create Keystore, Keys and Certificate Requests&lt;/span&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="font-weight:bold;"&gt;Generate a Java keystore and key pair&lt;/span&gt;&lt;br /&gt;&lt;pre class="prettyprint"&gt;keytool -genkey -alias mydomain -keyalg RSA -keystore keystore.jks -storepass password&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-weight:bold;"&gt;Generate a certificate signing request (CSR) for an existing Java keystore&lt;/span&gt;&lt;br /&gt;&lt;pre class="prettyprint"&gt;keytool -certreq -alias mydomain -keystore keystore.jks -storepass password -file mydomain.csr&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-weight:bold;"&gt;Generate a keystore and self-signed certificate&lt;/span&gt;&lt;br /&gt;&lt;pre class="prettyprint"&gt;keytool -genkey -keyalg RSA -alias selfsigned -keystore keystore.jks -storepass password -validity 360&lt;/pre&gt;&lt;/li&gt;&lt;/ul&gt;&lt;span style="font-weight:bold;"&gt;Import Certificates&lt;/span&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="font-weight:bold;"&gt;Import a root or intermediate CA certificate to an existing Java keystore&lt;/span&gt;&lt;br /&gt;&lt;pre class="prettyprint"&gt;keytool -import -trustcacerts -alias root -file Thawte.crt -keystore keystore.jks -storepass password&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-weight:bold;"&gt;Import a signed primary certificate to an existing Java keystore&lt;/span&gt;&lt;br /&gt;&lt;pre class="prettyprint"&gt;keytool -import -trustcacerts -alias mydomain -file mydomain.crt -keystore keystore.jks -storepass password&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-weight:bold;"&gt;Import New CA into Trusted Certs&lt;/span&gt;&lt;br /&gt;&lt;pre class="prettyprint"&gt;keytool -import -trustcacerts -file /path/to/ca/ca.pem -alias CA_ALIAS -keystore $JAVA_HOME/jre/lib/security/cacerts&lt;/pre&gt;&lt;/li&gt;&lt;/ul&gt;&lt;span style="font-weight:bold;"&gt;Export Certificates&lt;/span&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="font-weight:bold;"&gt;Export a certificate from a keystore&lt;/span&gt;&lt;br /&gt;&lt;pre class="prettyprint"&gt;keytool -export -alias mydomain -file mydomain.crt -keystore keystore.jks -storepass password&lt;/pre&gt;&lt;/li&gt;&lt;/ul&gt;&lt;span style="font-weight:bold;"&gt;Check/List/View&lt;/span&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="font-weight:bold;"&gt;Check a stand-alone certificate&lt;/span&gt;&lt;br /&gt;&lt;pre class="prettyprint"&gt;keytool -printcert -v -file mydomain.crt&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-weight:bold;"&gt;Check which certificates are in a Java keystore&lt;/span&gt;&lt;br /&gt;&lt;pre class="prettyprint"&gt;keytool -list -v -keystore keystore.jks -storepass password&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-weight:bold;"&gt;Check a particular keystore entry using an alias&lt;/span&gt;&lt;br /&gt;&lt;pre class="prettyprint"&gt;keytool -list -v -keystore keystore.jks -storepass password -alias mydomain&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-weight:bold;"&gt;List Trusted CA Certs&lt;/span&gt;&lt;br /&gt;&lt;pre class="prettyprint"&gt;keytool -list -v -keystore $JAVA_HOME/jre/lib/security/cacerts&lt;/pre&gt;&lt;/li&gt;&lt;/ul&gt;&lt;span style="font-weight:bold;"&gt;Delete Certificates&lt;/span&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="font-weight:bold;"&gt;Delete a certificate from a Java Keytool keystore&lt;/span&gt;&lt;br /&gt;&lt;pre class="prettyprint"&gt;keytool -delete -alias mydomain -keystore keystore.jks -storepass password&lt;/pre&gt;&lt;/li&gt;&lt;/ul&gt;&lt;span style="font-weight:bold;"&gt;Change Passwords&lt;/span&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="font-weight:bold;"&gt;Change a Java keystore password&lt;/span&gt;&lt;br /&gt;&lt;pre class="prettyprint"&gt;keytool -storepasswd -new new_storepass -keystore keystore.jks -storepass password&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-weight:bold;"&gt;Change a private key password&lt;/span&gt;&lt;br /&gt;&lt;pre class="prettyprint"&gt;keytool -keypasswd -alias client -keypass old_password -new new_password -keystore client.jks -storepass password&lt;/pre&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5735449966988481504-6096962523539240740?l=ruchirawageesha.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ruchirawageesha.blogspot.com/feeds/6096962523539240740/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ruchirawageesha.blogspot.com/2010/07/java-keytool-keystore-commands.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5735449966988481504/posts/default/6096962523539240740'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5735449966988481504/posts/default/6096962523539240740'/><link rel='alternate' type='text/html' href='http://ruchirawageesha.blogspot.com/2010/07/java-keytool-keystore-commands.html' title='Java Keytool Keystore Commands'/><author><name>wageesha</name><uri>http://www.blogger.com/profile/06227183882522305231</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/_FBxc7ILPVV8/SsW6Hduf6XI/AAAAAAAAACE/l9GDzujJIHg/S220/img_4008.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5735449966988481504.post-8832630976929733752</id><published>2010-06-18T02:11:00.000-07:00</published><updated>2011-06-17T06:13:08.732-07:00</updated><title type='text'>Ubuntu - Copy Everything Except</title><content type='html'>If you want to copy everything within a directory, except certain files or directories, you can use the following command.&lt;br /&gt;&lt;pre class="prettyprint lang-sh"&gt;cp -a `ls | grep -v yourexcludepattern` ../destinationdir/&lt;/pre&gt;&lt;br /&gt;Assume, you want to copy all files, except *.java within from the current directory to the foo directory. Then, the command would be,&lt;br /&gt;&lt;pre class="prettyprint lang-sh"&gt;cp -a `ls | grep -v *.java` /home/wageesha/foo&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5735449966988481504-8832630976929733752?l=ruchirawageesha.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ruchirawageesha.blogspot.com/feeds/8832630976929733752/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ruchirawageesha.blogspot.com/2010/06/ubuntu-copy-everything-except.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5735449966988481504/posts/default/8832630976929733752'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5735449966988481504/posts/default/8832630976929733752'/><link rel='alternate' type='text/html' href='http://ruchirawageesha.blogspot.com/2010/06/ubuntu-copy-everything-except.html' title='Ubuntu - Copy Everything Except'/><author><name>wageesha</name><uri>http://www.blogger.com/profile/06227183882522305231</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/_FBxc7ILPVV8/SsW6Hduf6XI/AAAAAAAAACE/l9GDzujJIHg/S220/img_4008.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5735449966988481504.post-2826274188533763519</id><published>2010-06-11T00:44:00.000-07:00</published><updated>2011-06-17T06:14:18.217-07:00</updated><title type='text'>How to copy a file into multiple directories in Ubuntu</title><content type='html'>Assume that you want to copy a file into multiple directories in the current directory, then all you have to do is, just entering following command in the terminal. Here, file.txt will be copied into all directories in the current directory. In case of a directory coping, replace &lt;span style="font-weight:bold;"&gt;file.txt&lt;/span&gt; with &lt;span style="font-weight:bold;"&gt;-rf [your dir]&lt;/span&gt;.&lt;br /&gt;&lt;pre class="prettyprint lang-sh"&gt;for dir in *; do [ -d "$dir" ] &amp;&amp; cp file.txt "$dir" ; done&lt;br /&gt;&lt;/pre&gt;&lt;pre class="prettyprint lang-sh"&gt;for dir in *; do [ -d "$dir" ] &amp;&amp; cp -rf /home/wageesha/images "$dir" ; done&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5735449966988481504-2826274188533763519?l=ruchirawageesha.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ruchirawageesha.blogspot.com/feeds/2826274188533763519/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ruchirawageesha.blogspot.com/2010/06/how-to-copy-file-into-multiple.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5735449966988481504/posts/default/2826274188533763519'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5735449966988481504/posts/default/2826274188533763519'/><link rel='alternate' type='text/html' href='http://ruchirawageesha.blogspot.com/2010/06/how-to-copy-file-into-multiple.html' title='How to copy a file into multiple directories in Ubuntu'/><author><name>wageesha</name><uri>http://www.blogger.com/profile/06227183882522305231</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/_FBxc7ILPVV8/SsW6Hduf6XI/AAAAAAAAACE/l9GDzujJIHg/S220/img_4008.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5735449966988481504.post-625876378504214414</id><published>2010-06-01T08:43:00.000-07:00</published><updated>2010-06-01T09:00:03.670-07:00</updated><title type='text'>WSO2 Stratos is LIVE</title><content type='html'>WSO2 Stratos Alpha1 is live. You can register for any of the following WSO2 Cloud Services at &lt;a href="http://cloud.wso2.com"&gt;http://cloud.wso2.com&lt;/a&gt;.&lt;br /&gt;&lt;strong&gt;&lt;br /&gt;   Mashup Server&lt;br /&gt;   Gadget Server&lt;br /&gt;   Application Server&lt;br /&gt;   Identity Server&lt;br /&gt;   Governance&lt;br /&gt;   BAM&lt;br /&gt;&lt;/strong&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5735449966988481504-625876378504214414?l=ruchirawageesha.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ruchirawageesha.blogspot.com/feeds/625876378504214414/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ruchirawageesha.blogspot.com/2010/06/wso2-stratos-is-live.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5735449966988481504/posts/default/625876378504214414'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5735449966988481504/posts/default/625876378504214414'/><link rel='alternate' type='text/html' href='http://ruchirawageesha.blogspot.com/2010/06/wso2-stratos-is-live.html' title='WSO2 Stratos is LIVE'/><author><name>wageesha</name><uri>http://www.blogger.com/profile/06227183882522305231</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/_FBxc7ILPVV8/SsW6Hduf6XI/AAAAAAAAACE/l9GDzujJIHg/S220/img_4008.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5735449966988481504.post-1575045387444300362</id><published>2010-05-23T09:18:00.000-07:00</published><updated>2011-06-17T06:20:23.635-07:00</updated><title type='text'>WSO2 Mashup Server - Google Maps API Key Mashup</title><content type='html'>If you are using Google Maps in your web site, you need to get an API key from Google.com. In order to do that, you need to login using an existing Google account, accept their terms and policies and finally you will be able to get the Google Maps API key. Although this is the usual procedure, if they provide a web service for it, it will be much useful in places where you want to get the key at runtime. &lt;br /&gt;&lt;br /&gt;As an example, WSO2 Mashup Server has a Twitter Maps Mashup which shows recent tweets in a Google map. In order to have the proper functionality of this mashup independent of the domain where the server is running, it needs to dynamically generate an API key for that domain and use it within the Twitter map mashup. That was the original motivation towards this mashup.&lt;br /&gt;&lt;br /&gt;You will need to deploy the following mashup in the WSO2 Mashup Server 2.0.2 or a newer one.&lt;br /&gt;&lt;pre class="prettyprint lang-js"&gt;getAPIKey.inputTypes = { "username" : "string", "password" : "string", "url" : "string" };&lt;br /&gt;getAPIKey.output = "string";&lt;br /&gt;function getAPIKey(username, password, url) {&lt;br /&gt;    var client = new HttpClient();&lt;br /&gt;    var code = client.executeMethod("GET", "https://www.google.com/accounts/Login");&lt;br /&gt;    if (code == 200) {&lt;br /&gt;        var galx = client.cookies[0].value;&lt;br /&gt;        var content = [&lt;br /&gt;            { name : "Email", value : username },&lt;br /&gt;            { name : "Passwd", value : password },&lt;br /&gt;            { name : "signIn", value : "Sign in" },&lt;br /&gt;            { name : "GALX", value : String(galx) },&lt;br /&gt;            { name : "dsh", value : "5537526595243201224"},&lt;br /&gt;            { name : "rmShown", value : "1"},&lt;br /&gt;            { name : "PersistentCookie", value : "yes"}&lt;br /&gt;        ];&lt;br /&gt;        code = client.executeMethod("POST", "https://www.google.com/accounts/LoginAuth", content);&lt;br /&gt;        if (code == 302 || code == 200) {&lt;br /&gt;            code = client.executeMethod("GET", "http://code.google.com/apis/maps/signup/createkey", [&lt;br /&gt;                { name : "referer", value : url }&lt;br /&gt;            ]);&lt;br /&gt;            if (code == 200) {&lt;br /&gt;                var response = eval('(' + client.response + ')');&lt;br /&gt;                client.releaseConnection();&lt;br /&gt;                return response.generated_key;&lt;br /&gt;            } else {&lt;br /&gt;                client.releaseConnection();&lt;br /&gt;                return new XML("&lt;error&gt;&lt;code&gt;" + code + "&lt;/code&gt;&lt;message&gt;" + client.statusText + "&lt;/message&gt;&lt;/error&gt;");&lt;br /&gt;            }&lt;br /&gt;        } else {&lt;br /&gt;            client.releaseConnection();&lt;br /&gt;            return new XML("&lt;error&gt;&lt;code&gt;" + code + "&lt;/code&gt;&lt;message&gt;" + client.statusText + "&lt;/message&gt;&lt;/error&gt;");&lt;br /&gt;        }&lt;br /&gt;    } else {&lt;br /&gt;        client.releaseConnection();&lt;br /&gt;        return new XML("&lt;error&gt;&lt;code&gt;" + code + "&lt;/code&gt;&lt;message&gt;" + client.statusText + "&lt;/message&gt;&lt;/error&gt;");&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5735449966988481504-1575045387444300362?l=ruchirawageesha.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ruchirawageesha.blogspot.com/feeds/1575045387444300362/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ruchirawageesha.blogspot.com/2010/05/wso2-mashup-server-google-maps-api-key.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5735449966988481504/posts/default/1575045387444300362'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5735449966988481504/posts/default/1575045387444300362'/><link rel='alternate' type='text/html' href='http://ruchirawageesha.blogspot.com/2010/05/wso2-mashup-server-google-maps-api-key.html' title='WSO2 Mashup Server - Google Maps API Key Mashup'/><author><name>wageesha</name><uri>http://www.blogger.com/profile/06227183882522305231</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/_FBxc7ILPVV8/SsW6Hduf6XI/AAAAAAAAACE/l9GDzujJIHg/S220/img_4008.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5735449966988481504.post-6962817475774104054</id><published>2010-04-23T02:34:00.000-07:00</published><updated>2011-06-17T06:19:01.502-07:00</updated><title type='text'>Subversion: How to revert to a previous revision</title><content type='html'>Assume that your current revision is 100 and you want to revert the repository to the revision 90. Then you can use the following command, &lt;br /&gt;&lt;pre class="prettyprint lang-js"&gt;$ svn merge -rHEAD:90 .&lt;/pre&gt;As you have used . at the end, it will revert your local repository. Once commited you will get a new revision such as 101 which is same as revision 90. You can do this directly to a remote repository as well. In that case, replace . with repository url.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5735449966988481504-6962817475774104054?l=ruchirawageesha.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ruchirawageesha.blogspot.com/feeds/6962817475774104054/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ruchirawageesha.blogspot.com/2010/04/subversion-how-to-revert-to-previous.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5735449966988481504/posts/default/6962817475774104054'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5735449966988481504/posts/default/6962817475774104054'/><link rel='alternate' type='text/html' href='http://ruchirawageesha.blogspot.com/2010/04/subversion-how-to-revert-to-previous.html' title='Subversion: How to revert to a previous revision'/><author><name>wageesha</name><uri>http://www.blogger.com/profile/06227183882522305231</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/_FBxc7ILPVV8/SsW6Hduf6XI/AAAAAAAAACE/l9GDzujJIHg/S220/img_4008.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5735449966988481504.post-1894474755105086051</id><published>2010-04-07T21:09:00.000-07:00</published><updated>2010-04-07T22:05:01.966-07:00</updated><title type='text'>GCE O/L, A/L and Grade V Examination Results</title><content type='html'>Do you want to view O/L, A/L and Grade V results a bit earlier than &lt;a href="http://www.doenets.lk"&gt;&lt;span style="font-weight:bold;"&gt;http://www.doenets.lk&lt;/span&gt;&lt;/a&gt; lets us. I have tried it when it says, "New Await Results". You can do this using firebug addon on firefox.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;www.doenets.lk&lt;/span&gt; lets us to check previous result too. These are displayed by the "New Await Results" table. So what you need to do is first select one of those forms and change action url to &lt;span style="font-weight:bold;"&gt;exam_OL.jsp&lt;/span&gt;, &lt;span style="font-weight:bold;"&gt;exam_AL.jsp&lt;/span&gt; or &lt;span style="font-weight:bold;"&gt;exam_GV.jsp&lt;/span&gt; as appropriate. You would also need to change the &lt;span style="font-weight:bold;"&gt;size/maxLength&lt;/span&gt; of the inputput field as well. Otherwise it won't let us to insert our full index number. That's all, fill it with your index number, submit and get your results. You can also do a http POST using your own form as well.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Attention :&lt;/span&gt; I am not responsible for the accuracy of results as www.doenets.lk might not have officialy released the results when you use this.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5735449966988481504-1894474755105086051?l=ruchirawageesha.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ruchirawageesha.blogspot.com/feeds/1894474755105086051/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ruchirawageesha.blogspot.com/2010/04/ol-al-and-grade-v-examination-results.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5735449966988481504/posts/default/1894474755105086051'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5735449966988481504/posts/default/1894474755105086051'/><link rel='alternate' type='text/html' href='http://ruchirawageesha.blogspot.com/2010/04/ol-al-and-grade-v-examination-results.html' title='GCE O/L, A/L and Grade V Examination Results'/><author><name>wageesha</name><uri>http://www.blogger.com/profile/06227183882522305231</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/_FBxc7ILPVV8/SsW6Hduf6XI/AAAAAAAAACE/l9GDzujJIHg/S220/img_4008.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5735449966988481504.post-5539624263866203432</id><published>2010-03-21T09:40:00.000-07:00</published><updated>2010-03-21T09:42:45.188-07:00</updated><title type='text'>How to enable mod rewrite on Apache</title><content type='html'>Tired up trying to enable mode rewrite on apache? Try this link which explains it quite well.&lt;br /&gt;&lt;a href="http://drupal.org/node/134439"&gt;http://drupal.org/node/134439&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5735449966988481504-5539624263866203432?l=ruchirawageesha.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ruchirawageesha.blogspot.com/feeds/5539624263866203432/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ruchirawageesha.blogspot.com/2010/03/how-to-enable-mod-rewrite-on-apache.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5735449966988481504/posts/default/5539624263866203432'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5735449966988481504/posts/default/5539624263866203432'/><link rel='alternate' type='text/html' href='http://ruchirawageesha.blogspot.com/2010/03/how-to-enable-mod-rewrite-on-apache.html' title='How to enable mod rewrite on Apache'/><author><name>wageesha</name><uri>http://www.blogger.com/profile/06227183882522305231</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/_FBxc7ILPVV8/SsW6Hduf6XI/AAAAAAAAACE/l9GDzujJIHg/S220/img_4008.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5735449966988481504.post-6224620414976606108</id><published>2009-12-06T03:37:00.000-08:00</published><updated>2011-06-17T06:24:40.280-07:00</updated><title type='text'>Serialize Javascript to PHP</title><content type='html'>When interacting Javascript with PHP, you might need to serialise any Javascript data type into the PHP serialized format, where it can be unserialized using PHP. The following function will serialize any Javascript data.&lt;br /&gt;&lt;pre class="prettyprint lang-js"&gt;function serialize(mixed_value) {&lt;br /&gt;    var _getType = function(inp) {&lt;br /&gt;        var type = typeof inp, match;&lt;br /&gt;        var key;&lt;br /&gt;        if (type == 'object' &amp;&amp; !inp) {&lt;br /&gt;            return 'null';&lt;br /&gt;        }&lt;br /&gt;        if (type == "object") {&lt;br /&gt;            if (!inp.constructor) {&lt;br /&gt;                return 'object';&lt;br /&gt;            }&lt;br /&gt;            var cons = inp.constructor.toString();&lt;br /&gt;            match = cons.match(/(\w+)\(/);&lt;br /&gt;            if (match) {&lt;br /&gt;                cons = match[1].toLowerCase();&lt;br /&gt;            }&lt;br /&gt;            var types = ["boolean", "number", "string", "array"];&lt;br /&gt;            for (key in types) {&lt;br /&gt;                if (cons == types[key]) {&lt;br /&gt;                    type = types[key];&lt;br /&gt;                    break;&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;        return type;&lt;br /&gt;    };&lt;br /&gt;    var type = _getType(mixed_value);&lt;br /&gt;    var val, ktype = '';&lt;br /&gt;&lt;br /&gt;    switch (type) {&lt;br /&gt;        case "function":&lt;br /&gt;            val = "";&lt;br /&gt;            break;&lt;br /&gt;        case "null":&lt;br /&gt;        case "undefined":&lt;br /&gt;            val = "N";&lt;br /&gt;            break;&lt;br /&gt;        case "boolean":&lt;br /&gt;            val = "b:" + (mixed_value ? "1" : "0");&lt;br /&gt;            break;&lt;br /&gt;        case "number":&lt;br /&gt;            val = (Math.round(mixed_value) == mixed_value ? "i" : "d") + ":" + mixed_value;&lt;br /&gt;            break;&lt;br /&gt;        case "string":&lt;br /&gt;            val = "s:" + mixed_value.length + ":\"" + mixed_value + "\"";&lt;br /&gt;            break;&lt;br /&gt;        case "array":&lt;br /&gt;        case "object":&lt;br /&gt;            val = "a";&lt;br /&gt;            var count = 0;&lt;br /&gt;            var vals = "";&lt;br /&gt;            var okey;&lt;br /&gt;            var key;&lt;br /&gt;            for (key in mixed_value) {&lt;br /&gt;                ktype = _getType(mixed_value[key]);&lt;br /&gt;                if (ktype == "function") {&lt;br /&gt;                    continue;&lt;br /&gt;                }&lt;br /&gt;&lt;br /&gt;                okey = (key.match(/^[0-9]+$/) ? parseInt(key, 10) : key);&lt;br /&gt;                vals += serialize(okey) +&lt;br /&gt;                        serialize(mixed_value[key]);&lt;br /&gt;                count++;&lt;br /&gt;            }&lt;br /&gt;            val += ":" + count + ":{" + vals + "}";&lt;br /&gt;            break;&lt;br /&gt;    }&lt;br /&gt;    if (type != "object" &amp;&amp; type != "array") {&lt;br /&gt;        val += ";";&lt;br /&gt;    }&lt;br /&gt;    return val;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;The code fragment below will do the serializing in Javascript and the later code will unserialize it in PHP.&lt;br /&gt;&lt;pre class="prettyprint lang-js"&gt;var array = ["ruchira", "wageesha"];&lt;br /&gt;//serialize value&lt;br /&gt;var serialize_array = serialize(array);&lt;br /&gt;&lt;/pre&gt;&lt;pre class="prettyprint lang-php"&gt;$array = unserialize($_POST['array']);&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5735449966988481504-6224620414976606108?l=ruchirawageesha.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ruchirawageesha.blogspot.com/feeds/6224620414976606108/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ruchirawageesha.blogspot.com/2009/12/serialize-javascript-to-php.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5735449966988481504/posts/default/6224620414976606108'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5735449966988481504/posts/default/6224620414976606108'/><link rel='alternate' type='text/html' href='http://ruchirawageesha.blogspot.com/2009/12/serialize-javascript-to-php.html' title='Serialize Javascript to PHP'/><author><name>wageesha</name><uri>http://www.blogger.com/profile/06227183882522305231</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/_FBxc7ILPVV8/SsW6Hduf6XI/AAAAAAAAACE/l9GDzujJIHg/S220/img_4008.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5735449966988481504.post-1385562463324863726</id><published>2009-09-11T13:12:00.000-07:00</published><updated>2011-06-17T10:43:19.960-07:00</updated><title type='text'>Javascript Popup - close after redirect</title><content type='html'>If you want to redirect the popup window to another location (a page or a file download) and then close the window, you can simply use the following javascript.&lt;br /&gt;&lt;pre class="prettyprint lang-js"&gt;&amp;lt;script type="text/javascript"&amp;gt;&lt;br /&gt;    window.opener.location = "new_page.htm";&lt;br /&gt;    window.close();&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5735449966988481504-1385562463324863726?l=ruchirawageesha.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ruchirawageesha.blogspot.com/feeds/1385562463324863726/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ruchirawageesha.blogspot.com/2009/09/javascript-popup-close-after-redirect.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5735449966988481504/posts/default/1385562463324863726'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5735449966988481504/posts/default/1385562463324863726'/><link rel='alternate' type='text/html' href='http://ruchirawageesha.blogspot.com/2009/09/javascript-popup-close-after-redirect.html' title='Javascript Popup - close after redirect'/><author><name>wageesha</name><uri>http://www.blogger.com/profile/06227183882522305231</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/_FBxc7ILPVV8/SsW6Hduf6XI/AAAAAAAAACE/l9GDzujJIHg/S220/img_4008.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5735449966988481504.post-7742162802504232847</id><published>2009-08-30T11:40:00.000-07:00</published><updated>2011-06-17T10:47:44.982-07:00</updated><title type='text'>Find and Replace using grep and sed</title><content type='html'>Following command finds all the occurences of &amp;lt;br&amp;gt; in all .xml files in the current directory, and replace those &amp;lt;br&amp;gt; with &amp;lt;br/&amp;gt; . Please note that &lt; and &gt; have been surrounded with [ and ] in the sed command. / in the &amp;lt;br/&amp;gt; tag has been escaped using \. If you want to replace foo with bar, then you can just use those words.&lt;br /&gt;&lt;pre class="prettyprint lang-sh"&gt;find . -iname "*.xml" | xargs grep -l "&amp;lt;br&amp;gt;" | xargs sed -i -e 's/[&amp;lt;]br[&amp;gt;]/&amp;lt;br\/&amp;gt;/g'&lt;br /&gt;&lt;/pre&gt;&lt;pre class="prettyprint lang-sh"&gt;find . -iname "*.xml" | xargs grep -l "&amp;lt;br&amp;gt;" | xargs sed -i -e 's/foo/bar/g'&lt;br /&gt;&lt;/pre&gt;A more general form of the expression would be&lt;br /&gt;&lt;pre class="prettyprint lang-sh"&gt;find . \( -name "*.php" -or -name "*.html" \) | xargs grep -l 'TEXT TO SEARCH' | xargs sed -i -e 's/TEXT TO REPLACE/REPLACEMENT STRING/g'&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5735449966988481504-7742162802504232847?l=ruchirawageesha.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ruchirawageesha.blogspot.com/feeds/7742162802504232847/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ruchirawageesha.blogspot.com/2009/08/find-and-replace-using-grep-and-sed.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5735449966988481504/posts/default/7742162802504232847'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5735449966988481504/posts/default/7742162802504232847'/><link rel='alternate' type='text/html' href='http://ruchirawageesha.blogspot.com/2009/08/find-and-replace-using-grep-and-sed.html' title='Find and Replace using grep and sed'/><author><name>wageesha</name><uri>http://www.blogger.com/profile/06227183882522305231</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/_FBxc7ILPVV8/SsW6Hduf6XI/AAAAAAAAACE/l9GDzujJIHg/S220/img_4008.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5735449966988481504.post-2366706587053932571</id><published>2009-08-27T11:58:00.000-07:00</published><updated>2011-06-17T10:48:11.009-07:00</updated><title type='text'>Rename Files with find command in linux</title><content type='html'>If you want to rename files recusivelly using linux find command, here are two example usage of it with exec and xargs. This command will convert all the *.xml files into *.html files.&lt;br /&gt;&lt;br /&gt;Using xags&lt;br /&gt;&lt;pre class="prettyprint lang-sh"&gt;find . | xargs rename 's/\.xml$/\.html/i'&lt;br /&gt;&lt;/pre&gt;Using exec&lt;br /&gt;&lt;pre class="prettyprint lang-sh"&gt;find . -exec rename 's/\.xml$/\.html/i' {} +&lt;br /&gt;&lt;/pre&gt;Above commands recurrsively replace files within inner directories too. If you want to do it for current directory only you can use -prune.&lt;br /&gt;i.e&lt;br /&gt;&lt;pre class="prettyprint lang-sh"&gt;find . -prune | xargs rename 's/\.xml$/\.html/i'&lt;br /&gt;&lt;/pre&gt;&lt;pre class="prettyprint lang-sh"&gt;find . -prune -exec rename 's/\.xml$/\.html/i' {} +&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5735449966988481504-2366706587053932571?l=ruchirawageesha.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ruchirawageesha.blogspot.com/feeds/2366706587053932571/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ruchirawageesha.blogspot.com/2009/08/rename-files-with-find-command-in-linux.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5735449966988481504/posts/default/2366706587053932571'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5735449966988481504/posts/default/2366706587053932571'/><link rel='alternate' type='text/html' href='http://ruchirawageesha.blogspot.com/2009/08/rename-files-with-find-command-in-linux.html' title='Rename Files with find command in linux'/><author><name>wageesha</name><uri>http://www.blogger.com/profile/06227183882522305231</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/_FBxc7ILPVV8/SsW6Hduf6XI/AAAAAAAAACE/l9GDzujJIHg/S220/img_4008.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5735449966988481504.post-765711233577204886</id><published>2009-08-10T12:44:00.000-07:00</published><updated>2011-06-17T10:52:03.429-07:00</updated><title type='text'>Multiple Joins on the same table</title><content type='html'>Here are few example queries which shows how to use multiple inner joins with sql.&lt;br /&gt;&lt;br /&gt;&lt;pre class="prettyprint lang-sql"&gt;SELECT Fruit1, F1FruitName = F1.FruitName, F1FruitCost = F1.FruitCost,&lt;br /&gt;Fruit2, F2FruitName = F2.FruitName, F2FruitCost = F2.FruitCost&lt;br /&gt;FROM T1&lt;br /&gt;JOIN T2 F1 ON Fruit1 = F1.Fruit_ID&lt;br /&gt;JOIN T2 F2 ON Fruit2 = F2.Fruit_ID&lt;br /&gt;&lt;/pre&gt;If you want each fruit on it's on line(Record set), then it looks like&lt;br /&gt;&lt;pre class="prettyprint lang-sql"&gt;SELECT UserID, Fruit1 AS FruitID, FruitName, FruitCost&lt;br /&gt;FROM T1&lt;br /&gt;JOIN T2 ON Fruit1 = Fruit_ID&lt;br /&gt;UNION&lt;br /&gt;SELECT UserID, Fruit2 AS FruitID, FruitName, FruitCost&lt;br /&gt;FROM T1&lt;br /&gt;JOIN T2 ON Fruit2 = Fruit_ID&lt;br /&gt;&lt;/pre&gt;Here is two equivalent queries where one of them uses join and other doesn't.&lt;br /&gt;&lt;pre class="prettyprint lang-sql"&gt;SELECT codice, &lt;br /&gt;other1.value AS value_one, &lt;br /&gt;other2.value AS value_two&lt;br /&gt;FROM main&lt;br /&gt;LEFT OUTER JOIN other as other1 ON (main.id = other1.id_main AND type = 'type_one')&lt;br /&gt;LEFT OUTER JOIN other as other2 ON (main.id = other2.id_main AND type = 'type_two)&lt;br /&gt;&lt;/pre&gt;is equivalent to &lt;br /&gt;&lt;pre class="prettyprint lang-sql"&gt;SELECT codice,&lt;br /&gt;(SELECT value FROM other WHERE id_main = id AND type = 'type_one') AS value_one,&lt;br /&gt;(SELECT value FROM other WHERE id_main = id AND type = 'type_two') AS value_two&lt;br /&gt;FROM codice&lt;br /&gt;&lt;/pre&gt;Query below will give you a clear idea about how to use mutliple joins in the same query. Hope this will help you to understand the usage.&lt;br /&gt;&lt;pre class="prettyprint lang-sql"&gt;SELECT u1.displayname AS Player1&lt;br /&gt;, u2.displayname AS Player2&lt;br /&gt;, u3.displayname AS Player3&lt;br /&gt;, u4.displayname AS Player4&lt;br /&gt;, u5.displayname AS Player5&lt;br /&gt;, u6.displayname AS Player6&lt;br /&gt;FROM (&lt;br /&gt;(&lt;br /&gt;(&lt;br /&gt;(&lt;br /&gt;(&lt;br /&gt;DCMLeagues AS L&lt;br /&gt;INNER &lt;br /&gt;JOIN Users AS u1 &lt;br /&gt;ON u1.userid = L.player1&lt;br /&gt;)&lt;br /&gt;INNER &lt;br /&gt;JOIN Users AS u2&lt;br /&gt;ON u2.userid = L.player2&lt;br /&gt;)&lt;br /&gt;INNER &lt;br /&gt;JOIN Users AS u3 &lt;br /&gt;ON u3.userid = L.player3&lt;br /&gt;)&lt;br /&gt;INNER &lt;br /&gt;JOIN Users AS u4 &lt;br /&gt;ON u4.userid = L.player4&lt;br /&gt;)&lt;br /&gt;INNER &lt;br /&gt;JOIN Users AS u5 &lt;br /&gt;ON u5.userid = L.player5&lt;br /&gt;)&lt;br /&gt;INNER &lt;br /&gt;JOIN Users as u6 &lt;br /&gt;ON u6.userid = L.player6&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5735449966988481504-765711233577204886?l=ruchirawageesha.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ruchirawageesha.blogspot.com/feeds/765711233577204886/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ruchirawageesha.blogspot.com/2009/08/multiple-joins-on-same-table.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5735449966988481504/posts/default/765711233577204886'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5735449966988481504/posts/default/765711233577204886'/><link rel='alternate' type='text/html' href='http://ruchirawageesha.blogspot.com/2009/08/multiple-joins-on-same-table.html' title='Multiple Joins on the same table'/><author><name>wageesha</name><uri>http://www.blogger.com/profile/06227183882522305231</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/_FBxc7ILPVV8/SsW6Hduf6XI/AAAAAAAAACE/l9GDzujJIHg/S220/img_4008.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5735449966988481504.post-562607088307766797</id><published>2009-06-25T02:06:00.000-07:00</published><updated>2011-06-17T10:53:27.293-07:00</updated><title type='text'>find command - search content of a file</title><content type='html'>find in Unix is a very powerful tool for users which give you a very good flexibility. find command has a very broad usage among users. Here is the way how you can use find command to search files and content within files.&lt;br /&gt;&lt;br /&gt;In order to search for a particular file named "test.txt" in /home directory, use&lt;br /&gt;&lt;pre class="prettyprint lang-sh"&gt;find /home -name "test.txt" -print&lt;br /&gt;&lt;/pre&gt;Search all the .txt files in /home directory, use&lt;br /&gt;&lt;pre class="prettyprint lang-sh"&gt;find /home -name "*.txt" -print&lt;br /&gt;&lt;/pre&gt;if you want to search for a string through all the files .txt files, there are two ways&lt;br /&gt;&lt;pre class="prettyprint lang-sh"&gt;find /home -name "*.txt" -exec grep -q "string-to-be-searched" '{}' \; -print&lt;br /&gt;&lt;/pre&gt;&lt;pre class="prettyprint lang-sh"&gt;find /home -name "*.txt" | xargs grep "string-to-be-searched"&lt;br /&gt;&lt;/pre&gt;second one is more fast and efficient. Removal of -q in the first command will output the text segment where the specified string is. If you want to search all files for the string, just remove -name "*txt" option.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5735449966988481504-562607088307766797?l=ruchirawageesha.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ruchirawageesha.blogspot.com/feeds/562607088307766797/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ruchirawageesha.blogspot.com/2009/06/how-to-search-using-find-command.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5735449966988481504/posts/default/562607088307766797'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5735449966988481504/posts/default/562607088307766797'/><link rel='alternate' type='text/html' href='http://ruchirawageesha.blogspot.com/2009/06/how-to-search-using-find-command.html' title='find command - search content of a file'/><author><name>wageesha</name><uri>http://www.blogger.com/profile/06227183882522305231</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/_FBxc7ILPVV8/SsW6Hduf6XI/AAAAAAAAACE/l9GDzujJIHg/S220/img_4008.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5735449966988481504.post-6264042810331044182</id><published>2009-06-25T01:52:00.000-07:00</published><updated>2011-06-17T10:54:55.384-07:00</updated><title type='text'>How to Increase JVM(Java) Heap Size</title><content type='html'>If you're building a big project using ant/maven then your jvm heap size may not sufficient and give you a java.lang.OutOfMemoryError: PermGen space exception. Increasing of maven/ant heap size might not sufficient enough for that and an increase of jvm heap size might also needed. When you're starting an application through command line, you can do it by specifying &lt;br /&gt;&lt;pre class="prettyprint lang-sh"&gt;java -Xms32m -Xmx128m your_application&lt;br /&gt;&lt;/pre&gt;it will be a temporary increase of heap size and if you want to increase it permanently set the following environment variable as needed.&lt;br /&gt;&lt;pre class="prettyprint lang-sh"&gt;export _JAVA_OPTIONS="-Xms64m -Xmx128m"&lt;br /&gt;&lt;/pre&gt;-Xms64m is the startup size(64MB) and -Xmx128m is the maximum size(128MB)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5735449966988481504-6264042810331044182?l=ruchirawageesha.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ruchirawageesha.blogspot.com/feeds/6264042810331044182/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ruchirawageesha.blogspot.com/2009/06/how-to-increase-jvmjava-heap-size.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5735449966988481504/posts/default/6264042810331044182'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5735449966988481504/posts/default/6264042810331044182'/><link rel='alternate' type='text/html' href='http://ruchirawageesha.blogspot.com/2009/06/how-to-increase-jvmjava-heap-size.html' title='How to Increase JVM(Java) Heap Size'/><author><name>wageesha</name><uri>http://www.blogger.com/profile/06227183882522305231</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/_FBxc7ILPVV8/SsW6Hduf6XI/AAAAAAAAACE/l9GDzujJIHg/S220/img_4008.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5735449966988481504.post-27334500900501882</id><published>2009-05-25T18:34:00.000-07:00</published><updated>2011-06-17T11:03:20.292-07:00</updated><title type='text'>PNG Tranparency in IE6</title><content type='html'>1 . First Download this &lt;a href="http://www.twinhelix.com/test/iepngfix.zip"&gt;Zip&lt;/a&gt; file and unzip&lt;br /&gt;&lt;br /&gt;2 . Copy and paste iepngfix.htc and blank.gif into your website folder.&lt;br /&gt;&lt;br /&gt;3 . Copy and paste this into your website's CSS or HTML:&lt;br /&gt;&lt;pre class="prettyprint lang-css"&gt;&amp;lt;style type="text/css"&amp;gt;&lt;br /&gt;    img, div { behavior: url(iepngfix.htc) }&lt;br /&gt;&amp;lt;/style&amp;gt;&lt;br /&gt;&lt;/pre&gt;That CSS selector must include the tags/elements on which you want PNG support -- basically, give it a comma-separated list of tags you use. It must also include the correct path to the .HTC relative to the HTML document location (not relative to the CSS document!). For instance, yours may look like this:&lt;br /&gt;&lt;pre class="prettyprint lang-css"&gt;&amp;lt;style type="text/css"&amp;gt;&lt;br /&gt;    img, div, a, input { behavior: url(/css/resources/iepngfix.htc) }&lt;br /&gt;&amp;lt;/style&amp;gt;&lt;br /&gt;&lt;/pre&gt;4 . If your site uses subfolders, open the .HTC file in a text editor like Windows Notepad and change the blankImg variable to include a correct path to blank.gif like so:&lt;br /&gt;&lt;pre class="prettyprint lang-js"&gt;IEPNGFix.blankImg = '/images/blank.gif';&lt;br /&gt;&lt;/pre&gt;Again the path is relative to the HTML file. Otherwise, you will see a "broken image" graphic!&lt;br /&gt;&lt;br /&gt;5 . If you want support for CSS1 background-repeat and background-position, make sure you include the add-on .JS file in your &amp;lt;head&amp;gt;:&lt;br /&gt;&lt;pre class="prettyprint lang-js"&gt;&amp;lt;script type="text/javascript" src="iepngfix_tilebg.js"&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&lt;/pre&gt;Otherwise, background images will work but won't repeat or position.&lt;br /&gt;&lt;br /&gt;You can view two other methods at&lt;br /&gt;&lt;a href="http://jquery.andreaseberhard.de/pngFix/"&gt;http://jquery.andreaseberhard.de/pngFix/&lt;/a&gt;&lt;br /&gt;&lt;a href="http://koivi.com/ie-png-transparency/"&gt;http://koivi.com/ie-png-transparency/&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5735449966988481504-27334500900501882?l=ruchirawageesha.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ruchirawageesha.blogspot.com/feeds/27334500900501882/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ruchirawageesha.blogspot.com/2009/05/png-tranparency-in-ie6.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5735449966988481504/posts/default/27334500900501882'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5735449966988481504/posts/default/27334500900501882'/><link rel='alternate' type='text/html' href='http://ruchirawageesha.blogspot.com/2009/05/png-tranparency-in-ie6.html' title='PNG Tranparency in IE6'/><author><name>wageesha</name><uri>http://www.blogger.com/profile/06227183882522305231</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/_FBxc7ILPVV8/SsW6Hduf6XI/AAAAAAAAACE/l9GDzujJIHg/S220/img_4008.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5735449966988481504.post-6285797664280513152</id><published>2009-01-10T01:11:00.000-08:00</published><updated>2011-06-17T10:58:56.151-07:00</updated><title type='text'>Add, Multiply, Divide Numbers in Fractional Format</title><content type='html'>Here is a way to do fractional calculations in Java. This might be useful when you want to get the exact values for some arithmetic operations like division. You can keep the result as a fractional number and to the operations what ever you like. i.e. add, subtract, multiply and divide.&lt;br /&gt;&lt;br /&gt;Here are two classes named Fraction.java and Util.java. As an example you can create the fractional number 7/8 using the constructor Fraction("8", "7"). There are many other constructors too in the Fraction class. If you want to get 10 as a fractional number, i.e. 10/1, you can use the contructor new Fraction("10").&lt;br /&gt;&lt;br /&gt;In order to add two fractional numbers a and b, you can use Util.add(a, b) method. Likewise you can to subtraction, multiplication and division. Please refer the code, it might be useful to understand the usage.&lt;br /&gt;&lt;br /&gt;Fraction.java&lt;br /&gt;&lt;pre class="prettyprint lang-java"&gt;public class Fraction {&lt;br /&gt;   &lt;br /&gt;    private Long denominator;&lt;br /&gt;    private Long numerator;&lt;br /&gt;    /** Creates a new instance of Fraction */&lt;br /&gt;    public Fraction(String denominator, String numerator) {&lt;br /&gt;        this(new Long(denominator), new Long(numerator));&lt;br /&gt;    }&lt;br /&gt;   &lt;br /&gt;    public Fraction(Long denominator, Long numerator) {&lt;br /&gt;        long gcd = Util.gcd(denominator, numerator);       &lt;br /&gt;        this.denominator = denominator / gcd;&lt;br /&gt;        this.numerator = numerator /gcd;&lt;br /&gt;    }&lt;br /&gt;   &lt;br /&gt;    public Fraction(String number) {&lt;br /&gt;        this.denominator = new Long("1");&lt;br /&gt;        this.numerator = new Long(number);&lt;br /&gt;    }&lt;br /&gt;   &lt;br /&gt;    public Fraction(long number) {&lt;br /&gt;        this.denominator = new Long("1");&lt;br /&gt;        this.numerator = new Long(number);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public Long getDenominator() {&lt;br /&gt;        return denominator;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public Long getNumerator() {&lt;br /&gt;        return numerator;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;Util.java&lt;br /&gt;&lt;pre class="prettyprint lang-java"&gt;public class Util {&lt;br /&gt;   &lt;br /&gt;    /** Creates a new instance of Util */&lt;br /&gt;    public Util() {&lt;br /&gt;    }&lt;br /&gt;  &lt;br /&gt;    public static long gcd(Long a, Long b) {      &lt;br /&gt;        if (b==0)&lt;br /&gt;            return a;&lt;br /&gt;        else&lt;br /&gt;            return gcd(b, a % b);&lt;br /&gt;    }&lt;br /&gt;   &lt;br /&gt;    public static long lcm(Long a, Long b) {&lt;br /&gt;        return (a/gcd(a, b))*b;&lt;br /&gt;    }&lt;br /&gt;   &lt;br /&gt;    // (a + b)&lt;br /&gt;    public static Fraction add(Fraction a, Fraction b) {&lt;br /&gt;       &lt;br /&gt;        Long denominator = lcm(a.getDenominator(), b.getDenominator());&lt;br /&gt;        Long numerator = a.getNumerator()*(denominator/a.getDenominator()) +&lt;br /&gt;                b.getNumerator()*(denominator/b.getDenominator());&lt;br /&gt;        return new Fraction(denominator, numerator);&lt;br /&gt;    }&lt;br /&gt;   &lt;br /&gt;    // (a - b)&lt;br /&gt;    public static Fraction substract(Fraction a, Fraction b) {&lt;br /&gt;       &lt;br /&gt;        Long denominator = lcm(a.getDenominator(), b.getDenominator());&lt;br /&gt;        Long numerator = a.getNumerator()*(denominator/a.getDenominator()) -&lt;br /&gt;                b.getNumerator()*(denominator/b.getDenominator());&lt;br /&gt;        return new Fraction(denominator, numerator);&lt;br /&gt;    }&lt;br /&gt;   &lt;br /&gt;    // (a * b)&lt;br /&gt;    public static Fraction multiply(Fraction a, Fraction b) {&lt;br /&gt;        return new Fraction(a.getDenominator() * b.getDenominator(), a.getNumerator() * b.getNumerator());&lt;br /&gt;    }&lt;br /&gt;   &lt;br /&gt;    // (a / b)&lt;br /&gt;    public static Fraction divide(Fraction a, Fraction b) {&lt;br /&gt;        return new Fraction(a.getDenominator() * b.getNumerator(), a.getNumerator() * b.getDenominator());&lt;br /&gt;    }&lt;br /&gt;   &lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5735449966988481504-6285797664280513152?l=ruchirawageesha.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ruchirawageesha.blogspot.com/feeds/6285797664280513152/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ruchirawageesha.blogspot.com/2009/01/add-multiply-divide-numbers-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5735449966988481504/posts/default/6285797664280513152'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5735449966988481504/posts/default/6285797664280513152'/><link rel='alternate' type='text/html' href='http://ruchirawageesha.blogspot.com/2009/01/add-multiply-divide-numbers-in.html' title='Add, Multiply, Divide Numbers in Fractional Format'/><author><name>wageesha</name><uri>http://www.blogger.com/profile/06227183882522305231</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/_FBxc7ILPVV8/SsW6Hduf6XI/AAAAAAAAACE/l9GDzujJIHg/S220/img_4008.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5735449966988481504.post-5123715240766230722</id><published>2009-01-10T00:11:00.000-08:00</published><updated>2011-06-17T11:00:52.879-07:00</updated><title type='text'>How to find gcd and lcm in Java</title><content type='html'>Here is the easiest and efficient way to get the Greatest Common Divisor(gcd) and Least Common Multiple(lcm) in Java. This algorithm could be used for any language. Here I have used Long data type. You can use integer as needed.&lt;br /&gt;&lt;pre class="prettyprint lang-java"&gt;public static long gcd(long a, long b) {      &lt;br /&gt;    if (b==0)&lt;br /&gt;        return a;&lt;br /&gt;    else&lt;br /&gt;        return gcd(b, a % b);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;pre class="prettyprint lang-java"&gt;public static long lcm(long a, long b) {&lt;br /&gt;    return (a / gcd(a, b)) * b;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5735449966988481504-5123715240766230722?l=ruchirawageesha.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ruchirawageesha.blogspot.com/feeds/5123715240766230722/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ruchirawageesha.blogspot.com/2009/01/how-to-find-gcd-and-lcm-in-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5735449966988481504/posts/default/5123715240766230722'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5735449966988481504/posts/default/5123715240766230722'/><link rel='alternate' type='text/html' href='http://ruchirawageesha.blogspot.com/2009/01/how-to-find-gcd-and-lcm-in-java.html' title='How to find gcd and lcm in Java'/><author><name>wageesha</name><uri>http://www.blogger.com/profile/06227183882522305231</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/_FBxc7ILPVV8/SsW6Hduf6XI/AAAAAAAAACE/l9GDzujJIHg/S220/img_4008.jpg'/></author><thr:total>0</thr:total></entry></feed>
