Spring集成:int-http:入站网关,带有url Path Variables

时间:2014-10-10 13:11:56

标签: java spring-mvc spring-integration

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

<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));

我总是找不到404,你能不能给我一些提示?

非常感谢!

1 个答案:

答案 0 :(得分:0)

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

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

因此,您的path应为path="{origin}/{msgtype}/{priority}"