Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
java_dzienna_15_09
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Patryk Czarnik
java_dzienna_15_09
Commits
b020b8ff
Commit
b020b8ff
authored
Oct 07, 2022
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MessageBodyWriter tworzący pusty PDF
parent
05956ec8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
77 additions
and
0 deletions
+77
-0
RProductsPDF.java
PC34-RestSerwer/src/main/java/sklep/rest/RProductsPDF.java
+44
-0
PDFWriter.java
PC34-RestSerwer/src/main/java/sklep/rest/ext/PDFWriter.java
+33
-0
No files found.
PC34-RestSerwer/src/main/java/sklep/rest/RProductsPDF.java
0 → 100644
View file @
b020b8ff
package
sklep
.
rest
;
import
javax.ws.rs.GET
;
import
javax.ws.rs.Path
;
import
javax.ws.rs.PathParam
;
import
javax.ws.rs.Produces
;
import
sklep.db.DBConnection
;
import
sklep.db.DBException
;
import
sklep.db.ProductDAO
;
import
sklep.db.RecordNotFound
;
import
sklep.model.Product
;
import
sklep.model.ProductList
;
import
sklep.photo.PhotoUtil
;
@Path
(
"/products.pdf"
)
@Produces
(
"application/pdf"
)
public
class
RProductsPDF
{
@GET
public
ProductList
readAll
()
throws
DBException
{
try
(
DBConnection
db
=
DBConnection
.
open
())
{
ProductDAO
productDAO
=
db
.
productDAO
();
return
new
ProductList
(
productDAO
.
readAll
());
}
}
@GET
@Path
(
"/{id}"
)
public
Product
readOne
(
@PathParam
(
"id"
)
int
productId
)
throws
DBException
,
RecordNotFound
{
try
(
DBConnection
db
=
DBConnection
.
open
())
{
ProductDAO
productDAO
=
db
.
productDAO
();
return
productDAO
.
findById
(
productId
);
}
}
@GET
@Path
(
"/{id}/photo"
)
@Produces
(
"image/jpeg"
)
public
byte
[]
getPhoto
(
@PathParam
(
"id"
)
int
productId
)
throws
DBException
,
RecordNotFound
{
return
PhotoUtil
.
readBytes
(
productId
);
}
}
PC34-RestSerwer/src/main/java/sklep/rest/ext/PDFWriter.java
0 → 100644
View file @
b020b8ff
package
sklep
.
rest
.
ext
;
import
java.io.IOException
;
import
java.io.OutputStream
;
import
java.lang.annotation.Annotation
;
import
java.lang.reflect.Type
;
import
javax.ws.rs.WebApplicationException
;
import
javax.ws.rs.core.MediaType
;
import
javax.ws.rs.core.MultivaluedMap
;
import
javax.ws.rs.ext.MessageBodyWriter
;
import
javax.ws.rs.ext.Provider
;
import
sklep.model.ProductList
;
@Provider
public
class
PDFWriter
implements
MessageBodyWriter
<
ProductList
>
{
@Override
public
boolean
isWriteable
(
Class
<?>
type
,
Type
genericType
,
Annotation
[]
annotations
,
MediaType
mediaType
)
{
// TODO Auto-generated method stub
return
true
;
}
@Override
public
void
writeTo
(
ProductList
lista
,
Class
<?>
type
,
Type
genericType
,
Annotation
[]
annotations
,
MediaType
mediaType
,
MultivaluedMap
<
String
,
Object
>
httpHeaders
,
OutputStream
output
)
throws
IOException
,
WebApplicationException
{
// TODO Auto-generated method stub
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment