|
From: Milton J. <mi...@te...> - 2010-03-19 13:38:12
|
Hey Justin. Hmm, well, mysteries of the web..? About the issue of reaching GeoServer even though the response didn't get to JavaScript: I just found out that it happens even when the script is on a different host altogether! So, it seems that the same origin policy blocks only the response... Weird, great security, heh? I guess one can just go and do all the PUTS he wants then.. :P Cheers Milton Justin Deoliveira wrote: > On 3/17/10 11:26 AM, Milton Jonathan wrote: >> Hi Justin >> >> Thanks for coming in! >> >> I've found out: yes, it WAS the same origin policy.. But now I AM >> confused. >> >> First thing: thanks a LOT for stating that I had to put it in the www >> directory. I had put it originally directly in the "webapps/geoserver", >> and it WAS accessible via http:localhost:8080/geoserver/myscript.html. >> So how would one know what's the path for the "right origin"? > > Afaik same origin applies to the host + port portion of the url. So I > guess this should have been the same origin. Perhaps it had something to > do with the location. >> >> Second thing, and this is what most confuses me: the request WAS going >> all the way to GeoServer and being processed! How come? Is the same >> origin policy only applied for issuing the response?? I thought it >> should have prevented the request from ever reaching the REST service >> code.. > Good question. I actually don't know how browsers enforce this policy. A > javascript devel would know the answer. But it might have something to > do with the fact that your resource was actually hitting the same origin > (since your page is beign served up from webapps/geoserver). > >> >> Anyway, thanks a ton. I see now that the OpenLayers WFS layer I never >> got to work is also fine (I'm still having problems setting up the >> proxy.cgi here on Windows, maybe it's a Python problem). >> >> Cheers >> Milton >> >> >> Justin Deoliveira wrote: >>> Hi Milton, >>> >>> Where are you serving the javascript from? The same origin policy will >>> apply for content accessed via the REST api. You need to ensure that >>> your javascript is being served by geoServer (www directory) or that >>> you are proxying for geoserver on the same host that is serving your >>> javascript. >>> >>> You may also find the following of interest: >>> >>> http://svn.codehaus.org/geoserver/trunk/src/extension/restconfig/src/client/javascript/lib/ >>> >>> >>> >>> It was a javascript REST api that was started but never got finished. >>> >>> -Justin >>> >>> >>> On 3/17/10 10:12 AM, Milton Jonathan wrote: >>>> Hey there >>>> >>>> This is not exactly a GeoServer issue, but I thought you guys might >>>> tell >>>> me if I'm on the wrong path (probably the case). >>>> >>>> I've recently tried to use GeoServer's REST API in JavaScript but could >>>> not get any GET requests to work. REST is in place and working: if I >>>> type "http://localhost:8080/geoserver/rest/layers" in the browser, it >>>> works and I get the list of layers in the server. Using CURL also works >>>> fine. >>>> >>>> However, when trying to use JavaScript, I never get these GET requests >>>> to work: the response theat arrives in JavaScript always has an empty >>>> response.responseText and a null response.responseXml. But its status >>>> is OK! >>>> >>>> I tried both using OpenLayers.Request.GET and directly using >>>> XMLHttpRequest. In both cases, I can see that the request arrives at >>>> GeoServer and is processed fine (I've put a breakpoint in GeoServer's >>>> code to make sure), so there's no proxy-like issue here (and after all, >>>> it's all running on localhost). >>>> >>>> So, what am I missing? It seems that the problem is to get >>>> JavaScript to >>>> correctly parse or understand the request's response. I always thought >>>> that this kind of REST API was especially relevant for use in >>>> JavaScript, but I keep scratching my head about how people use it. >>>> Should I simply not do this? Is there another way to do this request >>>> and >>>> get the response into JavaScript? >>>> >>>> Here's the code for the request using OpenLayers.Request: >>>> >>>> var request = OpenLayers.Request.GET({ >>>> url: "http://localhost:8080/geoserver/rest/layers", >>>> callback: handler >>>> }); >>>> >>>> function handler(request) { >>>> alert('responseXML: ' + request.responseXML); >>>> alert('responseText: ' + request.responseText); >>>> alert('status: ' + request.statusText); >>>> } >>>> >>>> >>>> And here's the code for the request using XMLHttpRequest: >>>> >>>> var xmlhttp = new XMLHttpRequest(); >>>> xmlhttp.open("GET", >>>> "http://localhost:8080/geoserver/rest/layers",true); >>>> xmlhttp.onreadystatechange=function() { >>>> if (xmlhttp.readyState==4) { >>>> alert('responseXML: ' + request.responseXML); >>>> alert('responseText: ' + request.responseText); >>>> alert('status: ' + request.statusText); >>>> } >>>> } >>>> xmlhttp.send(); >>>> >>>> In both cases, results are: >>>> responseXML: null >>>> responseText: >>>> status: OK >>>> >>>> >>>> Thanks for all >>>> Milton >>>> >>> >>> >> > > -- Milton Jonathan Grupo GIS e Meio Ambiente Tecgraf/PUC-Rio Tel: +55-21-3527-2502 |