- How to integrate online editors into your own website on Java Spring
- Overview
- Important security info
- For Windows
- Step 1. Install ONLYOFFICE Docs
- Step 2. Download the Java code for the editors integration
- Step 3. Install the prerequisites
- Step 4. Set environment variables
- Step 5. Start application with Maven
- Step 6. Check accessibility
- For Linux
- Step 1. Install ONLYOFFICE Docs
- Step 2. Install the prerequisites and run the website with the editors
- Step 3. Check accessibility
- For Docker
How to integrate online editors into your own website on Java Spring
Overview
This example will help you integrate ONLYOFFICE Docs into your web application written in Java with Spring Boot.
Spring Boot has a lot of functionality, but its most significant features are: dependency management, auto-configuration, and built-in servlet containers.
The integration examples are used to demonstrate document editors functions and the ways to connect Document Server to your own application. DO NOT USE these examples on your own server without PROPER CODE MODIFICATIONS! If you enabled any of the test examples, disable it before going for production.
Important security info
Please keep in mind the following security aspects when you are using test examples:
- There is no protection of the storage from unauthorized access since there is no need for authorization.
- There are no checks against parameter substitution in links, since the parameters are generated by the code according to the pre-arranged scripts.
- There are no data checks in requests of saving the file after editing, since each test example is intended for requests only from ONLYOFFICE Document Server.
- There are no prohibitions on using test examples from other sites, since they are intended to interact with ONLYOFFICE Document Server from another domain.
For Windows
Step 1. Install ONLYOFFICE Docs
Download and install ONLYOFFICE Docs (packaged as Document Server).
See the detailed guide to learn how to install Document Server for Windows.
Step 2. Download the Java code for the editors integration
Download the Java-Spring example from our site.
To connect the editors to your website, specify the path to the editors installation, server port and the path to the storage folder in the \src\main\resources\application.properties file:
files.storage=
server.port=port
files.docservice.url.site=https://documentserver/
where the documentserver is the name of the server with the ONLYOFFICE Docs installed, port is any available port and files.storage is the path where files will be created and stored (in the project folder by default). You can set an absolute path. For example, D:\\folder. Please note that on Windows OS the double backslash must be used as a separator.
If you want to experiment with the editor configuration, modify the parameters in the \src\main\webapp\editor.jsp file.
Step 3. Install the prerequisites
To run the Java-Spring example code, install the Java version 11 appropriate for your OS and framework Apache Maven:
- Java (download from the Oracle official website);
- Apache Maven (download from the official website).
Step 4. Set environment variables
After you have installed Java on Windows, set the JAVA_HOME environment variable to point to the Java installation directory.
Find out where Java is installed. If you didn’t change the path during installation, it will be something like this:
C:\Program Files\Java\jdk11
In Windows 7, right click My Computer and select Properties, then click Advanced.
In Windows 8, go to Control Panel and select System, then click Advanced System Settings.
Click the Environment Variables button.
Under System Variables, click New.
In the Variable Name field, enter JAVA_HOME if you installed the JDK (Java Development Kit) or JRE_HOME if you installed the JRE (Java Runtime Environment).
In the Variable Value field, enter your JDK or JRE installation path, for example C:\Program Files\Java\jdk11.
Check if the variable created successfully by echo command in the Command Prompt:
echo %JAVA_HOME%
Set the MAVEN_HOME environment variable:
Unzip the downloaded archive with Maven to any directory. It will be something like this:
C:\apache-maven-3.8.1
In Windows 7, right click My Computer and select Properties, then click Advanced.
In Windows 8, go to Control Panel and select System, then click Advanced System Settings.
Click the Environment Variables button.
Under System Variables, click New.
In the Variable Name field, enter MAVEN_HOME.
In the Variable Value field, enter your JDK or JRE installation path, for example C:\apache-maven-3.8.1.
In the system variables, find PATH, click the Edit… button. In the Edit environment variable dialog, click the New button and add C:\apache-maven-3.8.1\bin to the PATH system variable.
Check if the variable created successfully by echo command in the Command Prompt:
echo %MAVEN_HOME%
Step 5. Start application with Maven
Open a console and go to the java-spring folder using the cd command:
cd C:\Program Files\document-server-integration\web\documentserver-example\java-spring
In the open console, enter the following commands:
mvn clean
mvn package
mvn spring-boot:run
Open your browser using server.address and server.port:
http://server.address:server.port/
Step 6. Check accessibility
In case the example and Document Server are installed on different computers, make sure that your server with the example installed has access to the Document Server with the address which you specify instead of documentserver in the configuration files. Make sure that the Document Server in its turn has access to the server with the example installed with the address which you specify instead of example.com in the configuration files.
If you integrated the editors successfully the result should look like the demo preview on our site.
For Linux
Step 1. Install ONLYOFFICE Docs
Download and install ONLYOFFICE Docs (packaged as Document Server).
See the detailed guide to learn how to install Document Server for Linux.
Step 2. Install the prerequisites and run the website with the editors
- Install Java: sudo add-apt-repository ppa:webupd8team/java sudo apt-get update sudo apt-get install oracle-java11-installer
There are two ways to get the Java-Spring example:
download the archive with the Java-Spring example and unpack it:
wget https://api.onlyoffice.com/app\_data/editor/Java%20Spring%20Example.zip unzip Java\ Spring\ Example.zip
clone the git repository:
git clone https://github.com/ONLYOFFICE/document-server-integration.git
Change the current directory for the project directory:
in the archive:
cd Java\ Spring\ Example/
in the git repository:
cd document-server-integration/web/documentserver-example/java-spring
Edit the application.properties configuration file. Specify the name of your local server with the ONLYOFFICE Docs installed.
nano src/main/resources/application.properties
Edit the following lines:
files.storage=
server.port=port
files.docservice.url.site=https://documentserver/
where the documentserver is the name of the server with the ONLYOFFICE Docs installed, port is any available port and files.storage is the path where files will be created and stored (in the project folder by default). You can set an absolute path.
Install Maven:
sudo apt-get install maven
Build:
mvn package
Start Java-Spring example:
./mvnw spring-boot:run
Open your browser using server.address and server.port:
Step 3. Check accessibility
In case the example and Document Server are installed on different computers, make sure that your server with the example installed has access to the Document Server with the address which you specify instead of documentserver in the configuration files. Make sure that the Document Server in its turn has access to the server with the example installed with the address which you specify instead of example.com in the configuration files.
If you integrated the editors successfully the result should look like the demo preview on our site.
For Docker
Edit the application.properties configuration file. Specify the name of your local server with the ONLYOFFICE Docs installed.
nano src/main/resources/application.properties
Edit the following lines:
files.storage=
server.port=port
files.docservice.url.site=https://documentserver/
where the documentserver is the name of the server with the ONLYOFFICE Docs installed, port is any available port and files.storage is the path where files will be created and stored (in the project folder by default). You can set an absolute path.
Run the next command in the Java-Spring example directory:
docker-compose up
Open your browser using server.address and server.port: