Web Application

From BaseX Documentation

Jump to: navigation, search

This page is part of the Getting Started Section. It describes how BaseX can be used for web applications. The following three HTTP services are available:

This article describes different ways of deploying and configuring these services. The services can be deployed as follows:


[edit] Servlet Container

In order to deploy BaseX HTTP Services in a servlet container, you may download the WAR distribution of BaseX from the download site or compile it via mvn compile war:war in the basex-api package. The WAR file can then be deployed following the instructions of the corresponding servlet container (jetty, tomcat).

Configuring port, context path, etc. can be done by following the corresponding instructions of the used servlet container. This is needed if you want to replace the default URL path (e.g. http://localhost:8080/rest) with a custom one (e.g. http://localhost:8080/BaseX711/rest).

If run on a Jetty server you may use a jetty.xml file for detailed server configuration. You can e.g. enable SSL connections or Jetty logging. Place the jetty.xml right next to the web.xml. For detailed configuration refer to the Jetty Documentation. A sample jetty.xml is placed in the basex-api package.

To run on Apache Tomcat, start the tomcat server and add any *.war distribution to deploy using the Tomcat web interface. By default, the interface is accessible via http://localhost:8080/manager/html/.

[edit] Configuration

All database options can be specified in the web.xml file. They need to be represented as context parameters and prefixed with org.basex.. The most important options for the web application context are as follows:

Option Default Description
USER admin Applies to REST and WebDAV service: If no user is specified, the credentials must be passed on by the client. Please check by yourself if it is safe to store your credentials in plain text.
PASSWORD admin Applies to REST and WebDAV service: If no password is specified, it must be passed on by the client. Please check by yourself if it is safe to store your credentials in plain text.
HTTPLOCAL false Operation mode. By default, a database server instance will be started, as soon as the first HTTP service is called. The database server can be disabled by setting this flag to true.
RESTXQPATH . Relative or absolute directory referencing the RESTXQ modules. By default, the option points to the standard web application directory.
RESTPATH . Relative or absolute directory referencing queries and command-scripts that can be invoked via the run operation of REST. By default, the option points to the standard web application directory.
AUTHMETHOD Basic The default authentication method proposed by the server. The available methods are Basic and Digest.

Path options may contain an absolute or relative path. If a relative path is specified, its root will be the servlet (webapp) path:

    <!-- will be rewritten to ..../webapp/WEB-INF/data -->
    <!-- will be kept as is -->

Context parameters can be requested from XQuery via proc:property-names and proc:property. How to set these options is specific to the servlet container. For example, in Jetty it can be done by overriding the web.xml file. Another option is to directly edit the WEB-INF/web.xml file in the WAR archive (WAR files are simple ZIP files). Refer to the sample web.xml of the basex-api package.

Different credentials can be assigned to the REST and WebDAV service by specifying local init parameters. In the following example, specific credentials are set for the REST service:


[edit] Available Services

To enable or disable one of the provided services, the corresponding servlet entry in the web.xml file needs to be removed/commented. The default URL paths are listed in the following table:

Service URL Usage
Default web server http://[host]:[port]/[servlet_context_path]/static Access your standard web files (e.g. HTML, JavaScript or CSS).
RESTXQ http://[host]:[port]/[servlet_context_path] Create XQuery web services and applications.
REST http://[host]:[port]/[servlet_context_path]/rest Access XML database and its resources.
WebDAV http://[host]:[port]/[servlet_context_path]/webdav or
webdav://[host]:[port]/[servlet_context_path]/webdav (depending on client)
Access databases via the filesystem.

[edit] Maven

Checkout the BaseX sources via Eclipse or Git. Execute mvn install in the main project directory and then mvn install jetty:run in the basex-api sub-directory. This will start a Jetty instance in which the servlets will be deployed.

[edit] Configuration

The same options as in the case of deployment in a servlet container apply. In this case, however, there is no WAR archive. Instead, Jetty looks up all files in the directory basex-api/src/main/webapp. Jetty and servlet options can be configured in the jetty.xml and web.xml files as described above in the Servlet Container Configuration. The Jetty stop port can be changed in the Maven Jetty Plugin sesion in the pom.xml file.

[edit] User Management

By default, the REST and WebDAV services require client-side authentication. Default credentials can be stored server-side in the web.xml file or specified via command-line arguments. If the HTTP server is started with no pre-defined credentials, users and passwords can be sent via HTTP Basic Authentication or Digest Authentication.

Users are specified in a users.xml file, which is stored in the database directory (see User Management for more information).

With cURL, and most browsers, you can specify the user name and password with each HTTP request within the request string as plain text, using the format USER:PASSWORD@URL. An example:


[edit] Changelog

Version 8.0
Version 7.7
Version 7.5
Version 7.3
Version 7.2
Personal tools