blob: d4c11b63a6faeb463ea6d11424b5078b8ccc7c62 [file] [log] [blame]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Apache Wink : 5.5 Spring Integration</title>
<link rel="stylesheet" href="styles/site.css" type="text/css" />
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<table class="pagecontent" border="0" cellpadding="0" cellspacing="0" width="100%" bgcolor="#ffffff">
<tr>
<td valign="top" class="pagebody">
<div class="pageheader">
<span class="pagetitle">
Apache Wink : 5.5 Spring Integration
</span>
</div>
<div class="pagesubheading">
This page last changed on Oct 12, 2009 by <font color="#0050B2">bluk</font>.
</div>
<h1><a name="5.5SpringIntegration-SpringIntegration"></a>Spring Integration</h1>
<p>Apache Wink provides an additional module deployed as an external jar in order to provide Spring integration. The Spring integration provides the following features:</p>
<ul>
<li>The ability to register resources and providers from the Spring context, registered as classes or as Spring beans</li>
</ul>
<ul>
<li>The ability to define the lifecycle of resources or providers that are registered as Spring beans, overriding the default scope specified by the JAX-RS specification.</li>
</ul>
<ul>
<li>Resources and providers can benefit from Spring features such as IoC and post-processors.</li>
</ul>
<ul>
<li>Customize Apache Wink from the Spring context. When working with Spring, Apache Wink defines a core spring context that contains customization hooks, enabling easy customization that would otherwise require coding.</li>
</ul>
<h2><a name="5.5SpringIntegration-SpringRegistration"></a>Spring Registration</h2>
<p>Spring makes it convenient to register resources and providers as spring beans.<br/>
Spring Context Loading. In order to load the Spring Context, it is necessary to add a Context Load Listener definition to the web.xml file. The contextConfigLocation context-param must specify the location of the Apache Wink core context file and the application context file, as described in the following example:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml"><span class="code-tag">&lt;context-param&gt;</span>
<span class="code-tag">&lt;param-name&gt;</span>contextConfigLocation<span class="code-tag">&lt;/param-name&gt;</span>
<span class="code-tag">&lt;param-value&gt;</span>classpath:META-INF/server/winkCoreContext-server.xml
classpath:mycontext.xml
<span class="code-tag">&lt;/param-value&gt;</span>
<span class="code-tag">&lt;/context-param&gt;</span>
<span class="code-tag">&lt;listener&gt;</span>
<span class="code-tag">&lt;listener-class&gt;</span>
org.springframework.web.context.ContextLoaderListener
<span class="code-tag">&lt;/listener-class&gt;</span>
<span class="code-tag">&lt;/listener&gt;</span>
</pre>
</div></div>
<h3><a name="5.5SpringIntegration-RegisteringResourcesandProviders"></a>Registering Resources and Providers</h3>
<p>Apache Wink provides the org.apache.wink.spring.Registrar class in order to register resources and providers through a Spring context. The Registrar class extends the WinkApplication class and must be registered as a singleton spring bean. It is possible to define multiple registrars in the same context. All registrars are automatically collected by the runtime and registered as WinkApplication objects during the context loading. The registrar provides the following properties:</p>
<ul>
<li><b>instances</b> &#45; instances of resources and providers. Ordinarily, these instances are Spring beans, so they can benefit from IoC and other Spring features.</li>
</ul>
<ul>
<li><b>classes</b> &#45; a set of resources and providers class names. This property is similar to the getClasses() method of the Application class.</li>
</ul>
<ul>
<li><b>priority</b> &#45; the priority of the WinkApplication</li>
</ul>
<div class='panelMacro'><table class='infoMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="images/icons/emoticons/information.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Reference</b><br />For more information on Priorities refer to section <a href="5.1 Registration and Configuration.html#5.1RegistrationandConfiguration-Priorities">5.1 Registration and Configuration</a>.</td></tr></table></div>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml"><span class="code-tag">&lt;bean class=<span class="code-quote">"org.apache.wink.spring.Registrar"</span>&gt;</span>
<span class="code-tag">&lt;property name=<span class="code-quote">"classes"</span>&gt;</span>
<span class="code-tag">&lt;set value-type=<span class="code-quote">"java.lang.Class"</span>&gt;</span>
<span class="code-tag">&lt;value&gt;</span>package.className<span class="code-tag">&lt;/value&gt;</span>
<span class="code-tag">&lt;/set&gt;</span>
<span class="code-tag">&lt;/property&gt;</span>
<span class="code-tag">&lt;property name=<span class="code-quote">"instances"</span>&gt;</span>
<span class="code-tag">&lt;set&gt;</span>
<span class="code-tag">&lt;ref bean=<span class="code-quote">"resources.resource1"</span> /&gt;</span>
<span class="code-tag">&lt;ref bean=<span class="code-quote">"resources.resource2"</span> /&gt;</span>
<span class="code-tag">&lt;ref bean=<span class="code-quote">"providers.provider1"</span> /&gt;</span>
<span class="code-tag">&lt;/set&gt;</span>
<span class="code-tag">&lt;/property&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span>
</pre>
</div></div>
<h2><a name="5.5SpringIntegration-CustomPropertiesFileDefinition"></a>Custom Properties File Definition</h2>
<p>Apache Wink provides a set of customizable properties. When working with Spring, the user should redefine the custom properties file using the Spring context:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">&lt;bean id=<span class="code-quote">"customPropertiesFactory"</span>
class=<span class="code-quote">"org.springframework.beans.factory.config.PropertiesFactoryBean"</span>&gt;
<span class="code-tag">&lt;property name=<span class="code-quote">"locations"</span>&gt;</span>
<span class="code-tag">&lt;list&gt;</span>
<span class="code-tag">&lt;value&gt;</span>WEB-INF/configuration.properties<span class="code-tag">&lt;/value&gt;</span>
<span class="code-tag">&lt;/list&gt;</span>
<span class="code-tag">&lt;/property&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span>
<span class="code-tag">&lt;bean id=<span class="code-quote">"customConfigurer"</span> class=<span class="code-quote">"org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"</span>&gt;</span>
<span class="code-tag">&lt;property name=<span class="code-quote">"ignoreUnresolvablePlaceholders"</span> value=<span class="code-quote">"true"</span> /&gt;</span>
<span class="code-tag">&lt;property name=<span class="code-quote">"order"</span> value=<span class="code-quote">"1"</span> /&gt;</span>
<span class="code-tag">&lt;property name=<span class="code-quote">"propertiesArray"</span>&gt;</span>
<span class="code-tag">&lt;list&gt;</span>
<span class="code-tag">&lt;props&gt;</span>
<span class="code-tag">&lt;prop key=<span class="code-quote">"wink.propertiesFactory"</span>&gt;</span>customPropertiesFactory<span class="code-tag">&lt;/prop&gt;</span>
<span class="code-tag">&lt;/props&gt;</span>
<span class="code-tag">&lt;/list&gt;</span>
<span class="code-tag">&lt;/property&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span>
</pre>
</div></div>
<ul>
<li>The customPropertiesFactory bean loads the properties file.</li>
</ul>
<ul>
<li>The customConfigurer bean overrides the default factory with a custom factory.</li>
</ul>
<ul>
<li>The order is set to "1". This makes the customConfigurer bean run before the default Apache Wink configurer.</li>
</ul>
<ul>
<li>In addition, notice that ignoreUnresolvablePlaceholders must be set to true, otherwise the configurer will fail, since some unresolved properties can remain in the context.</li>
</ul>
<h2><a name="5.5SpringIntegration-CustomizingMediaTypeMappings"></a>Customizing Media-Type Mappings</h2>
<p>Apache Wink provides the ability to customize the Media-Type mappings using Spring context.</p>
<div class='panelMacro'><table class='infoMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="images/icons/emoticons/information.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Reference</b><br />For more information on Media-Type Mapping refer to section <a href="5.1 Registration and Configuration.html#5.1RegistrationandConfiguration-MediaTypeMapping">5.1 Registration and Configuration</a> .</td></tr></table></div>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml"><span class="code-tag">&lt;bean id=<span class="code-quote">"custom.MediaTypeMapper"</span> class=<span class="code-quote">"org.apache.wink.server.internal.MediaTypeMapper"</span>&gt;</span>
<span class="code-tag">&lt;property name=<span class="code-quote">"mappings"</span>&gt;</span>
<span class="code-tag">&lt;list&gt;</span>
<span class="code-tag">&lt;map&gt;</span>
<span class="code-tag">&lt;entry key=<span class="code-quote">"userAgentStartsWith"</span> value=<span class="code-quote">"Mozilla/"</span> /&gt;</span>
<span class="code-tag">&lt;entry key=<span class="code-quote">"resultMediaType"</span>&gt;</span>
<span class="code-tag">&lt;util:constant static-field=<span class="code-quote">" javax.ws.rs.core.MediaType.ATOM"</span> /&gt;</span>
<span class="code-tag">&lt;/entry&gt;</span>
<span class="code-tag">&lt;entry key=<span class="code-quote">"typeToSend"</span>&gt;</span>
<span class="code-tag">&lt;util:constant static-field=<span class="code-quote">"javax.ws.rs.core.MediaType.TEXT_XML"</span> /&gt;</span>
<span class="code-tag">&lt;/entry&gt;</span>
<span class="code-tag">&lt;/map&gt;</span>
<span class="code-tag">&lt;/list&gt;</span>
<span class="code-tag">&lt;/property&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span>
<span class="code-tag">&lt;bean id=<span class="code-quote">"customConfigurer"</span> class=<span class="code-quote">"org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"</span>&gt;</span>
<span class="code-tag">&lt;property name=<span class="code-quote">"ignoreUnresolvablePlaceholders"</span> value=<span class="code-quote">"true"</span> /&gt;</span>
<span class="code-tag">&lt;property name=<span class="code-quote">"order"</span> value=<span class="code-quote">"1"</span> /&gt;</span>
<span class="code-tag">&lt;property name=<span class="code-quote">"propertiesArray"</span>&gt;</span>
<span class="code-tag">&lt;list&gt;</span>
<span class="code-tag">&lt;props&gt;</span>
<span class="code-tag">&lt;prop key=<span class="code-quote">"wink.MediaTypeMapper"</span>&gt;</span>custom.MediaTypeMapper<span class="code-tag">&lt;/prop&gt;</span>
<span class="code-tag">&lt;/props&gt;</span>
<span class="code-tag">&lt;/list&gt;</span>
<span class="code-tag">&lt;/property&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span>
</pre>
</div></div>
<ul>
<li>The custom.MediaTypeMapper bean creates a new Media-Type mapper.</li>
</ul>
<ul>
<li>The customConfigurer bean overrides the default factory with a custom factory.</li>
</ul>
<p><div class='panelMacro'><table class='noteMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="images/icons/emoticons/warning.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>customConfigurer</b><br />The order is set to "1". This makes the customConfigurer run before the default Apache Wink configurer.</td></tr></table></div>&#42; In addition, notice that ignoreUnresolvablePlaceholders must be set to true, otherwise the configurer will fail, since some unresolved properties can remain in the context.</p>
<h2><a name="5.5SpringIntegration-CustomizingAlternativeShortcuts"></a>Customizing Alternative Shortcuts</h2>
<p>Apache Wink provides the ability to customize the Alternative Shortcuts in one of two ways.</p>
<div class='panelMacro'><table class='infoMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="images/icons/emoticons/information.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Reference</b><br />For more information on Alternative Shortcuts Mappings refer to section <a href="5.1 Registration and Configuration.html#5.1RegistrationandConfiguration-CustomizingMappings">5.1 Registration and Configuration</a>.</td></tr></table></div>
<h3><a name="5.5SpringIntegration-ExternalPropertiesFile"></a>External Properties File</h3>
<p>The shortcuts are defined in a properties file. The shortcuts properties file is loaded in the same way that the configuration properties file is loaded.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">&lt;bean id=<span class="code-quote">"custom.Shortcuts"</span>
class=<span class="code-quote">"org.springframework.beans.factory.config.PropertiesFactoryBean"</span>&gt;
<span class="code-tag">&lt;property name=<span class="code-quote">"locations"</span>&gt;</span>
<span class="code-tag">&lt;list&gt;</span>
<span class="code-tag">&lt;value&gt;</span>WEB-INF/shortcuts<span class="code-tag">&lt;/value&gt;</span>
<span class="code-tag">&lt;/list&gt;</span>
<span class="code-tag">&lt;/property&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span>
<span class="code-tag">&lt;bean id=<span class="code-quote">"customConfigurer"</span> class=<span class="code-quote">"org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"</span>&gt;</span>
<span class="code-tag">&lt;property name=<span class="code-quote">"ignoreUnresolvablePlaceholders"</span> value=<span class="code-quote">"true"</span> /&gt;</span>
<span class="code-tag">&lt;property name=<span class="code-quote">"order"</span> value=<span class="code-quote">"1"</span> /&gt;</span>
<span class="code-tag">&lt;property name=<span class="code-quote">"propertiesArray"</span>&gt;</span>
<span class="code-tag">&lt;list&gt;</span>
<span class="code-tag">&lt;props&gt;</span>
<span class="code-tag">&lt;prop key=<span class="code-quote">"wink.alternateShortcutsMap"</span>&gt;</span>custom.Shortcuts<span class="code-tag">&lt;/prop&gt;</span>
<span class="code-tag">&lt;/props&gt;</span>
<span class="code-tag">&lt;/list&gt;</span>
<span class="code-tag">&lt;/property&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span>
</pre>
</div></div>
<h3><a name="5.5SpringIntegration-SpringContextFile"></a>Spring Context File</h3>
<p>Defines the map of the shortcuts in the Spring context.</p>
</td>
</tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td height="12" background="http://cwiki.apache.org/confluence/images/border/border_bottom.gif"><img src="images/border/spacer.gif" width="1" height="1" border="0"/></td>
</tr>
<tr>
<td align="center"><font color="grey">Document generated by Confluence on Nov 11, 2009 06:57</font></td>
</tr>
</table>
</body>
</html>