Minter_685-4App.fm Page 229 Wednesday, November 7, 2007 1:49 PM

APPENDIX ■ ■ ■ The Spring IDE Plug-in for

The Spring IDE plug-in for Eclipse enhances the Eclipse environment by providing a variety of features that make it easier to work with Spring projects. The Spring IDE provides tools for creating, validating, viewing, and editing your Spring configuration files. A particu- larly attractive feature is the provision of autocompletion when editing bean definitions. Although the Spring IDE is a separate project from Spring itself, there are developers who participate in both projects, so there is excellent support for the latest Spring features. In this appendix, I discuss the installation of the Spring IDE and then briefly present the features related to editing and viewing bean and Spring Web Flow definitions. It is not possible to discuss all of the Spring IDE features in depth in this appendix. I would recommend installing and working with the plug-in initially as an aid to the creation of bean definition files. The autocompletion feature works in a manner nearly identical to the Java source autocompletion features. After you are familiar with these aspects of the plug-in, you should visit the Spring IDE website (http://springide.org/) to learn more about the tool.

Installing the Plug-in

Although it is possible to download the Spring IDE components and install them manually, by far the easiest way to install the Spring IDE into Eclipse is to use the built-in Software Updates feature of the Eclipse environment. Version 2 of the Spring IDE supports versions of Spring up to and including Spring 2.1 and up to version 1 of Spring Web Flow. You will need at least version 3.2 of the Eclipse IDE in order to use version 2 of the Spring IDE, but unless you already have an established 3.2 Eclipse environment, you should start with version 3.3 of Eclipse released as a set of inte- grated environments called Europa. I would not advocate a migration to Eclipse 3.3 unless you are confident that all of your plug-ins are compatible with the newer version; Spring IDE works well in the Eclipse 3.2 environment if you are in this position, so it is safer to stay

229 Minter_685-4App.fm Page 230 Wednesday, November 7, 2007 1:49 PM

230 APPENDIX ■ THE SPRING IDE PLUG-IN FOR ECLIPSE

with a known-good environment. To use Spring IDE to its fullest potential, you should install the Eclipse IDE for Java EE Developers Europa release because this includes Web Standard Tools (WST) components that support XML parsing—necessary for use of the bean editing support. As Figure A-1 shows, the Software Updates feature is accessed from the Eclipse Help menu. Choose Software Updates ➤ Find and Install to start the installation wizard.

Figure A-1. Starting the installation process

The first page of the installation wizard, shown in Figure A-2, prompts you to select updates to existing features or to search for new features. To acquire the latest updates to an already-installed Spring IDE environment, you would select the first of these options. However, upon the initial installation you should select the Search for New Features to Install option and click the Next button.

Figure A-2. Installing new features

In the next wizard (not shown), click the New Remote Site button and then enter the details exactly as shown in Figure A-3. Minter_685-4App.fm Page 231 Wednesday, November 7, 2007 1:49 PM

APPENDIX ■ THE SPRING IDE PLUG-IN FOR ECLIPSE 231

Figure A-3. Specifying the update site details

The Name field in Figure A-3 is an arbitrary name that will be shown in subsequent pages of the installer, but the URL field is used to obtain the installation files and must be entered verbatim as http://springide.org/updatesite/. After you click the OK button, the next page will show a list of the update sites known to the Eclipse update installer, with only the Spring IDE site selected (if any other entries are selected, deselect them). Click Finish, and the installer will check the Spring IDE site for the features that are available from it. After the installer has obtained the list of features, they will be shown in the Updates dialog box. If you expand the tree view of features to install, the dialog should look much like Figure A-4, but with the Integrations features selected. If the page presents any error messages, deselect the tools that cannot be installed.

Figure A-4. Selecting the feature set to install Minter_685-4App.fm Page 232 Wednesday, November 7, 2007 1:49 PM

232 APPENDIX ■ THE SPRING IDE PLUG-IN FOR ECLIPSE

At the time of this writing, the AspectJ Development Tools component (AJDT) is not compatible with the Europa release of Eclipse, and the Mylyn integration tool is unlikely to be of immediate interest, so I have disabled their installation as shown in Figure A-4. Click Next, and you will be prompted to accept the license agreement for the tools. After you have accepted this, the installation will proceed. The installation files are not “signed,” so you will need to click Install when a dialog warns you of this. Finally, select Yes when you are asked whether you would like to restart the Eclipse environment. The Spring IDE plug- in is now installed.

Managing Bean Configurations

As you have seen throughout this book, a large part of your work with Spring involves either the editing of conventional Java code (for which existing language support in most IDEs is adequate) or the editing of XML bean definition files. To gain the benefits of the Spring IDE in managing these files, you need to add the Spring Project Nature to your Eclipse projects. Figure A-5 shows the standard Eclipse Project Explorer view of a set of projects gener- ated by using Maven’s eclipse:eclipse target. Currently these are decorated with two icons, a J symbol at the top right indicating that they are Java projects, and a standard warning symbol at the bottom left indicating that there are minor problems with the project configuration.

Figure A-5. An Eclipse project without the Spring Project Nature

■Caution Although you can generate Eclipse-compatible project definitions by using the Maven tool’s eclipse:eclipse build target, it cannot currently generate Spring IDE–compatible projects. You will need to apply and configure the Spring Project Nature manually. Once configured, the eclipse:eclipse target will not overwrite these settings, but the eclipse:clean build target to remove stale project definitions will remove them, which is often undesirable, so you may want to avoid using this target unless your project configuration has become irretrievably corrupt. Minter_685-4App.fm Page 233 Wednesday, November 7, 2007 1:49 PM

APPENDIX ■ THE SPRING IDE PLUG-IN FOR ECLIPSE 233

Right-click on each project in turn and choose the Apply Spring Project Nature option from the context menu. After performing this action, you will see the decoration in the top- right corner change from the J to an S, indicating that this is now a Spring project (a Spring project is always a Java project also, so the J decoration is no longer required). The resulting look is shown in Figure A-6.

Figure A-6. An Eclipse project with the Spring Project Nature

If you open one of the projects, as shown in Figure A-7, you will see that an additional entry has been added to the project details in the Project Explorer. This will represent the Spring-specific configuration details of your project. However, it is not automatically populated with entries.

Figure A-7. The Spring Elements node within a Spring project

Although the Spring Elements option is shown by default as a branch of the Project Explorer, it can be opened as a view in its own right by choosing the Window ➤ Show View ➤ Other ➤ Spring ➤ Spring Explorer menu option. To configure your bean configuration files for inclusion in the Spring Elements view, choose the Properties option from the Spring Elements leaf’s context menu, or open the project’s context menu, choose Properties, and select the Spring node in the tree on the left-hand side. Either way, you will be presented with a dialog box corresponding to Figure A-8. Minter_685-4App.fm Page 234 Wednesday, November 7, 2007 1:49 PM

234 APPENDIX ■ THE SPRING IDE PLUG-IN FOR ECLIPSE

Figure A-8. Configuring the Spring-specific project properties

The default page for this menu option allows you to enable and disable the various types of validation that will be used to check your bean definition files for errors. Usually you will leave the default options for validation and for the (hidden) project builders options. However, on large projects you may find that the validation can make the IDE less respon- sive, so you may want to disable some of the more rigorous options in this situation. Select the Beans Support option from the left-hand menu, and you will be presented with the Beans Support dialog box. Click the Add button to select the bean configuration files. This action tells the Spring IDE which bean configurations are relevant to your project (and indeed which XML files are bean configurations in the first place—the IDE does not attempt to autodetect bean configuration files). Figure A-9 shows the bean configuration files of the timesheets-webapp project selected from the Beans Support menu. Returning from this dialog to the Project Explorer window shown in Figure A-10, the Spring Elements branch of the project’s tree has been populated with the details of the configuration files, of the Spring beans defined within them, and of the properties assigned to those beans. Minter_685-4App.fm Page 235 Wednesday, November 7, 2007 1:49 PM

APPENDIX ■ THE SPRING IDE PLUG-IN FOR ECLIPSE 235

Figure A-9. Specifying the bean definition files for the project

Figure A-10. Viewing the bean definitions within the Spring project

Prior to the installation of the Spring IDE, if you were to attempt to use autocompletion within one of the Spring bean definition files, you would be presented with the basic XML autocompletion options shown in Figure A-11. These are better than nothing, but are really of very limited help when creating these files. Minter_685-4App.fm Page 236 Wednesday, November 7, 2007 1:49 PM

236 APPENDIX ■ THE SPRING IDE PLUG-IN FOR ECLIPSE

Figure A-11. Autocompletion of a bean definition in a typical Eclipse Java EE project

After the installation of the Spring IDE plug-in, you will find that autocompletion provides a much richer experience. Figure A-12 illustrates the options available when you use autocompletion on a property name. Without carrying out the registration of the bean configuration files via the Bean Support menu option described earlier, you will also have access to all of the bean names local to the file when populating references, and after regis- tering the configuration files, you will have access to bean references throughout the suite of configuration files.

Figure A-12. Autocompletion of a bean definition in a Spring project

The Spring IDE is also “schema aware,” allowing it to take advantage of the schema- based property specifications described in Chapter 3. Figure A-13 shows an example of autocompletion of a property defined in this manner. The features described so far allow you to manage the process of creating the bean defi- nitions, and the Spring Elements explorer branch (or the Spring Explorer view) provide some benefits in visualizing and navigating the configuration files. Double-clicking on the various nodes within the Spring Elements branch allows you to open a view on the corre- sponding configuration file positioned to the appropriate line for the detail that the node represents. Right-clicking provides a context menu that (where appropriate) allows you to open the Java source code corresponding to the bean in question. Minter_685-4App.fm Page 237 Wednesday, November 7, 2007 1:49 PM

APPENDIX ■ THE SPRING IDE PLUG-IN FOR ECLIPSE 237

Figure A-13. Autocompletion of schema-based properties

In addition to the normal Spring Explorer view of the beans, there is an Open Graph context menu option on the nodes within the Spring Explorer. Selecting this option presents a read-only graphical representation of the dependencies established by the defi- nition files. Figure A-14 shows part of a graph of the bean dependencies established by the timesheet-webapp project’s applicationContext.xml bean definition file.

Figure A-14. A graphical view of a set of bean definitions Minter_685-4App.fm Page 238 Wednesday, November 7, 2007 1:49 PM

238 APPENDIX ■ THE SPRING IDE PLUG-IN FOR ECLIPSE

Managing Spring Web Flow Configuration

Having looked at the bean configuration files, we will now take a look at the support for the Spring Web Flow web application framework. The Spring IDE provides an option under the Spring properties dialog box. Figure A-15 shows this dialog. The left menu is abbreviated because it has been accessed via the Spring Elements context menu instead of the top-level project’s context menu; otherwise, the dialogs of Figure A-8 and A-15 are identical in their behavior. Figure A-15 shows the Web Flow Support leaf selected, and a Web Flow configuration file has been added via the Add button. So far this is similar to the addition of bean definition files on the Beans Support node of the same dialog.

Figure A-15. Configuring a web flow definition

The configuration file selected in Figure A-15 is the flow definition file used to specify the interactions necessary to create a new user. We defined this file manually in Chapter 6. Minter_685-4App.fm Page 239 Wednesday, November 7, 2007 1:49 PM

APPENDIX ■ THE SPRING IDE PLUG-IN FOR ECLIPSE 239

The web flow has dependencies on the configured Spring beans. For example, our web flow defined in the createUser-flow.xml file invokes actions on a bean specified in the timesheet-webflow.xml bean definition file. Clicking the Edit button in Figure A-15 brings up the dialog box shown in Figure A-16, listing the bean definition files known to the project. Selecting appropriate bean definitions makes their contents available for access from the web flow definition.

Figure A-16. Adding bean definition dependencies to a web flow definition

With the web flow and its dependencies correctly specified, we get a similar range of benefits to those for bean definitions described earlier in the chapter—creating, validating, viewing, and editing your web flows. In Figure A-17, I have commented out a vital element of the web flow definition file. The error is flagged in the margin, and the first incorrect element has been underlined in red (a view-state element should not appear until a start-state element has been defined). Autocompletion is also provided for most of the elements and attributes of the file—and where bean-related information must be provided, the autocompletion can supply the valid options from the bean definition files that we associated with the web flow.

Figure A-17. Validation errors in the web flow definition Minter_685-4App.fm Page 240 Wednesday, November 7, 2007 1:49 PM

240 APPENDIX ■ THE SPRING IDE PLUG-IN FOR ECLIPSE

The same warning shown in Figure A-17 will appear as a problem for resolution in the standard Eclipse Problems view, as shown in Figure A-18. Working on Java source code, Spring bean definition files, and Spring web flow definition files becomes a part of the same work flow.

Figure A-18. Web flow definition validation errors in the Problems view of the project

If you select the context menu for the web flow definition in the Spring Elements tree, you will see an option for Open Graphical Editor. If you select this option for the createUser-flow.xml web flow, the graphical view of the web flow shown in Figure A-19 will appear. If you look back to Figure 6-2 in Chapter 6, you will see that this is a slightly more technical view of essentially the same state transition diagram.

Figure A-19. A graphical view of the createUser web flow

This ability to view the state defined by the web flow is a useful feature when verifying your web flow against the initial design, but it is more than that. Unlike the bean definition graph, this is an editable diagram, and the changes you make will be represented in the underlying configuration file. Minter_685-4App.fm Page 241 Wednesday, November 7, 2007 1:49 PM

APPENDIX ■ THE SPRING IDE PLUG-IN FOR ECLIPSE 241

For example, if you double-click on the starting createUser state at the top of the graph, you will be presented with the View State dialog box shown in Figure A-20.

Figure A-20. A dialog allowing you to edit details of the createUser view state

This is an exact representation of the corresponding state definition reproduced in Listing A-1. The first line of Listing A-1 specifies the id property of the state and the name of the view that represents it, which are both visible in Figure A-20. The Render Actions tab hidden in Figure A-20 contains the values corresponding to the render-actions element of Listing A-1.

Listing A-1. The Create User Flow Definition in XML Form

Minter_685-4App.fm Page 242 Wednesday, November 7, 2007 1:49 PM

242 APPENDIX ■ THE SPRING IDE PLUG-IN FOR ECLIPSE

The first of the transitions specified in Listing A-1 moves the flow from the createUser state when a preview event is raised. Double-clicking the arrow representing this transi- tion (drawn between createUser and previewUser in Figure A-19) brings up the Transition dialog box shown in Figure A-21. The originating and destination states are visible in the diagram, and the event that causes the transition in question is shown in the dialog. This information can also be acquired by hovering the cursor over the box containing a green triangle symbol that decorates this transition line, but the dialog allows the details of the transition to be changed as well as viewed.

Figure A-21. A dialog allowing you to edit details of the preview state transition

In addition to editing the existing elements of the web flow definition, we can create new elements by using the graphical tool. On the right-hand side of the graph is a Palette tool that can be expanded by selecting it with the cursor. This contains a list of elements that can be dropped onto the graph, as shown in Figure A-22. The palette contains all of the elements that can be created within the web flow defini- tion files, so you can create any of the contents of the file by using the GUI tool if you wish. Minter_685-4App.fm Page 243 Wednesday, November 7, 2007 1:49 PM

APPENDIX ■ THE SPRING IDE PLUG-IN FOR ECLIPSE 243

Figure A-22. The palette allowing new web flow details to be created

Using File-Creation Wizards

Three wizard tools are provided with the Spring IDE plug-in. The wizards are reached via the New ➤ Other ➤ Spring context menu option. They allow you to create the following:

• New Spring bean definition files

• New web flow definition files

• New projects with the Spring Project Nature

The bean definition wizard allows you to specify the name and location of the configu- ration file within the project and the set of XML Schema Definition declarations to include in the file (shown in Figure A-23). The wizard also allows you to add the new file to existing groupings of configuration files. Minter_685-4App.fm Page 244 Wednesday, November 7, 2007 1:49 PM

244 APPENDIX ■ THE SPRING IDE PLUG-IN FOR ECLIPSE

Figure A-23. Adding XSD namespace declarations to a new bean definition file

The flow definition file–creation wizard allows you to specify the name of the definition file and the set of Spring bean definition files that it depends on. The Spring project–creation wizard essentially allows you to specify only the project name, and is thus rather less versatile than the existing Java project wizards. Of the three, the two configuration file–creation wizards are the most useful because they enable you to avoid the error-prone task of copying boilerplate file content into the new files and of separately configuring the project to include them.

Conclusion

The Spring IDE is a rapidly growing tool that will soon justify a book dedicated to the subject if it has not already. It is not possible in a single chapter to give you more than a taste of the features that are offered, but even the limited parts of the Spring IDE that I have been able to cover here should give you more than enough reason to install and use the tool, and to investigate its capabilities further. Minter_685-4INDEX.fm Page 245 Thursday, November 15, 2007 2:30 PM

Index

■A allowIfAllAbstainDecisions property, 143 AbstractFormController class, 126 alwaysUseDefaultTargetUrl property, 142 AbstractWizardFormController class, 126 andReturn(), 222 AcceptHeaderLocaleResolver, 135 AnnotationConfiguration class, 70 Access Denied page, 144 annotations accessDecisionManager property, 155 annotation-based configuration in Account object, 64 Spring, 47 accountName attribute, 67, 180 Java 5 and, 47 accountParameterOperation(), 96 AnnotationSessionFactoryBean, 71 accountServiceOperation(), 96 anonymous processing filter, 142 accountTimesheetOperation(), 96 anonymous role, 144 Acegi Security. See AntPathMatcher class, 112 Acegi tag library aop:after-returning element, 91 importing into a JSP, 152 aop:aspect element, 89–90 restricting page content to aop:-autoproxy element, 94 administrators, 152 aop:before element, 90 AcegiGrantedAuthority class, 148 aop:config element, 85, 89, 91 action aop: element, 89 definition of, 122 , 20 points of invocation in a web flow, 122 Apache Axis, 186 Action interface, implementing, 122–123 Apache Struts, 10 ActionForm class, 125 Apache Tapestry, 10 class, 98 ApplicationContext advice, definition of, 86 interfaces extended by, table of, 52 @After annotation, 96 using as a starting point for creating afterPropertiesSet(), 47–48 Spring applications, 53 @AfterReturning annotation, 96–97 applicationContext.xml, 173, 237 @AfterThrowing annotation, 96 Apply Spring Project Nature option, 233 agile programming, 5 arg-names attribute, 90 You Ain’t Gonna Need It (YAGNI) @Around annotation, 96 principle, 59 aspect, definition of, 86 See also aspect-oriented programming AspectJ, 6–7, 98 (AOP) 245 Minter_685-4INDEX.fm Page 246 Thursday, November 15, 2007 2:30 PM

246 ■INDEX

@AspectJ annotations, Spring’s support configuring a pointcut for the timesheet for, 94 service advisor, 88 AspectJ Development Tools (AJDT), 232 configuring a proxy factory bean with an aspect-oriented programming (AOP) interceptor, 99 accountParameterOperation(), 96 configuring an advice class as a Spring bean, 89 accountServiceOperation(), 96 configuring an after returning advice with accountTimesheetOperation(), 96 a dynamic pointcut, 104 Advice class, 98 configuring an after returning advice with advice implementation class and a static pointcut, 103 methods, 89 creating a MethodInvocation object, 98 advice, definition of, 86 creating Advice and Pointcut objects advisor configuration, 102 independently, 100 @After annotation, 96 creating advice objects in code, 98 @AfterReturning annotation, 96–97 cross-cutting concern, definition of, 86 @AfterThrowing annotation, 96 declarative transaction management, allowing custom extensions to code example, 6 configuration schema, 87 declaring and configuring an advice annotated advice implementation implementation, 87 class, 96 defining a pointcut, 90 aop:after-returning element, 91 dynamic , implementing, 103 aop:aspect element, 89–90 extending the aop:aspectj-autoproxy element, 94 StaticMethodMatcherPointcut aop:before element, 90 interface, 101 aop:config element, 89, 91 findTimesheet(), 88, 90, 104 aop:pointcut element, 89 findTimesheetOperation(), 96 applying the aspect configuration with implementing a before advice, 100 @AspectJ annotations, 94 implementing a method interceptor arg-names attribute, 90 advice, 98 @Around annotation, 96 implementing an after returning advice, 101 aspect, definition of, 86 including the pointcut and advice AspectJ, 6–7 annotations in the same class, 98 AspectJ library, 98 listTimesheets(), 88–90, 92, 96 @Before annotation, 96–97 matches(), 102–103 CGLIB code-generation library, 100 methods to secure calls to the service layer checking the return value of interface, 88 findTimesheet(), 92 object-oriented programming (OOP) checking user access to the returned and, 6 timesheet, 93 pointcut, definition of, 86 code weaving, 98 @Pointcut annotation, 96 common uses for, 7 pointcut-ref attribute, 90–91 complete aspect definition, 91 Minter_685-4INDEX.fm Page 247 Thursday, November 15, 2007 2:30 PM

■INDEX 247

returning attribute, 91 Java Authentication and Authorization schema-based transaction declaration, 87 Service (JAAS), 149 single-line annotation configuration, 87 Lightweight Directory Access Protocol (LDAP), 149 Spring AOP, 6 other providers of authentication and Spring’s support for @AspectJ authorization resources, 149 annotations, 94 preventing access to another user’s static pointcuts, definition of, 101 private information, 153 timesheetReturningOperation(), 96 Provider class, 145 TimesheetSecurityAdvice object, 100 ProviderManager class, 145 TimesheetService class, 90, 96, 102 Remote Client Protocol (RCP), 149 tx: prefix on elements, 87 retrieving the UserAccount principal, 154 tx:advice element, 88 retrofitting Acegi to legacy designs, 148 types of advice that can be declared, 93 ROLE_ANONYMOUS role, 146 types of problems handled by, 86 SecurityContextHolder class, 153–154 using a DefaultPointcutAdvisor SiteMinder, 149 object, 100 storing authentication information within using a ProxyBeanFactory object to apply a request context, 153 an interceptor implementation, 98 UserAccount class, 148 using existing AOP libraries in Spring, 6 UserDetails interface, 147–148 using explicit implementations, 98 UserDetailsService interface, 147, 149 XML namespace extension facilities, 87 username anonymous, 146 See also agile programming X.509, 149 attributes bean, 155 See also channel security; Spring Security authentication authenticationFailureUrl property, 142 AcegiGrantedAuthority class, 148 authentication-processing filter, 142 authentication manager, configuring, 145 authorization, definition of, 137 Central Authentication Services (CAS), 149 autocompletion, 229, 235, 239 checking an authenticated user’s name against a data request, 153 autowiring configuring an anonymous authentication advantages and disadvantages of, 40 provider, 146 automatically determining the DAO authentication provider, code dependencies to inject, 40 example, 146 autowire attribute, table of values, 41 DaoAuthenticationProvider class, 146 definition of, 40 definition of, 137 extracting a bean from a factory by distinguishing a principal from a user type, 40 account, 145 factory configuration example using getAuthorities(), 148 autowiring, 40 getContext(), 153 identifying a view resolver, 115 GrantedAuthority interface, 148 mixing autowiring and explicit wiring of beans, 41 Minter_685-4INDEX.fm Page 248 Thursday, November 15, 2007 2:30 PM

248 ■INDEX

■B injecting a string property value, 42 bean definition wizard, 243 injecting ambiguously typed constructor element, 87 parameters, 45 BeanFactory ListableBeanFactory, 52 ApplicationContext, 52 ListFactoryBean, 46 automatically determining the manufacturing bean instances and dependencies to inject, 40 configuring their dependencies, 35 autowire attribute, table of values, 41 methods called on bean initialization, table of, 49 autowiring, advantages and disadvantages of, 40 methods called on shutdown, table of, 51 bean factories and XML configuration mixing autowiring and explicit wiring of files, 38 beans, 41 collection classes, 43 populating a factory with all relevant bean definitions, 38 configuring a bean with a single property, 41 programmatically assigning bean definition information, 37 configuring a constructor parameter, 45 providing a constructor-arg element configuring beans as singletons, 42 body, 45 configuring properties from XML as ref attribute, 42 elements, 42 ResourceLoader, 53 configuring two bean definitions for one implementation class, 37 RootBeanDefinition, 37 constructing manually, code example, 35 scope attribute, 42 containers and, 34–35 ServletContextAware, 51 creating a Spring bean factory from an setServletContext(), 51 XML file, 39 Spring beans and standard Java beans, 35 DefaultListableBeanFactory, 52 Spring configuration of a list property, 44 defining collections using the util Spring configuration of a map property, 43 namespace, 46 Spring configuration of a set property, 44 defining property values using the syntax for configuring references, 42 property namespace, 46 table of methods, 35 dependency lookup versus dependency using Java 5 generics in method injection, 39 signatures, 43 establishing a DefaultListableBeanFactory using PropertyEditor implementations, 42 instance, 37 value attribute, 42 examining the life cycle of beans and the bean factory, 49 WebApplicationContext, 52 extracting a bean from a factory by XML bean definitions as describing type, 40 singletons, 39 factory configuration example using beans autowiring, 40 afterPropertiesSet(), 47 getBean(), 37 ApplicationContext, 52 InitializingBean, 52 DefaultListableBeanFactory, 52 Minter_685-4INDEX.fm Page 249 Thursday, November 15, 2007 2:30 PM

■INDEX 249

ensuring that a bean’s required setters ■C have been called, 48 Caucho Technology, comparing Hessian and examining the life cycle of beans and the Burlap, 178, 182, 185 bean factory, 49 Central Authentication Services (CAS), 149 InitializingBean, 47, 52 channel decision manager, 151 ListableBeanFactory, 52 channel security methods called on bean initialization, accepting connections only on a secure table of, 49 port, 149 methods called on shutdown, table of, 51 amended filter invocation definition omitting a vital property from a bean source, 150 definition, 47 bean definitions for two channel ResourceLoader, 53 processors, 151 ServletContextAware, 51 channel decision manager, setServletContext(), 51 configuring, 151 verifying property values after injection channel-processing filter, defining, 150 using afterPropertiesSet(), 48 configuring a new PortMapperImpl WebApplicationContext, 52 bean, 152 Beans Support dialog box, 234 defining the required channel security level, 151 @Before annotation, 96–97 definition of, 137 bindAndValidate(), 125 filterInvocationDefinitionSource BindException object, 117–118 property, 151 bindOnNewForm attribute, 126 performance disadvantages of Burlap encrypting/decrypting advantages of its remoting communications, 150 mechanism, 178 portMappings property, 152 BurlapServiceExporter class, 184 REQUIRES_INSECURE_CHANNEL, 151 configuring a Burlap client proxy REQUIRES_SECURE_CHANNEL, 151 factory, 184 securing exchanges with a web configuring a Burlap implementation and application, 149 exporter beans, 184 securing only sensitive information, 150 configuring a dispatcher servlet, 182 using a default PortMapper defining a remote service interface, 183 implementation, 152 implementing a Burlap client, 184 using the Secure Sockets Layer (SSL) invoking a remote Burlap service from a encryption protocol, 149 client, 184 See also authentication; Spring Security transporting Hibernate entity classes cid: prefix, 167 across a network, 183 classpath: prefix, 109 using when a client device is memory ClassPathXmlApplicationContext, 54 constrained, 179 clear(), 202, 208 wrapping service implementation, 183 collection classes, 43 See also Hessian @Column annotation, 67 BurlapServiceExporter class, 184 Minter_685-4INDEX.fm Page 250 Thursday, November 15, 2007 2:30 PM

250 ■INDEX

command object SimpleFormController, 113–114 binding incoming form submissions See also Model View Controller (MVC); view to, 113 controller classes binding request parameters to, 113 mapping dispatcher URLs to, 112 definition of, 126 Spring MVC framework and, 8 fields populated by the controller, 126 CookieLocaleResolver, 135 maintaining the content of, 126 CORBA, 190 Common Client Interface (CCI), 56 coupling Common Object Request Broker dependency injection from conventional Architecture. See CORBA code, 34 ConfigHelper interface, 196, 201–202 implementation with two dependencies, @Configurable annotation code example, 32 uses for, 48 loose coupling, advantages of, 32 using AspectJ-specific AOP facilities, 49 loose coupling, code example, 31 Configuration class, 70 selecting candidates for making a configuration files (Spring) dependency injectable, 32–34 properties files (resource bundles), 26 tight coupling, code example, 31 using XML files for, 26 Create Timesheet page, 18 web.xml, 26 create(), 200 WEB-INF directory for Java EE create-drop parameter, 208 configuration files, 26 createMimeMessage(), 213 constructor injection, 45 createMock(), 221 constructor-arg element, 45 createTimesheet(), 82 ContextLoaderListener, 109 createUser state, 242 ContextLoaderServlet, 109–110 createUser.jsp, 125 contexts CreateUserAction bean, 123 context loader servlet, configuring, 109 createUser-flow.xml, 121, 239–240 ContextLoaderListener, 109 cross-cutting concern, definition of, 86 context-param entry, 108, 110 CRUD operations, DAO implementations load-on-startup parameter, 109 and, 58 managing other daughter contexts, 110 ■D Spring MVC dispatcher servlet, 110 DaoAuthenticationProvider class, 146 using lazy loading to initialize servlets, 109 DaoSupport class, 60 controller data access objects (DAOs) configuring a simple form controller, 114 accessing multiple DAO classes, 76 configuring a view controller for a single comparing the DAO support classes and page, 113 template classes, 60 definition of, 108 correlation of the DAO and service implementing a user list controller, 114 layers, 75 referenceData(), 114 Minter_685-4INDEX.fm Page 251 Thursday, November 15, 2007 2:30 PM

■INDEX 251

DAO layer, 56 DefaultListableBeanFactory, 37, 52 DaoSupport class, 60 DefaultPointcutAdvisor, 100 data access architecture, 56 defaultTargetUrl property, 142 data access layer, definition of, 15 DelegatingActionProxy, 10 data store (relational database), 56 DelegatingFilterProxy, 139–140 database tables for the UserAccount and DelegatingRequestProcessor, 10 UserRole entities, 58 “deny by default” rule, 138 DataSource, 60 dependencies element, 21 entities serviced by the DAO classes, 56 dependency injection (DI) grouping access to multiple data advantages and disadvantages of, 29 sources, 76 dependency injection from conventional grouping functionality for use by higher code, 34 layers, 76 detecting type inconsistencies at helper classes for supported database build-time, 30 access mechanisms, 60 inversion of control and, 29 Hibernate ORM framework, 55 losing the advantages of static type implementing the database access logic checking, 29 within DAO classes, 56 making applications loosely coupled, 30 interface for DAO implementations with providing dependencies from outside a CRUD operations, 58 class, 29 JDBC API, 55 selecting candidates for making a persistence APIs, 55 dependency injectable, 32–34 service layer, 56 Spring and dynamic type checking, 30 Spring’s support for building DAO unit testing and, 5 implementations, 59 using a framework for injecting Spring’s support for DAO classes, 10 dependencies, 29 template classes, 60 See also inversion of control (IOC) testing a DAO layer, 195 dependency lookup, 3–4 tests for the user account DAO, 195 DispatcherServlet UserAccount class, 56–57 configuring, 110 UserRole class, 56 loading HandlerMapping by See also JDBC (Java Database autowiring, 111 Connectivity) documentation data transfer objects (DTOs), 180 downloading documentation for the DataSource, 60–61, 63 , 11 DataSourceTransactionManager, 80 Javadoc API, 11 DataSourceUtils, 80 Don’t Repeat Yourself (DRY) principle, 5 declarative transaction management, code DriverManagerDataSource, 63 example, 6 dynamic pointcuts, 103 Minter_685-4INDEX.fm Page 252 Thursday, November 15, 2007 2:30 PM

252 ■INDEX

■E Spring Explorer, Open Graph context eager loading, 72 menu option, 237 EasyMock Updates dialog box, 231 createMock(), 221 using the Europa release, 229 creating a unit test suite, 219 using version 3.2 or greater of the Eclipse IDE, 229 generating mock objects, 219 Web Standard Tools (WST), 230 validating the results of the service method call, 222 eclipse:clean target, 232 Eclipse eclipse:eclipse target, 232 adding the Spring Project Nature to e-mail Eclipse projects, 232 abstract base class for the MailDAO applicationContext.xml, 237 implementations, 160 Apply Spring Project Nature option, 233 accepting a Resource object in preference to file paths, 169 AspectJ Development Tools (AJDT) component, 232 alternatives for adding files to an outgoing message, 169 autocompletion, 229, 235, 239 cid: prefix, 167 Beans Support dialog box, 234 configuring a JavaMailSender bean configuring bean configuration files for implementation, 159 the Spring Elements view, 233 configuring an image-aware DAO Eclipse IDE, Java Development Tools implementation, 169 edition, 11 constructing a SimpleMailMessage eclipse:clean target, 232 object, 158 eclipse:eclipse target, 232 creating HTML markup and adding Help menu, 230 dynamic data, 163 importing Maven projects into, 25 DAO implementation supporting installing the Eclipse IDE for Java EE attachments and inline images, 167 developers, 230 e-mail DAO interface, 157 installing the Spring IDE plug-in, 11, e-mail DAO tests, 209 229–232 getAccountName(), 163 mvn eclipse:eclipse command, 24 getConsultant(), 163 New Remote Site button, 230 having access to an SMTP mail Project Explorer, 232–233 gateway, 160 Search for New Features to Install including inline images and option, 230 attachments, 166 setting the M2_REPO classpath inlineImage identifier, 167 variable, 25 JavaMailSenderImpl, 159 Software Updates feature, 229 MailException, 161 specifying the bean definition files for a MailMessage, 158 project, 234 MimeMessageHelper, 166 Spring Elements option, 233 MimeMessagePreparator, 165 Minter_685-4INDEX.fm Page 253 Thursday, November 15, 2007 2:30 PM

■INDEX 253

Multipurpose Internet Mail Extensions _eventId parameter, 125 (MIME), 158 exception attribute, 119 notifying users of changes to an exception handling application environment, 157 configuring exception resolution, 119 objections to using references to isErrorPage attribute, 119 externally hosted materials, 166 LazyInitializationException, 133 passing a MimeMessage, 165 MailException, 161 prepare(), 165, 169 rolling back transactions for rcptAddress property, 162 checked/unchecked exceptions, 83 RFC 1738 URL address specification, 167 Spring MVC and, 118 send(), 158, 161 exceptionResolver, 119 sending e-mail containing HTML markup exception-translation filter, 144 or attachments, 158 expect(), 222 sending HTML-formatted e-mail, 163 Extreme Programming (XP), 5 sending plain-text e-mail, 160 sendTimesheetUpdate(), 161–162 ■F setText(), 166 FilterChainProxy, 139–140, 144 simple DAO for sending an HTML e-mail, filterInvocationDefinitionSource property, 164–165 141, 151 simple mail DAO, configuring and filters implementing, 161 accessing the /login URL, 142 SimpleMailMessage class, 158 Acegi filters, configuring, 139 Spring JavaMailSender interface, allowIfAllAbstainDecisions property, 143 158–159, 165 alwaysUseDefaultTargetUrl property, 142 Spring MailSender interface, 158–159, 165 amended filter invocation definition text/html content type, 166 source, 150 text/plain content type, 166 anonymous processing filter, code timesheet service bean configuration, 157 example, 142 using a classpath-relative resource, 169 authenticationFailureUrl property, 142 using the mail sender, 158 authentication-processing filter, code Velocity macro for sending a simple HTML example, 142 e-mail, 163 channel-processing filter, defining, 150 Velocity macro with a URI referencing configuring a delegating filter proxy, 134 inline content, 167 configuring the filter chain proxy, 141 Velocity markup language, 163 declaring the Spring velocityEngine bean, configuration OpenSessionInViewFilter, 133 details, 165 defaultTargetUrl property, 142 @Entity annotation, 67 defining the finest-grained URL patterns erasure, 127 first, 141 Errors object, 118 defining which roles can access which errors tag, 131, 135 URLs, 144 Minter_685-4INDEX.fm Page 254 Thursday, November 15, 2007 2:30 PM

254 ■INDEX

DelegatingFilterProxy, 139–140 flow registry, 121, 126 exception-translation filter, code forceHttps flag, 144 example, 144 foreign key, 68 FilterChainProxy, 139–140, 144 form prefix, 130 filterInvocationDefinitionSource FormAction class, 123 property, 141, 151 forms FilterSecurityInterceptor, 145 browser-side versus client-side FilterToBeanProxy, 140 validation, 117 handling a successful authentication but a rejecting either a single field or a whole failed authorization, 144 form as invalid, 118 handling failed authentication showForm(), 118 attempts, 144 forward: prefix, using in a view name, 129 Hibernate and, 133 frameworks implementing the Filter interface, 134 Apache Struts, 10 j_username and j_password Apache Tapestry, 10 parameters, 142 Common Client Interface (CCI), 56 javax.servlet.Filter, 139 definition of, 1 maintaining different sets of anonymous users, 143 Hibernate ORM, 1, 55 managing security in web requests, 139 iBATIS SQL Maps, 56 objectDefinitionSource property, 144 Java Data Objects (JDO), 55 omitting the Java Persistence API (JPA), 55 PATTERN_TYPE_APACHE_ANT Java Persistent Objects (JPOX), 56 declaration, 141 JavaServer Faces, 10 security interceptor filter, code JDBC, 55 example, 143 lightweight, definition of, 2 session context integration filter, code Oracle TopLink, 56 example, 145 Orient, 56 specifying URL patterns and chained filters, 141 Spring as a framework of frameworks, 1 Spring’s use of Java EE filters, 132 Spring MVC, 8 supplying configuration parameters to a Spring Portlet MVC, 9 filter, 134 Spring Web Flow, 9 thread context, 153 Spring-supported APIs and frameworks, using decision voters to adjudicate list of, 55 authentication, 143 FreeMarker FilterSecurityInterceptor, 145 configuring the FreeMarker view FilterToBeanProxy, 140 resolver, 128 findTimesheet(), 88, 90, 92, 104 macro tags, 132 findTimesheetOperation(), 96 ■G FixedLocaleResolver, 135 @GeneratedValue annotation, 67 flow definition file-creation wizard, 244 getAccountName(), 163 Minter_685-4INDEX.fm Page 255 Thursday, November 15, 2007 2:30 PM

■INDEX 255

getAuthorities(), 148 @Column annotation, 67 getBean(), 37, 178 Configuration class, 70 getConsultant(), 163 configuring a Hibernate DAO getContentType(), 129 implementation, 72 getContext(), 153 configuring a HibernateTransactionManager getCurrentSession(), 70 bean, 80 getFormObject(), 224 configuring a SessionFactory, code GrantedAuthority interface, 148 example, 71 ■H configuring stand-alone transactions, 80 HandlerMapping, 111 creating a user account using Hibernate, 69 helper classes, 60 creating a user account using JDBC, 69 Hessian eager loading, 72 accountName property, 180 @Entity annotation, 67 advantages of its remoting mechanism, 178 foreign key, 68 configuring a dispatcher servlet, 179 @GeneratedValue annotation, 67 configuring a Hessian client proxy getCurrentSession(), 70 factory, 181 Hibernate DAO, configuring, 70 configuring a Hessian service bean and Hibernate DAO, creating, 68 exporter, 181 Hibernate Query Language (HQL), 68 data transfer objects (DTOs), 180 Hibernate-based entity deletion defining a remote service interface, 180 method, 68 implementing a Hessian client, 181 HibernateConfigHelper implementing a Hessian server, 179 implementation, 206 initialize(), 180 HibernateDaoHelper, 71 invoking a remote Hessian service from a HibernateDaoSupport, 70 client, 182 HibernateSessionFilter, 72 LazyInitializationException, 179 HibernateTemplate, 206 listUserNames(), 180 HSQL database, 67 listUsers(), 180 HSQLDialect, 71 not using Java serialization, 179 @Id annotation, 67 transporting Hibernate entity classes injecting the Hibernate DAO across a network, 179 implementation into a service See also Burlap class, 72 Hibernate ORM javax.persistence package, 67 accountName attribute, 67 @JoinTable annotation, 68 advantages of, 65 JPA annotations and Hibernate-specific annotations, 67 advantages over JDBC-based logic, 69 lazy loading of associations, 72 AnnotationConfiguration class, 70 LazyInitializationException, 72 AnnotationSessionFactoryBean, 71 Minter_685-4INDEX.fm Page 256 Thursday, November 15, 2007 2:30 PM

256 ■INDEX

leaking Hibernate session instances, 70 integration testing, 226 @ManyToMany annotation, 67 inversion of control (IOC) mappings between database objects and benefits of, 29 Java classes, 65 creating an application’s glue code, 2 @NamedQuery annotations, 68 decoupling a class from a required required configuration information, 70 dependency, 4 Session objects, 70 dependency injection, 2, 4 SessionFactory class, 70 dependency injection as a form of, 29 SessionFactoryBean, 71 dependency lookup, definition of, 3 Spring Hibernate template, benefits of, 69 modifying code when moving application supplying mappings as XML files or Java 5 logic to a new environment, 4 annotations, 65 providing dependencies from outside a ThreadLocal class, 70 class, 29 use of lazy loading, 133 Spring’s handling of tangled dependencies, 2 UserAccount entity, 65, 67 unit testing and dependency injection, 5 UserRole entity, 67 See also dependency injection (DI) HibernateDaoHelper, 71 invoker path, 176 HibernateDaoSupport, 70 isErrorPage attribute, 119 HibernateSessionFilter, 72 HibernateTransactionManager, 80 ■J HSQL database, 16, 63, 67, 202–203 Jakarta Commons, 10 HSQLDialect, 71 Jakarta ORO, 141 HTTP invoker, 176–178 Java Authentication and Authorization HttpUnit Service (JAAS), 137, 149 comparing to Selenium, 227 Java Data Objects (JDO), 55 creating a JUnit test case, 226 Java EE debugging and testing JavaScript-based component stack, 2 issues, 226 differentiating static/dynamic and strong/weak typing, 30 ■ I Spring’s support for server programming iBATIS, 10 and web applications, 8 iBATIS SQL Maps, 56 Spring’s support for standard libraries, 7 ibiblio repository, 22 Java Message Service (JMS), 190 IBM WebSphere MQ, 190 Java Naming and Directory Interface @Id annotation, 67 (JNDI), 3 initialize(), 180 Java Persistence API (JPA), 55 InitializingBean, 47, 52 Java Persistent Objects (JPOX), 56 inlineImage identifier, 167 Javadoc API documentation, 11 InputStreamSource interface, 54 JavaMail API, 10 Minter_685-4INDEX.fm Page 257 Thursday, November 15, 2007 2:30 PM

■INDEX 257

JavaMailSender interface, 158–159, 165 userAccountDao property, 64 JavaMailSenderImpl, 159 using a RowMapper to materialize a list JavaServer Faces, 10 of entities, 63 javax.persistence package, 67 See also data access objects (DAOs) javax.servlet.Filter, 139 JdbcDaoSupport class JAX-RPC configuring a Driver ManagerDataSource, 63 configuring a SOAP JAX-RPC client proxy factory, 189 DataSource, 61, 63 configuring an Apache Axis servlet, 186 extending, 61 implementing a JAX-RPC client, 189 helper methods, 61 implementing a JAX-RPC endpoint JdbcTemplate class, 62–63, 80, 202 service, 188 JdbcUserAccountDaoImpl class, 201 implementing a JAX-RPC server, 186 jMock, using to generate mock objects, 219 invoking a remote SOAP JAX-RPC @JoinTable annotation, 68 service, 189 JstlView class, 116 remote service interface for a JAX-RPC JtaTransactionManager, 80 service, 187 JUnit, 195 JaxRpcPortProxyFactoryBean, 189 JDBC (Java Database Connectivity) ■K configuring a Driver key ManagerDataSource, 63 foreign, 68 creating a unit test, 201 primary, 67, 69 DAO implementation, configuring, 63 surrogate, 67 DAO implementation, creating, 61 ■L DAO implementation, injecting into a lazy loading service bean, 64 advantages and disadvantages of, 72 DataSource, 61, 63 Hibernate’s use of, 133 HSQL database, 63 initializing servlets, 109 JDBC API, 55 necessity of creating proxy objects, 72 JdbcDaoSupport class, 61, 63 using with XML configuration files and JdbcTemplate class, 62–63 annotations, 72 mapRow(), 62 LazyInitializationException, 72, 133, 179 ParameterizedRowMapper interface, 62 Lightweight Directory Access Protocol RowMapper implementation for the (LDAP), 137, 149 UserAccount Entity, 62 lightweight, definition of, 2 Spring JDBC delete method, code ListableBeanFactory, 52 example, 62 ListFactoryBean, 46 traditional JDBC delete method, code example, 61 listTimesheets(), 88–90, 92, 96 UserAccountDao bean, 64 listUserNames(), 180 Minter_685-4INDEX.fm Page 258 Thursday, November 15, 2007 2:30 PM

258 ■INDEX

listUsers(), 173, 180 mvn clean install command, 21 load-on-startup parameter, setting the value mvn eclipse:eclipse command, 24 of, 110 mvn install command, 21, 24 LocaleResolver bean, 135 mvn tomcat:deploy command, 24 localization mvn tomcat:undeploy command, 24 AcceptHeaderLocaleResolver, 135 obtaining, 22 configuring a resource bundle-based online repository at the ibiblio archive, 21 message source, 135 performing a build from scratch, 21 CookieLocaleResolver, 135 pom.xml, 20 FixedLocaleResolver, 135 Project Object Model (POM), 20 SessionLocaleResolver, 135 running test cases, 196 Spring’s locale resolver classes, table running unit tests on a Maven build, 26 of, 135 setting the M2_REPO classpath using a LocaleResolver bean variable, 25 implementation, 135 setting up the .project and .classpath /login URL, accessing, 142 files, 25 ■M settings.xml, 22–23 .m2 directory, 21 timesheets-core-1.0-SNAPSHOT.jar, 21 MailException, 161 using as a dependency management MailMessage class, 158 tool, 11 MailSender interface, 158–159, 165 using as a project management tool, 19 mock implementation, 210 message tag, 132, 135 Manage Timesheets page, 18 MethodInvocation, 98 @ManyToMany annotation, 67 Microsoft Message Queuing (MSMQ), 190 mapRow(), 62 MimeMessage, 165, 213 matches(), 102–103 MimeMessageHelper, 166 Maven 2 MimeMessagePreparator, 165 commands issued as parameters to the mock objects, 195, 219 mvn command, 22 MockRequestContext, 223 creating a new Java project, 19 MockRequestObject, 224 dependencies element, 21 Model View Controller (MVC) downloading dependencies, 21 building an MVC application with eclipse:clean target, 232 Java EE, 108 eclipse:eclipse target, 232 controller, configuring, 113 importing Maven projects into Eclipse, 25 controller, definition of, 108 invoking the install target, 21 model, definition of, 107 local repository, 21 Spring MVC, 108, 110 .m2 directory, 21 Spring Web Flow, 108, 120 See also controller; view Minter_685-4INDEX.fm Page 259 Thursday, November 15, 2007 2:30 PM

■INDEX 259

Multipurpose Internet Mail Extensions @Pointcut annotation, 96 (MIME) pointcut-ref attribute, 90–91 MimeMessageHelper, 166 pom.xml MimeMessagePreparator, 165 code example, 20 sending binary data via e-mail, 158 comparing to an Apache Ant build.xml mvn clean install command, 21 file, 20 mvn eclipse:eclipse command, 24 port, definition of, 189 mvn install command, 21, 24 portals, 9 mvn tomcat:deploy command, 24 portlet containers, 9 mvn tomcat:undeploy command, 24 PortMapper, using a default implementation, 152 ■N PortMapperImpl bean, 152 @NamedQuery annotations, 68 portMappings property, 152 namespaceUri property, 189 portName property, 189 New Remote Site button, 230 postprocessor, ■O setRequiredAnnotationType(), 48 objectDefinitionSource property, 144 prepare(), 165, 169 object-oriented programming (OOP), 6 presentation layer on attribute, 125 definition of, 14 onBind(), 117 login pages, 14 onBindAndValidate(), 117 manipulating the data in a model, 107 onInit(), 188 timesheet management pages, 14 onSubmit(), 117–118 user administration pages, 14 Open Graph context menu, 237 See also service layer Open Graphical Editor, 240 previewUser state, 242 options tag, 131 previewUser.jsp, 126 Oracle TopLink, 56 primary key, 67, 69 org.acegisecurity.annotations.Secured principal, definition of, 145 annotation, 154 Project Explorer, 232–233 org.springframework.core.io.Resource, 53 Project Object Model (POM), 20 org.springframework.remoting.rmi, 190 property injection Orient, 56 collection classes, 43 ■P configuring properties from XML as elements, 42 Palette tool, 242 injecting a string property value, 42 ParameterizedRowMapper interface, 62 ref attribute, 42 PathMatcher interface, 112 Spring configuration of a list property, 44 Plain Old Java Objects (POJOs), Spring’s use of, 8 Spring configuration of a map property, 43 pointcut, definition of, 86 Spring configuration of a set property, 44 Minter_685-4INDEX.fm Page 260 Thursday, November 15, 2007 2:30 PM

260 ■INDEX

syntax for configuring references, 42 remote method invocation (RMI) using Java 5 generics in method applicationContext.xml, 173 signatures, 43 client proxy to a service bean, 174 using PropertyEditor implementations, 42 configuring an RMI service exporter, 173 value attribute, 42 creating rich administrative property name namespace applications, 172 defining property values with, 46 implementing an RMI server, 173 not using to declare constructor importing a Spring RMI configuration, 173 parameters, 46 listUsers(), 173 referencing, 46 making an interface accessible over PropertyEditor RMI, 172 invoking, 42 registry port, 175 PropertyEditor classes, 117, 127 registryPort property, 174 type-converting a string value into a target RMI client application, 174–175 type, 42 serviceInterface property, 175 Provider class, 145 serviceName property, 174–175 ProviderManager class, 145 serviceUrl property, 175 proxy class specifying a service interface, 174 examining the stack trace of thrown Spring’s support for RMI-based exceptions, 82 remoting, 172 generating at runtime, 82 timesheet-client.xml, 176 having multiple AOP proxies within the “tunneling” the RMI wire protocol, 172 same call stack, 82 use of serialization, 172–173 managing transactions, 81 UserAccountService, 173 ProxyBeanFactory, 98 remoting mechanisms ■R Burlap, 178 rcptAddress property, 162 CORBA, 190 read(), 200, 222 custom objects and implementation readById(), 200 classes, 171 redirect: prefix, using in a view name, 129 Hessian, 178 ref attribute, 42 Java Message Service (JMS), 190 refactoring, 5 Java’s support for, 171 referenceData(), 114 mapping Java classes and interfaces to other protocols, 171 registryPort property, 174 remote method invocation (RMI), 172 regression testing SOAP, 185 adding to an existing unit test suite, 227 Spring’s HTTP invoker server, 176 purpose of, 227 Spring’s support for, 171 Remote Client Protocol (RCP), 149 Render Actions tab, 241 Minter_685-4INDEX.fm Page 261 Thursday, November 15, 2007 2:30 PM

■INDEX 261

render-actions element, 241 correlation with the DAO layer, 75 replay(), 222 DAO properties for implementing the RequestContext, 123, 224 timesheet service, 77 @Required annotation, 48 definition of, 15, 76 RequiredAnnotationBeanPostProcessor, 48 distinguishing between the service and data access layers, 78 REQUIRES_INSECURE_CHANNEL, 151 extracting a list of users from, 114 REQUIRES_SECURE_CHANNEL, 151 implementing services in Spring, 76 resource properties, 54 invoking a method as the beginning of a ResourceLoader, 53 transaction, 78 resources directory, 26 marking transactional boundaries, 78 ResultSet objects, 108 org.acegisecurity.annotations.Secured returning attribute, 91 annotation, 154 RFC 1738 URL address specification, 167 purposes of, 75 Roles set, 64 remote method invocation (RMI), 75 RootBeanDefinition, 37 @Secured annotation, configuring, 155 ■S securing, 154 save(), 124 simple mail transport protocol (SMTP), 77 scope attribute, 39, 42 SOAP, 15 Scrum, 5 substituting a proxy class for a service implementation, 81 Search for New Features to Install option, 230 timesheet service interface, 77 Secure Sockets Layer (SSL), 149 transactions and, 15 @Secured annotation, configuring, 155 typical service layer method, code security interceptor filter, 143 example, 15 SecurityContextHolder class, 153–154 updateTimesheet(), 78 Selenium using annotations for method-level, comparing to HttpUnit, 227 role-based security, 154 creating JavaScript-based scripts for See also presentation layer application testing, 226 serviceInterface property, 175 send(), 158, 161 serviceName property, 174–175, 189 sendTimesheetUpdate(), 161–162, 213–214 serviceUrl property, 175 server-config.wsdd, 186 Servlet API, listeners added in version 2.3, 109 service layer ServletContextAware, 51 accessDecisionManager property, 155 ServletEndpointSupport class, 188 annotating the user account service servlet-name element, 111 interface, 154 session context integration filter, 145 applying an AOP advice to, 154 Session objects, 70 attributes bean, 155 SessionFactory class, 70 combining business logic and data access layer components, 15 SessionFactoryBean, 71 Minter_685-4INDEX.fm Page 262 Thursday, November 15, 2007 2:30 PM

262 ■INDEX

SessionLocaleResolver, 135 serviceName property, 189 setDao(), 202 ServletEndpointSupport class, 188 setRequiredAnnotationType(), 48 SoapUserAccountService interface, 187 setServletContext(), 51 SoapUserAccountServiceEndpoint setText(), 166 class, 187 settings.xml, 22–23 Spring support for, 185 setUp(), 195, 202 Spring WS library, 185 setupForm(), 125 Web Service Deployment Descriptor (WSDD), 186 showForm(), 118 Web Services Description Language simple mail transport protocol (SMTP), 77 (WSDL), 186 SimpleFormController, 113–114 wsdlDocumentUrl property, 189 SimpleMailDaoImpl, 214 wsdlPortType property, 189 SimpleMailMessage class, 158, 213 wsdlServiceElement property, 189 SimpleNamingContext class, 226 wsdlTargetNamespace property, 189 SimpleUrlHandlerMapping class, 112 SoapUserAccountService interface, 187 SiteMinder, 149 SoapUserAccountServiceEndpoint class, 187 SMTP mail gateway, 160 Software Updates feature (Eclipse), 229 SOAP Spring Elements option, 233 advantages and disadvantages of, 185 Spring IDE communicating between heterogeneous adding bean definition dependencies, 239 platforms and languages, 185 adding the Spring Project Nature to configuring a SOAP JAX-RPC client proxy Eclipse projects, 232 factory, 189 applicationContext.xml, 237 configuring an Apache Axis servlet, 186 Apply Spring Project Nature option, 233 implementing a JAX-RPC client, 189 autocompletion, 229, 235, 239 implementing a JAX-RPC endpoint service, 188 bean definition wizard, 243 implementing a JAX-RPC server, 186 Beans Support dialog box, 234 invoking a remote SOAP JAX-RPC compatibility with the Eclipse 3.2 service, 189 environment, 229 JAX-RPC library, 185 configuring a web flow definition, 238 JaxRpcPortProxyFactoryBean, 189 configuring bean configuration files for the Spring Elements view, 233 namespaceUri property, 189 createUser state, 242 onInit(), 188 createUser-flow.xml, 239–240 origin of the acronym, 185 Eclipse plug-in, features of, 229 port, definition of, 189 Eclipse plug-in, installing, 229–232 portName property, 189 Eclipse plug-in, online resources, 229 remote service interface for a JAX-RPC service, 187 flow definition file-creation wizard, 244 server-config.wsdd, Axis service installing the Eclipse IDE for Java EE definition, 186 developers, 230 Minter_685-4INDEX.fm Page 263 Thursday, November 15, 2007 2:30 PM

■INDEX 263

Open Graphical Editor, 240 controller classes, 8, 110 Palette tool, 242 creating clean, decoupled web previewUser state, 242 applications, 110 Render Actions tab, 241 data access objects (DAOs), 8 render-actions element, 241 declaring exception handler views, 119 as “schema aware”, 236 determining the content type: value, 129 selecting the Web Flow Support leaf, 238 dispatcher servlet, configuring, 110 specifying the bean definition files for a DispatcherServlet, 111 project, 234 Errors object, 118 Spring Elements option, 233 exception attribute, 119 Spring Explorer, Open Graph context exception handling, 118 menu option, 237 exceptionResolver, 119 Spring project-creation wizard, 244 extracting a list of users from the service timesheet-webflow.xml, 239 layer, 114 Transition dialog box, 242 FreeMarker, 127 using file-creation wizards, 243 getContentType(), 129 validation errors in the web flow implementing the user list controller, 114 definition, 239 implementing the View interface, 128 View State dialog box, 241 isErrorPage attribute, 119 Web Standard Tools (WST), 230 JSP for rendering the admin/listUser Spring MVC view, 116 AbstractFormController class, 126 JstlView class, 116 AbstractWizardFormController class, 126 maintaining the content of a command AntPathMatcher helper class and object, 126 wildcards, 112 mapping dispatcher URLs to controller BindException object, 117–118 classes, 112 command object, 126 onBind(), 117 components of, 110 onBindAndValidate(), 117 configuring a servlet path, 111 onSubmit(), 117–118 configuring a simple form controller, 114 PathMatcher interface, 112 configuring a view controller for a single PropertyEditor classes, 117, 127 page, 113 referenceData(), 114 configuring a view resolver, 115 rejecting either a single field or a whole configuring exception resolution, 119 form as invalid, 118 configuring single or multiple server-side form validation, 117 dispatchers, 111 session objects, 126 configuring Spring’s VelocityConfigurer showForm(), 118 class, 127 SimpleFormController, 113–114 configuring the FreeMarker view SimpleUrlHandlerMapping class, 112 resolver, 128 special view prefixes, 129 configuring the Velocity view resolver, 127 Minter_685-4INDEX.fm Page 264 Thursday, November 15, 2007 2:30 PM

264 ■INDEX

TimesheetSecurity exception, 119 anonymous role, 144 transfer classes (form beans) as applying an AOP advice to the service conventional POJOs, 9 layer, 154 UrlBasedViewResolver, 115 attributes bean, 155 UserAccountService bean, 114 authentication manager, configuring, 145 users attribute, 116 authentication, definition of, 137 using session scope to maintain state, 8 authenticationFailureUrl property, 142 using the forward: prefix in a view authentication-processing filter, code name, 129 example, 142 using the redirect: prefix in a view authorization, definition of, 137 name, 129 bean definitions for two channel validator implementation, code processors, 151 example, 117 Central Authentication Services (CAS), 149 Velocity, 127 channel decision manager, view technologies supported, 127 configuring, 151 views as typically JSPs, 8 channel security, definition of, 137 Spring OpenSessionInViewFilter, channel-processing filter, defining, 150 declaring, 133 checking an authenticated user’s name Spring Portlet MVC against a data request, 153 using portlet containers (portals) to build concerns when securing a web large web applications, 9 application, 138 working within a JSR 168–compliant configuring a new PortMapperImpl portlet environment, 9 bean, 152 spring prefix, 130 configuring an anonymous authentication Spring project-creation wizard, 244 provider, 146 Spring Security configuring the filter chain proxy, 141 accepting connections only on a secure DAO authentication provider, code port, 149 example, 146 Access Denied page, 144 DaoAuthenticationProvider class, 146 accessDecisionManager property, 155 defaultTargetUrl property, 142 accessing the /login URL, 142 defining the finest-grained URL patterns first, 141 Acegi filters, configuring, 139 defining the required channel security AcegiGrantedAuthority class, 148 level, 151 allowIfAllAbstainDecisions property, 143 defining which roles can access which alwaysUseDefaultTargetUrl property, 142 URLs, 144 amended filter invocation definition DelegatingFilterProxy, 139–140 source, 150 “deny by default” rule, 138 annotating the user account service distinguishing a principal from a user interface, 154 account, 145 anonymous processing filter, code exception-translation filter, code example, 142 example, 144 Minter_685-4INDEX.fm Page 265 Thursday, November 15, 2007 2:30 PM

■INDEX 265

FilterChainProxy, 139–140, 144 restricting content to the user’s access filterInvocationDefinitionSource roles, 152 property, 141, 151 restricting page content to administrators, FilterSecurityInterceptor, 145 code example, 152 FilterToBeanProxy, 140 restricting user access to particular URLs, 139 forceHttps flag, 144 retrieving the UserAccount principal, 154 getAuthorities(), 148 retrofitting Acegi to legacy designs, 148 getContext(), 153 ROLE_ANONYMOUS role, 146 GrantedAuthority interface, 148 @Secured annotation, configuring, 155 handling a successful authentication but a failed authorization, 144 securing exchanges with a web application, 149 handling failed authentication attempts, 144 securing only sensitive information, 150 importing the Acegi tag library into a securing the service layer, 154 JSP, 152 security interceptor filter, code j_username and j_password example, 143 parameters, 142 SecurityContextHolder class, 153–154 Java Authentication and Authorization session context integration filter, code Service (JAAS), 137, 149 example, 145 Lightweight Directory Access Protocol SiteMinder, 149 (LDAP), 137, 149 specifying URL patterns and chained maintaining different sets of anonymous filters, 141 users, 143 storing authentication information within objectDefinitionSource property, 144 a request context, 153 omitting the thread context, 153 PATTERN_TYPE_APACHE_ANT UserAccount class, 148 declaration, 141 UserDetails interface, 147–148 org.acegisecurity.annotations.Secured UserDetailsService interface, 147, 149 annotation, 154 username anonymous, 146 other providers of authentication and authorization resources, 149 using a default PortMapper implementation, 152 performance disadvantages of encrypting/decrypting using annotations for method-level, communications, 150 role-based security, 154 portMappings property, 152 using decision voters to adjudicate authentication, 143 preventing access to another user’s private information, 153 using filters to manage security in web requests, 139 Provider class, 145 using the Secure Sockets Layer (SSL) ProviderManager class, 145 encryption protocol, 149 Remote Client Protocol (RCP), 149 X.509, 149 REQUIRES_INSECURE_CHANNEL, 151 See also authentication; channel security REQUIRES_SECURE_CHANNEL, 151 Minter_685-4INDEX.fm Page 266 Thursday, November 15, 2007 2:30 PM

266 ■INDEX

Spring Web Flow identifying the states in a model, 122 AbstractFormController class, 126 implementing the Action interface, AbstractWizardFormController class, 126 122–123 action, points of invocation, 122 implementing the View interface, 128 ActionForm class, 125 importing a schema namespace, 121 adding action method calls to a web flow listing the events that cause state declaration, 124 transitions, 122 adding bean definition dependencies, 239 maintaining the content of a command object, 126 bindAndValidate(), 125 mapping to the flow: namespace building a web flow for creating new prefix, 121 users, 120 modeling application behavior as a state command object, 126 machine, 9 complementing an existing Spring MVC on attribute, 125 framework, 9 Open Graphical Editor, 240 configuring a flow controller bean, 120 Palette tool, 242 configuring a flow executor, 121 previewUser state, 242 configuring a single web flow controller, 120 Render Actions tab, 241 configuring a web flow definition, 238 render-actions element, 241 configuring Spring’s VelocityConfigurer RequestContext object, 123 class, 127 save(), 124 configuring the FreeMarker view schema definition for a web flow resolver, 128 configuration file, 121 configuring the Velocity view resolver, 127 selecting the Web Flow Support leaf, 238 createUser state, 242 session objects, 126 CreateUserAction bean, configuring and setupForm(), 125 implementing, 123 specifying a set of flow configuration createUser-flow.xml, 121, 239–240 files, 121 determining the content type: value, 129 states declared in a web flow _eventId parameter, 125 configuration, 122 events to raise when processing a request testing a Spring Web Flow action class, 223 or submission, 125 timesheet-webflow.xml, 239 flow registry, 121 Transition dialog box, 242 _flowId parameter, 126 user journeys and web applications, 120 form elements from createUser.jsp, 125 validation errors in the web flow form elements from previewUser.jsp, 126 definition, 239 FormAction class, 123 Velocity, 127 FreeMarker, 127 View State dialog box, 241 getContentType(), 129 view technologies supported, 127 getFormObject(), 224 Spring WS library, 185 Minter_685-4INDEX.fm Page 267 Thursday, November 15, 2007 2:30 PM

■INDEX 267

SQL, converting HQL queries into, 68 timesheet application static pointcuts administrative username and password, definition of, 101 14, 27 extending the advantages of using layered StaticMethodMatcherPointcut components, 16 interface, 101 architecture of its component layers, 13 surrogate key, 67 configuring a simple form controller, 114 ■T configuring exception resolution, 119 Create Timesheet page, 18 tag libraries createTimesheet(), 82 advantages of, 130 data access layer, definition of, 15 errors tag, 131, 135 deploying a web application with Apache making the appropriate taglib Tomcat version 5.5, 14 declaration, 130 downloading the source code, 22 message tag, 132, 135 e-mail DAO interface, 157 options tag, 131 employing a flexible application Spring’s custom tag libraries, 130 specification, 17 Spring’s generic custom tags, table of, 131 HSQL database, 16 Spring’s standard form tags, table of, 131 interacting with using a web browser, 26 theme tag, 135 Manage Timesheets page, 18 using the form:form custom tag, 131 notifying the administrator when a user using the spring and form prefixes, 130 updates a timesheet, 157 tearDown(), 195, 213 pom.xml, 20 template classes, 60 presentation layer, 14, 75 TestCase class, 195 Project Object Model (POM), 20 Test-Driven Development (TDD), 5, 194 rendering presentation views with JSPs, 14 testEdit(), 224 sendTimesheetUpdate(), 162 testFindUser(), 222 service layer, definition of, 15 testing settings.xml, source code, 23 comparing manual and automated showcasing Spring’s features, 13 tests, 193 source code archive, table of files and integration testing, 226 folders, 22 philosophies of, 193 timesheet service bean configuration, 157 regression testing, 227 timesheet service interface, 77 testing Spring-based application code, 193 timesheet-client.xml, 176 web testing, 226 timesheets-core-1.0-SNAPSHOT.jar, 21 See also unit testing tomcat-users.xml, 14 testReadById(), 200 two use case scenarios, 17 theme tag, 135 typical service layer method, code thread context, 153 example, 15 ThreadLocal class, 70 Minter_685-4INDEX.fm Page 268 Thursday, November 15, 2007 2:30 PM

268 ■INDEX

underlying database and mail server manually managing a transaction, 79 components, 16 rolling back for checked/unchecked updateTimesheet(), 78 exceptions, 83 UserAccountService, 173, 178 service method individually annotated as using Maven 2 as a project management transactional, 79 tool, 19 substituting a proxy class for a service using Spring MVC and Spring Web Flow implementation, 81 for controllers, 14 using declarative transaction View Timesheet page, 18 management, 79 timesheetReturningOperation(), 96 transfer classes, Spring MVC framework and, 9 TimesheetSecurity exception, 119 Transition dialog box, 242 TimesheetSecurityAdvice, 100 tx:advice element, 85, 88 TimesheetService class, 90, 96, 102 tx:method element, table of properties, 85 timesheet-webflow.xml, 239 type systems, differentiating static/dynamic tomcat-users.xml, 14 and strong/weak typing, 30 TopLink, 10 @Transactional annotation, 79, 83 ■U transactions unit testing annotating individual methods instead of andReturn(), 222 a whole class, 79 asserting expectation of a non-null id annotating the implementation classes to value, 200 be transactional, 79 asserting expectation of a retrieved bean’s annotations as not inherited, 84 properties, 201 aop:config element, 85 clear(), 202, 208 configuring a comparing unit tests to integration tests, 208 HibernateTransactionManager ConfigHelper interface, 196, 201–202 bean, 80 create(), 200 configuring annotation-based create-drop parameter, 208 transactions, 81 createMimeMessage(), 213 configuring the createMock(), 221 DataSourceTransactionManager, 80 creating, configuring, and assigning a configuring the DAO implementation, 202 JtaTransactionManager, 80 definition of, 194–195 createTimesheet(), 82 EasyMock-based unit test suite, 219 DataSourceUtils class, 80 e-mail DAO tests, 209 declarative XML configuration, 84 environment of the three mail DAO test declaring a transaction manager bean, 80 methods, 213 invoking a method as the beginning of a expect(), 222 transaction, 78 getFormObject(), 224 JdbcDaoSupport class, 80 Hibernate DAO, 205 JdbcTemplate class, 80 Minter_685-4INDEX.fm Page 269 Thursday, November 15, 2007 2:30 PM

■INDEX 269

HibernateConfigHelper standard Spring mock object classes, table implementation, 206 of, 225 HibernateTemplate, 206 tearDown(), 213 HSQL database, 202–203 TestCase class, 195 implementation of findUser(), 218 Test-Driven Development (TDD), 194 instantiating a UserAccount bean, 200 testEdit(), 224 JavaMailSender API, methods of, 209 testing a DAO layer, 195 JDBC unit test, 201 testing a Spring Web Flow action class, 223 JdbcConfigHelper class testing the CreateUserAction’s save implementation, 203 method, 224 JdbcTemplate class, 202 testing the presentation layer, 223 JdbcUserAccountDaoImpl class, 201 testing the service layer, 218 jMock, 219 testing the UserAccountDao interface’s JUnit test suites, 195 methods, 196 MimeMessage, 213 testing the VelocityMailDaoImpl implementation, 214, 216 mock MailSender implementation, 210 testReadById(), 200 mock objects, definition of, 195 tests for the user account DAO, 195 mock objects, generating automatically, 219 throwing a test, 195 MockRequestContext, 223 tracking down implementation bugs, 194 MockRequestObject, 224 unit test for the JDBC-based UserAccount DAO, 201 “obviously correct” implementations, 195 UserAccountService interface, 218 read(), 200, 222 using an embedded database for, 208 readById(), 200 validating the results of the service refactoring code, 194, 213 method call, 222 replay(), 222 writing unit tests before coding, 194 RequestContext, 224 See also testing retrieving an entity by primary key, 200 Updates dialog box, 231 running test cases in Maven 2, 196 updateTimesheet() scripting a mock distinguishing between the service and control in testFindUser(), 222 data access layers, 78 sendTimesheetUpdate(), 213–214 making the method transactional, 78 setDao(), 202 UrlBasedViewResolver, 115–116 setUp(), 202 user list controller, implementing, 114 SimpleMailDaoImpl DAO UserAccount class, 56–57, 65, 67, 148 implementation, 214 UserAccountDao bean, 64 SimpleMailMessage class, 213 userAccountDao property, 64 SimpleNamingContext class, 226 UserAccountService bean, 114, 218 Minter_685-4INDEX.fm Page 270 Thursday, November 15, 2007 2:30 PM

270 ■INDEX

UserDetails interface, 147–148 ■W UserDetailsService interface, 147, 149 Web Service Deployment Descriptor UserRole class, 56, 67 (WSDD), 186 users attribute, 116 Web Services Description Language (WSDL), 186 util namespace, defining collections with, 46 Web Standard Tools (WST), 230 ■V web testing value attribute, 42 HttpUnit, 226 Velocity Selenium, 226 configuring the Velocity view resolver, 127 web.xml macro for sending a simple HTML context-param entry, 108 e-mail, 163 declaring a context loader listener, 108 macro tags, 132 servlet-name element, 111 macro with a URI referencing inline web application’s deployment descriptor content, 167 file, 108 testing the VelocityMailDaoImpl WebApplicationContext implementation, 214 hierarchical capabilities of, 53 Velocity markup language, 163 making configuration information more VelocityConfigurer class, configuring, 127 modular, 53 velocityEngine bean, configuration WEB-INF directory, 26 details, 165 wsdlDocumentUrl property, 189 view wsdlPortType property, 189 defining a view type, 128 wsdlServiceElement property, 189 definition of, 107 wsdlTargetNamespace property, 189 getContentType(), 129 implementing Spring’s View interface, 128 ■X programmatically generating the contents X.509, 149 of a view, 128 XML representing the data in a model, 108 advantages of XML configuration files, 38 special view prefixes, 129 autowiring, definition of, 40 Spring’s support for view bean factories and XML configuration technologies, 127 files, 38 using the forward: prefix in a view combining implementation classes with name, 129 XML schema syntax, 45 using the redirect: prefix in a view creating a Spring bean factory from an name, 129 XML file, 39 See also controller; Model View defining collections using the util Controller (MVC) namespace, 46 View State dialog box, 241 defining property values using the View Timesheet page, 18 property namespace, 46 Minter_685-4INDEX.fm Page 271 Thursday, November 15, 2007 2:30 PM

■INDEX 271

sample Spring XML configuration file, 38 ■Y scope attribute, 39 You Ain’t Gonna Need It (YAGNI) Spring configuration files, 11 principle, 59 Spring configuration of a map property, 43 XML bean definitions as describing singletons, 39