简体   繁体   English

Spring集成:带有URL路径变量的int-http:inbound-gateway

[英]Spring Integration : int-http:inbound-gateway with url Path Variables

I am trying to test an Inbound http gatway using Spring Integration int-http:inbound-gateway: 我正在尝试使用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>

My Web.xml : 我的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>

Using the RestTemplate I am trying to make a POST request to the gateway: 我使用RestTemplate尝试向网关发出POST请求:

The

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

I am alway getting NOT FOUND 404, would you any please give me some hints? 我总是找不到404,请给我一些提示吗?

Thank you very much! 非常感谢你!

First of all you should show the uri which you use to send HTTP request. 首先,您应该显示用于发送HTTP请求的uri

From other side if you map servlet to the /correlateOut/* you must not to use it in the target mapping , because all other endpoints are under that context. 另一方面,如果将servlet映射到/correlateOut/* ,则必须不要在目标mapping使用它,因为所有其他端点都在该上下文下。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM