Deploying the Web Application
Sending the page to another Web server is made simple by the webAF Package Wizard.
Note that the only version of Tomcat formally supported by SAS is Version 4.18;
anything newer (Tomcat 5, for instance) is not guaranteed to work. The example below was run in Tomcat 4.30.
Note also that the application has to have access to the SAS server. For that reason, the connection to the local host should use the SAS server name, not a local address like 127.0.0.1.
To create a Web archive (WAR) file from the application in webAF, just click on Tools X Wizards X Package Wizard. There are only two steps; you probably want to accept the defaults, so just click Next each time. The WAR file should contain all of the components needed to deploy the file.
Now open the Tomcat Manager application on the Web server. Go to Upload a WAR file to install. You should be able to browse to a file called Demo.war in the project directory. Click Install. The WAR file (which can be quite large) will be copied to the server and deployed. If all goes well, you should get the following message:
OK - Installed application at context path /Demo.
Chapter 9 Developing Java Server-Side Applications with webAF Software 201
Now enter the URL for the servlet, in this case the following:
http://<hostname>:8080/Demo/ControllerServlet
Again, it may take some time for the contents of the WAR file to be extracted. You should see the same page as shown in Display 9.23. Congratulations. You have now created and deployed a Java Web application.
Using SAS Remote Compute Services
In addition to accessing SAS data, it is also possible to run SAS programs remotely. The SAS AppDev Studio 3.1 tag library is an addition to, rather than a replacement for, the older component palette. Chapter 11, “Building Web Applications with SAS and Java,”
explains how to use stored processes to run SAS jobs on a remote host. This chapter covers some of the older but still useful interfaces that were part of SAS AppDev Studio 2.0, in particular the SAS SubmitInterface and the DataSetInfo interfaces.
Remote Computing Using SubmitInterface
The SubmitInterface control can be used to send SAS program statements to the server.
The following program revisits the retail data set used in the CGI examples. The SAS source code for this program is the same as that used in Chapter 6, “SAS/IntrNet: the Application Dispatcher.”
Example 9.5 Sample PROC REPORT Macro
options nodate nonumber noovp nocenter pagesize=20;
/* Sample Program: shoes.sas */
%macro salesrpt(region);
proc report data=sashelp.shoes;
by region;
%if ( ®ion ne null ) %then %do;
where region="®ion";
%end;
title "<h2>Shoe Sales by Region x Product</h2>";
footnote "Data are current as of &systime &sysdate9";
column product sales;
define product / group;
define sales / analysis sum;
quit;
%mend salesrpt;
%salesrpt(<%= request.getParameter("region") %>)
The code has been modified from that shown earlier in that the macro variable REGION is read from the URL as a parameter. (The macro code is shown in bold in the example.) If the parameter is not supplied, the default is to run the report for all of the observations in the data set. This example illustrates that it is actually possible to insert Java code within the SAS program.
The following JSP code can be used to send this program to the SAS server:
Example 9.6 JavaServer Page Using SubmitInterface
<%@ taglib uri="http://www.sas.com/taglib/sasads"
prefix="sasads" %>
<%@ include file="header.html" %>
<body>
<h1>SubmitInterface Example</h1>
<sasads:Connection id="connection1"
serverArchitecture="IOM"
host="hunding"
port="8591"
username="sas"
password="sasuser">
<sasads:Submit
connection="connection1"
display="LASTOUTPUT" scope="page">
<%@ include file="shoes.sas" %>
</sasads:Submit>
</sasads:Connection>
</body>
<html>
In order to use the SAS AppDev Studio 2.0 sasads:Connection and sasads:Submit custom tags, the taglib directive for this library must be included in the page. When creating the project, specify the SAS Taglib and Tbeans (Version 2) run-time classes in the New Project Wizard. This will add a JSP taglib directive as shown in Example 9.7:
<%@ taglib uri="http://www.sas.com/taglib/sasads"
prefix="sasads" %>
To build the JSP, first add the connection control shown, with the following attributes:
id – a unique name for the connection
serverArchitecture – the connection type, in this case IOM
host – the name of the remote host
port – the port on which the spawner is listening; 8591 is the default for a workspace server
username – a valid user on the host system
password – a valid password, must be included in the JSP
For this example, the connection scope parameter defaults to page, so the connection is closed with the HTML page; specifying scope="session"maintains the connection for the duration of the HTTP session.
The SubmitInterface component takes the following attributes (the defaults are shown in bold):
Chapter 9 Developing Java Server-Side Applications with webAF Software 203
Table 9.2 SubmitInterface Attributes
Attribute Name Value Comment
connection "java.lang.String" Valid connection to a SAS/CONNECT server connectionObject “com.sas.rmi.Connection” InformationBean: reference a
subclass if necessary display "NONE|LOG|LASTLOG|OUTPUT|LASTOUTPUT" Specify output type format "MONOSPACE|SAS" Default value inserts <pre>
</pre> tags around the output; otherwise HTML formatting is lost
id "value" Case-sensitive name used to
identify the object instance ref "java.lang.String" Object created earlier in the
same scope; alternative to id scope "page|request|session|application" The scope (or page context)
within which the reference is available
In the preceding example, the display format is specified as LASTOUTPUT; in this way only the current report is shown. Otherwise resubmitting the page would result in cumulative multiple-output reports.