Announcement

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

    DataSource data url problem

    I recently ran into SOP issues when deploying my app behind a reverse proxy, and figured out that the problem was that I was using absolute data paths when contacting the server.

    However, when trying to change the paths in my datasources, I can't get it to work. I started out with absolute paths like so:

    Code:
    this.setDataURL(GWT.getModuleBaseURL() + "resource");
    and this would successfully contact the server, as I wanted. Now, however, when trying to change the paths to relative ones, what I'm left with is:

    Code:
    this.setDataURL("/resource");
    I've tried specifying the resource without slashes, with only trailing slash, and with both starting and trailing slashes, but the only thing that happens is that my datasource tries to fetch data from the folder "resource" in the war directory, it's not making a call to my server as I would have expected.

    My datasource looks like this:

    Code:
    public class MyDataSource extends DataSource 
    {
      private static final String FETCH_URL = "resource";
    
      public MyDataSource() 
      {
         this.setClientOnly(false);
         this.setDataFormat(DSDataFormat.JSON);  
         DataSourceField idField = new DataSourceField("id", FieldType.TEXT,  "Id");  
         this.setFields(idField);  
         this.setDataURL(FETCH_URL);  
      }
    }
    The start of the error I get looks like so (and then it goes on to describing the directory "resource" in my war folder):

    Code:
    13:05:10.808 [ERROR] [resource] 13:05:10.824:XRP6:WARN:DataSource:isc_MyDataSource_0:Error 
    evaluating JSON: SyntaxError: illegal XML character, JSON text: 
    <HTML><HEAD><TITLE>Directory: /resource/</TITLE></HEAD><BODY>
    <H1>Directory: /resource/</H1><TABLE BORDER=0><TR><TD><A 
    HREF=/resource/../ ...
    I can also say that using the relative data url when making manual calls to the server works just as it should, as shown below:

    Code:
    String url = URL.encode(FETCH_URL);
    RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
    builder.sendRequest(null, new RequestCallback() //.. and so on... //
    I am running Windows 7, latest versions of Chrome and Firefox, and a smartgwt build from about a month ago. Got any idea what I'm doing wrong? How can I get my datasource to understand that it needs to contact my server?

    #2
    It *is* contacting the server. It looks like the /resource URL you've configured is returning an HTML directory listing instead of the expected JSON response. This should be clear in the RPC tab of the Developer Console.

    Comment


      #3
      I don't get it. When I call the same resource manually I get the correct json result sent back to me:

      Code:
      String url = URL.encode("resource");
      RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
      builder.sendRequest(null, new RequestCallback()
      The above returns the correct result. Why won't my datasource get the same results?

      Comment


        #4
        Almost certainly because a different URL is being used, or a different HTTP verb (GET vs POST). Look in the RPC tab and/or Firebug's Net panel.

        Comment


          #5
          The method is GET in both cases. However, the url I get from the developer console is just "resource". If my absolute path is www.mysite.com/resource , how do I specify a relative url such that the datasource gets what I'm talking about?

          Comment


            #6
            It works just like you'd expect, SmartGWT uses your relative URL directly with the underlying xmlHttpRequest and the browser interprets it as relative to the current page URL.

            So as previously suggested, use the Firebug Net panel to see what's different about this request.

            Comment


              #7
              Managed to solve it. Thanks for your help.

              Comment


                #8
                Can you please share how you solve it ?

                Comment


                  #9
                  The problem was that I was using absolute paths rather than relative ones.
                  Last edited by banang; 3 Jan 2011, 00:33.

                  Comment

                  Working...
                  X