Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
alx_java2b_20250412
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
alx_java2b_20250412
Commits
ef520006
Commit
ef520006
authored
May 10, 2025
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Pierwsze adnotacje JAX-WS i JAXB
parent
bcf17be7
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
33 additions
and
10 deletions
+33
-10
notatki.txt
PC24-SklepSoap/notatki.txt
+3
-0
Hello.java
PC24-SklepSoap/src/main/java/hello/Hello.java
+8
-1
Product.java
PC24-SklepSoap/src/main/java/sklep/model/Product.java
+8
-3
Sklep.java
PC24-SklepSoap/src/main/java/sklep/soap/Sklep.java
+14
-6
No files found.
PC24-SklepSoap/notatki.txt
View file @
ef520006
Technologia Javy JAX-WS : Java (Jakarta) API for XML Web Services
Technologia Javy JAX-WS : Java (Jakarta) API for XML Web Services
JAXB - Java (Jakarta) Architecture for XML Binding - automatyczne konwersje obiektów Java na fragmenty XML i odwrotnie
Obie działają w oparciu o odnotacje.
Ogólnie:
Ogólnie:
...
...
PC24-SklepSoap/src/main/java/hello/Hello.java
View file @
ef520006
...
@@ -2,6 +2,8 @@ package hello;
...
@@ -2,6 +2,8 @@ package hello;
import
java.time.LocalDateTime
;
import
java.time.LocalDateTime
;
import
jakarta.jws.WebParam
;
import
jakarta.jws.WebResult
;
import
jakarta.jws.WebService
;
import
jakarta.jws.WebService
;
@WebService
@WebService
...
@@ -11,11 +13,16 @@ public class Hello {
...
@@ -11,11 +13,16 @@ public class Hello {
return
"Witaj "
+
imie
;
return
"Witaj "
+
imie
;
}
}
@WebResult
(
name
=
"timestamp"
)
public
String
currentTime
()
{
public
String
currentTime
()
{
return
LocalDateTime
.
now
().
toString
();
return
LocalDateTime
.
now
().
toString
();
}
}
public
long
oblicz
(
long
liczba1
,
long
liczba2
,
String
operacja
)
{
@WebResult
(
name
=
"wynik"
)
public
long
oblicz
(
@WebParam
(
name
=
"liczba1"
)
long
liczba1
,
@WebParam
(
name
=
"liczba2"
)
long
liczba2
,
@WebParam
(
name
=
"operacja"
)
String
operacja
)
{
return
switch
(
operacja
)
{
return
switch
(
operacja
)
{
case
"+"
->
liczba1
+
liczba2
;
case
"+"
->
liczba1
+
liczba2
;
case
"-"
->
liczba1
-
liczba2
;
case
"-"
->
liczba1
-
liczba2
;
...
...
PC24-SklepSoap/src/main/java/sklep/model/Product.java
View file @
ef520006
...
@@ -3,8 +3,16 @@ package sklep.model;
...
@@ -3,8 +3,16 @@ package sklep.model;
import
java.math.BigDecimal
;
import
java.math.BigDecimal
;
import
java.util.Objects
;
import
java.util.Objects
;
import
jakarta.xml.bind.annotation.XmlAccessType
;
import
jakarta.xml.bind.annotation.XmlAccessorType
;
import
jakarta.xml.bind.annotation.XmlAttribute
;
import
jakarta.xml.bind.annotation.XmlElement
;
@XmlAccessorType
(
XmlAccessType
.
FIELD
)
public
class
Product
{
public
class
Product
{
@XmlAttribute
(
name
=
"id"
)
private
Integer
productId
;
private
Integer
productId
;
@XmlElement
(
name
=
"product-name"
)
private
String
productName
;
private
String
productName
;
private
BigDecimal
price
;
private
BigDecimal
price
;
private
BigDecimal
vat
;
private
BigDecimal
vat
;
...
@@ -57,9 +65,6 @@ public class Product {
...
@@ -57,9 +65,6 @@ public class Product {
return
description
;
return
description
;
}
}
public
void
setDescription
(
String
description
)
{
this
.
description
=
description
;
}
@Override
@Override
public
int
hashCode
()
{
public
int
hashCode
()
{
...
...
PC24-SklepSoap/src/main/java/sklep/soap/Sklep.java
View file @
ef520006
...
@@ -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
sklep.db.DBConnection
;
import
sklep.db.DBConnection
;
import
sklep.db.DBException
;
import
sklep.db.DBException
;
...
@@ -14,7 +16,7 @@ import sklep.model.Product;
...
@@ -14,7 +16,7 @@ import sklep.model.Product;
@WebService
@WebService
public
class
Sklep
{
public
class
Sklep
{
@WebResult
(
name
=
"product"
)
public
List
<
Product
>
readAllProducts
()
throws
DBException
{
public
List
<
Product
>
readAllProducts
()
throws
DBException
{
try
(
DBConnection
db
=
DBConnection
.
open
())
{
try
(
DBConnection
db
=
DBConnection
.
open
())
{
ProductDAO
productDAO
=
db
.
productDAO
();
ProductDAO
productDAO
=
db
.
productDAO
();
...
@@ -22,14 +24,18 @@ public class Sklep {
...
@@ -22,14 +24,18 @@ public class Sklep {
}
}
}
}
public
List
<
Product
>
readProductsByPrice
(
BigDecimal
minPrice
,
BigDecimal
maxPrice
)
throws
DBException
{
@WebResult
(
name
=
"product"
)
public
List
<
Product
>
readProductsByPrice
(
@WebParam
(
name
=
"min"
)
BigDecimal
minPrice
,
@WebParam
(
name
=
"max"
)
BigDecimal
maxPrice
)
throws
DBException
{
try
(
DBConnection
db
=
DBConnection
.
open
())
{
try
(
DBConnection
db
=
DBConnection
.
open
())
{
ProductDAO
productDAO
=
db
.
productDAO
();
ProductDAO
productDAO
=
db
.
productDAO
();
return
productDAO
.
findByPrice
(
minPrice
,
maxPrice
);
return
productDAO
.
findByPrice
(
minPrice
,
maxPrice
);
}
}
}
}
public
Product
readOneProduct
(
int
productId
)
throws
DBException
,
RecordNotFound
{
@WebResult
(
name
=
"product"
)
public
Product
readOneProduct
(
@WebParam
(
name
=
"id"
)
int
productId
)
throws
DBException
,
RecordNotFound
{
try
(
DBConnection
db
=
DBConnection
.
open
())
{
try
(
DBConnection
db
=
DBConnection
.
open
())
{
ProductDAO
productDAO
=
db
.
productDAO
();
ProductDAO
productDAO
=
db
.
productDAO
();
return
productDAO
.
findById
(
productId
);
return
productDAO
.
findById
(
productId
);
...
@@ -37,7 +43,7 @@ public class Sklep {
...
@@ -37,7 +43,7 @@ public class Sklep {
}
}
// zapisywanie produktu (Product jest parametrem wejściowym)
// zapisywanie produktu (Product jest parametrem wejściowym)
public
void
saveProduct
(
Product
product
)
throws
DBException
{
public
void
saveProduct
(
@WebParam
(
name
=
"product"
)
Product
product
)
throws
DBException
{
try
(
DBConnection
db
=
DBConnection
.
open
())
{
try
(
DBConnection
db
=
DBConnection
.
open
())
{
ProductDAO
productDAO
=
db
.
productDAO
();
ProductDAO
productDAO
=
db
.
productDAO
();
productDAO
.
save
(
product
);
productDAO
.
save
(
product
);
...
@@ -46,14 +52,16 @@ public class Sklep {
...
@@ -46,14 +52,16 @@ public class Sklep {
}
}
// odczyt zamówienia wg ID a może też odczyt wszystkich zamówień wskazanego klienta
// odczyt zamówienia wg ID a może też odczyt wszystkich zamówień wskazanego klienta
public
Order
readOneOrder
(
int
orderId
)
throws
DBException
,
RecordNotFound
{
@WebResult
(
name
=
"order"
)
public
Order
readOneOrder
(
@WebParam
(
name
=
"id"
)
int
orderId
)
throws
DBException
,
RecordNotFound
{
try
(
DBConnection
db
=
DBConnection
.
open
())
{
try
(
DBConnection
db
=
DBConnection
.
open
())
{
OrderDAO
orderDAO
=
db
.
orderDAO
();
OrderDAO
orderDAO
=
db
.
orderDAO
();
return
orderDAO
.
findById
(
orderId
);
return
orderDAO
.
findById
(
orderId
);
}
}
}
}
public
List
<
Order
>
readCustomerOrders
(
String
email
)
throws
DBException
{
@WebResult
(
name
=
"order"
)
public
List
<
Order
>
readCustomerOrders
(
@WebParam
(
name
=
"customer-email"
)
String
email
)
throws
DBException
{
try
(
DBConnection
db
=
DBConnection
.
open
())
{
try
(
DBConnection
db
=
DBConnection
.
open
())
{
OrderDAO
orderDAO
=
db
.
orderDAO
();
OrderDAO
orderDAO
=
db
.
orderDAO
();
return
orderDAO
.
customerOrders
(
email
);
return
orderDAO
.
customerOrders
(
email
);
...
...
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