Ready to get started?

Download a free trial of the SAP Netweaver Gateway Driver to get started:

 Download Now

Learn more:

SAP Netweaver Gateway Icon SAP Netweaver Gateway JDBC Driver

Rapidly create and deploy powerful Java applications that integrate with SAP Netweaver Gateway.

Connect to SAP Netweaver Gateway Data from a Connection Pool in Jetty



The SAP Netweaver Gateway JDBC Driver supports connection pooling: This article shows how to connect faster to SAP Netweaver Gateway data from Web apps in Jetty.

The CData JDBC driver for SAP Netweaver Gateway is easy to integrate with Java Web applications. This article shows how to efficiently connect to SAP Netweaver Gateway data in Jetty by configuring the driver for connection pooling. You will configure a JNDI resource for SAP Netweaver Gateway 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 SAP Netweaver Gateway data source at the level of the Web app, in WEB-INF\jetty-env.xml.

    <Configure id='sapgatewaydemo' class="org.eclipse.jetty.webapp.WebAppContext"> <New id="sapgatewaydemo" class="org.eclipse.jetty.plus.jndi.Resource"> <Arg><Ref refid="sapgatewaydemo"/></Arg> <Arg>jdbc/sapgatewaydb</Arg> <Arg> <New class="cdata.jdbc.sapgateway.SAPGatewayDriver"> <Set name="url">jdbc:sapgateway:</Set> <Set name="User">user</Set> <Set name="Password">password</Set> <Set name="URL">https://sapes5.sapdevcenter.com/sap/opu/odata/IWBEP/GWSAMPLE_BASIC/</Set> <Set name="InitiateOAuth">GETANDREFRESH</Set> </New> </Arg> </New> </Configure>

    SAP Gateway allows both basic and OAuth 2.0 authentication. You can use basic authentication to connect to your own account, or you can use OAuth to enable other users to retrieve data from your service with their accounts. In addition to authenticating, set the following connection properties to access SAP Gateway tables.

    • Url: Set this to the URL of your environment, or to the full URL of the service. For example, the full URL might appear as: https://sapes5.sapdevcenter.com/sap/opu/odata/IWBEP/GWSAMPLE_BASIC/. In this example, the environment URL would just be: https://sapes5.sapdevcenter.com.
    • Namespace: Set the appropriate Service Namespace. In the example above, IWBEP is the namespace. It is optional if the full URL to the service is specified.
    • Service: Set this to the service you want to retrieve data from. In the example above, the service is GWSAMPLE_BASIC. It is not required if the full URL is specified.

    Authenticate via Basic Authentication

    In basic authentication, you use your login credentials to connect. Set the following properties:

    • User: This is the username you use to log in to SAP Gateway.
    • Password: This is the password you use to log in to SAP Gateway.

    Authenticate via OAuth Authentication

    You can connect to SAP Gateway using the embedded OAuth connectivity (without setting any additional authentication connection properties). When you connect, the OAuth endpoint opens in your browser. Log in and grant permissions to complete the OAuth process. See the OAuth section in the online Help documentation for more information on other OAuth authentication flows.

  4. Configure the resource in the Web.xml:

    jdbc/sapgatewaydb javax.sql.DataSource Container
  5. You can then access SAP Netweaver Gateway with a lookup to java:comp/env/jdbc/sapgatewaydb: InitialContext ctx = new InitialContext(); DataSource mysapgateway = (DataSource)ctx.lookup("java:comp/env/jdbc/sapgatewaydb");

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.