Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
2
20230403
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
20230403
Commits
1d7d841a
Commit
1d7d841a
authored
Jun 02, 2023
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Brakujące klasy i dodatkowa metoda
parent
fcf6507d
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
115 additions
and
18 deletions
+115
-18
P08_RestClient_JSON_Lista.java
...ain/java/sklep/klient_rest/P08_RestClient_JSON_Lista.java
+17
-18
DoUploadPhoto.java
...wy/sklep_web/src/main/java/sklep/photo/DoUploadPhoto.java
+40
-0
Photo.java
...lomodulowy/sklep_web/src/main/java/sklep/photo/Photo.java
+46
-0
Sklep.java
...ielomodulowy/soap_api/src/main/java/sklep/soap/Sklep.java
+3
-0
SklepImpl.java
...ulowy/soap_serwer/src/main/java/sklep/soap/SklepImpl.java
+9
-0
No files found.
PC39-Wielomodulowy/rest_klient/src/main/java/sklep/klient_rest/P08_RestClient_JSON_Lista.java
View file @
1d7d841a
...
@@ -7,28 +7,27 @@ import jakarta.ws.rs.client.ClientBuilder;
...
@@ -7,28 +7,27 @@ import jakarta.ws.rs.client.ClientBuilder;
import
jakarta.ws.rs.core.GenericType
;
import
jakarta.ws.rs.core.GenericType
;
import
jakarta.ws.rs.core.Response
;
import
jakarta.ws.rs.core.Response
;
import
sklep.model.Product
;
import
sklep.model.Product
;
import
sklep.model.ProductList
;
public
class
P08_RestClient_JSON_Lista
{
public
class
P08_RestClient_JSON_Lista
{
private
static
final
GenericType
<
List
<
Product
>>
typListy
=
new
GenericType
<
List
<
Product
>>()
{};
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
Client
client
=
ClientBuilder
.
newClient
();
// Te rzeczy są "closeable", więc można tak (podobnie jak sql Connection i ResultSet)
try
(
Client
client
=
ClientBuilder
.
newClient
();
Response
response
=
client
.
target
(
Ustawienia
.
ADRES_USLUGI
)
Response
response
=
client
.
target
(
Ustawienia
.
ADRES_USLUGI
)
.
path
(
"products.json"
)
.
path
(
"products.json"
)
.
request
().
buildGet
()
.
request
().
buildGet
()
.
invoke
();
.
invoke
())
{
System
.
out
.
println
(
"Mam odpowiedź: "
+
response
);
System
.
out
.
println
(
"Mam odpowiedź: "
+
response
);
System
.
out
.
println
(
"Status: "
+
response
.
getStatus
());
System
.
out
.
println
(
"Status: "
+
response
.
getStatus
());
System
.
out
.
println
(
"C-Type: "
+
response
.
getMediaType
());
System
.
out
.
println
(
"C-Type: "
+
response
.
getMediaType
());
System
.
out
.
println
(
"Length: "
+
response
.
getLength
());
System
.
out
.
println
(
"Length: "
+
response
.
getLength
());
List
<
Product
>
products
=
response
.
readEntity
(
typListy
);
GenericType
<
List
<
Product
>>
typListy
=
new
GenericType
<
List
<
Product
>>()
{};
for
(
Product
product
:
products
)
{
System
.
out
.
println
(
product
);
List
<
Product
>
products
=
response
.
readEntity
(
typListy
);
}
for
(
Product
product
:
products
)
{
System
.
out
.
println
(
product
);
}
}
}
}
...
...
PC39-Wielomodulowy/sklep_web/src/main/java/sklep/photo/DoUploadPhoto.java
0 → 100644
View file @
1d7d841a
package
sklep
.
photo
;
import
java.io.IOException
;
import
jakarta.servlet.ServletException
;
import
jakarta.servlet.annotation.MultipartConfig
;
import
jakarta.servlet.annotation.WebServlet
;
import
jakarta.servlet.http.HttpServlet
;
import
jakarta.servlet.http.HttpServletRequest
;
import
jakarta.servlet.http.HttpServletResponse
;
import
jakarta.servlet.http.Part
;
// Włączona obsługa zapytań multipart ("z załącznikami"). Maks rozmiar zapytania/pliku: 16M
@WebServlet
(
"/doUploadPhoto"
)
@MultipartConfig
(
maxRequestSize
=
16
*
1024
*
1024
)
public
class
DoUploadPhoto
extends
HttpServlet
{
private
static
final
long
serialVersionUID
=
1L
;
protected
void
doPost
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
ServletException
,
IOException
{
try
{
String
paramId
=
request
.
getParameter
(
"productId"
);
if
(
paramId
!=
null
)
{
int
productId
=
Integer
.
parseInt
(
paramId
);
Part
part
=
request
.
getPart
(
"plik"
);
if
(
part
!=
null
)
{
// przysłano plik
// Tutaj nazwa pliku jest dla nas bez znaczenia, ale gdybyśmy potrzebowali, to w ten sposób:
// String nazwaPliku = part.getSubmittedFileName();
// Przypisujemy bajty ze strumienia do pliku w katalogu ze zdjęciami:
PhotoUtil
.
writeStream
(
productId
,
part
.
getInputStream
());
}
}
}
catch
(
Exception
e
)
{
// wypisujemy błąd, ale metoda kończy się normalnie
e
.
printStackTrace
();
}
response
.
sendRedirect
(
"products9.jsp"
);
}
}
PC39-Wielomodulowy/sklep_web/src/main/java/sklep/photo/Photo.java
0 → 100644
View file @
1d7d841a
package
sklep
.
photo
;
import
java.io.IOException
;
import
jakarta.servlet.ServletException
;
import
jakarta.servlet.ServletOutputStream
;
import
jakarta.servlet.annotation.WebServlet
;
import
jakarta.servlet.http.HttpServlet
;
import
jakarta.servlet.http.HttpServletRequest
;
import
jakarta.servlet.http.HttpServletResponse
;
import
sklep.exn.RecordNotFound
;
@WebServlet
(
"/photo"
)
public
class
Photo
extends
HttpServlet
{
private
static
final
long
serialVersionUID
=
1L
;
/* Ten serwlet wczytuje z dysku plik ze zdjęciem o podanym numerze (z parametru productId).
* Aby odesłać odpowiedź "binarną" (a nie tekstową) używamy getOutputStream() zamiast getWriter().
* Aby przeglądarka wiedziała, że otrzymuje grafikę, ustawiamy content-type image/jpeg.
*/
protected
void
doGet
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
ServletException
,
IOException
{
String
parametrId
=
request
.
getParameter
(
"productId"
);
if
(
parametrId
==
null
)
{
return
;
}
try
{
int
id
=
Integer
.
parseInt
(
parametrId
);
byte
[]
bytes
=
PhotoUtil
.
readBytes
(
id
);
response
.
setContentType
(
"image/jpeg"
);
ServletOutputStream
output
=
response
.
getOutputStream
();
output
.
write
(
bytes
);
output
.
close
();
}
catch
(
RecordNotFound
e
)
{
response
.
setStatus
(
404
);
response
.
setContentType
(
"text/plain"
);
response
.
setCharacterEncoding
(
"utf-8"
);
response
.
getWriter
().
println
(
"Nie ma zdjęcia dla produktu o nr "
+
parametrId
);
}
catch
(
Exception
e
)
{
response
.
setStatus
(
500
);
e
.
printStackTrace
();
}
}
}
PC39-Wielomodulowy/soap_api/src/main/java/sklep/soap/Sklep.java
View file @
1d7d841a
...
@@ -34,6 +34,9 @@ public interface Sklep {
...
@@ -34,6 +34,9 @@ public interface Sklep {
@WebResult
(
name
=
"order"
)
@WebResult
(
name
=
"order"
)
Order
zamowienieWgId
(
@WebParam
(
name
=
"id"
)
int
orderId
)
throws
DBException
,
RecordNotFound
;
Order
zamowienieWgId
(
@WebParam
(
name
=
"id"
)
int
orderId
)
throws
DBException
,
RecordNotFound
;
@WebResult
(
name
=
"order"
)
public
List
<
Order
>
zamowieniaKlienta
(
@WebParam
(
name
=
"email"
)
String
email
)
throws
DBException
;
@WebResult
(
name
=
"customer"
)
@WebResult
(
name
=
"customer"
)
Customer
klient
(
@WebParam
(
name
=
"email"
)
String
email
)
throws
DBException
,
RecordNotFound
;
Customer
klient
(
@WebParam
(
name
=
"email"
)
String
email
)
throws
DBException
,
RecordNotFound
;
...
...
PC39-Wielomodulowy/soap_serwer/src/main/java/sklep/soap/SklepImpl.java
View file @
1d7d841a
...
@@ -3,6 +3,8 @@ package sklep.soap;
...
@@ -3,6 +3,8 @@ package sklep.soap;
import
java.math.BigDecimal
;
import
java.math.BigDecimal
;
import
java.util.List
;
import
java.util.List
;
import
jakarta.jws.WebParam
;
import
jakarta.jws.WebResult
;
import
jakarta.jws.WebService
;
import
jakarta.jws.WebService
;
import
jakarta.xml.ws.soap.MTOM
;
import
jakarta.xml.ws.soap.MTOM
;
import
sklep.db.CustomerDAO
;
import
sklep.db.CustomerDAO
;
...
@@ -60,6 +62,13 @@ public class SklepImpl implements Sklep {
...
@@ -60,6 +62,13 @@ public class SklepImpl implements Sklep {
}
}
}
}
public
List
<
Order
>
zamowieniaKlienta
(
String
email
)
throws
DBException
{
try
(
DBConnection
db
=
DBConnection
.
open
())
{
OrderDAO
orderDAO
=
db
.
orderDAO
();
return
orderDAO
.
customerOrders
(
email
);
}
}
public
Customer
klient
(
String
email
)
throws
DBException
,
RecordNotFound
{
public
Customer
klient
(
String
email
)
throws
DBException
,
RecordNotFound
{
try
(
DBConnection
db
=
DBConnection
.
open
())
{
try
(
DBConnection
db
=
DBConnection
.
open
())
{
CustomerDAO
customerDAO
=
db
.
customerDAO
();
CustomerDAO
customerDAO
=
db
.
customerDAO
();
...
...
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