Using the Gmail Connector
In this tutorial, you use the Gmail connector to send an email containing the response received from SettlePaymentEP in the previous tutorial.
See the following topics for a description of the concepts that you need to know when creating ESB artifacts:
Before you begin,
Install Oracle Java SE Development Kit (JDK) version 1.8.* and set the JAVA_HOME environment variable.
Go to the product page of WSO2 Enterprise Integrator, select Other Installation Options, and download the Binary distribution. Extract the ZIP file of the binary. This will be your
<EI_HOME>directory.Select and download the relevant WSO2 Integration Studio ZIP file based on your operating system from here and then extract the ZIP file.
The path to this folder will be referred to as<EI_TOOLING>throughout this tutorial.If you did not try the Storing and Forwarding Messages tutorial yet, open WSO2 Integration Studio, click File, and then click Import. Next, select Existing WSO2 Projects into workspace under the WSO2 category, click Next and upload the pre-packaged project. This contains the configurations of the Storing and Forwarding Messages tutorial so that you do not have to repeat those steps.
Download the MSF4J service from here and copy the JAR file to
<EI_HOME>/wso2/msf4j/deployment/microservicesfolder. The back-end service is now deployed in the MSF4J profile of WSO2 EI.
Let's get started!
- 1 Setting up the message broker profile
- 2 Creating the credentials for using the Gmail Connector
- 3 Importing the Gmail Connector into WSO2 Integration Studio
- 4 Creating the Deployable Artifacts
- 5 Packaging the artifacts
- 6 Starting the Message Broker runtime
- 7 Starting the MSF4J profile
- 8 Starting the ESB profile and deploying the artifacts
- 9 Sending requests to the ESB
Setting up the message broker profile
Open the <EI_HOME>/conf/jndi.properties file and add the following line after the queue.MyQueue = example.MyQueue line:
queue.PaymentRequestJMSMessageStore=PaymentRequestJMSMessageStoreCreating the credentials for using the Gmail Connector
Creating a Client ID and Client Secret
Follow the steps below if you want to use your own email address for sending the emails.
As the email sender, navigate to the URL https://console.developers.google.com/projectselector/apis/credentials and log in to your google account.
If you do not already have a project, create a new project.
Click Google APIs -> Credentials -> Create Credential -> OAuth client ID.
Select Web Application and create a client.
Provide https://developers.google.com/oauthplayground as the redirect URL under Authorized redirect URIs and click Create.
The client ID and client secret will then be displayed.Click on the Library on the side menu, and select Gmail API.
Click Enable.
Obtaining the Access Token and Refresh Token
Follow these steps to automatically refresh the expired token when connecting to Google API:
Navigate to the https://developers.google.com/oauthplayground URL, click at the top right corner of the screen, and select Use your own OAuth credentials.
Provide the client ID and client secret you previously created and click Close.
Now under Step 1, select Gmail API v1 from the list of APIs, select all the scopes listed under it, and click Authorize APIs.
You will then be prompted to allow permission, click Allow.
Under Step 2, click Exchange authorization code for tokens to generate and display the access token and refresh token.
Importing the Gmail Connector into WSO2 Integration Studio
Right click on Sample Services in the Project Explorer and Select Add or Remove Connector.
Select Add Connector and click Next.
Select Connector Store location and click Connect to connect to WSO2 Connector store.
Scroll down and select Gmail from the list of connectors.
Click Finish.
The connector is now downloaded into your WSO2 Integration Studio and the connector operations will be available in the Gmail Connector palette.
Let's use these connector operations in the configuration.
Creating the Deployable Artifacts
The connector operations are used in the PaymentRequestProcessingSequence. Select this sequence, and do the following updates:
Add a Property Mediator just before the Call mediator to retrieve and store the patient's email address. With the Property mediator selected, access the Property tab of the mediator and fill in the information in the following table:
Add another Property mediator just after the Log mediator to retrieve and store the response sent from SettlePaymentEP. This will be used within the body of the email.
With the Property mediator selected, access the Property tab and fill in the information in the following table:
Drag and drop the init method from the Gmail Connector palette adjoining the Property mediator you added in the previous step.
With the init method selected, access the Property tab and fill in the information in the following table:
Add the sendMail method from the Gmail Connector palette and access the Property tab and fill in the information in the following table:
The updated PaymentRequestProcessingSequence should now look like this:
Save the updated sequence configuration.
Right click on SampleServicesConnectorExporter and navigate to New → Other → Add/Remove Connectors and select Add connector and click on Next. Select Workspace to list down the connectors that were added.
Select the Gmail connector from the list and click OK and then Finish.
Packaging the artifacts
Since you added a connector to the Connector Exporter Project, this will need to be packaged into our existing C-App.
Package the C-App names SampleServicesCompositeApplication project with the artifacts created.
Ensure the following artifact check boxes are selected in the Composite Application Project POM Editor.
SampleServices
HealthcareAPI
ClemencyEP
GrandOakEP
PineValleyEP
ChannelingFeeEP
SettlePaymentEP
SampleServicesRegistry
SampleServicesConnectorExporter