具有spring-integration的HTTP客户端

时间:2014-10-04 00:58:47

标签: spring-integration

我需要编写一个简单的HTTP客户端来生成简单的GET请求并使用Spring集成获取JSON响应。 调用失败,异常中没有消息:org.springframework.web.client.HttpServerErrorException:500内部服务器错误。 我尝试调试Spring代码并成功完成,直到我有源代码,即直到 在AbstractMessageHandler.handleMessage方法中(消息消息) 抽象的handleMessageInternal(消息消息)已经被调用了 异常说请求 网址= http://example.com?q= {q}& authKey = {authKey}& rows = {rows}& page = {page}& filter = {filter} 失败。 URL看起来与我引用的完全相同,即表达式尚未执行。

消息中的有效负载始终如此 - 如果ZtInput具有正确的字段值,则为实例。

有谁能让我知道该怎么做?

这是spring-integration-zt-context.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-http="http://www.springframework.org/schema/integration/http"
xmlns:oxm="http://www.springframework.org/schema/oxm" 
xsi:schemaLocation="http://www.springframework.org/schema/integration/http http://www.springframework.org/schema/integration/http/spring-integration-http-2.1.xsd
    http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-3.0.xsd
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-3.0.xsd">

<int:channel id="InChannelZt"></int:channel>
<int:channel id="OutChannelZt"></int:channel>

<!-- Gateway Start -->
<int:gateway id="ZtGateway" default-request-timeout="5000" default-reply-timeout="5000" 
default-request-channel="InChannelZt" service-interface="com.example.service.ZtService">
    <int:method name="getResults" request-channel="InChannelZt" reply-channel="OutChannelZt" />
</int:gateway>  

<int-http:outbound-gateway id="locationZtGateway"
                           request-channel="InChannelZt" 
                           reply-channel="OutChannelZt"
                           url="${zt_url}?q={q}&amp;authKey={authKey}&amp;rows={rows}&amp;page={page}&amp;filter={filter}"
                           http-method="GET"
                           reply-timeout='5000'                            
                           expected-response-type="com.example.vo.ZtResponse">
        <int-http:uri-variable name="q" expression="payload.getQ()"/>
       <int-http:uri-variable name="authKey" expression="payload.getAuthKey()"/>
       <int-http:uri-variable name="rows" expression="payload.getRows()"/>
       <int-http:uri-variable name="page" expression="payload.getPage()"/>
       <int-http:uri-variable name="filter" expression="payload.getFilter()"/>
</int-http:outbound-gateway>

和其中提到的两个类:

import com.xxxx.vo.ZtInput;
import com.xxxx.vo.ZtResponse;
public interface ZtService {
    ZtResponse getSearchResults(ZtInput ztInput);
}

有效载荷:

public class ZtInput {

private String q; //=pink
private String authKey = "baef7f8e39c53f852c8a14b7f6018b58";
private String rows="20";
private String page="1";
private String filter = "";


public ZtInputVO() {
}
public String getQ() {
    return q;
}
public void setQ(String q) {
    this.q = q;
}
public String getAuthKey() {
    return authKey;
}
public void setAuthKey(String authKey) {
    this.authKey = authKey;
}
public String getRows() {
    return rows;
}
public void setRows(String rows) {
    this.rows = rows;
}
public String getPage() {
    return page;
}
public void setPage(String page) {
    this.page = page;
}
public String getFilter() {
    return filter;
}
public void setFilter(String filter) {
    this.filter = filter;
}
}

1 个答案:

答案 0 :(得分:0)

异常中的URI是原始的(未展开的URI);扩展被执行到一个不同的变量。 (我们应该/将更改它以记录扩展的URI)。但底线是您的服务器不喜欢扩展的URI并返回500内部服务器错误。

您可以使用network / tcp监视器(eclipse内置了一个或者您可以使用wireshark)来检查发送到服务器的实际URL。您还可以查看服务器日志(如果已启用)。

或者,在调试器中,逐步执行第415行(在当前源代码中 - 版本4.0.4)并检查realUri

编辑:例外现在包括扩展的URI(目前在4.0.5.BUILD-SNAPSHOT and 4.1.0.BUILD-SNAPSHOT)中可用。