Jump to: navigation, search

Difference between revisions of "EDT:Third Party Service Introduction"

(New page: =  Introduction = Web service is an important web development technical. EGL also supports it. And with the help of EDT, you can easily build up your web service applications. <br>An...)
 
Line 1: Line 1:
= &nbsp;Introduction =
+
= &nbsp;Introduction =
  
Web service is an important web development technical. EGL also supports it. And with the help of EDT, you can easily build up your web service applications. <br>And also, there are lots of public 3rd party services provided by Google, Yahoo and many other companies. EGL can easily adopt there 3rd party services as well. Here we made an introduction of 3rd party services in EDT. <br>
+
Web service is an important web development technical. EGL also supports it. And with the help of EDT, you can easily build up your web service applications. <br>And also, there are lots of public 3rd party services provided by Google, Yahoo and many other companies. EGL can easily adopt there 3rd party services as well. Here we made an introduction of 3rd party services in EDT. <br>  
  
== Create Record for 3rd Party Service ==
+
== Create Record for 3rd Party Service ==
  
There are two protocols for response data. The XML data or JSON data. If the response data is XML structured, then you need to create the “Record from XML”. The JSON structured data use the “Record from JSON”. For the wizards of these two types are basically the same, we use the “Record from JSON” wizard as demo.
+
There are two protocols for response data. The XML data or JSON data. If the response data is XML structured, then you need to create the “Record from XML”. The JSON structured data use the “Record from JSON”. For the wizards of these two types are basically the same, we use the “Record from JSON” wizard as demo.  
  
 +
<br>
  
 +
1. Open “New EGL Record” wizard by Right Click on Project/Package --&gt; New --&gt; Record.
  
1. Open “New EGL Record” wizard by Right Click on Project/Package --&gt; New --&gt; Record.
+
<br>
  
 +
2. Fill the EGL Record page of this wizard
  
 +
The “Source folder” field filled with the EGLSource folder of the project you selected. If you want to change this field, just open the browser by clicking the “Browse…” button at the right of this field
  
2. Fill the EGL Record page of this wizard
+
The “Package” field should filled with the package you right click on. If you open this wizard by right clicking on project node, then the “Package” field would be empty. You can also browse the target package by clicking the “Browse…” button at the right of this field. Otherwise the record will be created to the default package.
  
The “Source folder” field filled with the EGLSource folder of the project you selected. If you want to change this field, just open the browser by clicking the “Browse…” button at the right of this field
+
In this demo, we use the “Record from JSON” wizard as demo. So select the “Record from JSON” template. Then click “Next”.<br>
  
The “Package” field should filled with the package you right click on. If you open this wizard by right clicking on project node, then the “Package” field would be empty. You can also browse the target package by clicking the “Browse…” button at the right of this field. Otherwise the record will be created to the default package.
+
3. Fill the Records from JSON page
  
In this demo, we use the “Record from JSON” wizard as demo. So select the “Record from JSON” template. Then click “Next”.<br>
+
You will see three radio selections in this page. They are “Create from a URL”, “Create from a file” and “Create from a string”. For the third party services are published to the internet, we can get them from a URL. So we use the “Create from a URL” selection when creating record for third party services.  
  
3. Fill the Records from JSON page
+
Select Create record from a URL. Input the third party REST service URL to the text field. Then click next, the record will be created automatically.<br>
  
You will see three radio selections in this page. They are “Create from a URL”, “Create from a file” and “Create from a string”. For the third party services are published to the internet, we can get them from a URL. So we use the “Create from a URL” selection when creating record for third party services.
+
4. Check the Record Creation result.  
  
Select Create record from a URL. Input the third party REST service URL to the text field. Then click next, the record will be created automatically.<br>
+
When you fill the right third party URL in last page, you should have this result page as the picture shows. The record in Preview TextArea is the third party record created automatically by wizard. The TextArea below shows all errors &amp; warnings. You may check the details by these two information TextAreas. Then click “Finish” to end this wizard. You will find the record created in the target package of the target Source folder. Just open it by source editor to take a review.  
  
4. Check the Record Creation result.
+
<br>
  
When you fill the right third party URL in last page, you should have this result page as the picture shows. The record in Preview TextArea is the third party record created automatically by wizard. The TextArea below shows all errors &amp; warnings. You may check the details by these two information TextAreas. Then click “Finish” to end this wizard. You will find the record created in the target package of the target Source folder. Just open it by source editor to take a review.
+
== Create Interface for 3rd Party Service  ==
  
 +
Here is a sample interface.
  
 +
<pre>
  
== Create Interface for 3rd Party Service ==
+
Interface IGeoName <br>&nbsp; &nbsp; function search(query string in) returns(GeoNames) {@GetRest {uriTemplate="http://ws.geonames.org/search?q={query}", responseFormat=XML} };<br>&nbsp; &nbsp; function searchJSON(query string in) returns(GeoNames) {@GetRest {uriTemplate="http://ws.geonames.org/searchJSON?q={query}", responseFormat=JSON}};<br>End
  
