XJSONDataSource has some problem to access my web site

Hello all,

i modify this sample [ Yahoo! JSON Service ] and juse modify

yahooDS.setDataURL("http://api.search.yahoo.com/ImageSearchService/V1/imageSearch?appid=YahooDemo&output=json");

change to

yahooDS.setDataURL("http://test.mysite/a.html");

the sample source code here ==> http://www.smartclient.com/smartgwt/showcase/sourcegen/dataintegration/json/YahooJsonServicesSample.java.html
,

and i copy the text result from “http://api.search.yahoo.com/ImageSearchService/V1/imageSearch?appid=YahooDemo&output=json&query=snowboarding” to my website, and save it “a.html”

{"ResultSet":{"totalResultsAvailable":"10414286","totalResultsReturned":10,"firstResultPosition":1,"Result":[{"Title":"GraunkeSnow670x541 jpg","Summary":"Snow Covered Home in Colorado","Url":"http:\/\/snowdonhopkins.com\/graphics\/GraunkeSnow670x541.jpg","ClickUrl":"http:\/\/snowdonhopkins.com\/graphics\/GraunkeSnow670x541.jpg","RefererUrl":"http:\/\/snowdonhopkins.com\/GraunkeRes.html","FileSize":386355,"FileFormat":"jpeg","Height":"541","Width":"670","Thumbnail":{"Url":"http:\/\/thm-a01.yimg.com\/image\/156cb3036ccf0f76","Height":"121","Width":"150"}},{"Title":"Edenpics com 001 007 Plain near a forest edge with snow and frontal sun Switzerland Vaud Marchairuz jpg","Summary":"cat1024 jpg Taille   1024x768 Edenpics com 001 007 Plain near a forest edge with snow and frontal sun Switzerland Vaud Marchairuz jpg Taille   1024x768","Url":"http:\/\/www.bergoiata.org\/fe\/divers60\/Edenpics-com_001-007-Plain-near-a-forest-edge-with-snow-and-frontal-sun-Switzerland-Vaud-Marchairuz.jpg","ClickUrl":"http:\/\/www.bergoiata.org\/fe\/divers60\/Edenpics-com_001-007-Plain-near-a-forest-edge-with-snow-and-frontal-sun-Switzerland-Vaud-Marchairuz.jpg","RefererUrl":"http:\/\/www.bergoiata.org\/fe\/divers60\/25.htm","FileSize":113254,"FileFormat":"jpeg","Height":"768","Width":"1024","Thumbnail":{"Url":"http:\/\/thm-a02.yimg.com\/image\/eb82ad9be22586da","Height":"120","Width":"160"}},{"Title":"Edenpics com 001 007 Plain near a forest edge with snow and frontal sun Switzerland Vaud Marchairuz jpg","Summary":"cat1024 jpg Taille   1024x768 Edenpics com 001 007 Plain near a forest edge with snow and frontal sun Switzerland Vaud Marchairuz jpg Taille   1024x768","Url":"http:\/\/www.bergoiata.org\/fe\/divers60\/Edenpics-com_001-007-Plain-near-a-forest-edge-with-snow-and-frontal-sun-Switzerland-Vaud-Marchairuz.jpg","ClickUrl":"http:\/\/www.bergoiata.org\/fe\/divers60\/Edenpics-com_001-007-Plain-near-a-forest-edge-with-snow-and-frontal-sun-Switzerland-Vaud-Marchairuz.jpg","RefererUrl":"http:\/\/www.bergoiata.org\/fe\/divers60\/10.htm","FileSize":113254,"FileFormat":"jpeg","Height":"768","Width":"1024","Thumbnail":{"Url":"http:\/\/thm-a01.yimg.com\/image\/eb82ad9be22586da","Height":"120","Width":"160"}},{"Title":"Snow Capped  Grand Tetons  Wyoming jpg","Summary":"Putnam County  New York jpg Taille   400x300 Snow Capped  Grand Tetons  Wyoming jpg Taille   400x300","Url":"http:\/\/www.bergoiata.org\/fe\/winter\/Snow%20Capped,%20Grand%20Tetons,%20Wyoming.jpg","ClickUrl":"http:\/\/www.bergoiata.org\/fe\/winter\/Snow%20Capped,%20Grand%20Tetons,%20Wyoming.jpg","RefererUrl":"http:\/\/www.bergoiata.org\/fe\/winter\/25.htm","FileSize":376832,"FileFormat":"jpeg","Height":"1200","Width":"1600","Thumbnail":{"Url":"http:\/\/thm-a02.yimg.com\/image\/e36d276c780afb74","Height":"127","Width":"170"}},{"Title":"compo1 jpg","Summary":"Snow \u306b\u95a2\u9023\u3059\u308b\u753b\u50cf","Url":"http:\/\/www.its.caltech.edu\/~atomic\/snowcrystals\/designer3\/compo1.jpg","ClickUrl":"http:\/\/www.its.caltech.edu\/~atomic\/snowcrystals\/designer3\/compo1.jpg","RefererUrl":"http:\/\/www.wordswarp.com\/Snow.html","FileSize":97177,"FileFormat":"jpeg","Height":"804","Width":"842","Thumbnail":{"Url":"http:\/\/thm-a01.yimg.com\/image\/f7bac17af2dd172c","Height":"152","Width":"160"}},{"Title":"snow1 jpg","Summary":"","Url":"http:\/\/www.switzerland.k12.in.us\/images\/snow%20pics\/snow1.jpg","ClickUrl":"http:\/\/www.switzerland.k12.in.us\/images\/snow%20pics\/snow1.jpg","RefererUrl":"http:\/\/www.switzerland.k12.in.us\/admin_closing_info.php","FileSize":197836,"FileFormat":"jpeg","Height":"333","Width":"500","Thumbnail":{"Url":"http:\/\/thm-a02.yimg.com\/image\/0815e60c69f0e662","Height":"96","Width":"145"}},{"Title":"Snow Covered Trees  Varmland  Sweden jpg","Summary":"Snow Flocks Yosemite National Park  California jpg Taille   160x120 Snow Covered Trees  Varmland  Sweden jpg Taille   160x120","Url":"http:\/\/www.bergoiata.org\/fe\/winter\/Snow-Covered%20Trees,%20Varmland,%20Sweden.jpg","ClickUrl":"http:\/\/www.bergoiata.org\/fe\/winter\/Snow-Covered%20Trees,%20Varmland,%20Sweden.jpg","RefererUrl":"http:\/\/www.bergoiata.org\/fe\/winter\/10.htm","FileSize":338432,"FileFormat":"jpeg","Height":"1200","Width":"1600","Thumbnail":{"Url":"http:\/\/thm-a01.yimg.com\/image\/e792a810263081d6","Height":"127","Width":"170"}},{"Title":"white snow jpg","Summary":"Minor White Snow on Garage Door  Rochester  New York","Url":"http:\/\/www.masters-of-photography.com\/images\/screen\/white\/white_snow.jpg","ClickUrl":"http:\/\/www.masters-of-photography.com\/images\/screen\/white\/white_snow.jpg","RefererUrl":"http:\/\/www.masters-of-photography.com\/W\/white\/white_snow.html","FileSize":34918,"FileFormat":"jpeg","Height":"275","Width":"259","Thumbnail":{"Url":"http:\/\/thm-a02.yimg.com\/image\/3b7ad8335708995a","Height":"130","Width":"122"}},{"Title":"snow jpg","Summary":"Answering His First Question  Tony Snow Misleads White House Press Corps","Url":"http:\/\/thinkprogress.org\/wp-content\/uploads\/2006\/05\/snow.jpg","ClickUrl":"http:\/\/thinkprogress.org\/wp-content\/uploads\/2006\/05\/snow.jpg","RefererUrl":"http:\/\/thinkprogress.org\/?p=5363&sortby=toprated","FileSize":16281,"FileFormat":"jpeg","Height":"240","Width":"320","Thumbnail":{"Url":"http:\/\/thm-a01.yimg.com\/image\/41c5b926528cf89e","Height":"97","Width":"130"}},{"Title":"SnowBuds jpg","Summary":"","Url":"http:\/\/www.rishi-tea.com\/store\/images\/SnowBuds.jpg","ClickUrl":"http:\/\/www.rishi-tea.com\/store\/images\/SnowBuds.jpg","RefererUrl":"http:\/\/www.rishi-tea.com\/store\/product.php?productid=5057&cat=7&page=1","FileSize":30617,"FileFormat":"jpeg","Height":"310","Width":"310","Thumbnail":{"Url":"http:\/\/thm-a02.yimg.com\/image\/2a9153431ab9e6ce","Height":"130","Width":"130"}}]}}

