org.codehaus.enunciate.modules.spring_app
Class SpringAppDeploymentModule

java.lang.Object
  extended by org.codehaus.enunciate.modules.BasicDeploymentModule
      extended by org.codehaus.enunciate.modules.FreemarkerDeploymentModule
          extended by org.codehaus.enunciate.modules.spring_app.SpringAppDeploymentModule
All Implemented Interfaces:
EnunciateClasspathListener, EnunciateModelAware, DeploymentModule

public class SpringAppDeploymentModule
extends FreemarkerDeploymentModule
implements EnunciateClasspathListener

Spring App Module

The spring app deployment module produces the configuration files and application extensions needed to apply the Spring container to the Web service application.

Steps

generate

The "generate" step generates the Spring configuration file and application extensions. Refer to configuration to learn how to customize these things.

The "generate" step is the only relevant step in the spring app deployment module.

Configuration

The configuration for the Spring App deployment module is specified by the "spring-app" child element under the "modules" element of the enunciate configuration file.

Structure

The following example shows the structure of the configuration elements for this module. Note that this shows only the structure. Some configuration elements don't make sense when used together.

<enunciate>   <modules>     <spring-app contextLoaderListenerClass="..."       applicationContextFilename="..." contextConfigLocation="..."       springVersion="...">       <springImport file="..." uri="..."/>       <springImport file="..." uri="..."/>       ...       <globalServiceInterceptor interceptorClass="..." beanName="..."/>       <globalServiceInterceptor interceptorClass="..." beanName="..."/>       ...       <handlerInterceptor interceptorClass="..." beanName="..."/>       <handlerInterceptor interceptorClass="..." beanName="..."/>       ...       <handlerMapping pattern="..." beanName="..."/>       <handlerMapping pattern="..." beanName="..."/>       ...     </spring-app>   </modules> </enunciate>

attributes

The "springImport" element

The "springImport" element is used to specify a spring configuration file that will be imported by the main spring servlet config. It supports the following attributes:

One use of specifying spring a import file is to wrap your endpoints with spring interceptors. This can be done by simply declaring a bean that is an instance of your endpoint class, which can be advised as needed.

It's important to note that the type on which the bean context will be searched is the type of the endpoint interface, and then only if it exists. If there are more than one beans that are assignable to the endpoint interface, the bean that is named the name of the service will be used. Otherwise, the deployment of your endpoint will fail.

The same procedure can be used to specify the beans to use as REST endpoints. In this case, the bean context will be searched for each REST interface that the endpoint implements. If there is a bean that implements that interface, it will used instead of the default implementation. If there is more than one, the bean that is named the same as the REST endpoint will be used.

There also exists a mechanism to add certain AOP interceptors to all service endpoint beans. Such interceptors are referred to as "global service interceptors." This can be done by using the "globalServiceInterceptor" element (see below), or by simply creating an interceptor that implements org.codehaus.enunciate.modules.spring_app.EnunciateServiceAdvice or org.codehaus.enunciate.modules.spring_app.EnunciateServiceAdvisor and declaring it in your imported spring beans file.

Each global interceptor has an order. The default order is 0 (zero). If a global service interceptor implements org.springframework.core.Ordered, the order will be respected. As global service interceptors are added, it will be assigned a position in the chain according to it's order. Interceptors of the same order will be ordered together according to their position in the config file, with priority to those declared by the "globalServiceInterceptor" element, then to instances of org.codehaus.enunciate.modules.spring_app.EnunciateServiceAdvice, then to instances of org.codehaus.enunciate.modules.spring_app.EnunciateServiceAdvisor.

For more information on spring bean configuration and interceptor advice, see the spring reference documentation.

The "globalServiceInterceptor" element

The "globalServiceInterceptor" element is used to specify a Spring interceptor (instance of org.aopalliance.aop.Advice or org.springframework.aop.Advisor) that is to be injected on all service endpoint beans.

The "handlerInterceptor" element

The "handlerInterceptor" element is used to specify a Spring interceptor (instance of org.springframework.web.servlet.HandlerInterceptor) that is to be injected on the handler mapping.

For more information on spring bean configuration and interceptor advice, see the spring reference documentation.

The "handlerMapping" element

The "handlerMapping" element is used to specify a custom Spring handler mapping.

For more information on spring handler mappings, see the spring reference documentation.

Artifacts

The spring app deployment module exports no artifacts.

Author:
Ryan Heaton

Field Summary
 
Fields inherited from class org.codehaus.enunciate.modules.BasicDeploymentModule
enunciate
 
