2014-10-10 35 views
0

我想測試一個入站HTTP gatway使用Spring Integration的INT-HTTP:入站網關:Spring集成:INT-HTTP:入站網關與URL路徑變量

<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,你會給我一些提示嗎?

非常感謝!

+0

可以爲您在您的文章包括您所使用的URI? – andreadi 2014-10-10 13:20:14

回答

0

首先你應該顯示你用來發送HTTP請求的uri

從其他方面來看,如果您將servlet映射到/correlateOut/*,則不得在目標mapping中使用它,因爲所有其他端點都在該上下文之下。

所以,你path應該是path="{origin}/{msgtype}/{priority}"