Difference between revisions of "Web Application"

From BaseX Documentation
Jump to navigation Jump to search
m (Text replacement - "syntaxhighlight" to "pre")
 
(7 intermediate revisions by the same user not shown)
Line 2: Line 2:
  
 
=Startup=
 
=Startup=
 
{{Announce|With Version 10, the default admin password has been removed, and the default ports have been changed from 8984/8985 to 8080/8081.}}
 
  
 
* Run one of the {{Code|basexhttp}} or {{Code|basexhttp.bat}} scripts. Call the script with the {{Code|stop}} keyword to gracefully shut down the server.
 
* Run one of the {{Code|basexhttp}} or {{Code|basexhttp.bat}} scripts. Call the script with the {{Code|stop}} keyword to gracefully shut down the server.
 
* If you have installed BaseX on ''Windows'', click on the '''BaseX HTTP Server (Start)''' icon.
 
* If you have installed BaseX on ''Windows'', click on the '''BaseX HTTP Server (Start)''' icon.
  
Both an instance of [https://www.eclipse.org/jetty/ Jetty] and BaseX [[Database Server]] will be started. By default, Jetty listens to the port 8080, and the [[Database Server|BaseX Database Server]] is accessible on port {{Code|1984}}. After startup, you can access a plain HTML welcome page via http://localhost:8080.
+
Both an instance of [https://www.eclipse.org/jetty/ Jetty] and BaseX [[Database Server]] will be started. By default, Jetty listens to the port 8080, and the [[Database Server|BaseX Database Server]] is accessible on port 1984. After startup, you can access a plain HTML welcome page via http://localhost:8080.
  
 
Unless you have already chosen an admin password yet (e.g., via the Windows installer or a previous installation), you can do so by invoking the {{Command|PASSWORD}} command on your terminal:
 
Unless you have already chosen an admin password yet (e.g., via the Windows installer or a previous installation), you can do so by invoking the {{Command|PASSWORD}} command on your terminal:
Line 25: Line 23:
 
The Jetty logging level can be adjusted by adding the following properties to the start script:
 
The Jetty logging level can be adjusted by adding the following properties to the start script:
  
<syntaxhighlight lang="xml">
+
<pre lang="xml">
 
-Dorg.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog -D{classref}.LEVEL=DEBUG
 
-Dorg.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog -D{classref}.LEVEL=DEBUG
</syntaxhighlight>
+
</pre>
  
 
Various [[Command-Line_Options#HTTP Server|command-line options]] are available to simplify batch processing. The [[Start_Scripts|start script]] can be adjusted for individual purposes (e.g. if the default memory limit is too restrictive).
 
Various [[Command-Line_Options#HTTP Server|command-line options]] are available to simplify batch processing. The [[Start_Scripts|start script]] can be adjusted for individual purposes (e.g. if the default memory limit is too restrictive).
Line 39: Line 37:
 
You can configure the port, context path, etc. by following the instructions of the corresponding 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/basex/rest).
 
You can configure the port, context path, etc. by following the instructions of the corresponding 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/basex/rest).
  
If you use Jetty (which is the default HTTP server of BaseX), the server configuration is available via the {{Code|jetty.xml}} file, which is stored in the {{Code|WEB-INF}} directory next to the {{Code|web.xml}}. For detailed configuration, refer to the [https://www.eclipse.org/jetty/documentation/current/jetty-xml-config.html Jetty Documentation].
+
If you use Jetty (which is the default HTTP server of BaseX), the server configuration is defined in the {{Code|jetty.xml}} file, which is stored in the {{Code|WEB-INF}} directory next to the {{Code|web.xml}}. For detailed configuration, refer to the [https://www.eclipse.org/jetty/documentation/current/jetty-xml-config.html Jetty Documentation].
  
 
To run on [https://tomcat.apache.org/ Apache Tomcat], start the Tomcat server and add any <code>*.war</code> distribution to deploy via the Tomcat web interface. By default, the interface is accessible via http://localhost:8080/manager/html/.
 
To run on [https://tomcat.apache.org/ Apache Tomcat], start the Tomcat server and add any <code>*.war</code> distribution to deploy via the Tomcat web interface. By default, the interface is accessible via http://localhost:8080/manager/html/.
Line 45: Line 43:
 
==Maven==
 
==Maven==
  
Check out the BaseX sources via [[Developing with Eclipse|Eclipse]] or [[Git]]. Execute <code>mvn install</code> in the main project directory and then <code>mvn install jetty:run</code> in the <code>basex-api</code> sub-directory. This will start a Jetty instance in which the servlets will be deployed.
+
Check out the BaseX sources via [[Developing with Eclipse|Eclipse]] or [[Git]]. Execute <code>mvn install</code> in the main project directory and then <code>mvn install jetty:run</code> in the <code>basex-api</code> subdirectory. This will start a Jetty instance in which the servlets will be deployed.
  
 
The same options as in the case of deployment apply in a servlet container. In this case, however, there is no WAR archive. Instead, Jetty looks up all files in the directory <code>[https://github.com/BaseXdb/basex/tree/master/basex-api/src/main/webapp basex-api/src/main/webapp]</code>. Jetty and servlet options can be configured in the {{Code|jetty.xml}} and {{Code|web.xml}} files as described above in the [[#Configuration|Servlet Container Configuration]]. The Jetty stop port can be changed in the [https://www.eclipse.org/jetty/documentation/current/jetty-maven-plugin.html Maven Jetty Plugin] sesion in the {{Code|pom.xml}} file.
 
The same options as in the case of deployment apply in a servlet container. In this case, however, there is no WAR archive. Instead, Jetty looks up all files in the directory <code>[https://github.com/BaseXdb/basex/tree/master/basex-api/src/main/webapp basex-api/src/main/webapp]</code>. Jetty and servlet options can be configured in the {{Code|jetty.xml}} and {{Code|web.xml}} files as described above in the [[#Configuration|Servlet Container Configuration]]. The Jetty stop port can be changed in the [https://www.eclipse.org/jetty/documentation/current/jetty-maven-plugin.html Maven Jetty Plugin] sesion in the {{Code|pom.xml}} file.
Line 53: Line 51:
 
The following services are available and enabled by default:
 
The following services are available and enabled by default:
  
{| class="wikitable"  
+
{| class="wikitable"
 
|- valign="top"
 
|- valign="top"
 
! Name
 
! Name
Line 89: Line 87:
  
 
{| class="wikitable"  
 
{| class="wikitable"  
|-
+
|- valign="top"
 
! width="160" | Option
 
! width="160" | Option
 
! width="90" |Default
 
! width="90" |Default
 
! Description
 
! Description
|-
+
|- valign="top"
 
|{{Option|USER}}
 
|{{Option|USER}}
 
|{{Code|admin}}
 
|{{Code|admin}}
 
| If a user is specified, no credentials must be passed on by the client.
 
| If a user is specified, no credentials must be passed on by the client.
|-
+
|- valign="top"
 
|{{Option|HTTPLOCAL}}
 
|{{Option|HTTPLOCAL}}
 
|{{Code|false}}
 
|{{Code|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 {{Code|true}}.
 
|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 {{Code|true}}.
|-
+
|- valign="top"
 
|{{Option|RESTXQPATH}}
 
|{{Option|RESTXQPATH}}
 
|{{Code|.}}
 
|{{Code|.}}
 
|Relative or absolute directory referencing the [[RESTXQ]] modules. By default, the option points to the standard web application directory.
 
|Relative or absolute directory referencing the [[RESTXQ]] modules. By default, the option points to the standard web application directory.
|-
+
|- valign="top"
 
|{{Option|RESTPATH}}
 
|{{Option|RESTPATH}}
 
|{{Code|.}}
 
|{{Code|.}}
 
|Relative or absolute directory referencing queries and command-scripts that can be invoked via the [[REST#GET_Requests|run operation]] of REST. By default, the option points to the standard web application directory.
 
|Relative or absolute directory referencing queries and command-scripts that can be invoked via the [[REST#GET_Requests|run operation]] of REST. By default, the option points to the standard web application directory.
|-
+
|- valign="top"
 
|{{Option|AUTHMETHOD}}
 
|{{Option|AUTHMETHOD}}
 
|{{Code|Basic}}
 
|{{Code|Basic}}
Line 117: Line 115:
 
All options are prefixed with {{Code|org.basex.}}. Local file paths in options may be absolute or relative. If a relative path is specified, its root will be the servlet’s ({{Code|webapp}}) path:
 
All options are prefixed with {{Code|org.basex.}}. Local file paths in options may be absolute or relative. If a relative path is specified, its root will be the servlet’s ({{Code|webapp}}) path:
  
<syntaxhighlight lang="xml">
+
<pre lang="xml">
 
<context-param>
 
<context-param>
 
   <param-name>org.basex.dbpath</param-name>
 
   <param-name>org.basex.dbpath</param-name>
Line 128: Line 126:
 
   <param-value>f:/basex/repository</param-value>
 
   <param-value>f:/basex/repository</param-value>
 
</context-param>
 
</context-param>
</syntaxhighlight>  
+
</pre>  
  
Context parameters can be requested from XQuery via [[Process_Module#proc:property-names|proc:property-names]] and [[Process_Module#proc:property|proc:property]]. How to set these options is specific to the servlet container. For example, in Jetty it can be done by [http://www.eclipse.org/jetty/documentation/current/override-web-xml.html overriding the web.xml] file. Another option is to directly edit the {{Code|WEB-INF/web.xml}} file in the WAR archive (WAR files are simple ZIP files). Refer to the sample [https://github.com/BaseXdb/basex/blob/master/basex-api/src/main/webapp/WEB-INF/web.xml web.xml] of the basex-api package.
+
Context parameters can be requested from XQuery via [[Process_Module#proc:property-names|proc:property-names]] and [[Process_Module#proc:property|proc:property]]. How to set these options is specific to the servlet container. For example, in Jetty it can be done by [http://www.eclipse.org/jetty/documentation/current/override-web-xml.html overriding the web.xml] file. Another option is to directly edit the {{Code|WEB-INF/web.xml}} file in the WAR archive (WAR files are simple ZIP files). Refer to the sample [https://github.com/BaseXdb/basex/blob/master/basex-api/src/main/webapp/WEB-INF/web.xml web.xml] of the {{Code|basex-api}} package.
  
 
To enable or disable a specific service, the corresponding servlet entry in the {{Code|web.xml}} file needs to be removed/commented.
 
To enable or disable a specific service, the corresponding servlet entry in the {{Code|web.xml}} file needs to be removed/commented.
Line 138: Line 136:
 
No credentials need to be supplied if a default user is assigned to a service in the {{Code|web.xml}} file. In the following example, the user {{Code|rest-user}} is specified for the REST service:
 
No credentials need to be supplied if a default user is assigned to a service in the {{Code|web.xml}} file. In the following example, the user {{Code|rest-user}} is specified for the REST service:
  
<syntaxhighlight lang="xml">
+
<pre lang="xml">
 
<servlet>
 
<servlet>
 
   <servlet-name>REST</servlet-name>
 
   <servlet-name>REST</servlet-name>
Line 147: Line 145:
 
   </init-param>
 
   </init-param>
 
</servlet>
 
</servlet>
</syntaxhighlight>
+
</pre>
  
 
If the HTTP server is started with no pre-defined user, the credentials must be passed on by the client via [https://en.wikipedia.org/wiki/Basic_access_authentication Basic Authentication] or [https://en.wikipedia.org/wiki/Digest_authentication Digest Authentication], depending on the chosen authentication method in the configuration.
 
If the HTTP server is started with no pre-defined user, the credentials must be passed on by the client via [https://en.wikipedia.org/wiki/Basic_access_authentication Basic Authentication] or [https://en.wikipedia.org/wiki/Digest_authentication Digest Authentication], depending on the chosen authentication method in the configuration.
  
With cURL, internet browsers, and other tools, you can specify basic authentication credentials within the request string as plain text, using the format <code>USER:PASSWORD@URL</code>. An example:
+
With cURL, internet browsers, and other tools, you can specify basic authentication credentials within the request string as plain text, using the format <code>USER:PASSWORD@URL</code>:
  
: <code>http://admin:admin@localhost:8080/</code>
+
: <code>http://admin:...@localhost:8080/</code>
  
 
Users are specified in a {{Code|users.xml}} file, which is stored in the database directory (see [[User Management]] for more information).
 
Users are specified in a {{Code|users.xml}} file, which is stored in the database directory (see [[User Management]] for more information).
Line 166: Line 164:
  
 
;Version 8.6
 
;Version 8.6
* Updated: Authentication readded to RESTXQ.
+
* Updated: Authentication re-added to RESTXQ.
 
* Updated: No password must be specified in the <code>web.xml</code> file anymore.
 
* Updated: No password must be specified in the <code>web.xml</code> file anymore.
 
* Updated: Server-side user and authentication method is now enforced (cannot be overwritten by client).
 
* Updated: Server-side user and authentication method is now enforced (cannot be overwritten by client).
Line 183: Line 181:
  
 
;Version 7.3
 
;Version 7.3
 
 
* Updated: {{Code|client}} mode replaced with {{Code|server}} mode
 
* Updated: {{Code|client}} mode replaced with {{Code|server}} mode
  
 
;Version 7.2
 
;Version 7.2
 
 
* Web Application concept revised
 
* Web Application concept revised

Latest revision as of 17:39, 1 December 2023

This page is part of the Getting Started Section. It describes how BaseX can be used to both provide simple APIs and build complex web applications.

Startup[edit]

  • Run one of the basexhttp or basexhttp.bat scripts. Call the script with the stop keyword to gracefully shut down the server.
  • If you have installed BaseX on Windows, click on the BaseX HTTP Server (Start) icon.

Both an instance of Jetty and BaseX Database Server will be started. By default, Jetty listens to the port 8080, and the BaseX Database Server is accessible on port 1984. After startup, you can access a plain HTML welcome page via http://localhost:8080.

Unless you have already chosen an admin password yet (e.g., via the Windows installer or a previous installation), you can do so by invoking the PASSWORD command on your terminal:

basexhttp -c PASSWORD
BaseX [HTTP Server]
...
[main] INFO org.eclipse.jetty.util.log - Logging initialized @239ms to org.eclipse.jetty.util.log.Slf4jLog
...
HTTP STOP Server was started (port: 8081).
HTTP Server was started (port: 8080).
Password: _

The Jetty logging level can be adjusted by adding the following properties to the start script:

-Dorg.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog -D{classref}.LEVEL=DEBUG

Various command-line options are available to simplify batch processing. The start script can be adjusted for individual purposes (e.g. if the default memory limit is too restrictive).

BaseX can also be deployed as web servlet in a servlet container or with Maven:

Servlet Container[edit]

In order to deploy BaseX HTTP Services in a servlet container, you can download the WAR distribution of BaseX from the download site, or compile it by calling mvn compile war:war in the basex-api directory. The WAR file can then be deployed following the instructions of the corresponding servlet container (Jetty, Tomcat, etc.).

You can configure the port, context path, etc. by following the instructions of the corresponding 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/basex/rest).

If you use Jetty (which is the default HTTP server of BaseX), the server configuration is defined in the jetty.xml file, which is stored in the WEB-INF directory next to the web.xml. For detailed configuration, refer to the Jetty Documentation.

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

Maven[edit]

Check out 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 subdirectory. This will start a Jetty instance in which the servlets will be deployed.

The same options as in the case of deployment apply in a servlet container. 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.

Services[edit]

The following services are available and enabled by default:

Name Standard Path Description
RESTXQ / Write enriched APIs and full web applications with XQuery.
WebSockets ws/ Bidirectional client/server communication.
REST rest/ Straightforward access to XML databases and its resources.
WebDAV webdav/ Database access via the file system.
Default static/ Access to static server resources (HTML, JavaScript, CSS, images, …).

The DBA is a web-based database administration interface written in RESTXQ. It allows you to create and administrate databases, evaluate queries in realtime, view log files, manage users, etc. It is embedded in the full distributions of BaseX, and it can be accessed after startup via http://localhost:8080/dba/.

Configuration[edit]

Unless BaseX is deployed as servlet, the location of the web application directory can be adjusted via the WEBPATH option, and compression of HTTP responses can be enabled via the GZIP option.

Further database options can be defined as context parameters in the web.xml file. The most important options for the web application context are:

Option Default Description
USER admin If a user is specified, no credentials must be passed on by the client.
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.

All options are prefixed with org.basex.. Local file paths in options may be absolute or relative. If a relative path is specified, its root will be the servlet’s (webapp) path:

<context-param>
  <param-name>org.basex.dbpath</param-name>
  <!-- will be rewritten to ..../webapp/WEB-INF/data -->
  <param-value>WEB-INF/data</param-value>
</context-param>
<context-param>
  <param-name>org.basex.repopath</param-name>
  <!-- will be kept as is -->
  <param-value>f:/basex/repository</param-value>
</context-param>

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.

To enable or disable a specific service, the corresponding servlet entry in the web.xml file needs to be removed/commented.

Authentication[edit]

No credentials need to be supplied if a default user is assigned to a service in the web.xml file. In the following example, the user rest-user is specified for the REST service:

<servlet>
  <servlet-name>REST</servlet-name>
  <servlet-class>org.basex.http.rest.RESTServlet</servlet-class>
  <init-param>
    <param-name>org.basex.user</param-name>
    <param-value>rest-user</param-value>
  </init-param>
</servlet>

If the HTTP server is started with no pre-defined user, the credentials must be passed on by the client via Basic Authentication or Digest Authentication, depending on the chosen authentication method in the configuration.

With cURL, internet browsers, and other tools, you can specify basic authentication credentials within the request string as plain text, using the format USER:PASSWORD@URL:

http://admin:...@localhost:8080/

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

Changelog[edit]

Version 10.0
  • Updated: The default admin password has been removed, and the default ports have been changed from 8984/8985 to 8080/8081.
Version 9.0
  • Updated: jetty.xml configuration file (required for Jetty 9).
Version 8.6
  • Updated: Authentication re-added to RESTXQ.
  • Updated: No password must be specified in the web.xml file anymore.
  • Updated: Server-side user and authentication method is now enforced (cannot be overwritten by client).
Version 8.0
  • Added: digest authentication
  • Updated: user management
  • Updated: default user/password disabled in web.xml
Version 7.7
  • Added: service-specific permissions
Version 7.5
  • Added: jetty.xml: configuration for Jetty Server
  • Updated: server replaced with httplocal mode
Version 7.3
  • Updated: client mode replaced with server mode
Version 7.2
  • Web Application concept revised