Skip to content

Generating an OData Service

Before generating an OData service, you must obtain or create an OData CSDL XML (metadata) file. See Visual Studio Code Commands and Conventions for OData Metadata.

Caution

The initial generated WAR file will not have security enabled. Refer to the -login option and Securing the Generated Service for information on enabling security before deployment.

Using the Command-Line Tool

An OData service may be generated using the csdl-to-war command-line service generator tool. Find the "command" path for the csdl-to-war tool in .vscode/tasks.json, and invoke the tool from a Windows Command Prompt or Mac/Linux shell window.

Using the Terminal Menu Options

Use the Terminal menu options after defining tasks with SAP Business Application Studio or the Visual Studio Code Extension. The defined tasks will automatically invoke the command-line tool, as described below.

Note

The following steps include service generation and automated deployment. If you want to avoid automated deployment after service generation, please execute csdl-to-war-nodeploy in .vscode/tasks.json, and then see Deploying the Generated Service.

Automatic Database Table Creation

When the generated service is first started, it automatically creates SQL database tables (except when Working with Existing Database Tables).

The -application option is used to create a table name prefix and the -version option is used to create a table name suffix as follows:

  • If the major version number is zero, then the name suffix defaults to _MAJOR_MINOR_PATCH, e.g. _0_1_2.

  • If the major version number is greater than zero, then the name suffix defaults to _MAJOR_MINOR, e.g. _1_2.

If the OData CSDL Schema has changed in any way that requires incompatible SQL table definitions, the major or minor version number must be changed (except for pre-1.0.0 versions, in which case any version change will result in new tables). Any existing database tables from previous application versions will remain in the SQL database and you will have to use external SQL tools to delete the old tables or to migrate existing data from the old tables to the new tables.

Note

  • Additive schema changes, such as adding properties or adding entity types, are considered to be backwards compatible, and therefore do not require a version change.
  • Adding properties to entity types in a cache database may require reloading of data into the cache, because data already in the cache won't have meaningful values for any added properties.

SAP Business Application Studio

Ensure that necessary tools are installed and project files are created.

From the Terminal menu, select the Run Task... option to execute the appropriate task:

  • csdl-to-war to generate and deploy OData service for production environment. The service are generated and deployed to target platform automatically.

  • csdl-to-war-nodeploy to generate service only without deployment. It is used to add the service to an existing MTA project.

  • csdl-to-war-debug to generate and deploy service to the target platform, and then launch the debugger and enable the debugging automatically.

  • csdl-to-war-test to generate service with -h2db option and -test.mode and deploy the service to the target platform. -h2db option specifies database with H2 Database. -test.mode option ensure testing data is generated in JSON file and populate the H2 database for testing only.

  • csdl-to-sql to generate SQL file from the existing CSDL file. See existing tables for more details.

Using csdl-to-war, csdl-to-war-nodeploy, csdl-to-war-debug and csdl-to-war-test should generate Java source files and associated files, compile the project (using Apache Maven) into a Java EE WAR file. Except csdl-to-war-nodeploy, they will deploy the generated service, and start the server.

Target platform contains local server and Cloud Foundry.

  • After local deployment, the SAP Business Application Studio should auto-detect the running server, and offer to expose it for external access with a message such as the following. For local Tomcat deployment, i.e. "local" within the SAP Business Application Studio Dev Space.

    A service is listening to port 8080. Click "Expose and Open" to access the service externally, and preview it in a new tab.
    

    Use the Ports-related commands in the Command Palette (menu View > Find Command...) to manage the ports for external access.

  • After cloud deployment, look for the Cloud Foundry routes information in the Terminal window. Take the indicated host name and use the URL https://<host-name> as the Service Root URL.

Note

Using the Configure Default Build Task... menu option allows convenient execution of a designated build task using a menu option or keyboard shortcut.

Visual Studio Code Extension

Ensure that necessary tools are installed and project files are created.

From the Terminal menu, select the Run Task... option to execute the appropriate task:

  • csdl-to-war to generate and deploy service to target platform for production environment.

  • csdl-to-war-nodeploy to generate services only without deployment.

  • csdl-to-war-debug to generate and deploy service, and then launch the debugger and enable the debugging automatically.

  • csdl-to-war-test to generate services with -h2db option and -test.mode and deploy the service to the target platform.

  • csdl-to-sql to generated SQL file from the existing OData CSDL XML (metadata) file. See existing tables for more details.

Using csdl-to-war, csdl-to-war-nodeploy, csdl-to-war-debug and csdl-to-war-test should generate Java source files and associated files, compile the project (using Apache Maven) into a Java EE WAR file. Except csdl-to-war-nodeploy, they will deploy the generated service for target platform, and start the server.

Target platform contains local and Cloud Foundry server.

  • After local (Tomcat / TomEE / Virgo) deployment, look for the Service Root URL in the Terminal window, e.g. http://localhost:8080.

  • After cloud deployment, look for the Cloud Foundry routes information in the Terminal window. Note the indicated host name and use the URL https://<host-name> as the Service Root URL.

Note

Using the Terminal > Configure Default Build Task... menu option allows convenient execution of a designated build task using a menu option or keyboard shortcut.


Last update: November 16, 2020