Authors:
Seshu Adunuthula
Mala Anand
The Web Request Broker (WRB) API provides a programmatic interface to the Oracle Web Request Broker and enables applications developers to develop their applications (called cartridges in this document) for the WRB. The WRB API provides a higher level API that abstracts away the HTTP protocol while providing the necessary interfaces for application development.
The functionality provided by the WRB API can be divided into the following categories:
WRBReturnCode WRB_Init( void **clientCtx );
This callback is invoked by WRB Application Engine on its initialization. The WRB cartridge initializes its context in this routine which is then made available to the cartridge on subsequent call backs.
WRBReturnCode WRB_Exec( void *WRBCtx, void *clientCtx );
This callback is invoked by WRB Application Engine upon receiving a HTTP Request. The WRB cartridge is responsible for creating the response that is written back to the Listener in this callback .
WRBReturnCode WRB_Shutdown( void *WRBCtx, void *clientCtx);
The WRB Application Engine invokes this call back to provide an graceful exit for the WRB Client. Any memory allocated in the client context during the init callback should be deallocated here.
WRBReturnCode WRB_Reload(void *WRBCtx, void *clientCtx);
This callback is not required, but is recommended. The WRB Application Engine invokes this call back whenever the Web Listener has been signalled to reload its own configuration files. The Web Listener halts all new incoming connections, allows existing transactions to complete, and then signals each running WRB cartridge to execute its reload callback (if one exists). If your application uses configuration information from the OWS_APPFILE then you should call WRBGetAppConfig again, as these values may have.
char *WRB_Version();The version callback enables the cartridge to return a character string with information about the version of that cartridge. This callback is made by the ""wlctl2" utility
char *WRBGetURL( void* WRBCtx ); char *WRBGetURI( void* WRBCtx );Returns the URL/URI received from the HTTP Server. The cartridge developers may extract additional information from the URI/URL if required.
char *WRBGetEnvironmentVariable( void *WRBCtx, char *szEnvVar );
Returns the value of an environment variable. This provides a way for the WRB client to access CGI Environment variables. Returns NULL if szEnvVar points to a invalid environment variable.
char **WRBGetEnvironment(void *WRBCtx );Returns the HTTP Listener environment as an array of null terminated strings with the syntax varname=varvalue. Returns NULL in case of an error.
char *WRBGetContent( void *WRBCtx );
Returns either the Query String or the POST data content depending on the type of the request method. Returns NULL in case on an error.
char *WRBGetLanguage( void *WRBCtx );Returns the WRB Application Engine Language preferences. Returns NULL in case of an error. On success, returns a comma delimited list of the "Accept" languages.
char *WRBGetCharacterEncoding( void *WRBCtx );Returns the WRB Application Engine Character Encoding preferences. Returns NULL in case of an error. On success, returns a comma delimited list of the "Accept" encodings
WRBReturnCode WRBGetParsedQueryString(void *WRBCtx, WRBEntry **WRBEntries, int *numEntries);
typedef struct { char *name; char *value; } WRBEntry;Returns an array of name-value pairs after parsing the query string/POST data.
char *WRBGetNamedEntry( char *entryName, WRBEntry *WRBEntries, int numEntries);Returns a name/value pair from a list of entries generated by a call to WRBGetParsedContent. Returns NULL on error
char *WRBGetORACLE_HOME( void *WRBCtx );Returns the ORACLE_HOME which was set when the Web Listener was started
char **WRBGetAppConfig( void *WRBCtx );
Returns the configuration information for the current application. The structure of the return value is a pointer to an array of pointers to character strings. These character strings are of the form "name=val". The information is retrieved from the OWS_APPFILE at the time the Web Listener starts up. An example might be:
[MyCartidge] myparam1 = val1 myparam2 = val2
char *WRBGetConfigVal( void *WRBCtx, char *name );Returns a named item for the application's configuration. The information is retrieved from the OWS_APPFILE at the time the Web Listener starts up.
ssize_t WRBClientRead( void *WRBCtx, char *szData, int *nBytes );The WRB Client invokes this function to read the POST data of a HTTP request from the WRB Application Engine. In the current implementation, if a client is going to read POST data it must do so bwfore sending any data (through WRBClientWrite) back to the Web Listener. The return value is the number of bytes read.
ssize_t WRBClientWrite( void *WRBCtx, char *szData, int nBytes);
The WRB cartridge invokes this function to send data to the client. The return value is the number of bytes written.
ssize_t WRBHTTPReturnError( void *WRBCtx, WRBErrorCode, nErrorCode, char *szErrorMesg, boolean close);Invoked by the WRB client when it would like a standard HTTP error sent back to the browser. This call must occur before any other calls to WRBClientWrite, as it is a wrapper which sends : Status <nErrorCode> <szErrorMesg> The "close" flag set to false indicates that you wish to send additional HTTP header information and that you will close the HTTP header explicitly with a call to WRBCloseHTTPHeader.
WRBReturnCode WRBCallCartridge( void *WRBCtx, char *request);The WRB client calls this function to invoke a request which could be satisfied by a cartridge running on the local WRB, or by a remote HTTP Server or WRB.
WRBReturnCode WRBClientSetTimeOut( void *WRBCtx, int nTimeOut, WRBReturnCode (*WRBClientCleanUP)( *void WRBCtx ) );This function can be called by the WRB client to set a time out for long running calls. If WRB Client makes this call the WRB Application Engine sets up a timer to interrupt processing a HTTP request and return to the LIstener with a timedout error response. The WRB client can set a callback WRBClientCleanUp to clean up the client in case of a timeout. WRB Application Engine discards any response from the WRB client once the timeout has happened. If no callback is provided a default callback is used.
ssize_t WRBReturnHTTPRedirect( void *WRBCtx, char *szURI, boolean close);Invoked by the WRB client when it would like a standard HTTP error sent back to the browser. This call must come before any other calls to WRBClientWrite, as it is just a wrapper which sends : Status: <nErrorCode> <szErrorMesg>
The "close" flag set to FALSE indicates that you wish to send addition HTTP header information and that you will close the HTTP header explicitly with a call to WRBCloseHTTPHeader.
ssize_t WRBCloseHTTPHeaer( void *WRBCtx );Invoked by the WRB client when it would like to close an HTTP header. Generally used after calls to WRBReturnHTTPError or WRBReturnHTTPRedirect with the "close" flag set to FALSE.
void WRBLogMessage( void *WRBCtx, char *szMessage, int nSeverity );Logs the message szMessage to a file ?/ows2/log/wrb_<pid>.c where ? is the ORACLE_HOME and pid is the processid of the Web Request Broker. Currently nSeverity is not used and reserved for future versions.
int WRB_CMICreateObject( void *WRBCtx, char *fileName, int fMode );An entry for the object is created which is identified by the full virtual path to that object. If the cartridge does not have the necessary permissions to create the object then an error is returned. Error information can be obtained by
WRB_GetError
. On success an object descriptor is returned
which is used by the subsequent calls in the
interface. WRB_CreateObject
does an implicit open on the
object. The object can be opened in either read or write mode.
int WRB_CMIOpenObject (void *WRBCtx, char *fileName, int fMode );An object descriptor is returned for the object. The
fMode
determine the mode in which the object is opened. The object
descriptor is used by the subsequent calls to manage the object.
char *WRB_CMIGetAttribute( void *WRBCtx, int nObjDescriptor, int nAttrib);The attributes currently defined on the object are:
nObjDescriptor
is returned on
success. On failure a NULL is returned.
int WRB_CMISetAttribute( void *WRBCtx, int nObjDescriptor, int nAttribute, char *szAttribValue );The attributes of an object can be changed by the cartridge if it has the right permissions to do so. Not all attributes can be modified. An error value is returned if the cartridge tries to modify an attribute with permissions or an attribute that cannot be modified.
int WRB_CMIRead( int nObjDescriptor, unsigned char *sBuffer, int nBufSize );Read
nBufSize
bytes from the location pointed to by the
nObjDescriptor
into sBuffer
. The actual
number of bytes read is returned. An error value is returned on
failure.
int WRB_CMIWrite( int nObjDescriptor, unsigned char *sBuffer, int nBufSize );Writes
nBufSize
bytes from sBuffer
into the
location pointed to by the nObjDescriptor
. An error value
is returned on failure. Information on the error can be obtained by
making a call to WRB_GetError
int WRB_CMICopy( int nSourceDesc, int nDestDesc, int nMode);The source object is copied to the destination object. Copy has three different modes associated with it.
int WRB_TMIInitTransaction ( void *WRBCtx, void *xactionState );A cartridge can initiate a transaction by making this call and providing the
xactionState
which can be accessed by
subsequest requests to the same cartridge.
void *WRB_TMIGetXactionState( void *WRBCtx );Returns the state set by a call to
WRB_TMIGetXactionState
void *WRB_TMISetXactionState( void *WRBCtx );Sets the state by a call to
WRB_TMISetXactionState
int WRB_TMIEndTransaction( void *WRBCtx );Ends the transaction.