2012-02-14 90 views
2

我想在我的CXF休息客戶端中將HTTP狀態碼轉換爲Java異常。根據official documentation我需要使用ResponseExceptionMapper,但沒有任何例子可以使它工作。我的理解是,我需要將其註冊爲提供者,但我如何使用代理類型的客戶端來完成此操作?我嘗試下面的代碼在CXF JAX-RS客戶端中處理異常

//create a proxy client  
locationService = JAXRSClientFactory.create(applicationURI + "/rest/", LocationService.class); 

//registering my ResponseExceptionMapper 
ProviderFactory.getSharedInstance().registerUserProvider(LocationResponseExceptionMapper.getInstance()); 

,但它是不工作的,因爲ProviderFactory.getSharedInstance()返回不同ProviderFactory實例,然後通過我的客戶端使用的實例。

回答

1
使用 this signature

供應異常映射到代理廠家:

//create a proxy client with specified exception mapping provider 
List<Object> providers = new ArrayList<Object>(); 
providers.add(LocationResponseExceptionMapper.getInstance()); 
locationService = JAXRSClientFactory.create(applicationURI + "/rest/", LocationService.class, providers); 
+0

感謝,這是太明顯了,我還沒有想過這個問題:) – 2012-02-15 08:43:17