1. #1
    Sencha Premium Member
    Join Date
    Apr 2012
    Location
    Germany
    Posts
    118
    Answers
    3
    Vote Rating
    3
    clifficious is on a distinguished road

      0  

    Default Unanswered: ST2 and OpenLayers Proxy for WMS services

    Unanswered: ST2 and OpenLayers Proxy for WMS services


    Hi there,

    I'm using OpenLayers for an application I want to develop. Now I want to query a WMS-Service. My problem is, that I'm not allowed to access data on another server because of security reasons concerning XSS

    Origin http://localhost:8080 is not allowed by Access-Control-Allow-Origin.

    When I run my code inside a Tomcat I can add a proxy.cgi. But eventually I need to build a proper app and I do not have the option to run a Tomcat inside my app. So what option do I have to get the connection right to connect to a different domain?

    Here is my code for the Tomcat:

    Code:
    OpenLayers.ProxyHost = "./cgi-bin/proxy.cgi?url=";
    info = new OpenLayers.Control.WMSGetFeatureInfo({
        url: wmsURL, 
        // url: 'http://www.wms.nrw.de/wms/uebersicht_nrw2?',
        title: 'More Information',
        infoFormat: 'application/vnd.ogc.gml',
        layers: [poisWMS],
        queryVisible: false,
        maxFeatures: 5,
        vendorParams: {buffer: 15},
        eventListeners: {
            getfeatureinfo: function(event) {
                setPOIHTML(event.text,map.getLonLatFromPixel(event.xy));
            }
        }
    });
    I would be very thankful for any solution to this problem.
    Thanks in advance!

    Cliff

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    35,673
    Answers
    3355
    Vote Rating
    749
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    You need to have your server support CORS. Some info: http://enable-cors.org/
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    Oct 2012
    Posts
    2
    Vote Rating
    0
    ahmedeloufir is on a distinguished road

      0  

    Default Use proxy.cgi

    Use proxy.cgi


    Hi,

    If you are using MapServer bundle MS4W, you should use proxy.cgi which you need to place in your cgi-bin folder. Change the first line
    Code:
     #!C:/Python26/python.exe -u
    in order to point into your python.exe.

    Then, in your JS code :
    Code:
    OpenLayers.ProxyHost = "../cgi-bin/proxy.cgi?url=";
    var renderer = OpenLayers.Util.getParameters(window.location.href).renderer;
    renderer = (renderer) ? [renderer] : OpenLayers.Layer.Vector.prototype.renderers
    
    
        var wfs = new OpenLayers.Layer.Vector("States", {
            strategies: [new OpenLayers.Strategy.Fixed()],
            protocol: new OpenLayers.Protocol.WFS({
                url: "http://demo.opengeo.org/geoserver/wfs",
                featureType: "states",
                featureNS: "http://www.openplans.org/topp"
            }),
            renderers: renderer
        });
    map.addLayers([wfs]);
    proxy.cgi
    Code:
    #!C:/Python26/python.exe -u
    
    
    
    """This is a blind proxy that we use to get around browser
    restrictions that prevent the Javascript from loading pages not on the
    same server as the Javascript.  This has several problems: it's less
    efficient, it might break some sites, and it's a security risk because
    people can use this proxy to browse the web and possibly do bad stuff
    with it.  It only loads pages via http and https, but it can load any
    content type. It supports GET and POST requests."""
    
    
    import urllib2
    import cgi
    import sys, os
    
    
    # Designed to prevent Open Proxy type stuff.
    
    
    allowedHosts = ['www.openlayers.org', 'openlayers.org', 
                    'labs.metacarta.com', 'world.freemap.in', 
                    'prototype.openmnnd.org', 'geo.openplans.org',
                    'sigma.openplans.org', 'demo.opengeo.org',
                    'www.openstreetmap.org', 'sample.azavea.com',
                    'v2.suite.opengeo.org', 'v-swe.uni-muenster.de:8080', 
                    'vmap0.tiles.osgeo.org', 'www.openrouteservice.org']
    
    
    method = os.environ["REQUEST_METHOD"]
    
    
    if method == "POST":
        qs = os.environ["QUERY_STRING"]
        d = cgi.parse_qs(qs)
        if d.has_key("url"):
            url = d["url"][0]
        else:
            url = "http://www.openlayers.org"
    else:
        fs = cgi.FieldStorage()
        url = fs.getvalue('url', "http://www.openlayers.org")
    
    
    try:
        host = url.split("/")[2]
        if allowedHosts and not host in allowedHosts:
            print "Status: 502 Bad Gateway"
            print "Content-Type: text/plain"
            print
            print "This proxy does not allow you to access that location (%s)." % (host,)
            print
            print os.environ
      
        elif url.startswith("http://") or url.startswith("https://"):
        
            if method == "POST":
                length = int(os.environ["CONTENT_LENGTH"])
                headers = {"Content-Type": os.environ["CONTENT_TYPE"]}
                body = sys.stdin.read(length)
                r = urllib2.Request(url, body, headers)
                y = urllib2.urlopen(r)
            else:
                y = urllib2.urlopen(url)
            
            # print content type header
            i = y.info()
            if i.has_key("Content-Type"):
                print "Content-Type: %s" % (i["Content-Type"])
            else:
                print "Content-Type: text/plain"
            print
            
            print y.read()
            
            y.close()
        else:
            print "Content-Type: text/plain"
            print
            print "Illegal request."
    
    
    except Exception, E:
        print "Status: 500 Unexpected Error"
        print "Content-Type: text/plain"
        print 
        print "Some unexpected error occurred. Error text was:", E

Thread Participants: 2

Tags for this Thread

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar