2014-10-04 159 views
0

我需要編寫一個簡單的HTTP客戶端來進行簡單的GET請求,並使用Spring集成來獲得JSON響應。 調用失敗,異常中沒有消息:org.springframework.web.client.HttpServerErrorException:500內部服務器錯誤。 我試着調試春天代碼,並做到了成功,直到我的源代碼,即直到該方法AbstractMessageHandler.handleMessage(消息消息) 抽象handleMessageInternal(消息消息)被稱爲其拋出 例外說,要求與 URL = http://example.com?q= {q} & authKey = {authKey} & rows = {rows} & page = {page} & filter = {filter} 失敗。網址看起來與我引用的完全一樣,即表達式尚未執行。與彈簧集成的HTTP客戶端

消息中的負載總是與應該一樣 - 如果ZtInput具有正確的字段值,則爲實例。

任何人都可以給我一個想法該怎麼辦?

這裏是彈簧集成-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; 
} 
} 

回答

0

異常中的URI是原始的(未擴展的URI);擴展被執行到一個不同的變量。 (我們應該/會改變這種情況來記錄擴展的URI)。但底線是您的服務器不喜歡擴展的URI並返回500內部服務器錯誤。

您可以使用網絡/ TCP監視器(eclipse有一個內置的或者可以使用wireshark)來檢查發送到服務器的實際URL。如果啓用,您還可以查看服務器日誌。

或者在調試器中,下到第415行(在當前源代碼 - 版本4.0.4中)並檢查realUri

編輯:。唯一的例外現在包括擴展的URI(目前4.0.5.BUILD-SNAPSHOT and 4.1.0.BUILD-SNAPSHOT)提供

+0

非常感謝我確實被,包括未加工的URI異常消息誤導這是非常好的,你定吧。 – 2014-10-06 16:23:41