Discover how a bimodal integration strategy can address the major data management challenges facing your organization today.
Get the Report →Tutorial: Use the CData BizTalk Adapter for Gmail to Execute Updategrams
Create a simple application in which you use the adapter for Gmail to execute an updategram and then write the response from Gmail to a file.
The CData BizTalk Adapter for Gmail enables you to execute SQL commands, updategrams, and stored procedures on Gmail data in BizTalk. This article provides a walk-through of an application that uses an updategram to insert Gmail data.
- A one-way file receive location picks up the XML document that contains the updategram.
- The document is routed to a solicit-response send port configured for the adapter.
- The adapter executes the command. The result of an insert contains the Id of the new record and the rows affected.
- The response from Gmail is routed to a one-way file send port, which writes the BizTalk message to a file.
Create the Sample Application
The following sections walk through creating the sample application:
- Generate the Schema and an Updategram Instance
- Configure a Receive Port
- Configure a File Receive Location
- Configure the Adapter in a Solicit-Response Send Port
- Configure a File Send Port
- Create Filters to Route BizTalk Messages Through the Application
- Enlist and Enable the Locations and Ports
- View Application Logs
Generate the Schema and an Updategram Instance
You can use wizards in Visual Studio to generate the schema and updategram instance:
Add the Adapter to Your Project
Use the Add Adapter wizard to add the adapter to your project. You will use the adapter to query Gmail for metadata about the table you want to insert to; for example, "Inbox".
- Right-click on the project in the Solution Explorer and click Add -> Add Generated Items.
- Select Add Adapter Metadata in the resulting dialog box.
- In the resulting Add Adapter Wizard, select the CData BizTalk Adapter for Gmail from the list view.
- In the Port menu leave the selection blank. Or, if you want to use the connection string for an adapter you have already configured, select the send port or receive location from your BizTalk application.
Generate an Insert Schema
You will use the schema as a template for creating an updategram that will insert Gmail data. The schema is an .xsd file that defines the XML request and response. As an example, we show how to generate an insert updategram. You can follow the same process to generate update and delete updategrams.
- In the Connection String page of the Schema Wizard, enter authentication credentials and other connection properties.
- In the next step select the Send Port option.
- Clear the One-Way option. The One-Way option ignores any response from the adapter for the updategram, such as the AffectedRows value that is returned. The Id of the newly created row is also returned. By disabling the One-Way option you will get an updategram schema that supports retrieving the Id.
- In the Command Type menu select Updategram.
-
Select the Insert option and select the table and columns you want to insert into. This tutorial uses Subject and Size.
Note: When you create the updategram, you are limited to inserting the columns you include in the schema.
- On the summary page verify the settings you defined and click Finish to close the wizard.
Generate an Updategram Instance
In this step you will create the XML message that will in later steps be sent to the adapter. To create the updategram right-click the .xsd file in the Solution Explorer and then click Generate Instance. The location where the updategram is saved is listed in the Output tab.
The updategram is structured to define what response is desired from Gmail. For example updategrams and more information, see the help documentation for the adapter.
Configure the Receive Port
To add a receive location to your application, you first need to add a receive port. Receive ports can receive data from multiple receive locations.
- Open your application in the BizTalk Server Administration Console.
- Right-click Receive Ports and click New -> One-Way Receive Port. The Receive Port Properties dialog is displayed.
- Enter a name for the receive port.
Configure the File Receive Location
A static one-way file receive location will create a BizTalk message containing the updategram.
- Right-click Receive Locations and click New -> One-Way Receive Location.
- Select the receive port of which the new receive location will be a member. The Receive Location Properties dialog is displayed.
- Enter a name for the receive location.
- Select FILE in the Transport Type menu.
- Click Configure. The File Transport Properties dialog is displayed.
- In the Receive Folder box, enter the path to a folder; for example, DemoOutbound. The receive location will scan this folder for files that match the criteria in the File mask box.
- In the Receive Pipeline menu of the Receive Location Properties dialog, select the default option, PassThruReceive.
Configure the Gmail Adapter in a Solicit-Response Send Port
Configuration consists of the following steps:
- Create and Configure the Solicit-Response Send Port
- Configure the Adapter
- Configure the Connection to Gmail
Create and Configure the Solicit-Response Send Port
Use a solicit-response send port to obtain the result of an updategram command; in this tutorial the Id of the newly inserted record is returned in BizTalk.
- Open your BizTalk application in the BizTalk Administration Console.
- Right-click Send Ports and select New -> Static Solicit-Response Send Port. The Send Port Properties dialog is displayed.
- Enter a name for the send port.
- In the Transport Type menu select CData.Gmail.
Configure the CData Gmail Adapter
Define the command the adapter will execute in the Adapter Transport Properties dialog.
- In the send port properties click the Configure button. The Adapter Transport Properties dialog is displayed.
- In the CommandType property select Updategram.
Configure the Connection to Gmail
Configure credentials and other properties required to connect to Gmail:
- In the Adapter Transport properties dialog click the button in the Connection String property. The Connection String Options dialog is displayed.
Enter connection properties.
Below is a typical connection string:
User=username;Password=password;
There are two ways to authenticate to Gmail. Before selecting one, first ensure that you have enabled IMAP access in your Gmail account settings. See the "Connecting to Gmail" section under "Getting Started" in the installed documentation for a guide.
The User and Password properties, under the Authentication section, can be set to valid Gmail user credentials.
Alternatively, instead of providing the Password, you can use the OAuth authentication standard. To access Google APIs on behalf on individual users, you can use the embedded credentials or you can register your own OAuth app.
OAuth also enables you to use a service account to connect on behalf of users in a Google Apps domain. To authenticate with a service account, you will need to register an application to obtain the OAuth JWT values.
In addition to the OAuth values, you will need to provide the User. See the "Getting Started" chapter in the help documentation for a guide to using OAuth.
- Click Test Connection to verify the values.
Configure a File Send Port
The file send port will write to a file the Id that is returned from the insert. Follow the steps below to configure a one-way send port to write incoming messages to a file.
- Right-click Send Ports and then click Static One-Way Send Port.
- In the Type menu, select FILE.
- Click Configure.
- In the Destination Folder box enter the path to the folder where the message will be written. For example, DemoInbound.
Create Filters to Route BizTalk Messages Through the Application
Follow the steps below to create filter rules that will define the following associations in your application:
- Associate the solicit-response send port with the BizTalk message that contains the updategram.
- Associate the file send port with the BizTalk message created by the result of executing the updategram.
-
In the solicit-response send port properties, click Filters and set the following values:
- Property: Select BTS.InboundTransportLocation from the menu.
- Value: Enter the URI of the one-way receive location, "C:\DemoOutbound\*.xml" in this example.
-
In the one-way send port properties, click Filters and set the following values:
- Property: Select BTS.SPName from the menu.
- Value: Enter the name (not URI) of the solicit-response send port.
Enlist and Enable the Locations and Ports
To ensure that the updategram is picked up by the receive location, follow the steps below when starting your BizTalk application:
- Right-click the solicit-response send port and click Start. This will also enlist the send port.
- Right-click the one-way send port and click Start. This will also enlist the send port.
- Right-click the receive location and click Enable.
You can now copy the updategram into the folder that you configured for the receive location.
Open the folder that you configured for the one-way send port: This folder contains the new Id in an XML file. The message will resemble the following example:
<table xmlns="http://www.cdata.com/GmailProvider" AffectedRows="1">
<row>
<Id>0014000001XERBUAA5</Id>
</row>
</table>
View the Application Logs
In the Application Logs you can view error messages and quickly check that your application has initialized successfully. To open the logs expand the Event Viewer (Local) node in the navigation tree in the Administration Console. Expand Windows Logs and select Application.
A list of errors that have occurred will be available here. This will include error messages for all applications on the system, so it is important to check the source of the error message. For the receive location, the source should be "CData BizTalk Gmail Receive Adapter". Details of the error message should provide insight into why the error is occurring.
Contact [email protected] for guidance on resolving the error.