This section describes the code used to launch queries against the query table API of the WebSphere Process Server. For a quick start, you can simply select the name of a predefined query table that is shipped with the server. Optionally, you can use any query table of your choice by typing in the name of that query table.
The code snippets provided in this section have been extracted from the queryTablesEAR.ear enterprise application that is available from the Download section of this sample.
There are two source files that make up the core of this sample:
Hint:
For simplicity, the names of the predefined query tables are duplicated in the source code of this sample. This list can be
found in the Information Center
section Predefined query tables.
Note that starting with WebSphere Process Server 6.2.0.1, you can query the list predefined query tables dynamically, using the
API method findQueryTableMetaData as described in the
section Query table queries for meta data retrieval.
queryEntities to do the actual call.As mentioned, all the following explanations are focussing on the API calls used inside the QueryServlet.java file. If you need more details about the configuration needed to use the Business Flow Manager API, refer to the samples EJB API - Overview and EJB API - Details in the same samples category 'Interaction with processes and human tasks'.
Note: In the following code sections, exception handling is left out. A detailed description of the exceptions thrown by the particular commands can be found in the Javadoc.
As mentioned, the file QueryServlet.java contains the actual code that uses the query table API. This servlet is implemented by inheriting from the Servlet class and
thereby overwriting the doGet and the doPost methods; these methods do implement the behaviour when HTTP GET and
HTTP POST are issued against this servlet. Here, we want identical behaviour for GET and the POST requests, thus we can simply
reuse the code of the POST method for the GET method:
The doPost method now will do the actual work.
In that method, first the parameter strings are extracted from the HTTP request:
The query table name was specified as radio button setting and passed in the URL as parameter "selection", with one exception: when the user has selected "[OTHER]" then the name should rather be extracted from the text field named "other":
The query table name is attached, even if null, as attribute to HTTP request. Therefore the caller JSP will be able to see what was understood after extracting, removing escape chars, etc.:
The JNDI lookup for the remote EJB and the initialization of the session bean for the Business Flow Manager EJB is encapsulated in the auxiliary method that is defined at the end of this java file. Refer to the sample EJB API - Overview for more details. The auxiliary method is called now:
Next, filter options for the query are prepared and filled with the optional parameters if they were set by the user. In addition, a threshold for a maximum of 20 records is specified:
In case that a userid with admin privileges is logged in, AdminAuthorizationOptions are created
that will be passed to the query table call later on. This allows to query both instance data and template data.
Without passing AdminAuthorizationOptions, queries for instance data will work, but queries for template data
will be rejected with error "CWWBE0027E: No authorization for the requested action."
By default, null will be passed as AuthorizationOptions parameter:
For users in the BPESystemAdministrator J2EE role only, the AdminAuthorizationOptions class is instantiated. There is no need to call any setters, just passing this instance as AuthorizationOptions parameter is sufficient to get access to template data:
Finally, the call to the query table is issued:
If no exception occurred, the result is attached to the HTTP request:
Otherwise, if an exception has occurred, simple error handling is performed instead:
Click on the links to see the complete source code of the index.jsp and the QueryServlet.java.