2017-04-14 67 views
1

我送下面的請求我的REST API讀取矩陣參數: http://localhost:8080/accid234/accounts;[email protected]/departmentUse無法從代理的請求

REST的API的Java代碼:

@Path("/{accounts}") 
public Accounts getDeptAccounts(@PathParam("accounts") PathSegment pathSegment) { 

Map<String, String> matrixParams = pathSegment.getMatrixParameters(); 

for (String s: matrixParams.keySet()) { 
     System.out.println("***Matrix params Key:" + s + "Value:" + matrixParams.get(s)); 
    } 
} 

也能正常工作時,請求被髮送直接到上面提到的終點。

但是,當請求被封裝(在ForwardedHeaderFilter),我無法讀取矩陣參數。

原因我面臨這個問題:

我使用的彈簧雲Netflix的-zuul作爲代理路由服務,並將其添加代理頭如x-forwarded-hostx-forwarded-protox-forwarded-prefix等請求。這與包裝請求相同。

我配置了Zuul不添加代理標頭,然後Matrix參數工作。但是我想知道是否可以嘗試以任何其他方式解決問題,因爲我不確定在刪除代理標題時可能會遇到什麼問題。

現在的問題是:如何處理代理請求中的矩陣參數?

我嘗試使用Matrix變量而不是PathSegment,但它也沒有奏效。

回答

0

Spring的ForwardedHeaderFilter通過使用UrlPathHelper來剝離分號。您可以通過將UrlPathHelper.removeSemicolonContent設置爲false來解決此問題。

你會注意到ForwardedHeaderFilter.pathHelper是一個私人領域,所以你需要使用反射來訪問它。

+0

感謝這幫助 – Ram