Constructor Summary
SpringAppDeploymentModule()
           
 
Method Summary
 void addGlobalServiceInterceptor(GlobalServiceInterceptor interceptorConfig)
          Add a global service interceptor to the spring configuration.
 void addHandlerInterceptor(HandlerInterceptor interceptorConfig)
          Add a handler interceptor to the spring configuration.
 void addSpringImport(SpringImport springImports)
          Add a spring import.
protected  void copySpringConfig()
          Copy the spring application context and servlet config from the build dir to the WEB-INF directory.
 void doFreemarkerGenerate()
          Generate using Freemarker.
 java.lang.String getApplicationContextFilename()
          The name of the application context file.
protected  java.net.URL getApplicationContextTemplateURL()
           
 org.apache.commons.digester.RuleSet getConfigurationRules()
          Default implementation returns null.
 java.lang.String getContextConfigLocation()
          The context config location.
 java.lang.String getContextLoaderListenerClass()
          The class to use as the context loader listener.
 java.lang.String getName()
          The name of the deployment module.
 int getOrder()
          The order of execution for the deployment module.
 java.util.List<SpringImport> getSpringImports()
          The list of spring imports.
protected  java.util.ArrayList<java.lang.String> getSpringImportURIs()
          Get the string form of the spring imports that have been configured.
 Validator getValidator()
          Get the validator for this module, or null if none.
protected  java.io.File getWebInfDir()
          The directory where the config files are generated.
 void init(Enunciate enunciate)
          Sets the enunciate mechanism.
 void initModel(EnunciateFreemarkerModel model)
          Initialize the model.
 boolean isDisabled()
          Whether this deployment module has been disabled, e.g.
 boolean isEnableSecurity()
          Whether to enable security.
 void onClassesFound(java.util.Set<java.lang.String> classes)
          Logic for handling a set of classes that were found on the Enunciate classpath.
protected  java.lang.String resolveSpringImportFileName(java.lang.String fileName)
          Resolves the application context file name (in case there's a conflict).
 void setApplicationContextFilename(java.lang.String applicationContextFilename)
          The name of the application context file.
 void setContextConfigLocation(java.lang.String contextConfigLocation)
          The context config location.
 void setContextLoaderListenerClass(java.lang.String contextLoaderListenerClass)
          The class to use as the context loader listener.
 void setEnableSecurity(boolean enableSecurity)
          Whether to enable security.
 void setSpringVersion(java.lang.String version)
          The spring version to use.
 
Methods inherited from class org.codehaus.enunciate.modules.FreemarkerDeploymentModule
close, doGenerate, getConfiguration, getModel, getModelInternal, getObjectWrapper, getTemplateExceptionHandler, getTemplateLoader, processTemplate, processTemplate, processTemplate, processTemplate
 
Methods inherited from class org.codehaus.enunciate.modules.BasicDeploymentModule
debug, doBuild, doCompile, doPackage, getAliases, getBuildDir, getCompileDir, getEnunciate, getGenerateDir, getPackageDir, info, setBuildDir, setCompileDir, setDisabled, setGenerateDir, setPackageDir, step, warn
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SpringAppDeploymentModule

public SpringAppDeploymentModule()
Method Detail

getName

public java.lang.String getName()
Description copied from interface: DeploymentModule
The name of the deployment module. Identifies its section in the enunciate configuration.

Specified by:
getName in interface DeploymentModule
Overrides:
getName in class BasicDeploymentModule
Returns:
"spring-app"

getApplicationContextTemplateURL

protected java.net.URL getApplicationContextTemplateURL()
Returns:
The URL to "spring-servlet.fmt"

onClassesFound

public void onClassesFound(java.util.Set<java.lang.String> classes)
Description copied from interface: EnunciateClasspathListener
Logic for handling a set of classes that were found on the Enunciate classpath.

Specified by:
onClassesFound in interface EnunciateClasspathListener
Parameters:
classes - The classes that were found.

init

public void init(Enunciate enunciate)
          throws EnunciateException
Description copied from class: BasicDeploymentModule
Sets the enunciate mechanism.

Specified by:
init in interface DeploymentModule
Overrides:
init in class BasicDeploymentModule
Parameters:
enunciate - The enunciate mechanism.
Throws:
EnunciateException

initModel

public void initModel(EnunciateFreemarkerModel model)
Description copied from interface: EnunciateModelAware
Initialize the model.

Specified by:
initModel in interface EnunciateModelAware
Overrides:
initModel in class FreemarkerDeploymentModule
Parameters:
model - The model to initialize.

doFreemarkerGenerate

public void doFreemarkerGenerate()
                          throws java.io.IOException,
                                 freemarker.template.TemplateException
Description copied from class: FreemarkerDeploymentModule
Generate using Freemarker. Same as FreemarkerDeploymentModule.doGenerate() but can throw a TemplateException.

Specified by:
doFreemarkerGenerate in class FreemarkerDeploymentModule
Throws:
java.io.IOException
freemarker.template.TemplateException

copySpringConfig

protected void copySpringConfig()
                         throws java.io.IOException
Copy the spring application context and servlet config from the build dir to the WEB-INF directory.

Throws:
java.io.IOException

getSpringImportURIs

protected java.util.ArrayList<java.lang.String> getSpringImportURIs()
Get the string form of the spring imports that have been configured.

Returns:
The string form of the spring imports that have been configured.

resolveSpringImportFileName

protected java.lang.String resolveSpringImportFileName(java.lang.String fileName)
Resolves the application context file name (in case there's a conflict).

Parameters:
fileName - The file name.
Returns:
The resolved file name.

isDisabled

public boolean isDisabled()
Description copied from interface: DeploymentModule
Whether this deployment module has been disabled, e.g. in the config file. Since the discovery mechanism is used to discover the modules on the classpath, it may be necessary to be able to disable a module.

Specified by:
isDisabled in interface DeploymentModule
Overrides:
isDisabled in class BasicDeploymentModule
Returns:
Whether this deployment module has been disabled.

getSpringImports

public java.util.List<SpringImport> getSpringImports()
The list of spring imports.

Returns:
The list of spring imports.

addSpringImport

public void addSpringImport(SpringImport springImports)
Add a spring import.

Parameters:
springImports - The spring import to add.

addGlobalServiceInterceptor

public void addGlobalServiceInterceptor(GlobalServiceInterceptor interceptorConfig)
Add a global service interceptor to the spring configuration.

Parameters:
interceptorConfig - The interceptor configuration.

addHandlerInterceptor

public void addHandlerInterceptor(HandlerInterceptor interceptorConfig)
Add a handler interceptor to the spring configuration.

Parameters:
interceptorConfig - The interceptor configuration.

getContextLoaderListenerClass

public java.lang.String getContextLoaderListenerClass()
The class to use as the context loader listener.

Returns:
The class to use as the context loader listener.

setContextLoaderListenerClass

public void setContextLoaderListenerClass(java.lang.String contextLoaderListenerClass)
The class to use as the context loader listener.

Parameters:
contextLoaderListenerClass - The class to use as the context loader listener.

getApplicationContextFilename

public java.lang.String getApplicationContextFilename()
The name of the application context file.

Returns:
The name of the application context file.

setApplicationContextFilename

public void setApplicationContextFilename(java.lang.String applicationContextFilename)
The name of the application context file.

Parameters:
applicationContextFilename - The name of the application context file.

getContextConfigLocation

public java.lang.String getContextConfigLocation()
The context config location.

Returns:
The context config location.

setContextConfigLocation

public void setContextConfigLocation(java.lang.String contextConfigLocation)
The context config location.

Parameters:
contextConfigLocation - The context config location.

isEnableSecurity

public boolean isEnableSecurity()
Whether to enable security.

Returns:
Whether to enable security.

setEnableSecurity

public void setEnableSecurity(boolean enableSecurity)
Whether to enable security.

Parameters:
enableSecurity - Whether to enable security.

setSpringVersion

public void setSpringVersion(java.lang.String version)
The spring version to use.

Parameters:
version - The spring version to use.

getOrder

public int getOrder()
Description copied from interface: DeploymentModule
The order of execution for the deployment module.

Specified by:
getOrder in interface DeploymentModule
Overrides:
getOrder in class BasicDeploymentModule
Returns:
200

getConfigurationRules

public org.apache.commons.digester.RuleSet getConfigurationRules()
Description copied from class: BasicDeploymentModule
Default implementation returns null.

Specified by:
getConfigurationRules in interface DeploymentModule
Overrides:
getConfigurationRules in class BasicDeploymentModule
Returns:
null.

getValidator

public Validator getValidator()
Description copied from interface: DeploymentModule
Get the validator for this module, or null if none.

Specified by:
getValidator in interface DeploymentModule
Overrides:
getValidator in class BasicDeploymentModule
Returns:
null

getWebInfDir

protected java.io.File getWebInfDir()
The directory where the config files are generated.

Returns:
The directory where the config files are generated.