<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Dimuthu's Blog &#187; javascript</title>
	<atom:link href="http://www.dimuthu.org/catagory/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dimuthu.org</link>
	<description>Waiting for your comments</description>
	<lastBuildDate>Wed, 21 Dec 2011 05:39:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<image>
  <link>http://www.dimuthu.org</link>
  <url>http://www.dimuthu.org/favicon.ico</url>
  <title>Dimuthu's Blog</title>
</image>
		<item>
		<title>Security Considerations in Firefox When Accessing Different Domains</title>
		<link>http://www.dimuthu.org/blog/2008/12/22/security-considerations-in-firefox-when-accessing-different-domains/</link>
		<comments>http://www.dimuthu.org/blog/2008/12/22/security-considerations-in-firefox-when-accessing-different-domains/#comments</comments>
		<pubDate>Mon, 22 Dec 2008 18:14:57 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[firefox]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[domains]]></category>
		<category><![CDATA[external domains]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=843</guid>
		<description><![CDATA[If you are a web developer you may have experienced that there are many situations that you need to access remote domains for data sources. For an example if you are building a weather mashup, you may like to connect to some weather forecasting services like  http://www.weather.gov or http://weather.cnn.com/weather/forecast.jsp. Mostly these services are very simple, [...]]]></description>
			<content:encoded><![CDATA[<p>If you are a web developer you may have experienced that there are many situations that you need to access remote domains for data sources. For an example if you are building a weather mashup, you may like to connect to some weather forecasting services like  <a href="http://www.weather.gov">http://www.weather.gov</a> or <a href="http://weather.cnn.com/weather/forecast.jsp">http://weather.cnn.com/weather/forecast.jsp</a>. Mostly these services are very simple, so you can build these services from Javascript  itself. (FYI you can use the blog post, I wrote sometime back, <a href="http://www.dimuthu.org/blog/2008/12/11/calling-simple-web-services-from-javascript/">Calling Simple Web Services From Javascript</a>.) But browsers doesn&#8217;t make it this much straight forward.</p>
<p>For an example if you try running the following code, which basically do a simple AJAX call to an external domain,</p>
<pre class="javascript">    <span style="font-style: italic; color: #009900;">// some external domain</span>
    <span style="font-weight: bold; color: #003366;">var</span> url = <span style="color: #3366cc;">"http://test.dimuthu.org"</span>;

    <span style="font-style: italic; color: #009900;">// doing the ajax call</span>
    <span style="font-weight: bold; color: #003366;">var</span> req = <span style="font-weight: bold; color: #003366;">new</span> XMLHttpRequest<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;

    req.<span style="color: #000066;">open</span><span style="color: #66cc66;">(</span><span style="color: #3366cc;">"GET"</span>, url, <span style="font-weight: bold; color: #003366;">true</span><span style="color: #66cc66;">)</span>;
    req.<span style="color: #006600;">onreadystatechange</span> = <span style="font-weight: bold; color: #003366;">function</span> <span style="color: #66cc66;">(</span>e<span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>
        <span style="font-weight: bold; color: #000066;">if</span> <span style="color: #66cc66;">(</span>req.<span style="color: #006600;">readyState</span> == <span style="color: #cc0000;">4</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>
            <span style="font-weight: bold; color: #000066;">if</span><span style="color: #66cc66;">(</span>req.<span style="color: #000066;">status</span> == <span style="color: #cc0000;">200</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>
                <span style="color: #000066;">alert</span><span style="color: #66cc66;">(</span>req.<span style="color: #006600;">responseText</span><span style="color: #66cc66;">)</span>;
            <span style="color: #66cc66;">}</span>
        <span style="color: #66cc66;">}</span>
    <span style="color: #66cc66;">}</span>

    req.<span style="color: #006600;">send</span><span style="color: #66cc66;">(</span><span style="font-weight: bold; color: #003366;">null</span><span style="color: #66cc66;">)</span>;</pre>
<p>You will get a security exception from the Firefox (opera too gives a similar exception).</p>
<pre><span style="color: #ff0000;">uncaught exception: Access to restricted URI denied (NS_ERROR_DOM_BAD_URI)</span></pre>
<p>In order to avoid this, you have do some special work.</p>
<ol>
<li>You need to add the following code before doing any AJAX request to external domains, This will give the script special privileges to access any domain through XMLHttpRequest object.
<pre class="javascript">    <span style="font-weight: bold; color: #000066;">try</span> <span style="color: #66cc66;">{</span>
        netscape.<span style="color: #006600;">security</span>.<span style="color: #006600;">PrivilegeManager</span>.<span style="color: #006600;">enablePrivilege</span><span style="color: #66cc66;">(</span><span style="color: #3366cc;">"UniversalBrowserRead"</span><span style="color: #66cc66;">)</span>;
    <span style="color: #66cc66;">}</span> <span style="font-weight: bold; color: #000066;">catch</span> <span style="color: #66cc66;">(</span>e<span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>
        <span style="color: #000066;">alert</span><span style="color: #66cc66;">(</span><span style="color: #3366cc;">"Permission UniversalBrowserRead denied."</span><span style="color: #66cc66;">)</span>;
    <span style="color: #66cc66;">}</span></pre>
</li>
<li> If your script always jump to the exception, you have to configure your browser to allow the above setting. You can do this by going to the &#8220;about:config&#8221; page in Firefox (Just type the &#8220;about:config&#8221; in the url field and hit Enter) where it shows a list of configurations, there you need to set &#8220;signed.applets.codebase_principal_support&#8221; field to &#8220;true&#8221;. By default this field is set to false in Firefox 3.0</li>
</ol>
<p>After you completed above 2 steps, the page will show you an warning message saying that it is asking more privileges, in which the client have to click the &#8220;allow&#8221; button to continue.</p>
<p>This procedure is not much difficult to setup, but still it will be really painful for an average user, so it is better you avoid this as much as possible in your code.</p>
<p>The main reason this special setup is arranged in Firefox (and most of the other browsers) is attackers can run malicious scripts in some page which you trust, (for an example from one of your email message) and send your private data to some other domain that you don&#8217;t know and don&#8217;t trust.</p>
<p>Apart from XMLHttpRequest another famous way of accessing different domains from a web page is using framesets or iframes. using this technique, You can show an external web page inside yours as it is one part of that.</p>
<p>Before Firefox 3.0 and IE 7.0 you were able to change that external page (appearance or the content) according to your need when it is shown in a frame or iframe. This was possible to do by manipulating the DOM of that external page. But with Firefox 3.0 and IE 7.0 it is impossible. That is you still you can show an external page inside your web page, but you can&#8217;t change anything of it even it shows inside your page. Because it doesn&#8217;t allow you to access the DOM of that external page. See this issue is discussed in details at here, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=397828">https://bugzilla.mozilla.org/show_bug.cgi?id=397828</a></p>
<p>With this improvement, you can&#8217;t call the <a href="http://developer.mozilla.org/en/docs/DOM:window.document">window.document</a> if the page of the window is from external domain.</p>
<p>The reason to this limitation is apparent, if you ever thought of modifying external pages and put it in your web page, you will be able feel many security holes in there. You can show some web based email login page in one of iframe, and fool some users. If that web based email application is not changed by the iframe container, it won&#8217;t be a problem, but how it is changed to submit your username, password to the parent site by updating the submit event (onclick attribute) of the DOM of that external page.</p>
<p>In fact Firefox and most of the browsers are trying to protect your from all these security attacks by restricting lot of functionalities of the browsers. They are doing what they can do it in the client side, but you don&#8217;t know what exactly happens in the server side since it is always a black box. The all the restriction mentioned above (i.e. accessing remote services, changing and showing an external web page) can be done in very simple PHP or .NET code in server side. So it is right that you should use the right tools, but more important thing is you are aware of these attacks and you selectively browse web while avoiding them</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/12/22/security-considerations-in-firefox-when-accessing-different-domains/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Calling Simple Web Services From Javascript</title>
		<link>http://www.dimuthu.org/blog/2008/12/11/calling-simple-web-services-from-javascript/</link>
		<comments>http://www.dimuthu.org/blog/2008/12/11/calling-simple-web-services-from-javascript/#comments</comments>
		<pubDate>Thu, 11 Dec 2008 12:00:59 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[mashup server]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[SOA]]></category>
		<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[mashup]]></category>
		<category><![CDATA[SOAP]]></category>
		<category><![CDATA[web applications]]></category>
		<category><![CDATA[WSRequest]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=785</guid>
		<description><![CDATA[If you are a web developer, you may have found many occasions you have to create simple mashups for your web site. There you call web services or data services to fill the content of the web page. Most of the time we call web services from a server side script, since there are many [...]]]></description>
			<content:encoded><![CDATA[<p>If you are a web developer, you may have found many occasions you have to create simple mashups for your web site. There you call web services or data services to fill the content of the web page. Most of the time we call web services from a server side script, since there are many server side technologies like Java, PHP, .NET support web services.</p>
<p>But sometime it is in vain that you call your server scripts for a simple web service request. In fact You can use the famous XMLHttpRequest object to do the same thing from the client side itself. But you may need to prepare the complete SOAP envelope (Yea with SOAP headers, if required) in your hand to send it through XMLHttpRequest.</p>
<p>Another option is to  use the WSRequest script (<a href="http://mooshup.com/js/wso2/WSRequest.js">http://mooshup.com/js/wso2/WSRequest.js</a>). We normally use this script in the <a href="http://wso2.org/projects/mashup">WSO2 Mashup Server</a> to call the mashups designed in the serverside using stub. (The server side mashup is also mostly written in Javascript). We can use this script stand alone to call remote web services as well.</p>
<p>It introduce you the WSRequest class. It is exactly similar to the famous XMLHttpRequest class we used in  AJAX. In stead of plain message over HTTP like in the case of XMLHttpRequest, WSRequest send and receive messages in SOAP form. Here is its API in brief.</p>
<pre class="javascript"><span style="font-weight: bold; color: #003366;">var</span> WSRequest = <span style="font-weight: bold; color: #003366;">function</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>
    <span style="font-style: italic; color: #009900;">//----------------------------------------------------</span>
    <span style="font-style: italic; color: #009900;">// the public properties - equivalent to XMLHTTPRequest</span>
    <span style="font-style: italic; color: #009900;">//-----------------------------------------------------</span>
    <span style="font-weight: bold; color: #000066;">this</span>.<span style="color: #006600;">readyState</span> = <span style="color: #cc0000;">0</span>;
    <span style="font-weight: bold; color: #000066;">this</span>.<span style="color: #006600;">responseText</span> = <span style="font-weight: bold; color: #003366;">null</span>;
    <span style="font-weight: bold; color: #000066;">this</span>.<span style="color: #006600;">responseXML</span> = <span style="font-weight: bold; color: #003366;">null</span>;
    <span style="font-weight: bold; color: #000066;">this</span>.<span style="color: #006600;">error</span> = <span style="font-weight: bold; color: #003366;">null</span>;  <span style="font-style: italic; color: #009900;">// equivalent to httpErrorCode</span>
    <span style="font-weight: bold; color: #000066;">this</span>.<span style="color: #006600;">onreadystatechange</span> = <span style="font-weight: bold; color: #003366;">null</span>;
    <span style="font-weight: bold; color: #000066;">this</span>.<span style="color: #006600;">proxyAddress</span> = <span style="font-weight: bold; color: #003366;">null</span>;
    <span style="font-weight: bold; color: #000066;">this</span>.<span style="color: #006600;">proxyEngagedCallback</span> = <span style="font-weight: bold; color: #003366;">null</span>
<span style="color: #66cc66;">}</span>

<span style="font-style: italic; color: #009900;">//----------------------------------------------------</span>
<span style="font-style: italic; color: #009900;">// the public operations - equivalent to XMLHTTPRequest</span>
<span style="font-style: italic; color: #009900;">//-----------------------------------------------------</span>

<span style="font-style: italic; color: #009900;">/**
 * @description Prepare a Web Service Request .
 * @method open
 * @param {hash} options,
 *   possible options: possible values for the option
 *            useSOAP : false/true/1.1/1.2
 *            useWSA : true/false/1.0/submission
 *            useWSS : true/false (only for usernametoken &amp; timestamp)
 *
 * @param {string} URL
 * @param {boolean} asyncFlag
 * @param {string} username
 * @param {string} password
 */</span>
WSRequest.<span style="color: #006600;">prototype</span>.<span style="color: #000066;">open</span> = <span style="font-weight: bold; color: #003366;">function</span><span style="color: #66cc66;">(</span>options, URL, asnycFlag, username, password<span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>.. <span style="color: #66cc66;">}</span>

<span style="font-style: italic; color: #009900;">/**
 * @description Send the payload to the Web Service.
 * @method send
 * @param {dom} response xml payload
 */</span>
WSRequest.<span style="color: #006600;">prototype</span>.<span style="color: #006600;">send</span> = <span style="font-weight: bold; color: #003366;">function</span><span style="color: #66cc66;">(</span>payload<span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>.. <span style="color: #66cc66;">}</span></pre>
<p>I wrote a simple javascript/html demo which calls the data service that I published for my blog. This service is written using <a href="http://wso2.org/projects/wsf/php">WSF/PHP</a> Data Services. Check the demo and client, service sources  from the following links.</p>
<table border="0">
<tbody>
<tr>
<td class="first">AJAX Tag Search</td>
<td class="second"><a href="http://ws.dimuthu.org/blog/WordpressTagSearchJSClientNoAuth.html">Demo</a> |  <a href="http://ws.dimuthu.org/blog/WordpressTagSearchServiceNoAuth.php?wsdl">WSDL</a><a> | </a><a href="http://ws.dimuthu.org/source.php?src=tag.search.NoAuthclient">Client</a> |  <a href="http://ws.dimuthu.org/source.php?src=tag.search.NoAuthservice">Service</a></td>
<td class="third">Demonstrates how you use SOAP Data Services using WSRequest object to retrieve the data asynchronously from javascript</td>
</tr>
</tbody>
</table>
<p>There You can see, how easy to write an AJAX like page for call web services using the WSRequest javascript class.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/12/11/calling-simple-web-services-from-javascript/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

