【问题标题】:Spring Integration HTTP inbound adapter method name?Spring Integration HTTP入站适配器方法名称?
【发布时间】:2012-07-13 20:57:25
【问题描述】:

是否可以将方法名称映射到带有 int-http:inbound-gateway 的标头?例如:

<int-http:inbound-gateway request-channel="requests" reply-channel="replies"
    supported-moethds="GET,PUT"
    path="/user">
    <int-http:header name="requestMethod" expression="#requestMethod"/>
</int-http:inbound-gateway>

<!-- ... -->

<int:header-value-router input-channel="requests" header-name="requestMethod>
    <int:mapping value="GET" channel="getUserRequests"/>
    <int:mapping value="PUT" channel="addUserRequests"/>
</int:header-value-router>

此外,我看到了使用 #requestParams 的示例,但是 2.1 的 javadoc 提到了 #queryParameters,我在官方文档页面中没有看到其中任何一个的文档。你们知道一个很好的资源,它不仅描述了 SpEL 如何解析表达式,还描述了哪些字段可用于它?我只能说我有标题、有效负载、#pathVariables,也许还有#requestParams 或#queryParams,以及我在当前上下文中定义的任何其他@beans。

提前致谢!

【问题讨论】:

    标签: http spring-integration


    【解决方案1】:

    该方法总是映射到标头

    ... http_requestMethod=POST ...
    
    
    Message<?> message = messageBuilder
        .setHeader(org.springframework.integration.http.HttpHeaders.REQUEST_URL, request.getURI().toString())
        .setHeader(org.springframework.integration.http.HttpHeaders.REQUEST_METHOD, request.getMethod().toString())
        .setHeader(org.springframework.integration.http.HttpHeaders.USER_PRINCIPAL, servletRequest.getUserPrincipal())
        .build();
    

    javadoc 错误。另外两个变量是#requestParams 和#pathVariables。

    【讨论】:

    • 顺便说一句;请随时针对文档组件打开 JIRA 问题,以改进有关这些变量的文档。 jira.springsource.org/browse/INT
    • 太好了,谢谢!介意我指向你找到这个 sn-p 的源文件吗?
    • 当然,它在 HttpRequestHandlingEndpointSupport 中;这也是将变量添加到 SpEL 评估上下文的地方 evaluationContext.setVariable("requestParams", requestParams);, evaluationContext.setVariable("pathVariables", pathVariables);
    • 哇!该源文件比我能找到的任何文档都要好。谢谢!供将来参考:github.com/SpringSource/spring-integration/blob/master/…
    猜你喜欢
    • 1970-01-01
    • 2014-06-29
    • 2023-03-12
    • 1970-01-01
    • 2017-10-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多