Commit ca1e7c01 authored by Franz Reischl's avatar Franz Reischl 🏖
Browse files

Initial commit - includes Apache Tomcat and Apache Maven

parents
#########################################
#########################################
### ###
### MiniREST Standalone package ###
### ###
#########################################
#########################################
# Authors: #
# - k11771360 Reischl, Franz #
# - k01156101 Schmipelsberger, Michael #
# For Course Communication Engineering #
# CE [257.100] #
# Supervising professor: #
# - Oppl, Stefan #
#########################################
ABOUT
Mini-REST is a small project to demonstrate the use of REST communication on a small scale using practical examples.
The standalone package allows the user to run the MiniREST-server on his own local computer and use it just by himself,
and without the need for internet access.
The standalone MINI-Rest server package runs on Windows, Linux and (probably) Apple Mac.
REQUIREMENTS
Requirements for update and executing server package:
* Git: version control system. Make sure that 'git' can be called from the terminal.
* Java: Java runtime environment. Make sure that 'java' can be called from the terminal.
* JDK: Java development kit / SDK. Make sure that 'javac' can be called from the terminal.
* Internet access: For first time installation and subsequent updates. Not needed for running the server package.
Requirements for accessing the server package:
* Browser, to view the client interface.
* (Optional) Postman, integrated IDE-functionality or similar tools to access the REST interface manually.
HOW TO USE:
- Extract the downloaded package in a directory of your choosing.
NOTE that upon extracting the downloaded archive, no server files are included!
- Read this file first! (You didn't, did you?)
- When using for the first time, ...
+ WINDOWS: run the batch file '2-get_update.bat'
+ LINUX: run the shell script '2-get_update.sh'
+ MAC: run the shell script '2-get_update.sh'
... to download and compile the source code for the MiniREST-Server, and
- Start the Apache Tomcat server by ...
+ WINDOWS: run the batch file '3-catalina_start.bat'
+ LINUX: run the shell script '3-catalina_start.sh'
+ MAC: run the shell script '3-catalina_start.sh'
- Access the local MiniREST server instance by pointing your browser to http://localhost:8080 or use the link provided for you in the package folder.
- (Optional) If using an API tool like Postman, the base URL for the API is http://localhost:8080/webapi/
- To stop the Apache Tomcat server by...
+ WINDOWS: run the batch file '5-catalina_stop.bat'
+ LINUX: run the shell script '5-catalina_stop.sh'
+ MAC: run the shell script '5-catalina_stop.sh'
- For updating the server files to latest version, just execute script "get_update.*" again.
NOTE: The data you entered previously will not be touched by the update process.
It is stored separately in the MiniREST Standalone server package folder.
NOTE: No data is stored, installed or referenced permanently on your computer! If you delete the MiniREST package folder, all is gone! (including all data you may have input into your MiniREST instance)
\ No newline at end of file
@echo off
@REM -- Setting variables for the batch file
setlocal ENABLEDELAYEDEXPANSION
set "REPO_URL=https://gitlab.ce.jku.at/k11771360/tomcat-minirest.git"
set "REPO_NAME=tomcat-minirest"
set "MVN_PATH=apache-maven-3.6.0\bin"
rem echo %cd%
@REM change working directory to drive and folder of batch file location
%~d0
cd %~dp0
rem echo %cd%
@REM -- Checking GIT installation
git --version >NUL 2>NUL
if %ERRORLEVEL% NEQ 0 GOTO gitnogood
@REM -- Checking JAVA installation
java -version >NUL 2>NUL
if %ERRORLEVEL% NEQ 0 GOTO javanogood
@REM -- Checking GIT installation
::javac -version >NUL 2>NUL
::if %ERRORLEVEL% NEQ 0 GOTO jdknogood
@REM -- Stopping tomcat server, if running
CALL catalina_stop.bat
@REM -- Checking if the code folder exists, creating it if necessary
IF EXIST code goto existcode
rem echo "code" directory not found, creating it...
mkdir code
goto cont
:existcode
rem echo "code" directory already exists
:cont
@REM -- Changing working directory
cd code
@REM -- Check if the folder containing the git repository exists
IF NOT EXIST %REPO_NAME% goto init_repo
rem echo "Verzeichnis %REPO_NAME% vorhanden."
goto exist_repo
:init_repo
@REM -- Initialize the repository for the first time
git clone %REPO_URL% %REPO_NAME%
if %ERRORLEVEL% NEQ 0 goto clone_fail
:exist_repo
@REM -- Checking validity of git repository
cd %REPO_NAME%
git status >NUL 2>NUL
if %ERRORLEVEL% NEQ 0 goto bad_repo
:good_repo
@REM -- Update the git repository to the latest version.
cd %REPO_NAME%
git fetch --all
git checkout --force origin/master
git submodule sync
git submodule update --init --recursive
@REM -- Update the submodule (client files) to latest version
git submodule foreach git pull origin master
:maven
@REM Set JAVA_HOME
@REM Code snippet from XAMPP project
set KeyName=HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Development Kit
reg query "!KeyName!" /s
if !ERRORLEVEL! == 1 (
:: Workaround for new JDK versions
set KeyName=HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\JDK
reg query "!KeyName!" /s
if !ERRORLEVEL! == 1 (
echo . [XAMPP]: Cannot find current JDK installation!
echo . [XAMPP]: Cannot set JAVA_HOME. Aborting ...
goto :END
)
)
set Cmd=reg query "%KeyName%" /s
for /f "tokens=2*" %%i in ('%Cmd% ^| find "JavaHome"') do set JAVA_HOME=%%j
@REM -- Apache Maven Build
call ..\..\%MVN_PATH%\mvn.cmd compile
@REM -- Apache Maven Generate Site
call ..\..\%MVN_PATH%\mvn.cmd deploy
@REM -- Return to original path
cd ..\..
@REM -- Overwriting web server files
xcopy /E /C /H /R /Y /Q "code\%REPO_NAME%\target\at.jku.ce" "webapps\ROOT"
IF %ERRORLEVEL% NEQ 0 goto copy_fail
echo.
echo ---
echo Server files have successfully updated to latest version.
echo You can now restart Tomcat via 'catalina_start.bat'
echo ---
echo.
goto end
@REM --------------------
@REM -- Error handling --
@REM --------------------
:gitnogood
@REM -- Error: no valid git installation
echo.
echo ---
echo [ERROR] no valid git installation
echo Please make sure that git is installed and your PATH is set accordingly.
echo ---
echo You can get git at http://git-scm.com
echo.
goto end
:javanogood
@REM -- Error: no valid java installation
echo.
echo ---
echo [ERROR] no valid Java installation
echo Please make sure that Java Runtime Environment is installed
echo and your PATH is set accordingly.
echo You can test it by typing "java -version" in the command line.
echo ---
echo You can get Java at https://www.java.com/en/download/
echo.
goto end
:jdknogood
@REM -- Error: no valid jdk installation
echo.
echo ---
echo [ERROR] no valid JDK installation
echo Please make sure that the Java Development Kit is installed
echo and your PATH is set accordingly. You can test it by typing
echo "javac -version" in the command line.
echo ---
echo You can get the JDK at https://www.oracle.com/technetwork/java/javase/downloads/index.html
echo.
goto end
:bad_repo
@REM -- Error: damaged repo
echo.
echo ---
echo [ERROR] Repository code\%REPO_NAME% seems to be damaged.
echo Try deleting it and restart.
echo ---
echo.
goto end
:clone_fail
@REM -- Error: Cloning failed.
echo.
echo ---
echo [ERROR] Failed to clone repository.
echo Are you online? Can you write to disk?
echo ---
echo.
goto end
:copy_fail
@REM -- Error: Copying files failed.
echo.
echo ---
echo [ERROR] Failed to copy files to new location.
echo Is the server still running? Are some files opened elsewhere?
echo ---
echo.
goto end
:end
pause
endlocal
\ No newline at end of file
#!/bin/sh
# Setting variables for the script file
REPO_URL="https://gitlab.ce.jku.at/k11771360/tomcat-minirest.git"
REPO_NAME="tomcat-minirest"
MVN_PATH="apache-maven-3.6.0"
# Change working directory to where file resides
# cd $(dirname $(readlink -f "$0"))
# Checking GIT installation
git --version >/dev/null 2>&1
if [ $? -gt 0 ]
then
# -- Error: no valid git installation
echo >&2
echo --- >&2
echo [ERROR] no valid git installation >&2
echo Please make sure that git is installed and your PATH is set accordingly. >&2
echo You can test it by typing \"git --version\" in the shell. >&2
echo --- >&2
echo You can get git at http://git-scm.com >&2
echo >&2
echo "Press [Enter] to exit..."; sed -n q </dev/tty;
exit 1
fi
# Check Java installation
java -version > /dev/null 2>&1
if [ $? -gt 0 ]
then
# -- Error: no valid java installation
echo >&2
echo --- >&2
echo [ERROR] no valid Java installation >&2
echo Please make sure that Java Runtime Environment is installed and configured correctly. >&2
echo You can test it by typing \"java -version\" in the shell. >&2
echo --- >&2
echo You can get Java via your package manager \(rpm, apt, etc.\) >&2
echo or manually at https://www.java.com/en/download/ >&2
echo >&2
echo "Press [Enter] to exit..."; sed -n q </dev/tty;
exit 1
fi
# Check JDK installation
javac -version > /dev/null 2>&1
if [ $? -gt 0 ]
then
# -- Error: no valid jdk installation
echo >&2
echo --- >&2
echo [ERROR] no valid JDK installation >&2
echo Please make sure that Java Development Kit is installed and configured correctly. >&2
echo You can test it by typing \"javac -version\" in the shell. >&2
echo --- >&2
echo You can get Java via your package manager \(rpm, apt, etc.\) >&2
echo or manually at https://www.java.com/en/download/ >&2
echo >&2
echo "Press [Enter] to exit..."; sed -n q </dev/tty;
exit 1
fi
# Stopping tomcat server, if running
sh ./bin/catalina.sh stop
echo
# Checking if the code directory exists, creating it if necessary
if [ -d ./code ]
then
# \"code\" exists, no action
echo
else
echo \"code\" directory not found, creating it...
mkdir code
fi
# -- Changing working directory
cd code
pwd
# -- Check if the directory containing the git repository exists
if [ -d $REPO_NAME ]
then
# -- Directory exists, checking validity of git repository
cd $REPO_NAME
pwd
git status >/dev/null 2>&1
if [ $? -gt 0 ] # %ERRORLEVEL% NEQ 0 goto bad_repo
then #:bad_repo
# -- Error: damaged repo
echo >2&
echo --- >2&
echo [ERROR] Repository code\\$REPO_NAME seems to be damaged. >2&
echo Try deleting it and restart. >2&
echo --- >2&
echo >2&
echo "Press [Enter] to exit..."; sed -n q </dev/tty;
exit 1
fi
else
# -- Initialize the repository for the first time
git clone $REPO_URL $REPO_NAME
if [ $? -gt 0 ]
then #:clone_fail
# -- Error: Cloning failed.
echo >2&
echo --- >2&
echo [ERROR] Failed to clone repository. >2&
echo Are you online? Can you write to disk? >2&
echo --- >2&
echo >2&
echo "Press [Enter] to exit..."; sed -n q </dev/tty;
exit 1
fi
#:clone_good
cd $REPO_NAME
fi
# :good_repo
# -- Update the git repository to the latest version.
#pwd
git fetch --all
git checkout --force origin/master
git submodule sync
git submodule update --init --recursive
# -- Update the submodule (client files) to latest version
git submodule foreach git pull origin master
# :maven
# -- Apache Maven Build
#pwd
sh ../../$MVN_PATH/bin/mvn -e compile
# -- Apache Maven Generate Site
sh ../../$MVN_PATH/bin/mvn -e deploy
# -- Return to original path
cd ../..
pwd
# -- Overwriting Server site
cp -r -f "./code/$REPO_NAME/target/at.jku.ce/." "./webapps/ROOT"
if [ $? -gt 0 ]
then #:copy_fail
# -- Error: Copying files failed.
echo >2&
echo --- >2&
echo [ERROR] Failed to copy files to new location. >2&
echo Is the server still running? Are some files opened elsewhere? >2&
echo --- >2&
echo >2&
echo "Press [Enter] to exit..."; sed -n q </dev/tty;
exit 1
fi
echo
echo ---
echo Server files have successfully updated to latest version.
echo You can now restart Tomcat via 'catalina_start.sh'
echo ---
echo
echo "Press [Enter] to exit..."; sed -n q </dev/tty;
@echo off
setlocal ENABLEDELAYEDEXPANSION
::::::::::::::::::::::::::::::::::::
:: Set JAVA_HOME and ::
::::::::::::::::::::::::::::::::::::
IF EXIST tomcat\logs\catalina.pid (
del /F/Q tomcat\logs\catalina.pid
)
echo.
echo [XAMPP]: Searching JDK HOME with reg query ...
set KeyName=HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Development Kit
reg query "!KeyName!" /s
if !ERRORLEVEL! == 1 (
:: Workaround for new JDK versions
set KeyName=HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\JDK
reg query "!KeyName!" /s
if !ERRORLEVEL! == 1 (
echo . [XAMPP]: Cannot find current JDK installation!
echo . [XAMPP]: Cannot set JAVA_HOME. Aborting ...
goto :END
)
)
set "CURRENT_DIR=%cd%"
set "CATALINA_HOME=%CURRENT_DIR%"
:: only for windows 32 bit if you have problems with the tcnative-1.dll
:: set CATALINA_OPTS=-Djava.library.path="%CATALINA_HOME%\bin"
set Cmd=reg query "%KeyName%" /s
for /f "tokens=2*" %%i in ('%Cmd% ^| find "JavaHome"') do set JAVA_HOME=%%j
echo.
echo [XAMPP]: Seems fine!
echo [XAMPP]: Set JAVA_HOME : %JAVA_HOME%
echo [XAMPP]: Set CATALINA_HOME : %CATALINA_HOME%
echo.
if %ERRORLEVEL% == 0 (
echo run > logs\catalina.pid
)
"%CATALINA_HOME%\bin\catalina.bat" run
:END
echo done.
pause
#!/bin/sh
sh ./bin/catalina.sh start
[InternetShortcut]
URL=http://localhost:8080/
IDList=
HotKey=0
[{000214A0-0000-0000-C000-000000000046}]
Prop3=19,2
@echo off
setlocal ENABLEDELAYEDEXPANSION
::::::::::::::::::::::::::::::::::::
:: Set JAVA_HOME and ::
::::::::::::::::::::::::::::::::::::
echo.
echo [XAMPP]: Searching JDK HOME with reg query ...
set KeyName=HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Development Kit
reg query "!KeyName!" /s
if !ERRORLEVEL! == 1 (
:: Workaround for new JDK versions
set KeyName=HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\JDK
reg query "!KeyName!" /s
if !ERRORLEVEL! == 1 (
echo . [XAMPP]: Cannot find current JDK installation!
echo . [XAMPP]: Cannot set JAVA_HOME. Aborting ...
goto :END
)
)
set "CURRENT_DIR=%cd%"
set "CATALINA_HOME=%CURRENT_DIR%"
set Cmd=reg query "%KeyName%" /s
for /f "tokens=2*" %%i in ('%Cmd% ^| find "JavaHome"') do set JAVA_HOME=%%j
echo.
echo [XAMPP]: Seems fine!
echo [XAMPP]: Using JAVA_HOME : %JAVA_HOME%
echo [XAMPP]: Using CATALINA_HOME : %CATALINA_HOME%
echo.
if %ERRORLEVEL% == 0 {
del /F/Q logs\catalina.pid
}
"%CATALINA_HOME%\bin\catalina.bat" stop
:END
echo done.
pause
#!/bin/sh
sh ./bin/catalina.sh stop
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions: