Connect to Talkdesk Data from a Connection Pool in Jetty

Jerod Johnson
Jerod Johnson
Director, Technology Evangelism
The Talkdesk JDBC Driver supports connection pooling: This article shows how to connect faster to Talkdesk data from Web apps 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.

  1. 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
    
  2. Add the CData and license file, located in the lib subfolder of the installation directory, into the lib subfolder of the context path.
  3. 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

    1. Log in to your Talkdesk account and select OAuth Clients from the navigation menu.
    2. Click Create OAuth Client and give the client a descriptive name.
    3. Set Grant Type to Client Credentials.
    4. Click Add scopes and select the scopes for the data you want to access.
    5. 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.

  4. Configure the resource in the Web.xml:

    
    
      jdbc/talkdeskdb
      javax.sql.DataSource
      Container
    
    
  5. 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.

Ready to get started?

Download a free trial of the Talkdesk Driver to get started:

 Download Now

Learn more:

Talkdesk Icon Talkdesk JDBC Driver

Rapidly create and deploy powerful Java applications that integrate with Talkdesk data including Accounts, Attributes, BillingAccounts, Callbacks, Campaigns, Cases, Contacts, GuardianUsers, Invoices, Products, Subscriptions, Teams, Users, Wallets, and more!