Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Access-Control-Allow-Origin Header and DataSource Post

    Hi,
    I want to POST some Data from a SmartGWT App on Domain B to a Script on Domain A.
    The Script sends the header: Access-Control-Allow-Origin: *
    So from what I understand I should be allowed to post to this different domain (Chrome doesn't complain in the console with this header).
    Yet SmartGWT cancels the POST and says it cannot contact that host (same origin policy).

    Is the access-control-allow-origin header not supported by smartGWT?
    My post has the following data protocol: setDataProtocol(DSProtocol.POSTPARAMS);
    JSONP is not an option for me.

    Thanks

    #2
    The log message you receive when the post is cancelled tells you what to do to allow it through.

    Comment


      #3
      Thanks for your fast answer.
      The log message basically recommends using JSONP which is not an option for me (too much data to post):
      Code:
      SmartClient can't directly contact URL '...' due to browser same-origin policy. Remove the host and port number (even if localhost) to avoid this problem, or use XJSONDataSource for JSONP protocol (which allows cross-site calls), or use the server-side HttpProxy included with SmartClient Server.
      This warning may be suppressed by setting RPCManager.allowCrossDomainCalls to true.
      And since the contacted URL sends the header "Access-Control-Allow-Origin: *" I should be able to contact that URL via post request. See https://developer.mozilla.org/En/HTT...l-Allow-Origin

      So is this header not supported by SmartGWT?? Or is it a bug? Or am I missing something? Thanks

      edit. Or how can I set RPCManager.allowCrossDomainCalls in a DataSource? Where is the RPCManager object in the datasource?
      Last edited by Zordon; 27 Dec 2011, 14:39.

      Comment


        #4
        Right.. so.. what property does that log message tell you to set?

        Comment


          #5
          Thanks.
          My mistake.

          Comment


            #6
            How did you implement CORS?

            I am using Spring 3.2 with MVC and RESTful controllers. Although we could put controllers on the SmartGWT 4.0 web-app, we are trying to put the RESTful back-end on another server.

            Since we want the full CRUD support, and the full REST support for GET, PUT, POST, DELETE, then JSONP is not a good choice for us since JSONP only supports GET.

            We are using the CorsFilter back end which we found from another web-site, and that looks like it works. It needs the "Access-Control-Allow-Origin" in he header.

            So, what I am wondering is which DataSource did you use? RestDataSource or the XJSONDataSource? How did you include the new header for "Access-Control-Allow-Origin"? And what type of back-end are you using to support CORS? Is it Spring MVC 3.2 with a CORS filter?

            This is what I am trying to resolve today, and any help would be much appreciated. Thanks!

            Comment

            Working...
            X