Summary: This document provides basic information about the extension providing Apache Struts support for the JEE Analyzer.
Description
This extension provides support for Apache Struts - this support is in addition to the basic support provided for Apache Struts in the JEE Analyzer. The extension's main role is to improve the detection of links and transaction computations where Apache Struts is implicated.
Note that:
- At the current time, analysis results will contain duplicated objects: the Struts Operation object (created by the extension) corresponds to the Struts Action Mapping Operation object created by the JEE Analyzer - this duplication will be fixed in a future release.
- All Quality Rule results involving Apache Struts code are generated using the JEE Analyzer and not the Apache Struts extension.
- All Transaction results involving Apache Struts code are generated using the Struts Operation object (created by the extension) and not the Struts Action Mapping Operation object created by the JEE Analyzer.
In what situation should you install this extension?
If your JEE application source code uses the Apache Struts framework you should install this extension to benefit from improved support for Apache Struts.
Features
Object structure and links
- Creates Struts Operations which represent entry-points for web services. For each operation, one Struts Operation object is created.
- The dependent Web Services Linker is responsible for detecting and creating links between the UI (JSP/HTML etc) to the Struts Operation object created by the extension.
Struts 1.1 support
Application configuration
In the "web.xml" file, the extension will detect the servlet pointing to "org.apache.struts.action.ActionServlet" class, indicating that Struts 1.1 is being used. The extension will detect the servlet mapping (i.e. "*.perform" in the example below):
<web-app id="WebApp"> ... <servlet> <servlet-name>action</servlet-name> <display-name>Struts Action</display-name> <servlet-class>org.apache.struts.action.ActionServlet</servlet-class> .... </servlet> ... <servlet-mapping> <servlet-name>action</servlet-name> <url-pattern>*.perform</url-pattern> </servlet-mapping> .... </web-app>
In the struts config xml files (struts-XXX.xml), the extension will detect the correspondence between a URL and a java class (i.e. /logout corresponds to the "com.company.lightspeed.struts.logon.StrutsActionLogout" java class):
<struts-config> ... <action-mappings> <action path="/logout" type="com.company.lightspeed.struts.logon.StrutsActionLogout"> <forward name="loggedOut" path="lightspeed/LoggedOut.jsp" /> </action> .... </action-mappings> </struts-config>
The extension will search for all java classes which inherit directly or not from the "org.apache.struts.action.Action" class and will then search for the "execute" method in the class hierarchy.
For example:
The StrutsActionLogout class seen in the struts web.xml file is shown.
All request from clients whose URL is "logout.perform" will call the "execute" method. But, in many cases, this method is higher up in the hierarchy, and as such, the extension will analyze this method to see if a method of the subclass (here StrutsActionLogout) is called from "execute". In the above example, this is the case, "execute" calls "executeExtended" which is in the subclass. In this case, we create a Struts Operation named "/logout" (name found in the Struts xml file) and a call link between the operation and the "executeExtended" method.
Struts 2.x support
Application configuration
In the "web.xml" file, the extension will detect the filter pointing to "org.apache.struts2.dispatcher.FilterDispatcher" class, indicating that Struts 2.x is being used. The extension will detect the servlet mapping (i.e. "*.action;/*" in the example below). The extension will also obtain the filter "struts2" and "BaseStrutsFilter" because "BaseStrutsFilter" points to a class which exists in the analysis.
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:jsp="http://java.sun.com/xml/ns/javaee/jsp" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> ... <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class> <init-param> <param-name>actionPackages</param-name> <param-value>com.mapa.sipe.apresentacao.action, br.gov.mapa.arquitetura.apresentacao.struts</param-value> </init-param> </filter> <filter> <display-name>BaseStrutsFilter</display-name> <filter-name>BaseStrutsFilter</filter-name> <filter-class>com.mapa.sipe.apresentacao.filter.BaseStrutsSipeFilter</filter-class> <init-param> <param-name>public-url</param-name> <param-value>/sipe/imprimirGruPublica.action</param-value> </init-param> </filter> <filter-mapping> <filter-name>BaseStrutsFilter</filter-name> <url-pattern>*.action</url-pattern> <dispatcher>REQUEST</dispatcher> <dispatcher>FORWARD</dispatcher> </filter-mapping> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> <dispatcher>REQUEST</dispatcher> <dispatcher>ERROR</dispatcher> </filter-mapping> .... </web-app>
If a struts config file exists as shown below, the extension can obtain a correspondence between the path and a java class: in the example below, name="Login" gives the name of the operation that will be created:
<struts> ... <package name="chapterSixPublic" namespace="/chapterSix" extends="struts-default"> <action name="Login" class="manning.chapterSix.Login"> <result type="redirect">/chapterSix/secure/AdminPortfolio.action</result> <result name="input">/chapterSix/Login.jsp</result> </action> .... </package> </struts>
Classes with @Results annotation
The extension will search for all java classes using the "@Results" annotation which is resolved to "org.apache.struts2.config.Results".
For example:
@Results({@Result(name = "popup", value = "popUpRestringe", type = TilesResult.class), @Result(name = "popupRegistro", value = "popUpRestringeRegistro", type = TilesResult.class), @Result(name = "base", value = "base", type = ActionChainResult.class, params = {"method", "execute"})}) public class RestringeAction extends SipeBaseAction { public String carregarRegistro() throws Exception { VwPessoaVinculadaEstab vw = montarVwPessoaVinculadaEstab(); if (vw != null) { listaDadosRegistro = getSipeComumBD().consultarRegistroCadastro(vw.getIdPessoaEstabelecimento(), getJAASPrincipal().getIdPessoaFisica(), getIdAreaSelecionada(), getPreCadastroAtivo(), getStPerfil()); for (RegistroEstabCadDTO dados : listaDadosRegistro) { if (dados.getCdRegistroCadastro().equals(getRegistroSelecionado())) { vw.setDadosRegistro(dados); recuperarInformacoesUsuarioLogado(vw); break; } } adicionarEstabelecimentoSessao(vw); } return FW_BASE; } }
The extension will then search for all methods which are public and have "String" as the return type. The extension will create a Struts Operation with the name "/Restringe!carregarRegistro" (Restringe is the class name without the ending "Action"), and a call link to the method.
For example:
Classes implementing SessionAware
The extension will search for all java classes implementing "org.apache.struts2.interceptor.SessionAware".
For example:
import org.apache.struts2.interceptor.SessionAware; public class Login extends ActionSupport implements SessionAware { public String execute(){ User user = getPortfolioService().authenticateUser( getUsername(), getPassword() ); if ( user == null ) { /* User not valid, return to input page. */ return INPUT; } else{ session.put( Struts2PortfolioConstants.USER, user ); } return SUCCESS; } }
The extension will create a Struts Operation with the name "/Login" (this name is found in a struts xml config file, or the class name by default), and a call link to the "execute" method.
For example:
Classes inheriting from com.opensymphony.xwork2.ActionSupport
The extension will search for all java classes implementing "com.opensymphony.xwork2.ActionSupport".
For example:
import com.opensymphony.xwork2.ActionSupport; public class ManageFieldsPVAction extends ActionSupport{ private static final long serialVersionUID = -8126525052448102790L; private String first_name; private String last_name; public String execute() { //if (first_name==null) // return "login"; //setFirst_name(first_name+=" with added thingies from your favorite Action!!!"); return "success"; } ... }
The extension will create a Struts Operation with the name "/ManageFieldsPV" (this name is found in the class name without the Action part), and a call link to the "execute" method.
Classes inheriting from org.apache.struts.actions.DispatchAction
The extension will search for all java classes implementing "org.apache.struts.actions.DispatchAction".
For example:
import org.apache.struts.actions.DispatchAction; public class BookEditAction extends DispatchAction { public ActionForward editBook( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { BookEditForm bookEditForm = (BookEditForm) form; /* lalinuna.de 04.11.2004 * get id of the book from request */ Integer id = Integer.valueOf(request.getParameter("id")); // [laliluna] 28.11.2004 get business logic LibraryManager libraryManager = new LibraryManager(); bookEditForm.setBook(libraryManager.getBookByPrimaryKey(id)); return mapping.findForward("showEdit"); } ... }
We create a Struts Operation with the name "/BookEdit?do=editBook" (this name is found in the struts web xml file or, by default, is the class name without the Action part), and a call link to the "editBook" method. The "do" after the "?" is found in the struts web xml file in the "parameter" field of the "action" tag. The same is done for every method of the class.
Example of a struts-config.xml:
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd"> <struts-config> <action-mappings > <action attribute="bookEditForm" input="/jsp/bookEdit.jsp" name="bookEditForm" parameter="do" path="/bookEdit" scope="request" type="com.library.struts.action.BookEditAction"> <forward name="showBorrow" path="/jsp/borrowBook.jsp" /> <forward name="showEdit" path="/jsp/bookEdit.jsp" /> <forward name="showList" path="/bookList.do" redirect="true" /> <forward name="showAdd" path="/jsp/bookAdd.jsp" /> </action> </action-mappings> </struts-config>}
Results:
Supported Apache Struts versions
Apache Struts | Supported |
---|---|
1.x | |
2.x |
Supported client frameworks
- Function Points (transactions): a green tick indicates that OMG Function Point counting and Transaction Risk Index are supported
- Quality and Sizing: a green tick indicates that CAST can measure size and that a minimum set of Quality Rules exist
Function Points (transactions) | Quality and Sizing |
---|---|
CAST AIP release | Supported |
---|---|
8.3.x | |
8.2.x | |
8.1.x | |
8.0.x | |
7.3.4 and all higher 7.3.x releases |
Supported DBMS servers
This extension is compatible with the following DBMS servers:
CAST AIP release | CSS | Oracle | Microsoft |
---|---|---|---|
All supported releases |
Prerequisites
An installation of any compatible release of CAST AIP (see table above) |
Dependencies with other extensions
Some CAST extensions require the presence of other CAST extensions in order to function correctly. The Apache Struts extension requires that the following other CAST extensions are also installed:
- JEE Analyzer
- HTML5/JavaScript extension
- Web Services Linker
- com.castsoftware.internal.platform (internal extension)
Note that:
- when using the CAST Extension Downloader to download the extension and the Manage Extensions interface in CAST Server Manager to install the extension, any dependent extensions are automatically downloaded and installed for you. You do not need to do anything.
- the JEE Analyzer is not a dependency, but since this extension is always installed with AIP, you do not need to do anything.
Download and installation instructions
Please see:
The latest release status of this extension can be seen when downloading it from the CAST Extend server.
CAST Transaction Configuration Center (TCC) setup
If you are using the extension with CAST AIP ≥ 8.3.x, an Apache Struts specific setup is automatically imported when the extension is installed. These items will be available in the CAST Transaction Configuration Center:
Manual import action for CAST AIP ≤ 8.2.x
If you are using the extensions with CAST AIP ≤ 8.2.x, you can manually import the TCC setup, should you want to:
Packaging, delivering and analyzing your source code
Once the extension is installed, no further configuration changes are required before you can package your source code and run an analysis. The process of packaging, delivering and analyzing your source code does not change in any way:
- Package and deliver your application in the exact same way as you always have. You can refer to the existing official CAST AIP documentation for more information about this - see: Prepare and deliver the source code.
- Analyze your delivered application source code in the CAST Management Studio in the exact same way as you always have. You can refer to the existing official CAST AIP documentation for more information about configuring an analysis - see: Analysis Configuration and Execution
What results can you expect?
Objects
The following objects are displayed in CAST Enlighten:
Icon | Description |
---|---|
Struts Operation |