Here is a sample interface.
+
</pre>
  
&lt;pre&gt;
+
<br>
  
Interface IGeoName <br>&nbsp; &nbsp; function search(query string in) returns(GeoNames) {@GetRest {uriTemplate="http://ws.geonames.org/search?q={query}", responseFormat=XML} };<br>&nbsp; &nbsp; function searchJSON(query string in) returns(GeoNames) {@GetRest {uriTemplate="http://ws.geonames.org/searchJSON?q={query}", responseFormat=JSON}};<br>End
+
There are @GetRest and @PostRest. It determined by the third party service you called. And the '''responseFormat '''is the XML/JSON issue we mentioned before.  
  
&lt;/pre&gt;
+
<br>
  
 +
The uriTemplate is the third party service URL. EGL use {} in this URL to link with the input params in interface input. In this sample, parameter “query” in interface declaration will link to the {query} in ruiTemplate.
  
 +
<br>
  
There are @GetRest and @PostRest. It determined by the third party service you called. And the '''responseFormat '''is the XML/JSON issue we mentioned before.
+
The returns declaration defines the return type of this interface, the GeoNames in sample is the record we created in last section.<br>
  
 +
== Bind resource for 3rd Party Service  ==
  
 +
For details of Resource Binding, see&nbsp;[[EDT:Resource Binding Introduction|Resource Binding Introduction]].[[EDT:Resource Binding Introduction|Resource_Binding_Introduction]]
  
The uriTemplate is the third party service URL. EGL use {} in this URL to link with the input params in interface input. In this sample, parameter “query” in interface declaration will link to the {query} in ruiTemplate.
+
'''Notes:''' If you have set the uriTemplate field in interface declarations, then the “Base URI” field in Deployment Descriptor file can be empty. EDT will concat uriTemplate behind the Base URI as the final URL.  
  
 +
<br>
  
 +
== Call the 3rd Party Service  ==
  
The returns declaration defines the return type of this interface, the GeoNames in sample is the record we created in last section.<br>
+
'''Call Service Function''' <pre>  
  
== Bind resource for 3rd Party Service ==
+
function invokeService( e Event in)<br>&nbsp; &nbsp; case( serviceType.getSelection())<br>&nbsp; &nbsp; &nbsp; &nbsp; when( 1 )<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; srvc_GeoName IGeoName?{@Resource{}};<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (serviceTypeCombo.getSelection() == 1)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; call srvc_GeoName.search("London") returning to handleReturn onexception Exceptionhandler;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; call srvc_GeoName.searchJSON("London") returning to handleReturn onexception Exceptionhandler;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end<br>&nbsp; &nbsp; &nbsp; &nbsp; end<br>&nbsp; &nbsp; end
For details of Resource Binding, see&nbsp;[[EDT:Resource_Binding_Introduction|Resource Binding Introduction]].[[EDT:Resource_Binding_Introduction|Resource_Binding_Introduction]]
+
  
'''Notes:''' If you have set the uriTemplate field in interface declarations, then the “Base URI” field in Deployment Descriptor file can be empty. EDT will concat uriTemplate behind the Base URI as the final URL.
+
</pre>
  
 +
<br>
  
 +
'''Handle Return Function''' <pre>
  
== Call the 3rd Party Service ==
+
function handleReturn(resultRecord Geonames in)<br>&nbsp; &nbsp; i int = 0;<br>&nbsp; &nbsp; while (i&lt;resultRecord.geoname.getSize())<br>&nbsp; &nbsp; &nbsp; &nbsp; i += 1;<br>&nbsp; &nbsp; &nbsp; &nbsp; resultList.appendElement(resultRecord.geoname[i]);<br>&nbsp; &nbsp; end<br> end
  
'''Call Service Function'''
+
</pre>
&lt;pre&gt;
+
  
function invokeService( e Event in)<br>&nbsp; &nbsp; case( serviceType.getSelection())<br>&nbsp; &nbsp; &nbsp; &nbsp; when( 1 )<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; srvc_GeoName IGeoName?{@Resource{}};<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (serviceTypeCombo.getSelection() == 1)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; call srvc_GeoName.search("London") returning to handleReturn onexception Exceptionhandler;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; call srvc_GeoName.searchJSON("London") returning to handleReturn onexception Exceptionhandler;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end<br>&nbsp; &nbsp; &nbsp; &nbsp; end<br>&nbsp; &nbsp; end
+
<br>  
  
&lt;/pre&gt;
+
'''Handle Exception Function''' <pre>  
 
+
 
+
 
+
'''Handle Return Function'''
+
&lt;pre&gt;
+
 
+
function handleReturn(resultRecord Geonames in)<br>&nbsp; &nbsp; i int = 0;<br>&nbsp; &nbsp; while (i&lt;resultRecord.geoname.getSize())<br>&nbsp; &nbsp; &nbsp; &nbsp; i += 1;<br>&nbsp; &nbsp; &nbsp; &nbsp; resultList.appendElement(resultRecord.geoname[i]);<br>&nbsp; &nbsp; end<br> end
+
 
+
&lt;/pre&gt;
+
 
+
 
+
 
+
'''Handle Exception Function'''
+
&lt;pre&gt;
+
 
+
private function Exceptionhandler( exception AnyException in)<br>&nbsp; &nbsp; handleException();<br> end
+
 
+
&lt;/pre&gt;
+
  
 +
private function Exceptionhandler( exception AnyException in)<br>&nbsp; &nbsp; handleException();<br> end
  
 +
</pre>
  
 
[[Category:EDT]]
 
[[Category:EDT]]

Revision as of 22:47, 6 February 2012

 Introduction

Web service is an important web development technical. EGL also supports it. And with the help of EDT, you can easily build up your web service applications.
And also, there are lots of public 3rd party services provided by Google, Yahoo and many other companies. EGL can easily adopt there 3rd party services as well. Here we made an introduction of 3rd party services in EDT.

Create Record for 3rd Party Service

There are two protocols for response data. The XML data or JSON data. If the response data is XML structured, then you need to create the “Record from XML”. The JSON structured data use the “Record from JSON”. For the wizards of these two types are basically the same, we use the “Record from JSON” wizard as demo.


1. Open “New EGL Record” wizard by Right Click on Project/Package --> New --> Record.


2. Fill the EGL Record page of this wizard

The “Source folder” field filled with the EGLSource folder of the project you selected. If you want to change this field, just open the browser by clicking the “Browse…” button at the right of this field

The “Package” field should filled with the package you right click on. If you open this wizard by right clicking on project node, then the “Package” field would be empty. You can also browse the target package by clicking the “Browse…” button at the right of this field. Otherwise the record will be created to the default package.

In this demo, we use the “Record from JSON” wizard as demo. So select the “Record from JSON” template. Then click “Next”.

3. Fill the Records from JSON page

You will see three radio selections in this page. They are “Create from a URL”, “Create from a file” and “Create from a string”. For the third party services are published to the internet, we can get them from a URL. So we use the “Create from a URL” selection when creating record for third party services.

Select Create record from a URL. Input the third party REST service URL to the text field. Then click next, the record will be created automatically.

4. Check the Record Creation result.

When you fill the right third party URL in last page, you should have this result page as the picture shows. The record in Preview TextArea is the third party record created automatically by wizard. The TextArea below shows all errors & warnings. You may check the details by these two information TextAreas. Then click “Finish” to end this wizard. You will find the record created in the target package of the target Source folder. Just open it by source editor to take a review.


Create Interface for 3rd Party Service

Here is a sample interface.


Interface IGeoName <br>    function search(query string in) returns(GeoNames) {@GetRest {uriTemplate="http://ws.geonames.org/search?q={query}", responseFormat=XML} };<br>    function searchJSON(query string in) returns(GeoNames) {@GetRest {uriTemplate="http://ws.geonames.org/searchJSON?q={query}", responseFormat=JSON}};<br>End 


There are @GetRest and @PostRest. It determined by the third party service you called. And the responseFormat is the XML/JSON issue we mentioned before.


The uriTemplate is the third party service URL. EGL use {} in this URL to link with the input params in interface input. In this sample, parameter “query” in interface declaration will link to the {query} in ruiTemplate.


The returns declaration defines the return type of this interface, the GeoNames in sample is the record we created in last section.

Bind resource for 3rd Party Service

For details of Resource Binding, see Resource Binding Introduction.Resource_Binding_Introduction

Notes: If you have set the uriTemplate field in interface declarations, then the “Base URI” field in Deployment Descriptor file can be empty. EDT will concat uriTemplate behind the Base URI as the final URL.


Call the 3rd Party Service

Call Service Function
 

function invokeService( e Event in)<br>    case( serviceType.getSelection())<br>        when( 1 )<br>            srvc_GeoName IGeoName?{@Resource{}};<br>            if (serviceTypeCombo.getSelection() == 1)<br>                call srvc_GeoName.search("London") returning to handleReturn onexception Exceptionhandler;<br>            else<br>                call srvc_GeoName.searchJSON("London") returning to handleReturn onexception Exceptionhandler;<br>            end<br>        end<br>    end 


Handle Return Function
 

function handleReturn(resultRecord Geonames in)<br>    i int = 0;<br>    while (i<resultRecord.geoname.getSize())<br>        i += 1;<br>        resultList.appendElement(resultRecord.geoname[i]);<br>    end<br> end 


Handle Exception Function
 

private function Exceptionhandler( exception AnyException in)<br>    handleException();<br> end