Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

Spring makes it convenient to register resources and providers as spring beans.
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:

Code Block
xml
xml

<context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>classpath:META-INF/server/symphonyCoreContextwinkCoreContext-server.xml
               classpath:mycontext.xml
  </param-value>
</context-param>
<listener>
  <listener-class>
    org.springframework.web.context.ContextLoaderListener
  </listener-class>
</listener>

Registering Resources and Providers

Apache Wink provides the comorg.hpapache.symphonywink.spring.Registrar class in order to register resources and providers through a Spring context. The Registrar class extends the SymphonyApplication 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 SymphonyApplication WinkApplication objects during the context loading. The registrar provides the following properties:

...

  • priority - the priority of the SymphonyApplicationWinkApplication
Info
titleReference

Refer to chapter 3, section ‎3.4 TBD for For more information on Priorities refer to section 5.1 Registration and Configuration.

Code Block
xml
xml

<bean class="comorg.hpapache.symphonywink.spring.Registrar">
  <property name="classes">
    <set value-type="java.lang.Class">
      <value>package.className</value>
    </set>
  </property>
  <property name="instances">
    <set>
      <ref bean="resources.resource1" />
      <ref bean="resources.resource2" />
      <ref bean="providers.provider1" />
    </set>
  </property>
</bean>

...

Apache Wink provides a set of customizable properties. When working with Spring, the user developer should redefine the custom properties file using the Spring context:

Code Block
xml
xml

<bean id="customPropertiesFactory"
class="org.springframework.beans.factory.config.PropertiesFactoryBean">
  <property name="locations">
    <list>
      <value>WEB-INF/configuration.properties</value>
    </list>
  </property>
</bean>
<bean id="customConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
  <property name="ignoreUnresolvablePlaceholders" value="true" />
  <property name="order" value="1" />
  <property name="propertiesArray">
    <list>
      <props>
       <prop key="symphonywink.propertiesFactory">customPropertiesFactory</prop>
      </props>
    </list>
  </property>
</bean>

...

Apache Wink provides the ability to customize the Media-Type mappings using Spring context.

Info
titleReference

Refer to chapter 3, section ‎3.7 TBD for For more information on Media-Type Mapping refer to section 5.1 Registration and Configuration .

Code Block
xml
xml

<bean id="custom.MediaTypeMapper" class="comorg.hpapache.symphonywink.server.internal.MediaTypeMapper">
  <property name="mappings">
    <list>
      <map>
        <entry key="userAgentStartsWith" value="Mozilla/" />
        <entry key="resultMediaType">
          <util:constant static-field=" javax.ws.rs.core.MediaType.ATOM" />
        </entry>
        <entry key="typeToSend">
          <util:constant static-field="javax.ws.rs.core.MediaType.TEXT_XML" />
        </entry>
      </map>
    </list>
  </property>
</bean>
<bean id="customConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
  <property name="ignoreUnresolvablePlaceholders" value="true" />
  <property name="order" value="1" />
  <property name="propertiesArray">
    <list>
      <props>
        <prop key="symphonywink.MediaTypeMapper">custom.MediaTypeMapper</prop>
      </props>
    </list>
  </property>
</bean>

...

Note
titlecustomConfigurer

The order is set to "1". This makes the customConfigurer run before the default Apache Wink configurer.

* In addition, notice that ignoreUnresolvablePlaceholders must be set to true, otherwise the configurer will fail, since some unresolved properties can remain in the context.

Customizing Alternative Shortcuts

Apache Wink provides the ability to customize the Alternative Shortcuts in one of two ways.

Info
titleReference

Refer to chapter 3, section ‎3.8 TBD for For more information on Alternative Shortcuts Mappings refer to section 5.1 Registration and Configuration.

External Properties File

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.

Code Block
xml
xml

<bean id="custom.Shortcuts"
class="org.springframework.beans.factory.config.PropertiesFactoryBean">
  <property name="locations">
    <list>
      <value>WEB-INF/shortcuts</value>
    </list>
  </property>
</bean>
<bean id="customConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
  <property name="ignoreUnresolvablePlaceholders" value="true" />
  <property name="order" value="1" />
  <property name="propertiesArray">
    <list>
      <props>
        <prop key="symphonywink.alternateShortcutsMap">custom.Shortcuts</prop>
      </props>
    </list>
  </property>
</bean>

...