Connect to Talkdesk Data from a Connection Pool in Jetty
The CData JDBC driver for Talkdesk is easy to integrate with Java Web applications. This article shows how to efficiently connect to Talkdesk data in Jetty by configuring the driver for connection pooling. You will configure a JNDI resource for Talkdesk in Jetty.
Configure the JDBC Driver for Salesforce as a JNDI Data Source
Follow the steps below to connect to Salesforce from Jetty.
Enable the JNDI module for your Jetty base. The following command enables JNDI from the command-line:
java -jar ../start.jar --add-to-startd=jndi- Add the CData and license file, located in the lib subfolder of the installation directory, into the lib subfolder of the context path.
-
Declare the resource and its scope. Enter the required connection properties in the resource declaration. This example declares the Talkdesk data source at the level of the Web app, in WEB-INF\jetty-env.xml.
<Configure id='talkdeskdemo' class="org.eclipse.jetty.webapp.WebAppContext"> <New id="talkdeskdemo" class="org.eclipse.jetty.plus.jndi.Resource"> <Arg><Ref refid="talkdeskdemo"/></Arg> <Arg>jdbc/talkdeskdb</Arg> <Arg> <New class="cdata.jdbc.talkdesk.TalkdeskDriver"> <Set name="url">jdbc:talkdesk:</Set> <Set name="AccountName">myAccount</Set> <Set name="Region">US</Set> <Set name="OAuthClientId">myClientId</Set> <Set name="OAuthClientSecret">myClientSecret</Set> </New> </Arg> </New> </Configure>Talkdesk uses the OAuth 2.0 Client Credentials grant. There is no browser-based authorization step and no callback URL.
Set the following connection properties:
- AccountName: The name of your Talkdesk account.
- Region: The region where your Talkdesk instance is deployed. Supported values are US (default), EU, CA, AU, UK, and FedRamp.
- OAuthClientId: The Client Id assigned when you registered your custom OAuth application.
- OAuthClientSecret: The Client Secret assigned to your custom OAuth application.
Creating a Custom OAuth Application
- Log in to your Talkdesk account and select OAuth Clients from the navigation menu.
- Click Create OAuth Client and give the client a descriptive name.
- Set Grant Type to Client Credentials.
- Click Add scopes and select the scopes for the data you want to access.
- Click Create and copy the Client Id and Client Secret.
When you connect, the driver automatically requests an access token from Talkdesk, caches it, and refreshes it when it expires. Make sure the scopes selected for the application match the views you plan to query, or the token request can fail.
-
Configure the resource in the Web.xml:
jdbc/talkdeskdb javax.sql.DataSource Container -
You can then access Talkdesk with a lookup to java:comp/env/jdbc/talkdeskdb:
InitialContext ctx = new InitialContext(); DataSource mytalkdesk = (DataSource)ctx.lookup("java:comp/env/jdbc/talkdeskdb");
More Jetty Integration
The steps above show how to configure the driver in a simple connection pooling scenario. For more use cases and information, see the Working with Jetty JNDI chapter in the Jetty documentation.