网关方法名称为标头值

时间:2013-10-19 14:39:28

标签: spring-integration

我有一个带有默认请求通道的网关和多种方法。

public interface IUserService {
 public void updateUserName(Long id, String username);
 public void updatePassword(Long id, String password);
 ...
}

和以下xml配置

...
<gateway id="userService" service-interface="...IUserService"
         default-request-channel="dataRequestChannel" 
         default-reply-channel="dataResponseChannel" />
...

如何获取有关所调用方法的信息?

我知道可以应用静态标头值,但这是唯一的方法吗? 或者我完全错了?

由于

2 个答案:

答案 0 :(得分:1)

我们有open JIRA issue for this功能;请投票。

现在,#method变量在特定方法声明

中的表达式中可用
<int:gateway id="gw"
    service-interface="foo.Gateway"
    default-request-channel="input">
    <int:method name="sendAndReceive">
        <int:header name="gwMethod" expression="#method"/>
    </int:method>
</int:gateway>

但你仍然需要声明每种方法。

也许另一个相对简单的增强是在方法名称中支持通配符;类似......

<int:gateway id="gw"
    service-interface="foo.Gateway"
    default-request-channel="input">
    <int:method name="*">
        <int:header name="gwMethod" expression="#method"/>
    </int:method>
</int:gateway>

为所有方法添加方法*的标头。

答案 1 :(得分:0)

从3.0.1开始,您可以执行以下操作,在通过网关访问的所有方法中设置标头(您也可以像往常一样管理特定方法)。

我将展示如何设置两个标头属性,transportType和methodType,一个动态和一个静态:

<int:gateway id="gw" 
    service-interface="foo.async.Gateway" 
    default-request-channel="gateway-request-channel"
    default-reply-channel="gateway-response-channel">
    <int:default-header name="transportType" value="async-msg"/>
    <int:default-header name="methodType" expression="#gatewayMethod.name"/>
</int:gateway>

http://docs.spring.io/spring-integration/reference/html/messaging-endpoints-chapter.html#gateway-configuration-annotations

稍晚但对于后来跟随此帖子的人的正确解决方案。

相关问题