INT-3069 Add Global Gateway Method Metadata
https://jira.springsource.org/browse/INT-3069 Provide a mechanism to specify headers and payload-expression that can be applied to all methods in the gateway. - Headers defined as 'default' are globally applied to all gateway methods. - Also supports 'default-payload-expression'. - Headers defined on a specific method override the global settings. - An `@Header` in the interface is overridden by a specific <header/> for that method (current behavior) - An `@Header` in the interface is NOT overridden by a <default-header/> - Add 3 new SpEL variables: -- #methodName (synonym for #method - deprecated) -- #methodString (a string representation of the method showing return type and arg types) -- #methodObject (the Method object) <int:gateway id="sampleGateway" service-interface="org.springframework.integration.gateway.GatewayInterfaceTests.Bar" default-request-channel="requestChannelBaz"> <int:default-header name="name" expression="#methodName"/> <int:default-header name="string" expression="#methodString"/> <int:default-header name="object" expression="#methodObject"/> <int:method name="baz"> <int:header name="name" value="overrideGlobal"/> </int:method> </int:gateway> INT-3069 Polishing - PR Comments - Remove extra 'method' variables, just provide `gatewayMethod`. - Parser improvements - Schema now enforces default-header elements to precede method elements - Doc polishing
This commit is contained in:
committed by
Artem Bilan
parent
6d9e48b9ac
commit
36795e5ee8
@@ -116,9 +116,10 @@ public interface Cafe {
|
||||
|
||||
<programlisting language="xml"><![CDATA[<int:gateway id="myGateway" service-interface="org.foo.bar.TestGateway"
|
||||
default-request-channel="inputC">
|
||||
<int:default-header name="calledMethod" expression="#gatewayMethod.name"/>
|
||||
<int:method name="echo" request-channel="inputA" reply-timeout="2" request-timeout="200"/>
|
||||
<int:method name="echoUpperCase" request-channel="inputB"/>
|
||||
<int:method name="echoViaDefault"/>
|
||||
<int:method name="echoUpperCase" request-channel="inputB"/>
|
||||
<int:method name="echoViaDefault"/>
|
||||
</int:gateway>]]></programlisting>
|
||||
|
||||
<para>
|
||||
@@ -145,6 +146,45 @@ public interface Cafe {
|
||||
In the above case you can clearly see how a different value will be set for the 'RESPONSE_TYPE'
|
||||
header based on the gateway's method.
|
||||
</para>
|
||||
<para><emphasis role="bold">Expressions and "Global" Headers</emphasis></para>
|
||||
<para>
|
||||
The <code><header/></code> element supports <code>expression</code> as an alternative to
|
||||
<code>value</code>. The SpEL expression is evaluated to determine the value of the header. There is no
|
||||
<code>#root</code> object but the following variables are available:
|
||||
<itemizedlist>
|
||||
<listitem>
|
||||
#args - an <code>Object[]</code> containing the method arguments
|
||||
</listitem>
|
||||
<listitem>
|
||||
#gatewayMethod - the <classname>java.reflect.Method</classname> object representing the method in the
|
||||
<code>service-interface</code> that was invoked. A header containing this variable can be used
|
||||
later in the flow, for example, for routing. For example, if you wish to route on the simple method
|
||||
name, you might add a header, with expression <code>#gatewayMethod.name</code>.
|
||||
<note>
|
||||
The <classname>java.reflect.Method</classname> is not serializable; a header with expression
|
||||
<code>#gatewayMethod</code> will be lost if you later serialize the message. So, you may wish
|
||||
to use <code>#gatewayMethod.name</code> or <code>#gatewayMethod.toString()</code> in those cases;
|
||||
the <code>toString()</code> method provides a String representation of the method, including
|
||||
parameter and return types.
|
||||
</note>
|
||||
<note>
|
||||
Prior to 3.0, the <code>#method</code> variable was available, representing the method name only.
|
||||
This is still available, but deprecated; use <code>#gatewayMethod.name</code> instead.
|
||||
</note>
|
||||
</listitem>
|
||||
</itemizedlist>
|
||||
</para>
|
||||
<para>
|
||||
Since 3.0, <code><default-header/></code>s can be defined to add headers to all messages produced
|
||||
by the gateway, regardless of the method invoked. Specific headers defined for a method take precedence
|
||||
over default headers. Specific headers defined for a method here will override any <code>@Header</code> annotations
|
||||
in the service interface. However, default headers will NOT override any <code>@Header</code> annotations
|
||||
in the service interface.
|
||||
</para>
|
||||
<para>
|
||||
The gateway now also supports a <code>default-payload-expression</code> which will be applied for all methods
|
||||
(unless overridden).
|
||||
</para>
|
||||
|
||||
</section>
|
||||
<section id="gateway-calling-no-argument-methods">
|
||||
|
||||
@@ -155,6 +155,20 @@
|
||||
<section id="3.0-general">
|
||||
<title>General Changes</title>
|
||||
|
||||
<section id="3.0-gateway">
|
||||
<title><gateway> Changes</title>
|
||||
<para>
|
||||
<itemizedlist>
|
||||
<listitem>
|
||||
It is now possible to set common headers across all gateway methods, and more options
|
||||
are provided for adding, to the message, information about which method was invoked.
|
||||
</listitem>
|
||||
</itemizedlist>
|
||||
</para>
|
||||
<para>
|
||||
For more information see <xref linkend="gateway"/>.
|
||||
</para>
|
||||
</section>
|
||||
<section id="3.0-corr-endpoint-empty-groups">
|
||||
<title>Aggregator 'empty-group-min-timeout' property</title>
|
||||
<para><classname>AbstractCorrelatingMessageHandler</classname> provides a new property
|
||||
|
||||
Reference in New Issue
Block a user