Changes

Jump to navigation Jump to search
248 bytes added ,  09:30, 29 May 2018
This page is part of the [[Getting Started]] Section. It describes how BaseX can be used for to both provide simple APIs and build complex web applications. The following three HTTP services are available:
* [[RESTXQ]] allows you to write web applications with XQuery,* [[REST]] offers a straightforward RESTful API for accessing database resources via URLs,* [[RESTXQ]] allows you to write more complex APIs and full web applications with XQuery, and* [[WebDAV]] provides gives access to databases via the file system.
This article describes different ways of deploying and configuring these services. The services can be deployed as follows:
* as standalone application , by running the [[Startup#HTTP Server|BaseX HTTP Server]],
* as web servlet in a [[#Servlet Container|Servlet Container]], and
* as web servlet, using [[#Maven|Maven]]. Authentication: * If a user is defined in the <code>web.xml<br/code> file via the key <code>org.basex.user</code>, no password must be specified.* If the <code>admin<br/code>user is specified for an API, all features will be available without restriction.* Predefined authentication methods and default users cannot be overwritten by client. 
=Servlet Container=
In order to deploy BaseX HTTP Services in a servlet container, you may can download the WAR distribution of BaseX from the [http://basex.org/download download site] , or compile it via by calling <code>mvn compile war:war</code> in the <code>basex-api</code> packagedirectory. The WAR file can then be deployed following the instructions of the corresponding servlet container ([http://www.eclipse.org/jetty/documentation/current/quickstart-deploying-webapps.html jetty], [http://tomcat.apache.org/tomcat-7.0-doc/deployer-howto.html tomcat], etc.).
Configuring You can configure the port, context path, etc. can be done by following the corresponding instructions of the used 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:80808984/BaseX711basex/rest).
If run on a you use Jetty (which is the default HTTP server of BaseX), the server you may use a configuration is available via the {{Code|jetty.xml}} file for detailed server configuration. You can e.g. enable SSL connections or Jetty logging. Place , which is stored in the {{Code|jetty.xmlWEB-INF}} right directory next to the {{Code|web.xml}}. For detailed configuration refer to the [http://wikiwww.eclipse.org/Jetty/Reference/jetty.xml Jetty Documentation]. A sample [https:/documentation/github.comcurrent/BaseXdb/basex/blob/master/basexjetty-api/src/main/webapp/WEBxml-INF/jettyconfig.xml jetty.xmlhtml Jetty Documentation] is placed in the basex-api package.
To run on [http://tomcat.apache.org/ Apache Tomcat], start the tomcat Tomcat server and add any <code>*.war</code> distribution to deploy using via the Tomcat web interface. By default, the interface is accessible via http://localhost:8080/manager/html/.
==Configuration==
All database options can be specified in the {{Code|web.xml}} file.They need to be represented defined as context parameters and prefixed with {{Code|org.basex.}}.The most important options for the web application context are as follows:
{| class="wikitable"
|<code>[[Options#USER|USER]]</code>
|{{Code|admin}}
| Applies to REST and WebDAV service: If no a user is specified, the no credentials must be passed on by the client. Please check by yourself if it is safe to store your credentials in plain text.|-|<code>[[Options#USER|PASSWORD]]</code>|{{Code|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.
|-
|<code>[[Options#HTTPLOCAL|HTTPLOCAL]]</code>
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.
Different credentials can be assigned to the REST and WebDAV service by specifying local init parameters. In the following example, specific credentials are set an alternative user is specified for the REST service:
<pre class="brush:xml">
<param-name>org.basex.user</param-name>
<param-value>rest-user</param-value>
</init-param>
<init-param>
<param-name>org.basex.password</param-name>
<param-value>(:87!7X3$o3p</param-value>
</init-param>
</servlet>
=Maven=
Checkout 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.
==Configuration==
The same options as in the case of deployment apply in a servlet container apply. 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 [http://docs.codehaus.org/display/JETTY/Maven+Jetty+Plugin Maven Jetty Plugin] sesion in the {{Code|pom.xml}} file.
=User Management=
By default, RESTXQ uses the admin user, whereas the REST and WebDAV services require client-side authentication.Default credentials A default user can be stored server-side in the <code>web.xml</code> file or specified via[[Command-Line Options#BaseX HTTP Server|command-line arguments]].If In the HTTP server is started with no pre-defined credentials<code>web.xml</code> file, users both a global and passwords a servlet-specific user can be sent via[http://en.wikipedia.org/wiki/Basic_access_authentication HTTP Basic Authentication] or[http://en.wikipedia.org/wiki/Digest_authentication Digest Authentication]added (see above).
Users are specified in a {{Code|users.xml}} fileIf the HTTP server is started with no pre-defined user, which is stored in the database directory (see credentials must be passed on by the client via [http://en.wikipedia.org/wiki/Basic_access_authentication Basic Authentication] or [User Managementhttp://en.wikipedia.org/wiki/Digest_authentication Digest Authentication]] for more information(depending on the server setting).
With cURL, internet browsers, and most browsersother tools, you can specify the user name and password with each HTTP request basic authentication credentials within the request string as plain text, using the format <code>USER:PASSWORD@URL</code>. An example:
: <code>http://admin:admin@localhost:8984/</code>
 
Users are specified in a {{Code|users.xml}} file, which is stored in the database directory (see [[User Management]] for more information).
=Changelog=
 
;Version 9.0
* Updated: `jetty.xml` configuration file (required for Jetty 9).
 
;Version 8.6
* Updated: Authentication readded to RESTXQ.
* 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).
;Version 8.0
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu