GWT Cross-site request for autocomplete box

153 views
Skip to first unread message

Alp Yilancioglu

unread,
Nov 19, 2012, 6:06:29 AM11/19/12
to google-we...@googlegroups.com
Hi
i am trying to create a autosuggest box  which take data from my apacge solr server which is going to be in another domain for production
i just simply need to request a query with the address "http://localhost:8080/solr/select?q=ABC&callback=handleJsonResponse
i can get JSON as a result or an XML as a result

i followed th steps from the developers page tutorials;
it says give a parameter with a name of callback and set the callback func.name ;
and according to the tutorial it shows that the response has to be some thing like  GivenCallBackName([ JsonResults ])

Unfortunetly when i try to do this i got a reponse with the request parameters inside it when i do this manuelly from the iexplorer,
when i do this from gwt i get NULL as a returning result

 i got the code down below, wat should i do ?


request syntax :        
             getJson(UNIQUE_ID_FOR_JS,  "http://localhost:8080/solr/select?q=TUR&callback=handleJsonResponse&wt=json"_URL, this);

 
       
 
    public native static void getJson(int requestId, String url,
              ProTravel handler) /*-{
           var callback = "callback" + requestId;

           // [1] Create a script element.
           var script = document.createElement("script");
           script.setAttribute("src", url+callback);
           script.setAttribute("type", "text/javascript");

           // [2] Define the callback function on the window object.
           window[callback] = function(jsonObj) {
           // [3]
             handler.@com.gwt.pt.web.client.ProTestApp::handleJsonResponse(Lcom/google/gwt/core/client/JavaScriptObject;)(jsonObj);
             window[callback + "done"] = true;
           }

           // [4] JSON download has 1-second timeout.
           setTimeout(function() {
             if (!window[callback + "done"]) {
               handler.@com.gwt.pt.web.client.ProTestApp::handleJsonResponse(Lcom/google/gwt/core/client/JavaScriptObject;)(null);
             }

             // [5] Cleanup. Remove script and callback elements.
             document.body.removeChild(script);
             delete window[callback];
             delete window[callback + "done"];
           }, 1000);

           // [6] Attach the script element to the document body.
           document.body.appendChild(script);
          }-*/;
   
   
    /**
     * Handle the response to the request for stock data from a remote server.
     */
    public void handleJsonResponse(JavaScriptObject jso) {
// this is the callback
       }

Thomas Broyer

unread,
Nov 19, 2012, 6:45:25 AM11/19/12
to google-we...@googlegroups.com


On Monday, November 19, 2012 12:06:29 PM UTC+1, Alp Yilancioglu wrote:
Hi
i am trying to create a autosuggest box  which take data from my apacge solr server which is going to be in another domain for production
i just simply need to request a query with the address "http://localhost:8080/solr/select?q=ABC&callback=handleJsonResponse
i can get JSON as a result or an XML as a result

i followed th steps from the developers page tutorials;
it says give a parameter with a name of callback and set the callback func.name ;
and according to the tutorial it shows that the response has to be some thing like  GivenCallBackName([ JsonResults ])

The docs are outdated, there's JsonpRequestBuilder now.

And to ask Solr to return JSON-P, there's a json.wrf parameter: http://wiki.apache.org/solr/SolJSON#JSON_specific_parameters
This is the value to pass to JsonpRequestBuilder's setCallbackParam method.

Alp Yilancioglu

unread,
Nov 19, 2012, 9:02:08 AM11/19/12
to google-we...@googlegroups.com
Hi thanks for the information,
 
i have done what you have told,
and here is the code;
unfirtunety unable to recieve the results ?
 
 
 
Client Side Code;
   JsonpRequestBuilder jsonp = new JsonpRequestBuilder();
  
   String url = "http://localhost:8080/solr/select?q=TUR&wt=json";
   jsonp.setCallbackParam("json.wrf");
   
    jsonp.requestObject(url,new AsyncCallback<JavaScriptObject>() {
       
         public void onFailure(Throwable throwable) {    ...     }
         public void onSuccess(JavaScriptObject rs) {   ...  } 
    }
         );
 
 

Thomas Broyer

unread,
Nov 19, 2012, 9:10:02 AM11/19/12
to google-we...@googlegroups.com


On Monday, November 19, 2012 3:02:08 PM UTC+1, Alp Yilancioglu wrote:
Hi thanks for the information,
 
i have done what you have told,
and here is the code;
unfirtunety unable to recieve the results ?

What do you mean? onSuccess is not called or you don't know what to do with the received JavaScriptObject?

Alp Yilancioglu

unread,
Nov 19, 2012, 9:40:45 AM11/19/12
to google-we...@googlegroups.com
 i looked from firebug, Gwt sets a dynamic onSuccess function name to
 the parameter name i have set as "json.wrf"  which  seems okey

 Unfortunetly both  , onSuccess  and  onFailure functuions are not get called;

What should i do at this point?



 

 

 






Thomas Broyer

unread,
Nov 19, 2012, 9:54:30 AM11/19/12
to google-we...@googlegroups.com
Check that the response from Solr is correct: it might try to call another JS function than the one given in json.wrf, or there might be an error when calling that method and/or evaluating the script (Googling "solr jsonp" revealed a few bugs in Solr, they apparently have been fixed but you might have to check your version of Solr)

Alp Yilancioglu

unread,
Nov 19, 2012, 10:45:51 AM11/19/12
to google-we...@googlegroups.com
The JS function names seems to be the same

this is the request : http://localhost:8080/solr/collection1/select?q=TUR&wt=json&json.wrf=__gwt_jsonp__.P2.onSuccess

this is the response :
__gwt_jsonp__.P2.onSuccess({"responseHeader":{"status":0,"QTime":1,"params":{"json.wrf":"__gwt_jsonp__.P2.onSuccess","q":"TUR","wt":"json"}},"response":{"numFound":2,"start":0,"docs":[{"co":["Turkey"],"id":"1000017194","name":"TUR INN HOTEL","lvl2":"Kuşadası","lvl1":"Aydın","_version_":1419004459433852929},{"co":["Turkey"],"id":"1000019294","name":"HAL-TUR HOTEL","lvl2":"Denizli Merkez","lvl1":"Denizli","_version_":1419004459561779201}]}})


any other suggestions for me without JSONPRequestBuilder class
this is really important for me

Alp Yilancioglu

unread,
Nov 19, 2012, 11:24:14 AM11/19/12
to google-we...@googlegroups.com
i found my problem
 
By creating the callback function outside the requestObject()   ----> not like requestObject(new Async...(..) )
 

AsyncCallback abc= new AsyncCallback <JavaScriptObject> {}

and this way i set the object name with the parameter name 

jsonp.setCallbackParam("json.wrf=abc");

 

 

Alp Yilancioglu

unread,
Nov 19, 2012, 11:25:04 AM11/19/12
to google-we...@googlegroups.com
Thank you for your time and informatiom 
 
Best Regards..
 
Reply all
Reply to author
Forward
0 new messages