Skip to content
Snippets Groups Projects
Commit 1bc33a85 authored by Ján Macháček's avatar Ján Macháček
Browse files

feat: controller return sample file

parent 97334277
No related branches found
No related tags found
No related merge requests found
......@@ -2,9 +2,13 @@ package cz.muni.fi.pa165.report.server;
import cz.muni.fi.pa165.report.server.api.ReportApiDelegate;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.core.io.Resource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RestController;
import java.io.*;
@RestController
public class ReportController implements ReportApiDelegate{
......@@ -12,24 +16,34 @@ public class ReportController implements ReportApiDelegate{
@Override
public ResponseEntity<Resource> getReportFlightById(Long id){
byte[] bytes = new byte[(int) 246];
ByteArrayResource resource = new ByteArrayResource(bytes);
return ResponseEntity.ok(resource);
ClassLoader classLoader = getClass().getClassLoader();
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Type", "application/pdf");
headers.add("Content-Disposition", "attachment; filename=labels.pdf");
// the stream holding the file content
// funny, if can use Java 7, please uses Files.readAllBytes(path)
try(InputStream inputStream = classLoader.getResourceAsStream("sample.pdf")){
byte[] bytes = new byte[inputStream.available()];
inputStream.read(bytes);
ByteArrayResource resource = new ByteArrayResource(bytes);
return new ResponseEntity<>(resource, headers, HttpStatus.OK);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
public ResponseEntity<Resource> getReportAirportById(Long id){
byte[] bytes = new byte[(int) 246];
ByteArrayResource resource = new ByteArrayResource(bytes);
return ResponseEntity.ok(resource);
return getReportFlightById(id);
}
@Override
public ResponseEntity<Resource> getReportAirplaneById(Long id){
byte[] bytes = new byte[(int) 246];
ByteArrayResource resource = new ByteArrayResource(bytes);
return ResponseEntity.ok(resource);
return getReportFlightById(id);
}
}
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment