Spring Integration or Apache HTTP Client

后端 未结 3 1307
后悔当初
后悔当初 2021-01-01 23:29

I have a spring application which requires to call REST based external API calls for some data.

The data format from the API is JSON.

My question is which o

3条回答
  •  执念已碎
    2021-01-01 23:46

    As the others have mentioned both Spring RestTemplate and Jersey Rest Client will do the job. I have used both. Both them work great with Jackson and IIRC they will automatically use it if found (spring for sure).

    There is one advantage I like about Spring RestTemplate is that you can plugin Commons HTTP as the transport. So if you had some weird headers, cookies, timeout, threading you can configure Commons HTTP and then put it into the RestTemplate.

    RestTemplate restTemplate = new RestTemplate();
    restTemplate.getMessageConverters().add(new MappingJacksonHttpMessageConverter());
    restTemplate.setErrorHandler(new DefaultResponseErrorHandler());
    CommonsClientHttpRequestFactory f = new CommonsClientHttpRequestFactory();
    f.setReadTimeout(120 * 1000);
    

    The point is if you are thinking about using Commons HTTP Client then as @Skaffman says RestTemplate is a no-brainer over something more complicated!

提交回复
热议问题