OWASP O2 Platform Blog

O2 Script: DWR Functions Viewer and Invoker

I have been working on a project that uses DRW (http://directwebremoting.org) and I just added a DWR Functions Viewer and Invoker to O2 which should be quite useful when debugging and testing DWR based applications (think of this as a sort of WSDL for DWR)

The function is called Util – DWR Functions Viewer and Invoker.h2 and you can find it at the _Scripts\Languages_and_Frameworks\Javascript\DWR scripts folder (also available locally on the C:\O2\O2Scripts_Database\folder)

When executed this GUI will look like this:

 

By default this loads up the DWR sample files which are available online or from an apache that you deployed the dwr.war (availabled to download from the DWR website )

When you click on one of the files in the top-left treeview, the Javascript will be loaded, parsed and converted into a number of O2’s DWR objects that help its manipulation and invocation. Practically, what you will see is a list of functions in the bottom-left treeview, which when clicked will show the selected function’s details (namely its parameters, and invocation link and the invocation results)

 

Here is the code that builds this GUI :

var topPanel = O2Gui.open<Panel>("DWR Functions Viewer and Invoker",900,500);
Func<string, List<String>> dwr_getInterfaceJavascriptsFromDebugPage =
    (server) =>    {
                    "[DWR] loading demo data from: {0}".debug(server);                   
                    var fullUri = (server + "/dwr/index.html").uri();
                    var html = fullUri.getHtml();
                    var demoPages =  html.htmlDocument()
                                         .links()
                                         .values();                
                    var javascripts = new List<string>();
                    foreach(var demoPage in demoPages)
                        javascripts.Add("{0}/dwr/interface/{1}.js".format(server, demoPage));
                    return javascripts;
                 };

Action<string> loadData =
    (server)=>{
                   var files = dwr_getInterfaceJavascriptsFromDebugPage(server);         
                   topPanel.clear();
                 topPanel.createTestGuiFromJavascriptInterfaces(server,files);                    
              };

var serverTextBox = topPanel.insert_Above<Panel>(20)
                            .add_Label("Dwr Server")
                            .top(5)
                            .append_TextBox("").align_Right(topPanel)
                            .onEnter(loadData);

var demoServer = "http://directwebremoting.org/dwr-demo";
serverTextBox.set_Text(demoServer);
loadData(demoServer);

//O2File:API_DWR.cs 
//using O2.XRules.Database.Utils.ExtensionMethods
//O2Ref:O2_Misc_Microsoft_MPL_Libs.dll

The other key file to look at is the API_DWR.cs file (which is the one that contains the O2’s DWR object creation logic)

The GUI above will only work if you are running the DWR in debug mode (since it provides a nice list of all mapped DWR interfaces). If you only have the actually javascript file (that can usually be calculated from the exposed javascript links in the target’s website), you can explicitly load them like this:

var topPanel = O2Gui.open<Panel>("DWR Functions Viewer and Invoker",900,500);
var demoServer = "http://directwebremoting.org/dwr-demo";
var files = new List<string>();
files.add("http://directwebremoting.org/dwr-demo/dwr/interface/Intro.js")
     .add("http://directwebremoting.org/dwr-demo/dwr/interface/Demo.js")
     .add("http://directwebremoting.org/dwr-demo/dwr/interface/JDate.js");

topPanel.createTestGuiFromJavascriptInterfaces(demoServer,files);                    

//O2File:API_DWR.cs 

which will look like this:

March 7, 2011 - Posted by | IE Automation

1 Comment »


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: