2012-02-14 91 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