player.setAutoTerminationTimeout(100000);
// Following sample
// http://stackoverflow.com/questions/8293687/sample-http-range-request-session
RestTemplate httpClient = getRestTemplate();
{
HttpHeaders requestHeaders = new HttpHeaders();
MultiValueMap<String, String> postParameters = new LinkedMultiValueMap<String, String>();
HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<MultiValueMap<String, String>>(
postParameters, requestHeaders);
ResponseEntity<byte[]> response = httpClient.exchange(url,
HttpMethod.GET, requestEntity, byte[].class);
System.out.println(response);
assertTrue("The server doesn't accept ranges", response
.getHeaders().containsKey("Accept-ranges"));
assertTrue("The server doesn't accept ranges with bytes", response
.getHeaders().get("Accept-ranges").contains("bytes"));
}
long fileLength = 0;
{
// Range: bytes=0-
HttpHeaders requestHeaders = new HttpHeaders();
requestHeaders.set("Range", "bytes=0-");
MultiValueMap<String, String> postParameters = new LinkedMultiValueMap<String, String>();
HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<MultiValueMap<String, String>>(
postParameters, requestHeaders);
ResponseEntity<byte[]> response = httpClient.exchange(url,
HttpMethod.GET, requestEntity, byte[].class);
System.out.println(response);
assertEquals(
"The server doesn't respond with http status code 206 to a request with ranges",
HttpStatus.PARTIAL_CONTENT, response.getStatusCode());
fileLength = Long.parseLong(response.getHeaders()
.get("Content-Length").get(0));
}
{
HttpHeaders requestHeaders = new HttpHeaders();
long firstByte = fileLength - 3000;
long lastByte = fileLength - 1;
long numBytes = lastByte - firstByte + 1;
requestHeaders.set("Range", "bytes=" + firstByte + "-" + lastByte);
MultiValueMap<String, String> postParameters = new LinkedMultiValueMap<String, String>();
HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<MultiValueMap<String, String>>(
postParameters, requestHeaders);
ResponseEntity<byte[]> response = httpClient.exchange(url,
HttpMethod.GET, requestEntity, byte[].class);
System.out.println(response);
assertEquals(