【问题标题】:Spring Integration : int-http:inbound-gateway with url Path VariablesSpring 集成:带有 url 路径变量的 int-http:inbound-gateway
【发布时间】:2014-10-10 13:11:55
【问题描述】:

我正在尝试使用 Spring Integration int-http:inbound-gateway 测试入站 http 网关:

<int-http:inbound-gateway id="correlateOutgoingMessage"
    supported-methods="POST" request-channel="toOutCorrelator"
    reply-channel="fromOutCorrelator" view-name="/correlateOutgoingMessage"
    path="/correlateOut/{origin}/{msgtype}/{priority}"
    reply-timeout="50000">
    <int-http:header name="origin" expression="#pathVariables.origin" />
    <int-http:header name="msgtype" expression="#pathVariables.msgtype" />
    <int-http:header name="priority" expression="#pathVariables.priority" />
</int-http:inbound-gateway>

我的 Web.xml:

<servlet>
    <servlet-name>correlateOut</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>WEB-INF/intg-schema.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>correlateOut</servlet-name>
    <!-- controler/* -->
    <url-pattern>/correlateOut/*</url-pattern>
</servlet-mapping>

我正在尝试使用 RestTemplate 向网关发出 POST 请求:

uri =  "http://localhost:8080/test/correlateOutgoingMessage/{origin}/{msgtype}/{priority}"

    String origin = "xxxx";
    Integer msgtype = 2333;
    Integer priority = 2;

    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.TEXT_PLAIN);

    HttpEntity<?> request = null;

    ResponseEntity<String> httpResponse = null;

    request = new HttpEntity<Object>(messageContent);


    httpResponse = template.exchange(uri, HttpMethod.POST, request,
            String.class, getUrlParams(origin, msgtype, priority));

我总是收到 NOT FOUND 404,请给我一些提示吗?

非常感谢!

【问题讨论】:

  • 您可以在帖子中包含您正在使用的 uri 吗?

标签: java spring-mvc spring-integration


【解决方案1】:

首先,您应该显示用于发送 HTTP 请求的uri

如果您将 servlet 映射到 /correlateOut/*,则不能在目标 mapping 中使用它,因为所有其他端点都在该上下文中。

所以,你的path 应该是path="{origin}/{msgtype}/{priority}"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-15
    • 2023-01-21
    • 2021-10-18
    • 2013-06-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多