Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PA165 - Airport - project
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Contributor analytics
CI/CD analytics
Repository analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ján Macháček
PA165 - Airport - project
Commits
1bc33a85
There was an error fetching the commit references. Please try again later.
Commit
1bc33a85
authored
1 year ago
by
Ján Macháček
Browse files
Options
Downloads
Patches
Plain Diff
feat: controller return sample file
parent
97334277
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
report/src/main/java/cz/muni/fi/pa165/report/server/ReportController.java
+23
-9
23 additions, 9 deletions
...java/cz/muni/fi/pa165/report/server/ReportController.java
report/src/main/resources/sample.pdf
+198
-0
198 additions, 0 deletions
report/src/main/resources/sample.pdf
with
221 additions
and
9 deletions
report/src/main/java/cz/muni/fi/pa165/report/server/ReportController.java
+
23
−
9
View file @
1bc33a85
...
...
@@ -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
);
}
}
This diff is collapsed.
Click to expand it.
report/src/main/resources/sample.pdf
0 → 100644
+
198
−
0
View file @
1bc33a85
File added
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment