Upgrade APEX 4.1.1 to 4.2.1 on Oracle Linux with GlassFish

Environment: Oracle Linux 6.3, Oracle database 11.2.0.3.0 EE, APEX 4.1.1.00.23, GlassFish 3.1.2.2

This blog post explains how you can upgrade your Application Express installation from version 4.1.1 to version 4.2.1, with the APEX Listener deployed under GlassFish.

Steps:

1) download the software

You can download APEX 4.2.1 here. I downloaded the “all languages” zip file. Please note that the documentation is no longer included with the software. You can download the documentation separately here.

2) copy and extract the software

Now copy and extract the apex_4.2.1.zip file to your server. I use “unzip” to unzip the zip file. This will create a folder named “apex”. I usually keep this folder on my server in a permanent location, for example /u01/app/apex.

3) check the tablespace requirements

You need about 275MB of free space in the APEX tablespace (mine is called “APEX”) and 100MB of free space in the SYSTEM tablespace.

4) stop the APEX Listener

Before you start with the upgrade, you need to stop the APEX Listener to make sure no one is using the software during the upgrade.

To stop the APEX Listener under GlassFish, you can do it as follows:

– connect to the GlassFish administration console (by default this is port 4848 using SSL).

– log in with the “admin” user.

– click on Standalone Instances => Applications.

– select the “apex” application and select “Disable” from the “More Actions” drop down list.

The APEX Listener should now be stopped on your GlassFish instance.

5) start the upgrade

To upgrade the APEX software, you need to run the “apexins.sql” sql script from within the “apex” folder that you extracted above. You need to connect as SYS as SYSDBA with the oracle software owner (mine is called “oracle”). Make sure the “apex” folder is writeable!

apexins.sql needs 4 parameters: the name of the tablespace for the APEX user (in my case: APEX), the name of the tablespace for the FLOWS_FILES user (in my case: APEX), the name of the TEMP tablespace (in my case: TEMP) and the name of the virtual image directory (which is “/i/”).

$ su - oracle
$ cd /u01/app/apex
$ sqlplus /nolog
SQL*Plus: Release 11.2.0.3.0 Production on Thu Jan 3 11:21:39 2013

Copyright (c) 1982, 2011, Oracle. All rights reserved.

SQL> connect / as sysdba
Connected.
SQL> @apexins.sql APEX APEX TEMP /i/

The upgrade will now start. This will create a new schema called “APEX_040200”. The upgrade can take some time, depending on the speed of your server. On my server (with fairly recent hardware), it took about 17 minutes. After the upgrade, check the installation log file (in the same folder where you exectuted the apexins.sql file) to make sure no errors were encountered during the process.

6) verify the installation

I always verify my APEX installation after a upgrade by querying dba_registry:

$ sqlplus /nolog

SQL*Plus: Release 11.2.0.3.0 Production on Thu Jan 3 12:06:21 2013

Copyright (c) 1982, 2011, Oracle.  All rights reserved.

SQL> conn / as sysdba
Connected.
SQL> select status from dba_registry where comp_id='APEX';

STATUS
-------------------------------------------------------
VALID

7) copy the images

Next, copy the new and updated images from your installation folder to the GlassFish docroot (you might take a backup folder of the original docroot/i folder just in case):

