Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "Accessing a service"

(Accessing an EGL REST-RPC service)
(Removing all content from page)
 
(10 intermediate revisions by the same user not shown)
Line 1: Line 1:
<br>
 
  
:
 
 
= EDT version .7  =
 
 
In EDT version .7, a service is accessible only from a Rich UI application, and your task follows this pattern:&nbsp; declare a service-access variable and use it in a call statement.
 
 
== Accessing a dedicated service  ==
 
 
<source lang="java">
 
// 1. declare the service-access variable
 
myService MyServiceType?{@dedicatedService}
 
 
// 2. call the service
 
call myService.theFunction() returning to theCallBack
 
                onException theExceptionHandler;
 
 
/*
 
* Example: create a new EGL project for
 
* "Web 2.0 application with services". Add the
 
* the Service type shown next to the server package,
 
* and add the Handler type to the client package.
 
*
 
* Test the example in the Rich UI Preview tab
 
* by typing valid input into the first text box; for example:
 
*        5, 12, 4
 
*/
 
 
// the file with a Service type
 
package server;
 
 
Service MyServiceType
 
 
  // variables and constants can be here
 
 
  function calculate(myScores Int[] in) returns (Decimal(4,2))
 
      numberOfScores, i, mySum Int;
 
      numberOfScores = myScores.getSize();
 
 
      for (i from 1 to numberOfScores by 1)
 
        mySum = myScores[i] + mySum;      
 
      end
 
 
      return(mySum/numberOfScores);
 
  end
 
end
 
 
// the file with a Handler type
 
package client;
 
 
import server.MyServiceType;
 
import org.eclipse.edt.rui.widgets.GridLayout;
 
import org.eclipse.edt.rui.widgets.TextField;
 
import org.eclipse.edt.rui.widgets.GridLayoutData;
 
import dojo.widgets.DojoButton;
 
import dojo.widgets.DojoTextField;
 
 
handler MyHandler type RUIhandler{initialUI =[ui],
 
            onConstructionFunction = start,
 
            cssFile = "css/ProjectInEDT.7.css",
 
            title = "MyHandler"}
 
 
  ui GridLayout{columns = 3, rows = 4, cellPadding = 4,
 
                children =[myResult, myButton, scores]};
 
  scores TextField{layoutData =
 
      new GridLayoutData{row = 2, column = 2}};
 
  myButton DojoButton{layoutData =
 
      new GridLayoutData{row = 4, column = 2},
 
                        text = "Calculate",
 
                        onClick ::= ui_onClick};
 
  myResult DojoTextField{layoutData =
 
      new GridLayoutData{row = 4, column = 3}};
 
 
    function start()
 
 
    end
 
 
    function theExceptionHandler(exp AnyException in)
 
        SysLib.writeStdOut(exp.messageID + " " + exp.message);
 
       
 
        if (exp isa ServiceInvocationException)
 
            SysLib.writeStdOut((exp as ServiceInvocationException).detail1);
 
            SysLib.writeStdOut((exp as ServiceInvocationException).detail2);
 
            SysLib.writeStdOut((exp as ServiceInvocationException).detail3);
 
        end
 
    end
 
 
    function theCallBack(retResult decimal(4, 2) in)
 
        myResult.text = retResult;
 
    end
 
 
    function ui_onClick(event Event in)
 
 
        inputLength int = scores.text.length();
 
 
        myDelimiters string = ", ";
 
        myPosition int = 1;
 
        myToken string;
 
        myList int[];
 
        while(myPosition < inputLength)
 
            myToken = StringLib.getNextToken(scores.text,
 
                      myPosition, myDelimiters);
 
            if(myToken != null)
 
                myList.appendElement(myToken as int);
 
            end
 
        end
 
        myService MyServiceType?{@DedicatedService};
 
        call myService.calculate(myList) returning to theCallBack
 
                onException theExceptionHandler;
 
    end
 
end
 
</source>
 
 
== Accessing an EGL REST-RPC service  ==
 
 
Access of an EGL REST-RPC function is similar to accessing a dedicated service, but typically involves coding the variable declaration to reference an entry in the EGL deployment descriptor.
 
 
For example, you might change the previous handler to reference a deployment descriptor entry named <code>myService</code>. You can use one of two declarations for the service-access variable:
 
 
<source lang="java">
 
myService MyServiceType?{@Resource};
 
 
// or
 
 
myService MyServiceType?{@Resource{bindingKey="myService"}};
 
</source>
 
 
To demonstrate the access, update two aspects of your deployment descriptor: service deployment and resource binding. For details and a look at the version .8 code syntax, see [[EDT:Resource_Binding_Services]].
 
 
== Accessing a third-party REST service ==
 
 
= EDT version .8  =
 
 
<br>
 
 
<br>
 
 
<br>
 
 
<br>
 
 
<br>
 
 
<br> <source lang="java">
 
 
// From a a Access a dedicated service
 
 
 
 
 
 
 
 
http HttpRest{request.uri="http:host\\myService"};
 
srvc IRest?;
 
srvc = ServiceLib.completeBind(srvc, http);
 
</source>
 
 
'''Accessing HTTP request headers'''
 
 
<source lang="java">
 
http HttpRest{};
 
http.request.headers = new Dictionary { param1 = "a value to pass to my service" };
 
srvc IRest?{@Resource {}};
 
srvc = ServiceLib.completeBind(srvc, http);
 
</source>
 
 
'''HTTP request and response'''
 
 
<source lang="java">
 
function invokeDoSomething()
 
    call srvc.doSomething() returning to serviceCallback;
 
end
 
 
function serviceCallback(returnValueOne String, callbackHttp IHTTP in)
 
  // process callback request or response
 
end
 
</source>
 

Latest revision as of 12:06, 10 February 2012

Back to the top