Christophe Labouisse bio photo

Christophe Labouisse

Freelance Java expert, Docker enthusiast

Email Twitter Google+ LinkedIn Github Stackoverflow Hopwork

Following my post on Handling videos with RESTX here is the client counterpart. I have server handling both classical REST calls and video operations. On the client side I already have the rest client implemented using Spring Android wrapped by Android Annotations. As I did on the server side I want to use the same system to handle both REST calls and video transfers.

Using Android annotations, the rest client will look like this:

@Rest(converters = {MappingJackson2HttpMessageConverter.class})
public interface MyRestClient extends RestClientRootUrl {

    // Other methods omitted

    String addVideo(InputStream videoStream);

    File getVideo(String videoId);

The issue I face with this naive implementation is the same I faced on the server side: Jackson is trying to process the video stream. The solution I used was to create a custom HttpMessageConverter for the video stream.

I had a small issue here with the readInternal method. Initially I wanted to pass the http stream directly but it didn’t work as the http stream got closed at some point before I had time to use it. So I eventually implement a workaround by saving the video to a file.

Then in the rest client I have to add my converter:

@Rest(converters = {VideoHttpMessageConverter.class,
public interface MyRestClient extends RestClientRootUrl {
    // Not change to the class body