$ cp -rf /u01/app/apex/images/* /u01/app/glassfish/glassfish/nodes/localhost-domain1/node01/docroot/i/

8) start the APEX Listener

Finally, start the APEX Listener again (see under step 4) and check if all your applications work fine :-) You should now have a nicely upgraded APEX 4.2.1.00.08 installation!

HTH,

Matthias

 

Update:

If you are accessing network services from withing APEX, like LDAP authentication, print servers and such, you will need to grant the new APEX_040200 user network access or it won’t work. This is documented in the installation guide and is only needed for Oracle 11g. You can grant network access by running the following PL/SQL script with user SYS as SYSDBA:

DECLARE
ACL_PATH VARCHAR2(4000);
BEGIN
-- Look for the ACL currently assigned to '*' and give APEX_040200
-- the "connect" privilege if APEX_040200 does not have the privilege yet.
SELECT ACL INTO ACL_PATH FROM DBA_NETWORK_ACLS
WHERE HOST = '*' AND LOWER_PORT IS NULL AND UPPER_PORT IS NULL;
IF DBMS_NETWORK_ACL_ADMIN.CHECK_PRIVILEGE(ACL_PATH, 'APEX_040200',
'connect') IS NULL THEN
DBMS_NETWORK_ACL_ADMIN.ADD_PRIVILEGE(ACL_PATH,
'APEX_040200', TRUE, 'connect');
END IF;
EXCEPTION
-- When no ACL has been assigned to '*'.
WHEN NO_DATA_FOUND THEN
DBMS_NETWORK_ACL_ADMIN.CREATE_ACL('power_users.xml',
'ACL that lets power users to connect to everywhere',
'APEX_040200', TRUE, 'connect');
DBMS_NETWORK_ACL_ADMIN.ASSIGN_ACL('power_users.xml','*');
END;
/
COMMIT;
Advertisements

How to modify the version of Java used for GlassFish 3.1.2.2

Environment: GlassFish 3.1.2.2 OSE Web Profile, Oracle Linux 6.3, Java 7 Update 7.

Whenever you upgrade your Java installation or install a new version, you have to make sure that your GlassFish installation is using the new version.

1) Download and install the new Java JDK 

New versions of Java can be found here. For GlassFish, you need to download the JDK (so not JRE), and you can use both Java 6 or Java 7.

For example, I downloaded and installed JDK 7 Update 7 to /u01/app/jdk1.7.0_07 and I created a symbolic link “java7” to it:

$ /u01/app/java>tar -zxf jdk-7u7-linux-x64.tar.gz
$ /u01/app/java>ln -sf jdk1.7.0_07 java7
$ /u01/app/java>ls -la
total 93904
drwxr-xr-x   4 oracle oinstall     4096 Sep 10 15:16 .
drwxr-xr-x   7 oracle oinstall     4096 Feb 17  2012 ..
lrwxrwxrwx   1 oracle oinstall       11 Feb  7  2012 java6 -> jdk1.6.0_30
lrwxrwxrwx   1 oracle oinstall       11 Sep 10 15:16 java7 -> jdk1.7.0_07
drwxr-xr-x  10 oracle oinstall     4096 Feb  3  2012 jdk1.6.0_30
drwxr-xr-x   8 oracle oinstall     4096 Aug 29 03:12 jdk1.7.0_07

2) Modify the GlassFish domain config file and JAVA_HOME environment variable

Next, you need to modify the AS_JAVA  variable in the GlassFish config file “asenv.conf”. In my case, this file was stored in the folder /u01/app/glassfish/glassfish/config. I changed it as follows:

AS_JAVA=/u01/app/java/java7

You also need to modify the environment variable JAVA_HOME. This variable can be found in the .bash_profile file of the user which is used to start GlassFish. Run “echo $JAVA_HOME” to see its current value. After the changes, log out and log in again (or run .bash_profile) to reset it.

3) Restart the GlassFish domain server

Restart the GlassFish domain server and any other server instances you might have.

/u01/app/glassfish/bin/asadmin stop-local-instance
/u01/app/glassfish/bin/asadmin stop-domain domain1

/u01/app/glassfish/bin/asadmin start-domain domain1
/u01/app/glassfish/bin/asadmin start-local-instance

 

HTH,

Matthias

 

 

Monitoring JVM memory performance of GlassFish 3.1.2

Environment: GlassFish OSE 3.1.2.2, Oracle Linux 6.3

In this blog post I will explain how you can enable and monitor the memory statistics of the Java Virtual Machine in GlassFish 3.1.2.

1) Enable monitoring for the JVM module

There are 2 ways to enable JVM monitoring: by using the graphical admin console, or from the command line by running the asadmin command.

From the graphical admin console

Start up the admin console (by default this runs on port 4848), log in as admin and click on “Monitoring Data” in the left menu. Now click on “Configure Monitoring” in the right menu for the instance you want to monitor. You should now see the screen with the list of configurable components (see screenshot below). Set the Monitoring Level of the JVM component to “Low” and click on Save. No instance restart is needed for this change.

From the command line

Start up the asadmin command (under the ../glassfish/bin folder). Use the subcommand “enable-monitoring” or “disable-monitoring” to enable/disable monitoring for a specific component. To specify the instance that you want to configure, add the “–target” option.

asadmin> enable-monitoring --modules jvm=LOW --target myinstance
Command enable-monitoring executed successfully.

2) View JVM memory statistics

From the graphical admin console

Click on “Monitoring Data” in the left menu and then on “Server” (under “View Monitoring Data”) in the right menu. You should now see the Server Monitoring screen (see screenshot below). To view the JVM memory statistics, click on the blue arrow next to “JVM: Memory Statistics”.

From the command line

Start up the asadmin command. Use the “get –monitor” subcommand to retrieve the required monitoring statistics.

asadmin> get --monitor myinstance.jvm.memory.usedheapsize.*
myinstance:
myinstance.jvm.memory.dotted-name = myinstance.jvm.memory
myinstance.jvm.memory.usedheapsize-count-count = 119150920
myinstance.jvm.memory.usedheapsize-count-description = Amount of used memory in bytes
myinstance.jvm.memory.usedheapsize-count-lastsampletime = 1346166888774
myinstance.jvm.memory.usedheapsize-count-name = UsedHeapSize
myinstance.jvm.memory.usedheapsize-count-starttime = 1346144878093
myinstance.jvm.memory.usedheapsize-count-unit = bytes

Command get executed successfully.

3) Schedule monitoring

To schedule the monitoring of memory statistics, you could easily add a command line entry to your crontab file. The following example will execute every 10 minutes and write the datetime and the usedheapsize to a log file.

>crontab -l
*/10 * * * * echo `date`>>/tmp/glassfish_memory.log;/u01/app/glassfish/bin/asadmin get --monitor myinstance.jvm.memory.usedheapsize-count-count>>/tmp/glassfish_memory.log

HTH,
Matthias

Upgrading APEX Listener from 1.1.3 to 1.1.4 on GlassFish 3.1.2.2

Environment: APEX Listener 1.1.4, GlassFish 3.1.2.2 OSE Web Profile, Oracle Linux 6.2 64-bit

In this post I will explain how you can upgrade the APEX Listener from version 1.1.3 to version 1.1.4 deployed under GlassFish.

Note: unless you are running a GlassFish cluster, there is no way to upgrade the APEX Listener without interruptions. However, if you plan things well, you can minimize downtime to only a few minutes.

Step 1: download and unzip the new software

Version 1.1.4 of the APEX Listener can be downloaded here. There are no separate 32-bit/64-bit versions or different versions for Windows/Linux. Put the zip file somewhere on the file system of your server and unzip it. Inside the zip file you will find the documentation files and the apex.war file, which contains the source code.

Step 2: modify the web.xml file inside apex.war

Before deploying the new APEX Listener, we will first modify the location of the config file inside the apex.war file. By default, the config file is stored in /tmp, but since this is a temporary file system, you might lose this file after a server reboot and APEX will stop working.

To modify the location of the config file, we need to extract the apex.war file, modify the web.xml file and finally recreate the apex.war file.

First, extract the apex.war file into a new folder by using the Java “jar” utility:

oracle@ol6ora11g02 /u01/app/apex_listener/1.1.4/modified>/u01/app/java/java6/bin/jar xf ../apex.war
oracle@ol6ora11g02 /u01/app/apex_listener/1.1.4/modified>ls -la
total 32
drwxr-xr-x 8 oracle oinstall 4096 Aug 20 14:45 .
drwxr-xr-x 5 oracle oinstall 4096 Aug 20 14:44 ..
drwxr-xr-x 2 oracle oinstall 4096 Jun 15 22:04 api
drwxr-xr-x 2 oracle oinstall 4096 Jul 13 00:14 ____embedded
drwxr-xr-x 2 oracle oinstall 4096 Jul 13 00:19 META-INF
drwxr-xr-x 2 oracle oinstall 4096 Jun 15 22:02 resourceTemplates
drwxr-xr-x 5 oracle oinstall 4096 Jun 15 22:03 scripts
drwxr-xr-x 3 oracle oinstall 4096 Jul 13 00:19 WEB-INF

Next, use a text editor to uncomment and modify the “config.dir” param-value inside the WEB-INF/web.xml file. This is how the first part of my web.xml file looks like:

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
        xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
        <display-name>ApexMod</display-name>
        <context-param>
                <param-name>config.dir</param-name>
                <param-value>/home/oracle/apex_listener/config</param-value>
        </context-param>
        <context-param>
                <param-name>version</param-name>
                <param-value>1.1.4.195.00.12</param-value>
        </context-param>

Note that my APEX Listener config file is stored under /home/oracle/apex_listener/config/apex.

Now let’s recreate the apex.war file again using the “jar” utility:

oracle@ol6ora11g02 /u01/app/apex_listener/1.1.4/modified>/u01/app/java/java6/bin/jar cf ../apex.war .
oracle@ol6ora11g02 /u01/app/apex_listener/1.1.4/modified>cd ..
oracle@ol6ora11g02 /u01/app/apex_listener/1.1.4>ls -la
total 20140
drwxr-xr-x 5 oracle oinstall     4096 Aug 20 14:44 .
drwxr-xr-x 6 oracle oinstall     4096 Aug 17 11:22 ..
-rwxr-x--- 1 oracle oinstall 10719937 Aug 17 11:26 apex_listener.1.1.4.195.00.12.zip
-rw-r--r-- 1 oracle oinstall  9839841 Aug 20 15:09 apex.war
drwxr-xr-x 5 oracle oinstall     4096 Jul 13 00:20 docs
-rw-r--r-- 1 oracle oinstall     2906 Jul 13 00:20 index.htm
drwxr-xr-x 4 oracle oinstall     4096 Jul 13 00:20 javadoc
-rw-r--r-- 1 oracle oinstall    24890 Jul 13 00:20 license.html
drwxr-xr-x 8 oracle oinstall     4096 Aug 20 14:45 modified
-rw-r--r-- 1 oracle oinstall     3242 Jul 13 00:20 readme.html
oracle@ol6ora11g02 /u01/app/apex_listener/1.1.4>rm -rf modified

Step 3: redeploy the apex.war file under GlassFish

Start up the GlassFish admin console (by default it runs under port 4848), click on “Applications” and then click on “Redeploy” next to the “apex” application (or whatever you called your APEX Listener deployment).

 

In the next screen, browse to the new “apex.war” file and click on “OK”. This will remove the old APEX Listener and deploy the new version. If everything went fine, click on “Launch” to check if APEX is working fine again. In case of errors, you should check the server.log file for the GlassFish instance where you deployed the APEX Listener.

That’s it! Good luck :-)

 

Matthias

GlassFish Server release 3.1.2.2 fixes APEX file download bug

A new microrelease version of GlassFish Server has been released: version 3.1.2.2. According to the release notes, the following issues were fixed:

  • NetBeans bug 211962
  • JAX-WS issue JAX_WS-1059
  • GlassFish Server issue GLASSFISH-18446

I didn’t find the time to try out this new release yet, but according to the bug issue list, it also contains a fix for GlassFish issue 18444, something that I blogged about in one of my previous posts. Since this bug breaks the file downloads in APEX, it’s a critical issue, so it’s strange they didn’t mention this in the release notes.

 

Matthias

Upgrading GlassFish 3.1.1 to 3.1.2 on Oracle Linux 6.2 64-bit

Environment: GlassFish 3.1.1 Open Source Edition (Web Profile), Oracle Linux 6.2 64-bit, Application Express 4.1.1

There are 3 ways to upgrade GlassFish v3.1.1 to v3.1.2: by using the graphical Update Tool, by using the graphical Software Update Notifier, or by using the command-line version of the Update Tool: pkg. All these tools need to be installed first before they can be used.

In my environment, I have one domain administration server (DAS) and one local instance (“instance01”) under which Application Express 4.1.1 (APEX) is deployed. I didn’t cover the upgrade of clusters in this blog post. I refer to the complete GlassFish 3.1.2 Upgrade Guide for more information.

1) Upgrading GlassFish with the Update Tool

If you didn’t install the Update Tool yet, you can do this by running the updatetool command in your glassfish/bin folder. This will download and install the required software packages. Note: your server needs internet access for this!


oracle@ol6ora11g02 /u01/app/glassfish/bin>./updatetool

The software needed for this command (updatetool) is not installed.

If you choose to install Update Tool, your system will be automatically
configured to periodically check for software updates. If you would like
to configure the tool to not check for updates, you can override the
default behavior via the tool's Preferences facility.

When this tool interacts with package repositories, some system information
such as your system's IP address and operating system type and version
is sent to the repository server. For more information please see:

http://wikis.sun.com/display/updatecenter/UsageMetricsUC2

Once installation is complete you may re-run this command.

Would you like to install Update Tool now (y/n):

Proxy: Using system proxy settings.
Install image: /u01/app/glassfish
Installing pkg packages.
Downloading 3 packages.
Downloading pkg (511 files, 6,237,937 bytes).
File 511/511
Downloading pkg-java (5 files, 204,325 bytes).
File 5/5
Downloading python2.4-minimal (303 files, 6,537,301 bytes).
File 303/303
Executing 1 removal actions.
Executing 13 update actions.
Executing 934 install actions.
Installing updatetool packages.
Downloading 2 packages.
Downloading updatetool (564 files, 4,369,396 bytes).
File 564/564
Downloading wxpython2.8-minimal (317 files, 25,193,712 bytes).
File 317/317
Executing 1,048 install actions.
Registering notifier: Not able to register.  Returned exit code 3.
Starting notifier.
Initialization complete.

Software successfully installed. You may now re-run this command (updatetool).

Everything looks OK, however, when I run the updatetool command, I receive the following error:

/u01/app/glassfish/updatetool/bin/../../pkg/python2.4-minimal/bin/python:
/lib/ld-linux.so.2: bad ELF interpreter: No such file or directory

Apparently, this is a known issue with Linux 64-bit environments. To fix this error, you need to install the missing 32-bit versions of the libraries. To know which rpm packages contain the missing libraries, use the following command (with user root):

$ yum provides ld-linux.so.2

This will show you that you need to install the rpm package glibc.i686:

$ yum install glibc.i686

After the installation of this package and its dependencies, I received another error… and another one and another one and so on ;-) It’s annoying that there is no list of required libraries mentioned in the documentation (at least I couldn’t find one). In total, I had to download and install (by trial and error) the following rpm packages:

$ yum install glibc.i686
$ yum install libstdc++.so.6
$ yum install libgtk-x11-2.0.so.0
$ yum install libXxf86vm.so.1
$ yum install libSM.so.6
$ yum install libidn.so.11
$ yum install libpk-gtk-module.so
$ yum install libcanberra-gtk-module.so

After this, the Update Tool finally started!

At the bottom right you will see the total size and number of the components that can be upgraded (in my case: 31 components, 43.1 MB). Before I started with the upgrade, I first stopped my local instance and my domain administration server using the asadmin command:

$ ./asadmin stop-instance instance01
The instance, instance01, is stopped.
Command stop-instance executed successfully.
$ ./asadmin stop-domain domain1
Waiting for the domain to stop ...
Command stop-domain executed successfully.

Now I selected all Available Updates and clicked “Install” in the Update Tool.

After the download of all updates, exit the Update Tool and run the following command to upgrade your domain administration server (DAS):

$ ./asadmin start-domain --upgrade domain1

When the upgrade completes successfully, start up the DAS normally and also start any of your local instances:

$ ./asadmin start-domain domain1
$ ./asadmin start-instance instance01

Finally, check if your deployed applications are still working…

2) Upgrading GlassFish with the Software Update Notifier

The Software Update Notifier GUI is installed together with the Update Tool. So, the steps for installation and upgrade are actually comparable. The Software Update Notifier will check on regular intervals if software updates are available. The interval (daily, weekly and so on) can be configured from the “Preferences” menu in the Update Tool GUI. When update are available, a notification window will appear. After this you will be able to select and download updates in the same matter as with the Update Tool. Don’t forget to start your DAS with the –upgrade command line option.

3) Upgrading GlassFish with the pkg command line utility

The pkg utility can be installed by running the pkg command in the glassfish/bin folder:

oracle@ol6ora11g02 /u01/app/glassfish/bin>./pkg

The software needed for this command (pkg) is not installed.

When this tool interacts with package repositories, some system information
such as your system's IP address and operating system type and version
is sent to the repository server. For more information please see:

http://wikis.sun.com/display/updatecenter/UsageMetricsUC2

Once installation is complete you may re-run this command.

Would you like to install this software now (y/n): y

Proxy: Using system proxy settings.
Install image: /u01/app/glassfish
Installing pkg packages.
Downloading 3 packages.
Downloading pkg (511 files, 6,237,937 bytes)
File 511/511
Downloading pkg-java (5 files, 204,325 bytes).
File 5/5
Downloading python2.4-minimal (303 files, 6,537,301 bytes).
File 303/303
Executing 1 removal actions.
Executing 13 update actions.
Executing 934 install actions.
Initialization complete.

Software successfully installed. You may now re-run this command (pkg).

After the installation, I had the same problem as with the installation of the Update Tool (see higher) and I had to install a number of missing libraries (with user root):

$ yum install glibc.i686
$ yum install libstdc++.so.6
$ yum install libz.so.1
$ yum install libidn.so.11
$ yum install libgssapi_krb5.so.2

After this, stop your DAS and any local instances, and run the pkg image-update command:

$ ./asadmin stop-instance instance01
The instance, instance01, is stopped.
Command stop-instance executed successfully.
$ ./asadmin stop-domain domain1
Waiting for the domain to stop ...
Command stop-domain executed successfully.

$ ./pkg image-update
Download: glassfish-web-incorporation ...  Done
Download: jersey ...  Done
Download: javadb-core ...  Done
Download: glassfish-javahelp ...  Done
Download: javadb-common ...  Done
Download: glassfish-web-profile ...  Done
Download: javadb-client ...  Done
Download: glassfish-registration ...  Done
Download: glassfish-jta ...  Done
Download: glassfish-corba-base ...  Done
Download: glassfish-jts ...  Done
Download: glassfish-jsf ...  Done
Download: glassfish-hk2 ...  Done
Download: felix ...  Done
Download: glassfish-jpa ...  Done
Download: glassfish-cluster ...  Done
Download: glassfish-ejb-lite ...  Done
Download: glassfish-jdbc ...  Done
Download: glassfish-gui ...  Done
Download: glassfish-web ...  Done
Download: shoal ...  Done
Download: glassfish-jca ...  Done
Download: glassfish-grizzly ...  Done
Download: glassfish-common ...  Done
Download: glassfish-nucleus ...  Done
Download: glassfish-upgrade ...  Done
Download: glassfish-jcdi ...  Done
Download: glassfish-management ...  Done
Download: glassfish-grizzly-full ...  Done
Download: glassfish-osgi-http ...  Done
Download: glassfish-ha ...  Done
Removal Phase ...  Done
Install Phase ...  Done
Update Phase ...  Done

Now run the following command to upgrade your domain administration server (DAS):

$ ./asadmin start-domain --upgrade domain1

When the upgrade completes successfully, start up the DAS normally and also start any of your local instances:

$ ./asadmin start-domain domain1
$ ./asadmin start-instance instance01

Check the version of GlassFish:

$ ./asadmin version
Version = GlassFish Server Open Source Edition 3.1.2 (build 23)
Command version executed successfully.

Finally, check if your deployed applications are still working…

 

Matthias

Configuration and deployment of PDF printing in APEX 4.1.1 using GlassFish 3.1.2 and Apache FOP

Environment: Oracle database 11.2.0.3, APEX 4.1.1, GlassFish 3.1.2 Open Source Edition (Web Profile), Oracle Linux 6.2

Apache FOP (XSL-FO Processor) can be used together with APEX to allow PDF printing of classic or interactive reports. In this blog post, I will explain how you can deploy and configure FOP in APEX 4.1.1 with GlassFish 3.1.2.

Apache FOP can be installed on a Java application server by deploying the fop.war web archive, which can be found in the /utilities/fop folder inside the APEX installation files. However, the fop.war file does not work out of the box on GlassFish 3.1.2.

I faced two different kind of errors in my installation:

1) package oracle.xml.parser.v2 does not exist: this is because GlassFish can’t find the xmlparserv2.jar file which can be found in $ORACLE_HOME/lib.

2) java.lang.IllegalStateException: getOutputStream() has already been called: this has something to do with getOutputStream() being used more than once; I’m far from a Java specialist, but I found a workaround for this problem on the internet.

This is the solution:

First, we need to extract the original fop.war file (I used the jar utility from my Java 6 JDK installation):

$ /u01/app/java/java6/bin/jar -xf fop.war

You should see the following:

$ ls -la

-rw-r–r– 1 oracle oinstall 1792 May 4 12:44 apex_fop.jsp
-rw-r–r– 1 oracle oinstall 7016135 May 4 12:44 fop.war
drwxr-xr-x 4 oracle oinstall 4096 May 4 14:00 WEB-INF

Next, copy the xmlparserv2.jar file from $ORACLE_HOME/lib into the WEB-INF/lib folder:

$ cp -p /u01/app/oracle/product/11.2.0/db_1/lib/xmlparserv2.jar WEB-INF/lib

Now we need to modify the two apex_fop.jsp files in the top folder and under WEB-INF/classes. Add the following 2 lines just before the final “driver.run();” call:

out.clear();
out = pageContext.pushBody();

The full apex_fop.jsp file should look like this:

<%@ page import='java.io.*'%>
<%@ page import='org.xml.sax.InputSource'%>
<%@ page import='org.apache.fop.apps.Driver'%>
<%@ page import='org.apache.fop.apps.Options'%>
<%@ page import='oracle.xml.parser.v2.XMLDocument'%>
<%@ page import='oracle.xml.parser.v2.XSLProcessor'%>
<%@ page import='oracle.xml.parser.v2.XSLStylesheet'%>
<%@ page import='oracle.xml.parser.v2.DOMParser'%>
<%
response.setContentType("application/pdf");

XMLDocument   v_doc;
XSLStylesheet v_xsl = null;
String        v_fop;
DOMParser     parser = new DOMParser();
XSLProcessor processor = new XSLProcessor();
// set the encoding for the XML Processing
String        v_encode = "UTF-8";

// get the XSL
v_xsl = new XSLStylesheet(new java.io.StringReader(request.getParameter("template")),null);

// get the XML String from the form which was posted
parser.parse(new java.io.StringReader(request.getParameter("xml")));
// get the XML Document
v_doc = parser.getDocument();

// create an output stream to get the transformed results
ByteArrayOutputStream v_out = new ByteArrayOutputStream();
// transform the xml and xsl to get an FOP
processor.processXSL(v_xsl, v_doc, v_out);
// convert the FOP byte array to a string with encoding set above
v_fop = new String(v_out.toByteArray(),v_encode);

//
// Now call the apache FOP processing
//
Driver driver = new Driver();
// set the desired output
// see http://xml.apache.org/fop/output.html for all output types
driver.setRenderer(Driver.RENDER_PDF);

// set the input for the FOP engine
driver.setInputSource(new InputSource(new StringReader(v_fop)));
// set the output to stream to the browser
driver.setOutputStream(response.getOutputStream());
out.clear();
out = pageContext.pushBody();
// process
driver.run();
%>

Now we are going to recreate the fop.war file:

$ /u01/app/java/java6/bin/jar -cvf fop.war apex_fop.jsp WEB-INF

We are now ready to deploy the fop.war file in GlassFish:

– start up the GlassFish admin console (default: port 4848)

– click on Standalone Instances -> your instance

– click on Applications -> Deploy -> local packaged file… and browse to the “fop.war” file (see screenshot below)

– click on OK; “fop” should now appear in the list of Deployed Applications

After this, you can already test your Apache FOP deployment by opening http://<servername&gt;:<port>/fop/apex_fop.jsp in a web browser. If you see a Java NullPointerException error, things are looking good ;-)

Finally, we need to tell APEX where to find the print server:

– log in to the APEX workspace “internal” with the username “admin”

– click on Manage Instance -> Instance Settings

– fill in the Report Printing part (see screenshot below):

Print Server: External (Apache FOP)
Print Server Host Address: localhost
Print Server Port: (your APEX port)
Print Server Script: /fop/apex_fop.jsp

That’s it! Now try to print a report as PDF in APEX; it should work fine!

 

Matthias