When you point a web browser at a caGrid web service, the default response provided by AXIS 1.2 is:
Overriding this behavior to actually provide the suggested form can be complicated. However overriding this in a way that either changes the message or redirects the browser to a different URL is relatively simple. The rest of this page is a description of how to change the message or redirect the browser.
By default caGrid services use the AXIS servlet class org.globus.wsrf.container.AxisServlet. When an instance of this servlet class receives an http GET from your browser, it calls its reportServiceInfo method which generates the "Hi there,..." response. The reportServiceInfo method has protected scope, so you can override it to have different behavior. The details of how to do this are presented below through an example.
In this example, we will create a subclass of org.globus.wsrf.container.AxisServlet whose reportServiceInfo method redirects the browser to a URL that is configured in a properties file. If it cannot get the URL from the properties file, it will send a message to the browser telling the user that the redirection is misconfigured.
We name the subclass org.cagrid.indexService.IndexAxisServlet. Here is the beginning of its source code:
All but the last group of imports are from the standard Java API:
is needed to declare one of the arguments for the reportServiceInfo method. We will not need to make any other use of it.
is a class used to describe the configuration of wsrf, the layer of software that sits between the web container (tomcat, JBoss, ...) and the grid service.
is the class we are subclassing.
Here is the actual override of the reportServiceInfo method:
The above code gets a URL to redirect the browser to from a Properties object and then calls response.sendRedirect to send the redirection to the browser. If there is an error in getting thr URL or sending the redirection, the fallback strategy is to write some explanatory text to the browser.
The rest of the IndexAxisServlet appears below.
The getRedirectionProperties method in the above code returns a Properties object that is loaded with the contents of the file redirection.properties in the deployed service's WEB-INF/etc directory. The location of this and other configuration details are described in the next section of this page.
Under the previous section of this page, we described how to write a class that will override a grid service's default "Hi there..." behavior. In this section, we describe what need to be done to install the class into a grid service. In the next section we show how to automate that installation steps as an ant script.
There are three things that the installation needs accomplish:
- Put the new class where it will be on the grid service's class path.
- Arrange for the new class to be used in place of the usual servlet class.
- Put the redirection.properties file where the new class expects to find it.
All of the installation steps involve files that are or will be under a particular directory in the gird service's container. We will refer to this directory as DEPLOY_DIR.
- If you are using tomcat, then DEPLOY_DIR is $CATALINA_HOME/webapps/wsrf/WEB-INF.
- If you are using JBoss, then DEPLOY_DIR is $JBOSS_HOME/server/default/deploy/WEB-INF.
To put the new class on the service's class path, we copy it to a directory that is based on the name of the package it belongs to. If the new class belongs to a package named org.cagrid.indexService then copy it to DEPLOY_DIR/classes/org/cagrid/indexService
To arrange for the new class to be used in place of the usual servlet class, edit the file DEPLOY_DIR/web.xml. It contains an xml element that looks like
This xml element identifies the servlet class to be used for the web service. If the fully qualified name of the new class is org.cagrid.indexService.IndexAxisServlet, then we need to change the xml element to look like
We need to create a redirection.properties file that contains a redirectionURL property whose value is the URL to redirect to. This would look like
We then copy this properties file to DEPLOY_DIR/etc/redirection.properties
When all of these things are done, the new custom servlet class is installed and configured.
It is strongly recommended that you create an ant script to automate these steps. An ant script to perform this automation is described in the next section of this page.
In this section of this page we present a self-contained ant script that is called from your main ant script to install and configure a customized servlet class for redirection of browsers.
We assume that your grid service has the standard ant xml files generated by introduce. We also assume that deploy-redirect.xml is the name of the new self-contained script that installs and configures the redirection.
Before we look at at contents of redirection.properties, we take a look at the changes you should make to the dev-build-deploy.xml to integrate it with deploy-redirect.xml.
Add tasks like the ones shown to the preDeployTomcat and preDeployJBoss targets:
Here is the content of deploy-redirect.xml: