#LyX 1.6.7 created this file. For more info see http://www.lyx.org/
\lyxformat 345
\begin_document
\begin_header
\textclass scrbook
\begin_preamble
\input{preamble.tex}
\end_preamble
\use_default_options false
\language english
\inputencoding utf8
\font_roman lmodern
\font_sans helvet
\font_typewriter courier
\font_default_family default
\font_sc false
\font_osf false
\font_sf_scale 100
\font_tt_scale 100
\graphics default
\float_placement H
\paperfontsize default
\spacing single
\use_hyperref true
\pdf_bookmarks true
\pdf_bookmarksnumbered false
\pdf_bookmarksopen false
\pdf_bookmarksopenlevel 1
\pdf_breaklinks false
\pdf_pdfborder false
\pdf_colorlinks false
\pdf_backref false
\pdf_pdfusetitle true
\papersize letterpaper
\use_geometry false
\use_amsmath 2
\use_esint 1
\cite_engine basic
\use_bibtopic false
\paperorientation portrait
\secnumdepth 3
\tocdepth 3
\paragraph_separation indent
\defskip medskip
\quotes_language english
\papercolumns 1
\papersides 1
\paperpagestyle default
\bullet 0 5 11 -1
\bullet 1 5 24 -1
\bullet 2 0 0 -1
\tracking_changes false
\output_changes false
\author ""
\author ""
\end_header
\begin_body
\begin_layout Standard
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
input{chapter.tex}
\end_layout
\end_inset
\end_layout
\begin_layout Chapter
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjasperreports{}
\end_layout
\end_inset
and
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appphp{}
\end_layout
\end_inset
-- Linux
\end_layout
\begin_layout Standard
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
epigraph{Simplicity is prerequisite for reliability.}{Edsger Wybe Dijkstra}
\end_layout
\end_inset
\end_layout
\begin_layout Standard
This chapter describes how to integrate
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjasperreports{}
\end_layout
\end_inset
with
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appphp{}
\end_layout
\end_inset
and the
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appapachehttpserver{}
\end_layout
\end_inset
.
\begin_inset CommandInset ref
LatexCommand ref
reference "fig:Integration-Unix-HTTP-PHP"
\end_inset
shows the major components involved in
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjasperreports{}
\end_layout
\end_inset
integration with
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appphp{}
\end_layout
\end_inset
in Linux.
\end_layout
\begin_layout Standard
\begin_inset Float figure
wide false
sideways false
status collapsed
\begin_layout Plain Layout
\begin_inset Graphics
filename drawings/integration-http-php.png
display false
\end_inset
\end_layout
\begin_layout Plain Layout
\begin_inset Caption
\begin_layout Plain Layout
\begin_inset CommandInset label
LatexCommand label
name "fig:Integration-Unix-HTTP-PHP"
\end_inset
Integration -
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appapachehttpserver{}
\end_layout
\end_inset
and
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appphp{}
\end_layout
\end_inset
(Linux)
\end_layout
\end_inset
\end_layout
\end_inset
\end_layout
\begin_layout Standard
The components are as follows:
\end_layout
\begin_layout Itemize
\series bold
Browser.
\series default
Any web browser.
\end_layout
\begin_layout Itemize
\series bold
Web Server.
\series default
Apache's web server software that responds to web page requests.
\end_layout
\begin_layout Itemize
\series bold
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
filename{
\backslash
filephpdemo}
\end_layout
\end_inset
.
\series default
A web page containing a form and a button.
The user clicks the button to retrieve the report.
\end_layout
\begin_layout Itemize
\series bold
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
filename{
\backslash
filephpreport}
\end_layout
\end_inset
.
\series default
A web page that runs a report and returns a PDF directly to the browser.
\end_layout
\begin_layout Itemize
\series bold
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appphpjavabridge{}
\end_layout
\end_inset
.
\series default
Provides
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appphp{}
\end_layout
\end_inset
with the ability to execute
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjava{}
\end_layout
\end_inset
code.
\end_layout
\begin_layout Itemize
\series bold
Java Classes.
\series default
Passes parameters to
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjasperreports{}
\end_layout
\end_inset
using the report API.
\end_layout
\begin_layout Itemize
\series bold
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjasperreports{}
\end_layout
\end_inset
.
\series default
The reporting engine used to query the database and generate a PDF.
\end_layout
\begin_layout Itemize
\series bold
Database.
\series default
Any database that has a JDBC driver.
\end_layout
\begin_layout Standard
The system works as follows:
\end_layout
\begin_layout Enumerate
The web browser sends a request to the web server (Apache) for
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
filename{
\backslash
filephpdemo}
\end_layout
\end_inset
.
\end_layout
\begin_layout Enumerate
The web server returns the HTML for
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
filename{
\backslash
filephpdemo}
\end_layout
\end_inset
, which includes a form with a button.
\end_layout
\begin_layout Enumerate
The user clicks the button.
\end_layout
\begin_layout Enumerate
The web server passes
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
filename{
\backslash
filephpreport}
\end_layout
\end_inset
to the
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appphp{}
\end_layout
\end_inset
interpreter.
\end_layout
\begin_layout Enumerate
The
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appphp{}
\end_layout
\end_inset
interpreter opens a connection to the
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appphpjavabridge{}
\end_layout
\end_inset
.
\end_layout
\begin_layout Enumerate
The
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appphpjavabridge{}
\end_layout
\end_inset
creates an instance of the
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjasperreports{}
\end_layout
\end_inset
engine.
\end_layout
\begin_layout Enumerate
The
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjasperreports{}
\end_layout
\end_inset
engine runs a report.
\end_layout
\begin_layout Enumerate
The
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appphpjavabridge{}
\end_layout
\end_inset
returns the results of running the report to the
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appphp{}
\end_layout
\end_inset
interpreter.
\end_layout
\begin_layout Enumerate
The
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appphp{}
\end_layout
\end_inset
interpreter sends the PDF directly to the web browser.
\end_layout
\begin_layout Enumerate
The web browser displays (or saves) the PDF.
\end_layout
\begin_layout Standard
Consider integrating
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjasperreports{}
\end_layout
\end_inset
with
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appphp{}
\end_layout
\end_inset
only if no other choices are possible.
Given a choice, use
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appapachetomcat{}
\end_layout
\end_inset
, instead;
\emph on
only
\emph default
\shape italic
\emph on
install the
\shape default
\emph default
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appphpjavabridge{}
\end_layout
\end_inset
\shape italic
\emph on
if
\shape default
\emph default
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appphp{}
\end_layout
\end_inset
\shape italic
\emph on
is an
\emph default
absolute requirement
\emph on
.
\end_layout
\begin_layout Standard
In this chapter:
\end_layout
\begin_layout Itemize
\series bold
Prerequisites.
\series default
Software packages required to complete the integration.
\end_layout
\begin_layout Itemize
\series bold
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjava{}
\end_layout
\end_inset
.
\series default
Describes issues with conflicting Java Virtual Machines.
\end_layout
\begin_layout Itemize
\series bold
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appapachehttpserver{}
\end_layout
\end_inset
.
\series default
Brief installation guide and validation.
\end_layout
\begin_layout Itemize
\series bold
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appphp{}
\end_layout
\end_inset
.
\series default
Installation guide with instructions specifically for the
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appapachehttpserver{}
\end_layout
\end_inset
.
\end_layout
\begin_layout Itemize
\series bold
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appireport{}
\end_layout
\end_inset
.
\series default
Describes the installation steps for
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appireport{}
\end_layout
\end_inset
.
\end_layout
\begin_layout Itemize
\series bold
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appphpjavabridge{}
\end_layout
\end_inset
.
\series default
Installation steps for the
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appphpjavabridge{}
\end_layout
\end_inset
.
\end_layout
\begin_layout Section
Prerequisites
\end_layout
\begin_layout Standard
The instructions in this chapter require:
\end_layout
\begin_layout Itemize
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
apppostgres{}
\end_layout
\end_inset
(installed and running).
\end_layout
\begin_layout Itemize
A Linux distribution.
\end_layout
\begin_layout Standard
\begin_inset CommandInset include
LatexCommand input
filename "include/install_java.lyx"
\end_inset
\end_layout
\begin_layout Section
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appapachehttpserver{}
\end_layout
\end_inset
\end_layout
\begin_layout Standard
This section describes how to create a minimal
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appapachehttpserver{}
\end_layout
\end_inset
installation.
\end_layout
\begin_layout Subsection
Uninstallation
\end_layout
\begin_layout Standard
Uninstalling is optional; to remove an existing installation:
\end_layout
\begin_layout Enumerate
Type:
\end_layout
\begin_deeper
\begin_layout LyX-Code
sudo apache2ctl stop
\end_layout
\begin_layout LyX-Code
sudo aptitude remove --purge apache2 apache2-utils
\end_layout
\end_deeper
\begin_layout Enumerate
Type your password when prompted.
\end_layout
\begin_layout Enumerate
Type
\family typewriter
Y
\family default
when prompted.
\end_layout
\begin_layout Enumerate
Type
\family typewriter
Y
\family default
if prompted again.
\end_layout
\begin_layout Standard
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appapachehttpserver{}
\end_layout
\end_inset
is uninstalled.
\end_layout
\begin_layout Subsection
Validation
\end_layout
\begin_layout Standard
Verify that the
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appapachehttpserver{}
\end_layout
\end_inset
is no longer installed, type:
\end_layout
\begin_layout LyX-Code
/etc/init.d/apache2 status
\end_layout
\begin_layout Standard
The following text (or any other error message) is displayed:
\end_layout
\begin_layout Standard
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
begin{displayed}
\end_layout
\end_inset
No apache MPM package installed
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
end{displayed}
\end_layout
\end_inset
\end_layout
\begin_layout Subsection
Installation
\end_layout
\begin_layout Standard
Many Linux distributions have the
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appapachehttpserver{}
\end_layout
\end_inset
already installed.
If you have uninstalled a pre-existing version, install a new version of
the
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appapachehttpserver{}
\end_layout
\end_inset
as follows:
\end_layout
\begin_layout Enumerate
Type:
\end_layout
\begin_deeper
\begin_layout LyX-Code
sudo aptitude install apache2 apache2-utils
\end_layout
\end_deeper
\begin_layout Enumerate
Type
\family typewriter
Y
\family default
when prompted.
\end_layout
\begin_layout Enumerate
Browse to
\begin_inset CommandInset href
LatexCommand href
target "http://localhost/"
\end_inset
.
\end_layout
\begin_layout Standard
The following text appears:
\end_layout
\begin_layout Standard
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
begin{displayed}
\end_layout
\end_inset
It works!
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
end{displayed}
\end_layout
\end_inset
\end_layout
\begin_layout Section
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appphp{}
\end_layout
\end_inset
\end_layout
\begin_layout Standard
This section describes how to install and configure
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appphp{}
\end_layout
\end_inset
\lang english
for the
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appapachehttpserver{}
\end_layout
\end_inset
.
The installation described in this section also installs
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
apppostgres{}
\end_layout
\end_inset
database functions for
\begin_inset ERT
status open
\begin_layout Plain Layout
\backslash
appphp{}
\end_layout
\end_inset
\lang english
.
\end_layout
\begin_layout Subsection
Uninstallation
\end_layout
\begin_layout Standard
Uninstalling is optional; to remove an existing installation:
\end_layout
\begin_layout Enumerate
Type:
\end_layout
\begin_deeper
\begin_layout LyX-Code
sudo aptitude remove php5 php5-cli php5-pgsql
\end_layout
\end_deeper
\begin_layout Enumerate
Type
\family typewriter
Y
\family default
when prompted.
\end_layout
\begin_layout Standard
\begin_inset ERT
status open
\begin_layout Plain Layout
\backslash
appphp{}
\end_layout
\end_inset
\lang english
is uninstalled.
To verify that
\begin_inset ERT
status open
\begin_layout Plain Layout
\backslash
appphp{}
\end_layout
\end_inset
\lang english
is no longer installed, type:
\end_layout
\begin_layout LyX-Code
php
\end_layout
\begin_layout Standard
The following text (or similar error message) is displayed:
\end_layout
\begin_layout Standard
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
begin{displayed}
\end_layout
\end_inset
bash: /usr/bin/php: No such file or directory
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
end{displayed}
\end_layout
\end_inset
\end_layout
\begin_layout Subsection
Installation
\end_layout
\begin_layout Standard
Install
\begin_inset ERT
status open
\begin_layout Plain Layout
\backslash
appphp{}
\end_layout
\end_inset
\lang english
for the
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appapachehttpserver{}
\end_layout
\end_inset
as follows:
\end_layout
\begin_layout Enumerate
Type:
\end_layout
\begin_deeper
\begin_layout LyX-Code
\size small
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
vskip-1.2em
\end_layout
\end_inset
\size footnotesize
sudo aptitude install php5 php5-cli php5-pgsql libapache2-mod-php5
\end_layout
\end_deeper
\begin_layout Enumerate
Type
\family typewriter
Y
\family default
when prompted.
\end_layout
\begin_layout Enumerate
Type
\family typewriter
Y
\family default
if prompted again.
\end_layout
\begin_layout Enumerate
Type the following to enable the
\begin_inset ERT
status open
\begin_layout Plain Layout
\backslash
appphp{}
\end_layout
\end_inset
\lang english
module:
\end_layout
\begin_deeper
\begin_layout LyX-Code
sudo a2enmod php5
\end_layout
\end_deeper
\begin_layout Enumerate
Restart Apache:
\end_layout
\begin_deeper
\begin_layout LyX-Code
sudo /etc/init.d/apache2 restart
\end_layout
\end_deeper
\begin_layout Standard
\begin_inset ERT
status open
\begin_layout Plain Layout
\backslash
appphp{}
\end_layout
\end_inset
\lang english
is installed.
\end_layout
\begin_layout Subsection
Configuration
\end_layout
\begin_layout Standard
For the purposes of these configuration instructions, substitute your account
name for
\series bold
username
\series default
.
For example, if you login to your computer using your last name, then wherever
you see the word
\series bold
username
\series default
, replace it with your last name.
\end_layout
\begin_layout Standard
To simplify your web development environment, configure the
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appapachehttpserver{}
\end_layout
\end_inset
as follows:
\end_layout
\begin_layout Enumerate
Login as
\series bold
username
\series default
.
\end_layout
\begin_layout Enumerate
Open a terminal.
\end_layout
\begin_layout Enumerate
Create a directory for HTML files:
\end_layout
\begin_deeper
\begin_layout LyX-Code
mkdir
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
unixdirhttpdocs{}
\end_layout
\end_inset
\end_layout
\end_deeper
\begin_layout Enumerate
As root, edit
\family typewriter
/etc/apache2/sites-available/default
\family default
.
\end_layout
\begin_layout Enumerate
Change
\family typewriter
DocumentRoot /var/www/
\family default
to:
\end_layout
\begin_deeper
\begin_layout LyX-Code
DocumentRoot /home/
\series bold
username
\series default
/htdocs/
\end_layout
\end_deeper
\begin_layout Enumerate
Change
\family typewriter
<Directory /var/www/>
\family default
to:
\end_layout
\begin_deeper
\begin_layout LyX-Code
<Directory /home/
\series bold
username
\series default
/htdocs/>
\end_layout
\end_deeper
\begin_layout Enumerate
Save the file.
\end_layout
\begin_layout Enumerate
Restart the
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appapachehttpserver{}
\end_layout
\end_inset
:
\end_layout
\begin_deeper
\begin_layout LyX-Code
sudo /etc/init.d/apache2 restart
\end_layout
\end_deeper
\begin_layout Standard
The
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appapachehttpserver{}
\end_layout
\end_inset
is configured.
Save web-related files inside
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
unixdirhttpdocs{}
\end_layout
\end_inset
.
\end_layout
\begin_layout Subsection
Validation
\end_layout
\begin_layout Standard
Verify that
\begin_inset ERT
status open
\begin_layout Plain Layout
\backslash
appphp{}
\end_layout
\end_inset
\lang english
can be called from the
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appapachehttpserver{}
\end_layout
\end_inset
:
\end_layout
\begin_layout Enumerate
Edit
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
unixdirhttpdocs{}
\backslash
filename{
\backslash
filephpdemo}
\end_layout
\end_inset
.
\end_layout
\begin_layout Enumerate
Change the contents of
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
unixdirhttpdocs{}
\backslash
filename{
\backslash
filephpdemo}
\end_layout
\end_inset
to
\begin_inset CommandInset ref
LatexCommand ref
reference "alg:PHP-Test-Unix"
\end_inset
.
\end_layout
\begin_deeper
\begin_layout Standard
\begin_inset Float algorithm
wide false
sideways false
status collapsed
\begin_layout Plain Layout
\begin_inset Graphics
filename source/php/index-test.php.png
display false
\end_inset
\end_layout
\begin_layout Plain Layout
\begin_inset Caption
\begin_layout Plain Layout
\begin_inset CommandInset label
LatexCommand label
name "alg:PHP-Test-Unix"
\end_inset
\begin_inset ERT
status open
\begin_layout Plain Layout
\backslash
appphp{}
\end_layout
\end_inset
\lang english
Test
\end_layout
\end_inset
\end_layout
\end_inset
\end_layout
\end_deeper
\begin_layout Enumerate
Browse to
\begin_inset CommandInset href
LatexCommand href
target "http://localhost/index.php"
\end_inset
.
\end_layout
\begin_layout Standard
The following text appears:
\end_layout
\begin_layout Standard
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
begin{displayed}
\end_layout
\end_inset
PHP works!
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
end{displayed}
\end_layout
\end_inset
\end_layout
\begin_layout Standard
If the text does not appear as shown, view the contents of Apache's error
log (see
\begin_inset CommandInset ref
LatexCommand ref
reference "tab:Unix-Applications-Logs"
\end_inset
), correct the errors, and try again.
\end_layout
\begin_layout Standard
Note: If the web browser prompts you to save the
\begin_inset ERT
status open
\begin_layout Plain Layout
\backslash
appphp{}
\end_layout
\end_inset
\lang english
file, rather than execute the
\begin_inset ERT
status open
\begin_layout Plain Layout
\backslash
appphp{}
\end_layout
\end_inset
\lang english
script on the server, then complete the following instructions:
\end_layout
\begin_layout Enumerate
Clear the web browser's cache.
\end_layout
\begin_layout Enumerate
Re-load the web page.
\end_layout
\begin_layout Standard
\begin_inset CommandInset include
LatexCommand input
filename "include/install_ireport.lyx"
\end_inset
\end_layout
\begin_layout Section
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appphpjavabridge{}
\end_layout
\end_inset
\end_layout
\begin_layout Standard
This section describes how to install and configure the
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appphpjavabridge{}
\end_layout
\end_inset
.
Before installation can proceed, download the files for the
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appphpjavabridge{}
\end_layout
\end_inset
that are listed in
\begin_inset CommandInset ref
LatexCommand vref
reference "tab:Unix-Applications-Versions"
\end_inset
.
\end_layout
\begin_layout Subsection
Installation
\end_layout
\begin_layout Standard
Install the
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appphpjavabridge{}
\end_layout
\end_inset
as follows:
\end_layout
\begin_layout Enumerate
Create the directory:
\end_layout
\begin_deeper
\begin_layout LyX-Code
mkdir -p
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
unixdirhttpdocs{}
\end_layout
\end_inset
java/
\end_layout
\end_deeper
\begin_layout Enumerate
Copy
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
filename{
\backslash
fileincjava}
\end_layout
\end_inset
(see
\begin_inset CommandInset ref
LatexCommand vref
reference "tab:Unix-Applications-Versions"
\end_inset
) into
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
unixdirhttpdocs{}
\end_layout
\end_inset
\family typewriter
java/
\family default
.
\end_layout
\begin_layout Enumerate
Create the installation directory:
\end_layout
\begin_deeper
\begin_layout LyX-Code
mkdir -p
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
unixdirprogbridge{}
\end_layout
\end_inset
\end_layout
\end_deeper
\begin_layout Enumerate
Copy the following files into
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
unixdirprogbridge{}
\end_layout
\end_inset
:
\end_layout
\begin_deeper
\begin_layout Itemize
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
filename{
\backslash
filejarbridge}
\end_layout
\end_inset
(see
\begin_inset CommandInset ref
LatexCommand vref
reference "tab:Unix-Applications-Versions"
\end_inset
)
\end_layout
\begin_layout Itemize
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
filename{
\backslash
fileshellbridge}
\end_layout
\end_inset
(see
\begin_inset CommandInset ref
LatexCommand vref
reference "sub:fileshellbridge"
\end_inset
)
\end_layout
\end_deeper
\begin_layout Enumerate
Make the script executable:
\end_layout
\begin_deeper
\begin_layout LyX-Code
chmod +x
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
unixdirprogbridge
\backslash
filename{
\backslash
fileshellbridge}
\end_layout
\end_inset
\end_layout
\end_deeper
\begin_layout Standard
The
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appphpjavabridge{}
\end_layout
\end_inset
is installed.
\end_layout
\begin_layout Standard
Note: If you change
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appireport{}
\end_layout
\end_inset
's installation directory (from
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
unixdirprogireport{}
\end_layout
\end_inset
to anything else), you must update
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
filename{
\backslash
fileshellbridge}
\end_layout
\end_inset
accordingly.
\end_layout
\begin_layout Subsection
Execution
\end_layout
\begin_layout Standard
To run the
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appphpjavabridge{}
\end_layout
\end_inset
:
\end_layout
\begin_layout Enumerate
Open a new terminal window.
\end_layout
\begin_layout Enumerate
Type:
\end_layout
\begin_deeper
\begin_layout LyX-Code
cd
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
unixdirprogbridge{}
\end_layout
\end_inset
\end_layout
\begin_layout LyX-Code
./
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
filename{
\backslash
fileshellbridge}
\end_layout
\end_inset
\end_layout
\end_deeper
\begin_layout Standard
The
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appphpjavabridge{}
\end_layout
\end_inset
is waiting for requests on port 8080.
\end_layout
\begin_layout Standard
If port 8080 is unavailable, change the port number as follows:
\end_layout
\begin_layout Enumerate
Edit
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
unixdirprogbridge{}
\end_layout
\end_inset
.
\end_layout
\begin_layout Enumerate
Replace
\family typewriter
8080
\family default
with an available port number.
\end_layout
\begin_layout Enumerate
Edit
\family typewriter
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
unixdirhttpdocs{}
\end_layout
\end_inset
java/
\family default
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
filename{
\backslash
fileincjava}
\end_layout
\end_inset
.
\end_layout
\begin_layout Enumerate
Replace all occurrences of
\family typewriter
8080
\family default
with the available port number from step 2.
\end_layout
\begin_layout Standard
The
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appphpjavabridge{}
\end_layout
\end_inset
is waiting for requests on the new port.
\end_layout
\begin_layout Subsection
Validation
\end_layout
\begin_layout Enumerate
Edit
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
unixdirhttpdocs
\backslash
filename{
\backslash
filephpdemo}
\end_layout
\end_inset
.
\end_layout
\begin_layout Enumerate
Change the contents to reflect
\begin_inset CommandInset ref
LatexCommand ref
reference "alg:Java-and-PHP-Unix"
\end_inset
(see
\begin_inset CommandInset ref
LatexCommand vref
reference "sub:\\filephpdemo"
\end_inset
).
\end_layout
\begin_deeper
\begin_layout Standard
\begin_inset Float algorithm
wide false
sideways false
status collapsed
\begin_layout Plain Layout
\begin_inset Graphics
filename source/php/index.php.png
display false
\end_inset
\begin_inset Caption
\begin_layout Plain Layout
\begin_inset CommandInset label
LatexCommand label
name "alg:Java-and-PHP-Unix"
\end_inset
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjava{}
\end_layout
\end_inset
and
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appphp{}
\end_layout
\end_inset
\end_layout
\end_inset
\end_layout
\end_inset
\end_layout
\end_deeper
\begin_layout Enumerate
Browse to the following location:
\end_layout
\begin_deeper
\begin_layout Standard
\begin_inset CommandInset href
LatexCommand href
target "http://localhost/index.php"
\end_inset
\end_layout
\end_deeper
\begin_layout Standard
The current date and time appear, showing that Java was called successfully
from
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appphp{}
\end_layout
\end_inset
:
\end_layout
\begin_layout Standard
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
begin{displayed}
\end_layout
\end_inset
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
shortdayofweekname{
\backslash
day}{
\backslash
month}{
\backslash
year}
\backslash
shortmonthname{}
\backslash
twodigit{
\backslash
day}
\backslash
currenttime{}:05 EST
\backslash
number
\backslash
year{}
\end_layout
\end_inset
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
end{displayed}
\end_layout
\end_inset
\end_layout
\begin_layout Standard
If the date and time does not appear, view Apache's error logs to diagnose
the problem.
\end_layout
\begin_layout Subsection
Logging
\end_layout
\begin_layout Standard
To enable logging of
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appphpjavabridge{}
\end_layout
\end_inset
messages:
\end_layout
\begin_layout Enumerate
Edit
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
filename{
\backslash
fileshellbridge}
\end_layout
\end_inset
.
\end_layout
\begin_layout Enumerate
Change
\family typewriter
/dev/null
\family default
to:
\end_layout
\begin_deeper
\begin_layout LyX-Code
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
filename{
\backslash
filelogbridge}
\end_layout
\end_inset
\end_layout
\end_deeper
\begin_layout Enumerate
Save the file.
\end_layout
\begin_layout Standard
Log messages are written to
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
unixdirprogbridge
\backslash
filename{
\backslash
filelogbridge}
\end_layout
\end_inset
.
\end_layout
\begin_layout Section
Integration
\end_layout
\begin_layout Standard
The source code included with this manual contains
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appphp{}
\end_layout
\end_inset
files that demonstrate a fairly generic integration with
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjasperreports{}
\end_layout
\end_inset
:
\end_layout
\begin_layout Itemize
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
filename{
\backslash
filephpconstants}
\end_layout
\end_inset
- Defines constants for the server name, database name, user name, password,
JDBC driver, report directory path, and report file name extension.
By default the connection attempts to connect to the postgres database
running on localhost using the
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
apppostgres{}
\end_layout
\end_inset
JDBC driver.
For details, see
\begin_inset CommandInset ref
LatexCommand vref
reference "sub:\\filephpconstants"
\end_inset
.
\end_layout
\begin_layout Itemize
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
filename{
\backslash
filephpjasper}
\end_layout
\end_inset
- Implements a function that generates a PDF file and writes the contents
directly to the web browser that made the HTTP request.
For details, see
\begin_inset CommandInset ref
LatexCommand vref
reference "sub:\\filephpjasper"
\end_inset
.
\end_layout
\begin_layout Itemize
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
filename{
\backslash
filephpparameters}
\end_layout
\end_inset
- Defines functions that parse HTTP POST request parameters into
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjava{}
\end_layout
\end_inset
variables.
The HTTP POST request parameter names are mapped to the
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjava{}
\end_layout
\end_inset
variables and stored in a
\family typewriter
HashMap
\family default
.
The
\family typewriter
HashMap
\family default
is passed into
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjasperreports{}
\end_layout
\end_inset
, as shown in
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
filename{
\backslash
filephpjasper}
\end_layout
\end_inset
.
For details, see
\begin_inset CommandInset ref
LatexCommand vref
reference "sub:\\filephpparameters"
\end_inset
.
\end_layout
\begin_layout Itemize
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
filename{
\backslash
filephpcity}
\end_layout
\end_inset
- Shows how to execute a report using the integration files.
For details, see
\begin_inset CommandInset ref
LatexCommand vref
reference "sub:\\filephpcity"
\end_inset
.
\end_layout
\begin_layout Standard
There are a few items in
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
filename{
\backslash
filephpjasper}
\end_layout
\end_inset
that are worth noting:
\end_layout
\begin_layout Itemize
\series bold
Parameters.
\series default
By default, parameters are not parsed.
Enable parameter parsing as follows:
\end_layout
\begin_deeper
\begin_layout Enumerate
Edit
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
filename{
\backslash
filephpjasper}
\end_layout
\end_inset
.
\end_layout
\begin_layout Enumerate
Find and remove the hash marks (
\family typewriter
#
\family default
) from the following lines:
\end_layout
\begin_deeper
\begin_layout LyX-Code
\family typewriter
#include_once
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
textquotesingle{}
\end_layout
\end_inset
params.php
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
textquotesingle{}
\end_layout
\end_inset
;
\end_layout
\begin_layout LyX-Code
#$params = report_parse_parameters();
\end_layout
\end_deeper
\end_deeper
\begin_layout Itemize
\series bold
Unicode.
\series default
As
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appphp{}
\end_layout
\end_inset
does not support Unicode, the following line is mandatory to successfully
convert strings to byte arrays:
\end_layout
\begin_deeper
\begin_layout LyX-Code
java_set_file_encoding(
\family typewriter
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
textquotesingle{}
\end_layout
\end_inset
\family default
ISO-8859-1
\family typewriter
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
textquotesingle{}
\end_layout
\end_inset
\family default
);
\end_layout
\end_deeper
\begin_layout Section
Generate PDF
\end_layout
\begin_layout Standard
To generate a PDF file using this integration:
\end_layout
\begin_layout Enumerate
Copy the following files to
\family typewriter
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
unixdirhttpdocs{}
\end_layout
\end_inset
:
\end_layout
\begin_deeper
\begin_layout Itemize
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
filename{
\backslash
filephpconstants}
\end_layout
\end_inset
\end_layout
\begin_layout Itemize
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
filename{
\backslash
filephpjasper}
\end_layout
\end_inset
\end_layout
\begin_layout Itemize
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
filename{
\backslash
filephpparameters}
\end_layout
\end_inset
\end_layout
\begin_layout Itemize
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
filename{
\backslash
filephpcity}
\end_layout
\end_inset
\end_layout
\end_deeper
\begin_layout Enumerate
Copy
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
filename{
\backslash
filejaspercity}
\end_layout
\end_inset
to
\family typewriter
/reports/
\family default
.
\end_layout
\begin_layout Enumerate
Edit
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
filename{
\backslash
filephpconstants}
\end_layout
\end_inset
.
\end_layout
\begin_layout Enumerate
Set the constant values according to your environment.
\end_layout
\begin_layout Enumerate
Browse to
\begin_inset CommandInset href
LatexCommand href
target "http://localhost/city.php"
\end_inset
.
\end_layout
\begin_layout Standard
The city report is displayed as a PDF file.
If the report is not displayed, check the error logs (see
\begin_inset CommandInset ref
LatexCommand vref
reference "tab:Unix-Applications-Logs"
\end_inset
), resolve all the errors, and try again.
\end_layout
\begin_layout Section
Summary
\end_layout
\begin_layout Standard
Richard Feyman was the greatest physicist of his day; his role in nuclear
physics changed the world.
At the time of writing, a number of blogs, web pages, and technical manuals
exist that describe various
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjasperreports{}
\end_layout
\end_inset
integrations---many of them outdated or technically incorrect.
This part of the manual aims to provide succinct, yet technically accurate
installation instructions to fuse
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjasperreports{}
\end_layout
\end_inset
with select web-based environments.
\end_layout
\begin_layout Standard
Regarding Dijkstra's reliability quote, Unix systems are architecturally
simple (for example, where Windows systems have an internal
\family typewriter
DIR
\family default
command, Unix systems have an
\family typewriter
ls
\family default
executable to get a directory listing).
The advantage to the Windows method is that the
\family typewriter
DIR
\family default
command is always available.
The advantage to the Unix method is that the
\family typewriter
ls
\family default
command can be updated without affecting any other part of the system.
One way is modular; the other is tightly coupled.
Updating the
\family typewriter
ls
\family default
command cannot affect other commands, thereby providing a more reliable
system.
\end_layout
\begin_layout Standard
Integrating
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appphp{}
\end_layout
\end_inset
with
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjasperreports{}
\end_layout
\end_inset
is possible, but is more complex than integrating
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjasperreports{}
\end_layout
\end_inset
with a
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjava{}
\end_layout
\end_inset
-based web framework (such as
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appservlet{}
\end_layout
\end_inset
or
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjsp{}
\end_layout
\end_inset
s).
This complexity makes the integration less reliable because there are more
components that can fail.
The
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appphpjavabridge{}
\end_layout
\end_inset
might run out of memory,
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appphp{}
\end_layout
\end_inset
might inadvertantly expose a security flaw, the solution requires an extra
file descriptor (which are finite in supply), and so on.
A pure
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjava{}
\end_layout
\end_inset
solution eliminates these issues and is therefore a more reliable architecture.
\end_layout
\end_body
\end_document