when i run it, got error message :
the Log:Error: it says “must be have ‘;’”

14:11:52.203:INFO:Log:initialized
14:11:53.328:INFO:Log:isc.Page is loaded
14:12:23.421:MUP4:WARN:Log:Error:
	'必須要有 ';''
	in http://test.mysite/a.html?query=snowboarding&callback=isc.Comm._scriptIncludeReply_0
	at line 1
    Comm.sendScriptInclude(_1=>Obj)
    RPCManager.sendQueue(_1=>undef, _2=>undef, _3=>undef)
    RPCManager.sendNoQueue(_1=>Obj)
        "var _2=this.currentTransaction;this.currentTransaction=this.$385();this.$386(_1,this.currentTransaction);var _3=this.sendQueue();this.currentTransaction=_2;return _3"
    RPCManager.sendRequest(_1=>Obj)
    DataSource.sendDSRequest(_1=>Obj)
    DataSource.performDSOperation(_1=>"fetch", _2=>Obj, _3=>Obj, _4=>Obj)
    DataSource.fetchData(_1=>Obj, _2=>Obj, _3=>Obj)
        "this.performDSOperation("fetch",_1,_2,_3)"
    ResultSet.fetchRemoteData(_1=>Obj, _2=>0, _3=>75)
    ResultSet.$39w()
    ResultSet.getRangePaged(_1=>0, _2=>19, _3=>undef, _4=>undef)
    ResultSet.$39u(_1=>0, _2=>19, _3=>undef, _4=>undef)
    ResultSet.getRange(_1=>0, _2=>19, _3=>undef, _4=>undef)
    ListGrid.requestVisibleRows()
    Canvas.filterWithCriteria(_1=>Obj, _2=>Obj{ID:isc_OID_2_fetch}, _3=>Obj)
    Canvas.$wo(_1=>"fetch", _2=>Obj, _3=>undef, _4=>Obj)
    Class.invokeSuper(_1=>null, _2=>"$wo", _3=>undef, _4=>undef, _5=>undef, _6=>undef, _7=>undef, _8=>undef, _9=>undef, _10=>undef)
    Class.Super(_1=>"$wo", _2=>Array[4], _3=>Obj{length:4})
    ListGrid.$wo(_1=>"fetch", _2=>Obj, _3=>undef, _4=>Obj, _5=>undef)
    Canvas.fetchData(_1=>Obj, _2=>undef, _3=>undef)
        "if(!_3)_3={};if(!_3.textMatchStyle)_3.textMatchStyle="exact";this.$wo("fetch",_1,_2,_3)"
    FormItem.$17u(_1=>"click")
    FormItem.handleClick()
        "if(this.isDisabled())return;return this.$17u("click")"
    [o]IButton.click(Obj, undef)
    StatefulCanvas.handleActivate(_1=>Obj, _2=>undef)
    StatefulCanvas.handleClick(_1=>Obj, _2=>undef)
    EventHandler.bubbleEvent(_1=>[IButton ID:isc_ButtonItem_8_button], _2=>"click", _3=>undef, _4=>undef)
    EventHandler.handleClick(_1=>[IButton ID:isc_ButtonItem_8_button], _2=>undef)
    EventHandler.$k5(_1=>Obj{type:error}, _2=>undef)
    EventHandler.handleMouseUp(_1=>Obj{type:error}, _2=>undef)
    EventHandler.dispatch(_1=>EventHandler.handleMouseUp(), _2=>Obj{type:error})
    anonymous(event=>undef)
        "var returnVal=arguments.callee.$ch.isc.EH.dispatch(arguments.callee.$j2,event);return returnVal;"

and browser show a dialog “Finding Records that match your criteria…”, TreeList show “Loading data…”

someone can help me , what happen???

thanks a lot !!

See RPCRequest.callbackParam - you can’t use a static response for scriptInclude because SmartGWT set the callbackParam to an different function name each time a request is sent.

thanks a lot for your replay, i solved it.

Hi

can you give me a hint, how do you solved it?

thanks.

OK, now I get it :slight_smile:

help, please

can you give me a hint, how do you solved it?

thanks!

I have the same problem, and i have no idea how to bypass this problem.
I have something like this :

// RPCManager.setUseHttpProxy(true);
        XJSONDataSource dataSource = new XJSONDataSource();
        dataSource.setDataTransport(RPCTransport.SCRIPTINCLUDE);
        dataSource.setCallbackParam("callback");
        dataSource.setDataFormat(DSDataFormat.JSON);
        dataSource.setDataURL("http://localhost:8080/something.json");
        dataSource.setRecordXPath("users");
        DataSourceTextField nameField = new DataSourceTextField("enabled", "enabled");
        DataSourceTextField populationfield = new DataSourceTextField("idUser", "idUser");
        DataSourceTextField areaField = new DataSourceTextField("password", "password");
        DataSourceTextField governmentField = new DataSourceTextField("city", "city");
        governmentField.setValueXPath("person/city");

        dataSource.setFields(nameField, populationfield, areaField, governmentField);

        ListGrid grid = new ListGrid();
        grid.setDataSource(dataSource);
        grid.setWidth100();
        grid.setHeight(150);
        grid.setAutoFetchData(true);
        grid.draw();

I am gettinh the same error as above.

I am using SmartGWT 2.1 with gwt 2.0.3.

Can someone provide an idea, am new to smartGWT.

Thx.

Ok, i have found the solution. If someone has the same problem:

lets say that my json looks like this :

{“users”:[{“creationDate”:null,“enabled”:1}]}

I have to put this json, to generate the callback function name that is sent by callback parameter like this :

isc.Comm._scriptIncludeReply_0({“users”:[{“creationDate”:null,“enabled”:1}]})
where my url looks like this :
http://localhost:8080/something.json?callback = isc.Comm._scriptIncludeReply_0

I don’t know if you can provide static callback parameter value, does someone have any solution?

Can you be more specific on how to set callbackParam?

I tried the following:
dataSource.setDataTransport(RPCTransport.SCRIPTINCLUDE);
dataSource.setCallbackParam(“callback”);

I can tell the restful web service is called from the server log. But no data is shown on the grid, and the pop-up displays “Finding Records that match your criteria”.

It’s so close, but I am still missing something.

Any suggestions are greatly appreciated!!!

after having the same problem and also trying to solve this by myself
cause this forum just doestn help
ill try to give an answer

first ill try to sketch what i was trying to do:
given a php webservice using a zend_json_server i wanted to fill a ListGrid
so i can sort/filter the fields
problem was that the service was a bit custom (no rowcount, bound to zend’s json server which i had to modify to accept GET requests, …)

so my first problem was to understand that XJSONDataSource is only able to use GET cause this kind of DataSource Class uses ‘script include’ to retrieve the result
since im neither a JS nor expirienced GWT devel its very hard to get information here
as far as i understand script include means, that XJSONDataSource creates a script-Tag and sets the source of the ‘script’ to the given XJSONDataSource.setDataURL();
thats why it only can use GET and SOP (same origin policy) isnt a problem

what you can see now is that if your json service ONLY responds with plain json like this link
http://api.search.yahoo.com/ImageSearchService/V1/imageSearch?appid=YahooDemo&output=json&query=snowboard
included in a script tag, nothing will happen in the browser
so the callback everyone is talking about needs to be set by the json response
e.g. have a look at this yahoo link
http://api.search.yahoo.com/ImageSearchService/V1/imageSearch?appid=YahooDemo&output=json&query=snowboard&callback=somefancycallback

so if you can modify your json server its the easiest way to respond with javascript if a callback param is given
given the example of the previous post the http server would really respond with the string
isc.Comm._scriptIncludeReply_0({“users”:[{“creationDate”:null,“enabled”:1}]})

instead of just plain
{“users”:[{“creationDate”:null,“enabled”:1}]}

if you are bound to a server which is not capable of
http://developer.yahoo.com/javascript/json.html#callbackparam
im not sure if xjsondatasource is the way to go, also because the XJSONDataSource.transformResponse() cant be called if the server doesnt respond with javascript calling the given callback

another good resource: http://www.mmmeeja.com/blog/web-development/rest/json-callback-parameter.html

another point beside this whole XJSONDataSource thing, which maybe someone else can help/explain is:
Why does RPCManager has a feature implemented where it checks the sameorigin policy by itself and pops up an alert box that the request cant be done?
The problem i see with this approach is that RPCManagers SOP is not the same as the browsers
e.g. since firefox 3.5 SOP requests seem possible using http access control
https://developer.mozilla.org/En/HTTP_access_control

the section Access-Control-Allow-Origin is of interest
but maybe i dont see the big picture here (again) but currently i think those RPCManager-SOP-prevention is obsolete (or soon will be) and either way i dont unterstand why it has been done anyway

anyway, maybe someone will find this post helpful

Tags:
smartgwt datasource
XJSONDataSource
Finding Records that match your criteria
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.
SCRIPTINCLUDE

Hi,

Thanks for the last message. I had the same problem with xjsondatasource and it is somewhat resolved. But I am stuck in further problems. The webservice which I access is a spring-jpa based application(another module of the same project which might get deployed on a different domain). When I access the URL directly from browser I never see any exceptions on the server(spring module). But when I access it using the xjsondatasource I get the records and I can see them on the UI too, but the UI hangs also and on the server I see huge stack traces saying “java.lang.IllegalStateException: Transaction not active” and something like commit not allowed. The surprising thing is that I am not doing any commit operation. I am simply trying to fetch the list.

On the client I see this - Uncaught JavaScript exception [Script error.] in , line 0

I would like to mention one thing: I have wrapped the json output on the spring side as “isc.Comm._scriptIncludeReply_0(” + jsonData + “)”.
I doubt isc.Comm._scriptIncludeReply_0 does something internally which causes these exceptions on the server.

I am not able to get into the root of this problem. If anyone has any clue then please post it ASAP.

Presumably you’re talking about some hand-written Spring/JPA stack (not the SmartGWT server).

That call (“isc.Comm._scriptIncludeReply_0”) is executed in the browser, has effects only on the state of the browser, and cannot effect your server.

Look for another cause, such as differences in the HTTP requests received in each situation (different headers, etc) and see what might trigger bugs in your server code.

Thanks for the reply.
The server running the web service is not smartgwt server. It is a standalone application which has rest services exposed and these services have been written using jersey (on spring-jpa framework). If I directly access the URL say, http://ipaddress:port/service/module/fetchAll from the browser I get the json string properly and I don’t see any stacktrace on the server running the web service. This means the service is running properly.

However when I do the same from smartgwt client using xjsondatasource I see huge stacktrace.

Digging through various forums, I found the following suggestion which I tried yesterday:

XJSONDataSource myDataSource = new XJSONDataSource() 
		{
			protected Object transformRequest(com.smartgwt.client.data.DSRequest dsRequest) 
			{
				return dsRequest;
			};
		};

I get js error on client after doing this.

Could you explain a little more about the http stuff which you have suggested ?

That implementation of transformRequest is a no-op - it does nothing.

Sorry, you’re basically asking for help troubeshooting third-party technology and with HTTP fundamentals. We do have a range of services you could take advantage of, but on the forums we focus on identifying and solving SmartGWT problems, and this is not a SmartGWT problem. Best of luck.

So the scriptInclude mechanism requires the server to return a Javascript element of the form

   callBackParamValue( { ... the data in JSON ... } );

where callBackParamValue is a name dynamically set by Smart Client and passed as a GET parameter, where the parameter is, in turn, named by the callbackParam attribute of the XJSONDataSource object. Hence static responses are not valid: static data can’t add the required outer wrapping, the name of which is dynamically set.

Of course, I did finally find this in the RPCRequest.callbackParam documentation, but it would have been useful to have this more clearly linked, perhaps from the XJSONDataSource documentation itself.

It would be nice to have, again in the documentation, a brief discussion of the advantages of scriptInclude over xmlHttpRequest for returning JSON data.

There was a link, elsewhere in the forum, to a Yahoo developer site FAQ about scriptInclude but I can’t find that page anymore. If a fresher link could be found to explain the overall mechanism it would be appreciated.

The xmlHttpRequest approach works for me; I have to return a JSON file from a static tree. The static file is produced by a server, not directly linked to my front end, that does heavy analysis and stores results. That server cannot directly respond to user requests. I’m using JSON to produce lists of the available server output, which I’m then loading into my SmartClient front end using a ListGrid.