INT-3516: Allow Optional<> in POJO Method Args
JIRA: https://jira.spring.io/browse/INT-3516 * Add `Optional<>` support for `@Header` in the `MessagingMethodInvokerHelper` * Add `Optional<>` test-case * Change `sourceCompatibility` for test to the Java 8 INT-3516: Revert SF version to 4.1.1 Add Docs on the matter Fix WS Tests; Revert StubJavaMailSender
This commit is contained in:
committed by
Gary Russell
parent
c84b16e2b5
commit
a3d8776b5c
@@ -53,7 +53,26 @@
|
||||
not worrying about the contents of the message. Think of it as a NULL JMS message. An example use-case for such an
|
||||
implementation could be a simple counter/monitor of messages deposited on the input channel.
|
||||
</note>
|
||||
<para>
|
||||
<para>
|
||||
Starting with <emphasis>version 4.1</emphasis> the framework correct converts Message properties
|
||||
(<code>payload</code> and <code>headers</code>) to the Java 8 <classname>Optional</classname> POJO method
|
||||
parameters:
|
||||
<programlisting language="java"><![CDATA[public class MyBean {
|
||||
public String computeValue(Optional<String> payload,
|
||||
@Header(value="foo", required=false) String foo1,
|
||||
@Header(value="foo") Optional<String> foo2) {
|
||||
if (payload.isPresent()) {
|
||||
String value = payload.get();
|
||||
...
|
||||
}
|
||||
else {
|
||||
...
|
||||
}
|
||||
}
|
||||
|
||||
}]]></programlisting>
|
||||
</para>
|
||||
<para>
|
||||
Using a "ref" attribute is generally recommended if the custom Service Activator handler implementation can be reused
|
||||
in other <code><service-activator></code> definitions. However if the custom Service Activator handler implementation
|
||||
is only used within a single definition of the <code><service-activator></code>, you can provide an inner bean definition:
|
||||
|
||||
@@ -230,5 +230,12 @@
|
||||
See <xref linkend="resequencer"/>.
|
||||
</para>
|
||||
</section>
|
||||
<section id="4.1-Optional-Parameter">
|
||||
<title>Optional POJO method parameter</title>
|
||||
<para>
|
||||
Now Spring Integration consistently handles the Java 8's <classname>Optional</classname> type.
|
||||
See <xref linkend="service-activator-namespace"/>.
|
||||
</para>
|
||||
</section>
|
||||
</section>
|
||||
</chapter>
|
||||
|
||||
Reference in New Issue
Block a user