Ready to get started?

Learn more about the CData JDBC Driver for USPS or download a free trial:

Download Now

Configure the CData JDBC Driver for USPS in a Connection Pool in Tomcat

Connect to USPS data from a connection pool in Tomcat.

The CData JDBC Drivers support standard JDBC interfaces to integrate with Web applications running on the JVM. This article details how to connect to USPS data from a connection pool in Tomcat.

Connect to USPS Data through a Connection Pool in Tomcat

  1. Copy the CData JAR and CData .lic file to $CATALINA_HOME/lib. The CData JAR is located in the lib subfolder of the installation directory.
  2. Add a definition of the resource to the context. Specify the JDBC URL here.

    To authenticate with USPS, set the following connection properties.

    • PostageProvider: The postage provider to use to process requests. Available options are ENDICIA and STAMPS. If unspecified, this property will default to ENDICIA.
    • UseSandbox: This controls whether live or test requests are sent to the production or sandbox servers. If set to true, the Password, AccountNumber, and StampsUserId properties are ignored.
    • StampsUserId: This value is used for logging into authentication to the Stamps servers. This value is not applicable for Endicia and is optional if UseSandbox is true.
    • Password: This value is used for logging into Endicia and Stamps servers. If the postage provider is Endicia, this will be the pass phrase associated with your postage account. It is optional if UseSandbox is true.
    • AccountNumber: The shipper's account number. It is optional if UseSandbox is true.
    • PrintLabelLocation: This property is required to use the GenerateLabels or GenerateReturnLabels stored procedures. This should be set to the folder location where generated labels should be stored.

    The Cache Database

    Many of the useful task available from USPS require a lot of data. To ensure this data is easy to input and recall later, utilize a cache database to make requests. Set the cache connection properties in order to use the cache:

    • CacheLocation: The path to the cache location, for which a connection will be configured with the default cache provider. For example, C:\users\username\documents\uspscache

    As an alternative to CacheLocation, set the combination of CacheConnection and CacheProvider to configure a cache connection using a provider separate from the default.

    Built-in Connection String Designer

    For assistance in constructing the JDBC URL, use the connection string designer built into the USPS JDBC Driver. Either double-click the JAR file or execute the jar file from the command-line.

    java -jar cdata.jdbc.usps.jar

    Fill in the connection properties and copy the connection string to the clipboard.

    You can see the JDBC URL specified in the resource definition below.

    <Resource name="jdbc/usps" auth="Container" type="javax.sql.DataSource" driverClassName="cdata.jdbc.usps.USPSDriver" factory="org.apache.tomcat.jdbc.pool.DataSourceFactory" url="jdbc:usps:PostageProvider=ENDICIA; RequestId=12345; Password='abcdefghijklmnopqr'; AccountNumber='12A3B4C'" maxActive="20" maxIdle="10" maxWait="-1" />

    To allow a single application to access USPS data, add the code above to the context.xml in the application's META-INF directory.

    For a shared resource configuration, add the code above to the context.xml located in $CATALINA_BASE/conf. A shared resource configuration provides connectivity to USPS for all applications.

  3. Add a reference to the resource to the web.xml for the application. USPS data JSP jdbc/USPS javax.sql.DataSource Container
  4. Initialize connections from the connection pool: Context initContext = new InitialContext(); Context envContext = (Context)initContext.lookup("java:/comp/env"); DataSource ds = (DataSource)envContext.lookup("jdbc/USPS"); Connection conn = ds.getConnection();

More Tomcat Integration

The steps above show how to connect to USPS data in a simple connection pooling scenario. For more use cases and information, see the JNDI Datasource How-To in the Tomcat documentation.