[OpenLayers-Users] Catching JSON

Smaran Harihar smaran.harihar at gmail.com
Mon Aug 20 16:02:59 PDT 2012


Thanks again Phil.

So should I simply copy the jsp code that you have given into a file and
name it proxy.jsp?

And is there any other setting that you want me to do?

Thanks,
Smaran

On Mon, Aug 20, 2012 at 1:56 PM, Phil Scadden <p.scadden at gns.cri.nz> wrote:

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



-- 
Thanks & Regards
Smaran Harihar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/openlayers-users/attachments/20120820/11d50302/attachment.html>


More information about the Users mailing list