Thanks again Phil.<div><br></div><div>So should I simply copy the jsp code that you have given into a file and name it proxy.jsp?</div><div><br></div><div>And is there any other setting that you want me to do?</div><div><br>

</div><div>Thanks,</div><div>Smaran<br><br><div class="gmail_quote">On Mon, Aug 20, 2012 at 1:56 PM, Phil Scadden <span dir="ltr"><<a href="mailto:p.scadden@gns.cri.nz" target="_blank">p.scadden@gns.cri.nz</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im"><br>
> Did u mean that I should have my py script to which I making the AJAX<br>
> request in the same dir? Then I already have. Only issue is that, the<br>
> script is running on port 9000<br>
> (<a href="http://128.196.142.94:9000/info?lat=53.33935546875&lon=-121.99951171875" target="_blank">http://128.196.142.94:9000/info?lat=53.33935546875&lon=-121.99951171875</a>).<br>
> So the domain is same but the ports are different.<br>
</div>If ports are different, then its cross-domain.<br>
<a href="http://en.wikipedia.org/wiki/Same_origin_policy" target="_blank">http://en.wikipedia.org/wiki/Same_origin_policy</a><br>
<div class="im"><br>
><br>
> check that the passed URL is reasonable for the application to call<br>
><br>
> I was able to call py script url (wget<br>
> "<a href="http://128.196.142.94:9000/info?lat=53.33935546875&lon=-121.99951171875" target="_blank">http://128.196.142.94:9000/info?lat=53.33935546875&lon=-121.99951171875</a>"<br>
> -o test.1.log -O test.1), u can run this on terminal and it should<br>
> fetch you the JSON.<br>
</div>Then call it via a proxy. XHR has the very tight rules for a good<br>
reason. By trying to fight browser security, you are on just making life<br>
difficult for yourself.<br>
<div class="im">><br>
> So, after this, how should I complete the other two parts?<br>
><br>
>  2/ Open an http connection to the passed page<br>
> 3/ pipe the page content as output.<br>
</div>This is dependent on what your server and servlet container is. I use<br>
tomcat and so I have a proxy.jsp to do the work. Source code for<br>
white-list proxies are on the net.  After checking the IP is okay<br>
(involved for my case), then the jsp code is:<br>
     if (okFlag) {<br>
         BufferedReader brrr = request.getReader();<br>
         String s;<br>
         StringBuffer postContent = new StringBuffer();<br>
         while((s = brrr.readLine()) != null)<br>
             postContent.append(s);<br>
<br>
         HttpURLConnection connection = (HttpURLConnection)<br>
url.openConnection();<br>
         if (postContent.length() > 0) {<br>
             connection.setUseCaches(false);<br>
             connection.setRequestMethod("POST");<br>
             connection.setDoInput(true);<br>
             connection.setDoOutput(true);<br>
             connection.setRequestProperty("Content-Type",<br>
"application/xml");<br>
<br>
             OutputStreamWriter wr = new<br>
OutputStreamWriter(connection.getOutputStream());<br>
             wr.write(postContent.toString());<br>
             wr.flush();<br>
             wr.close();<br>
         }<br>
<br>
         String contentType = connection.getContentType();<br>
         if ("application/vnd.ogc.wms_xml".equals(contentType))<br>
             contentType = "text/xml";<br>
         response.setContentType(contentType);<br>
         InputStream input = connection.getInputStream();<br>
         BufferedInputStream bis = new BufferedInputStream(input);<br>
         ByteArrayOutputStream buf = new ByteArrayOutputStream();<br>
<br>
         int result = bis.read();<br>
         while (result != -1) {<br>
             byte b = (byte)result;<br>
             buf.write(b);<br>
             result = bis.read();<br>
         }<br>
         %><%=buf.toString()%><%<br>
     } else {<br>
         %>Access to <%=urlString%> prohibited<%<br>
     }<br>
You should seek help on writing/getting a proxy from user groups<br>
dedicated to your particular server arrangement. I cant help you there.<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
Notice: This email and any attachments are confidential. If received in error please destroy and immediately notify us. Do not copy or disclose the contents.<br>
<br>
_______________________________________________<br>
Users mailing list<br>
<a href="mailto:Users@lists.osgeo.org">Users@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/openlayers-users" target="_blank">http://lists.osgeo.org/mailman/listinfo/openlayers-users</a><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br>Thanks & Regards<div>Smaran Harihar</div><br>
</div>