# Calling makeRequest in GWT to Get External Data for an Opensocial Gadget and Creating an Overlay 

For this tutorial I use the following parameters:

$your\_namespace\_dots = the namespace of your unit with dots.  
$your\_namespace\_folders = the namespace of your unit with folder delimiters.  
$your\_website = the <span class="caps">URL</span> of a web site you control.

Since we may want to get information that’s not necessarily on the server our gadget is hosted on, cross site scripting restrictions limit us to using [makeRequest](http://code.google.com/apis/opensocial/articles/makerequest.html) to get external data. This tutorial builds on [a previous one](https://kb.ucla.edu/link/1109).

1. Create a Java class YourRecord.java for the overlay type in the client folder (you may want to reorganize this class for reuse later) as:  
    ```
    <br></br>package $your_namespace_dots.gwt.client;
    ```

import com.google.gwt.core.client.JavaScriptObject;

class YourRecord extends JavaScriptObject {  
 // Overlay types always have protected, zero-arg ctors  
 protected YourRecord() { }  
 // Typically, methods on overlay types are <span class="caps">JSNI</span>  
 public final native String getTitle() /**<del>{  
 return this.data.getElementsByTagName(“title”).item(0).textContent;  
 }</del>**/;  
}

1. To the YourGadget class add a reference to the EntryPoint:  
    ```
    <br></br>	public EntryPoint entryPoint = this;<br></br>
    ```
    
      
    In Javascript methods that call Java methods, we can usually use “this” like:  
    ```
    <br></br>this.@$your_namespace_dots.gwt.client.SomeGadget::handleResponse(L$your_namespace_folders/gwt/client/SomeObject;)(obj);<br></br>
    ```
    
      
    However, we’re going to put the method call in a callback so “this” is not what we want.
2. Now add two methods. The <span class="caps">JSNI</span> method calls makeRequest and and the makeRequest callback calls the Java method which applies the overlay.  
    ```
    <br></br>	public void handleResponse(YourRecord rr) {<br></br>		Window.alert(rr.getTitle());<br></br>	}<br></br>	native void callMakeRequest(EntryPoint ep) /<strong><del>{<br></br>		$wnd[“response”] = function(obj) {<br></br>			ep.@$your_namespace_dots.gwt.client.YourGadget::handleResponse(L$your_namespace_folders/gwt/client/YourRecord;)(obj);<br></br>		};<br></br>		var params = {};<br></br>		params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.<span class="caps">DOM</span>;<br></br>		var url = “<a href="http://www.clicc.ucla.edu/rss/laptops.php%E2%80%9D;">http://www.clicc.ucla.edu/rss/laptops.php”;</a><br></br>		gadgets.io.makeRequest(url, response, params);<br></br>	}</del></strong>/;<br></br>
    ```
3. Add a call to the method in a suitable place. For instance, in the button’s onClick event:  
    ```
    <br></br>callMakeRequest(entryPoint);<br></br>
    ```
4. Compile the code, copy it to your server (don’t forget to rename the folder), and check it out at $your\_website/YourGadget/yourgadgetcontainer.html.
5. Add the new file to the repostory, commit then work on adding functionality to the overlay and making handleResponse do what you want with the record.  
    svn add $your\_namespace\_folders/gwt/client/YourRecord.java  
    svn commit