This took me quite a while to work out so I wanted to share it. Most information came from SO and I wanted to consolidate into this one place.
My requirements are to upload files using a RESTFul POST. Due to possibly large files I wanted to stream the files. I obviously want to be able to read the response.
I planned to use Jersey as the REST Server and Spring's RestTemplate as the client (and for testing).
The problem I faced was streaming POSTs and receiving a response. How can I do that? (Rhetorical question - I answer this!)
I am using SpringBoot
1.2.4.RELEASE
with Jersey being pulled in by:I created the project with the brilliant Spring Starter Project (
Spring Tool Suite > New
or you can do through a website I believe and no doubt IntelliJ has this capability also). And chose 'Jersey (JAX-RS)' option. In the gradlebuild.gradle
I also added the dependency:I wrote this server side code.
Where i had most troubles was in getting a Response with a location.
Firstly I had to handle streaming large files. I followed https://stackoverflow.com/a/15785322/1019307 as you can see in the test below. I was NOT obtaining a Response no matter what I tried with the
HttpMessageConverterExtractor
as per that post:After finding https://stackoverflow.com/a/6006147/1019307 I wrote:
This gave me this test:
I need to refactor much in that test out into some services.