Announcement

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

    does smartgwt incorporate http access control headers?

    Hi all,

    i had a bit of a problem with cross domain requests by my application
    and on the serverside im setting some Access-Control-Allow headers
    to get around this in firefox.

    one problem now is that my application works like i want it but i keep getting
    the message 'SmartClient can't directly contact URL ... due to browser .....'
    everybody knows. in fact, all my livegrids load correctly, but i keep getting this message like some kind of hint that its not good practice

    just to make sure, it seems i have no problem with cross domain requests
    cause everything works great
    but from the pieces of the smartgwtcode i read, it seems that
    the code which causes the error message ignores specifications like
    https://developer.mozilla.org/En/HTTP_Access_Control

    as i understand this, its possible to do cross domain requests if the correct headers are set on the server side (which in my case works)
    and this post http://forums.smartclient.com/showthread.php?t=4164
    seems also to be outdated
    so my question:
    could it be that smartgwt's error message is some kind of out dated?

    for documentation, the headers on server side are:
    $toallowheader = $this->getRequest()->getHeader("Access-Control-Request-Headers");
    $this->getResponse()->setHeader('Cache-Control', 'no-cache, must-revalidate');
    $this->getResponse()->setHeader('Expires', 'Sat, 26 Jul 1997 05:00:00 GMT');
    $this->getResponse()->setHeader('Access-Control-Allow-Origin', '*');
    $this->getResponse()->setHeader('Access-Control-Allow-Methods', '*');
    $this->getResponse()->setHeader('Access-Control-Allow-Headers', "$toallowheader, *");
    $this->getResponse()->setHeader('Access-Control-Max-Age', '1');
    $this->getResponse()->setHeader('Access-Control-Allow-Credentials', 'true');


    smartgwt: 2.4
    firefox: 3.6.13

    the data source
    Code:
    package project.shared.Util.Json;
    
    import project.shared.Util.Window.Loading;
    import com.smartgwt.client.data.DSRequest;
    import com.smartgwt.client.data.DSResponse;
    import com.smartgwt.client.data.RestDataSource;
    import com.smartgwt.client.types.DSDataFormat;
    
    public class DataSource extends RestDataSource
    {
    	protected String service = null;
    	protected String method  = null;
    
    	public DataSource setService(String service, String method){
    		this.setDataFormat(DSDataFormat.JSON);
    		this.service = service;
    		this.method  = method;
    
    		this.resetDataUrl();
    
    		return this;
    	}
    
    	public DataSource resetDataUrl(){
                    // this will be e.g.
                    // http://127.0.0.1/rpc/Query/listData?output=json&sldquery=searchstuff&_operationType=fetch&_startRow=0&_endRow=50&_textMatchStyle=exact&_componentId=isc_DomainGrid_0&_dataSource=isc_DataSource_1&isc_metaDataPrefix=_&isc_dataFormat=json
    		this.setDataURL(ServiceCall.getServiceURL(this.service, this.method)+"?output=json");
    		return this;
    	}
    
    	protected Object transformRequest(DSRequest dsRequest){
    		//Loading.show(this.getDataURL(), "Loading data ...");
    		return super.transformRequest(dsRequest);
    	}
    
    	protected void transformResponse(DSResponse response,
                DSRequest request,
                Object data){
    		//Loading.hide(this.getDataURL());
    		super.transformResponse(response, request, data);
    	}
    }
    the grid
    Code:
    package project.shared;
    
    import project.client.gui.QueryResults;
    import com.smartgwt.client.data.Criteria;
    import com.smartgwt.client.data.DataSourceField;
    import com.smartgwt.client.data.fields.DataSourceTextField;
    import com.smartgwt.client.rpc.RPCManager;
    import com.smartgwt.client.types.FieldType;
    import com.smartgwt.client.types.ListGridFieldType;
    import com.smartgwt.client.types.PromptStyle;
    import com.smartgwt.client.widgets.grid.ListGrid;
    import com.smartgwt.client.widgets.grid.ListGridField;
    
    public class DomainGrid extends ListGrid{
    
    	public DomainGrid(){
    		RPCManager.setPromptStyle(PromptStyle.CURSOR);  
    		project.shared.Util.Json.DataSource dataSource = this.initDataSource();
    
    		this.setAutoFetchData(false);
    		this.setDataSource(dataSource);
    
    		this.setCanEdit(false);
    	}
    
    	protected project.shared.Util.Json.DataSource initDataSource(){
    		project.shared.Util.Json.DataSource ds = new project.shared.Util.Json.DataSource();
    		ds.setService("Query", "listData");
            ds.setRecordXPath("/result/response/data");
    
            DataSourceTextField someField = new DataSourceTextField("somefield", "somefield 128, true);
    
    		ds.setFields(someField);  
    
    		return ds;
    	}
    
    }
    Last edited by thinking; 11 Feb 2011, 10:46.

    #2
    bump... anyone?

    Comment


      #3
      We've added a new Boolean flag to explicitly disable this warning within your application.
      Look for the new RPCManager.setAllowCrossDomainCalls(Boolean allowCrossDomainCalls); API - it will be present in the next nightly build

      Thanks
      Isomorphic Software

      Comment

      Working...
      X