Wednesday, December 19, 2012

APEX Listener 2.0 !

The Oracle APEX Listener 2.0 is officially out. There's a TON of changes in this release. The first how you get it up and running. For the standalone version, it's very simple to be up and running quickly. Simply type "java -jar apex.war" and follow the prompts. This will get you up and running.  The biggest changes are in the REST services and I'll blog more on that later.

The command line has a options now.
$ java -jar apex.war help
java -jar apex.war  [Options] [Arguments]

The following commands are available:

               configdir         Set the value of the web.xml
                                 config.dir property

               help              Describe the usage of this
                                 program or its commands

               map-url           Map a URL pattern to the
                                 named database connection

               migrate           Migrate a 1.x configuration
                                 to 2.x format

               setup             Configure database connection

               standalone        Launch Oracle Application
                                 Express Listener in
                                 standalone mode

               static            Generate a Web Application
                                 Archive (WAR) to serve Oracle
                                 Application Express static
                                 resources

               user              Create or update credentials
                                 for a user

To see instructions on how to use each of these commands, type help
followed by the command name, for example

 java -jar apex.war help configdir

If no command is provided the Listener is started in standalone mode

The important one to not using the command line is the "user" command. You can use sqldeveloper 3.2.2 to now administer the APEX Listener. The user command lets you setup the authentication that sqldev will use to connect and administer in standalone mode.

java -jar apex.war user klrice "Listener Administrator"

SQL Developer 3.2.2 is the current and required version to administer the listener.  Use the View -> APEX Listener menu and change anything. Once the settings are done, use the test button in the tool bar to validate setting and finalize with the Upload Setting button. Alternatively, you can save the setting to a zip file and manually put them in place.



Java Script Validations?

In the new listener there's an option for the normal PL/SQL Validations.  Nothing has changed there however if you change the select box to javascript, you can now validate the request before hitting the database at all.  This has the obvious advantage of no database hit, no connection borrowed from the pool, no extra load on the database to simply refuse some requests.  The following are all available in javascript as variables.

HOST
PORT
REFERER
USER_AGENT
URI
QUERY_STRING
REMOTE_ADDR
REQUEST_METHOD
REQUEST_PROTOCOL
REQUEST_SCHEME
SCRIPT_NAME
SERVER_NAME
SERVER_PORT
SERVER_PROTOCOL
Also all querystring params and headers are put in as variables with their names. 
The only requirement is that there be a function named "isValid" that returns the string "true" or "false".  

function isValid(){ 
 // no more ie6 
    if ( USER_AGENT.indexOf("MSIE 6") > 0 ) {
        return "false";
     }
 // a procedure in the klrice schema named HI has been performing poorly so shut it off
   if ( SCRIPT_NAME == 'klrice.hi' ) { 
       return "FALSE";
   }
  return "true";
}