RequestPermissionException: URL is invalid or violates the same-origin security restriction

1,612 views
Skip to first unread message

Vrushali Patil

unread,
Sep 6, 2011, 11:45:19 AM9/6/11
to google-we...@googlegroups.com
Hi,

Can anyone help I am getting this error. And I have gone through all the older posts but not able to resolve. I am trying to send request to Tomcat server to get "SOS" data from a WAR file "52nSOSv3_WAR" 

Error:

com.google.gwt.http.client.RequestPermissionException: The URL http://localhost:8080/52nSOSv3_WAR/sos is invalid or violates the same-origin security restriction
at com.google.gwt.http.client.RequestBuilder.doSend(RequestBuilder.java:380)
    at com.google.gwt.http.client.RequestBuilder.sendRequest(RequestBuilder.java:256)
    at edu.xml.gwt.ibm.tutorialDemo1.client.TutorialDemo1.doPost(TutorialDemo1.java:73)
    at edu.xml.gwt.ibm.tutorialDemo1.client.TutorialDemo1.onModuleLoad(TutorialDemo1.java:51)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at com.google.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:396)
    at com.google.gwt.dev.shell.OophmSessionHandler.loadModule(OophmSessionHandler.java:193)
    at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:510)
    at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:352)
    at java.lang.Thread.run(Unknown Source)
Caused by: com.google.gwt.http.client.RequestException: (TypeError): Access is denied.

-----------------------------------------------------
My code is
     
        url = "http://localhost:8080/52nSOSv3_WAR/sos";
        requestquery = "REQUEST=GetCapabilities";
        StringBuffer posturl = new StringBuffer();
        posturl.append(URL.encode(url));
       
        StringBuffer postquery = new StringBuffer();
        postquery.append(URL.encode(requestquery));
       
        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, posturl.toString());
        builder.setHeader("Content-Type","text/xml");
       
            builder.sendRequest(postquery.toString(), new RequestCallback() {
            public void onError(Request request, Throwable exception) {
              // code omitted for clarity
                System.out.println(exception.getCause().toString());
            }

            @Override
            public void onResponseReceived(Request request,Response response) {
                // TODO Auto-generated method stub
                String var = "";
                var = response.getText();
                System.out.println("This is response");
                System.out.println(var);
               
            }
          });            
         
     

    }

Jens

unread,
Sep 6, 2011, 12:17:43 PM9/6/11
to google-we...@googlegroups.com
Where is your app (client side javascript) hosted? 

If the client code is not hosted on localhost:8080 then you have the Same Origin Policy problem. RequestBuilder or better JavaScript can only do requests to URLs that belong to the same domain and port under which the JavaScript/HTML Page is accessible. This is implemented in all browsers for security reasons.

Your options are:
- Deploy everything (including client side code) to your external server and start the app there. That way everything will be served from localhost:8080.
- use GWT's JSONPRequestBuilder which does a nifty trick to make cross domain/port requests work (you also have to update the remote servlets!)
- install a webserver that supports reverse proxy (Apache, nginx, etc.) and redirect/proxy the remote requests. For example if you request http://localhost/remote/request you can proxy the request to a different host like http://localhost:8080/app<request_uri>. Thats what I do because it matches my production setup.

-- J.


Vrushali Patil

unread,
Sep 6, 2011, 12:51:17 PM9/6/11
to google-we...@googlegroups.com, jens.ne...@gmail.com
Thanks Jen,

Can you give me a example for the third option for proxy. I am new with Java and GWT both. It will be very helpful if I have a example. I am using Apache Tomcat webserver. Proxy will be more useful since I will need to interact with few more servers in future.

Regards,
Vrushali


--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/01YeGjAItRsJ.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

Reply all
Reply to author
Forward
0 new messages