Commit 4c937405 by Patryk Czarnik

Wydzielenie interfejsu webserwisowego

parent 3172720b
......@@ -21,5 +21,7 @@
<module>wielomodulowy-web</module>
<module>wielomodulowy-ear</module>
<module>wielomodulowy-soap_serwer</module>
<module>wielomodulowy-soap_klient</module>
<module>wielomodulowy-soap_api</module>
</modules>
</project>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>pl.alx.kjava</groupId>
<artifactId>Wielomodulowy</artifactId>
<version>1.0</version>
</parent>
<artifactId>wielomodulowy-soap_api</artifactId>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>wielomodulowy-baza</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>jakarta.xml.ws</groupId>
<artifactId>jakarta.xml.ws-api</artifactId>
<version>4.0.0</version>
</dependency>
</dependencies>
</project>
package sklep.soap;
import java.math.BigDecimal;
import java.util.List;
import jakarta.jws.WebParam;
import jakarta.jws.WebResult;
import jakarta.jws.WebService;
import sklep.db.DBException;
import sklep.db.RecordNotFound;
import sklep.model.Customer;
import sklep.model.Order;
import sklep.model.Product;
@WebService
public interface Sklep {
@WebResult(name="product")
public List<Product> readAll() throws DBException;
@WebResult(name="product")
public List<Product> readByPrice(@WebParam(name="min") BigDecimal min, @WebParam(name="max") BigDecimal max) throws DBException;
@WebResult(name="product")
public Product readOne(@WebParam(name="id") int productId) throws DBException, RecordNotFound;
public void saveProduct(@WebParam(name="product") Product product) throws DBException;
@WebResult(name="customer")
public Customer oneCustomer(@WebParam(name="email") String email) throws DBException, RecordNotFound;
@WebResult(name="order")
public Order oneOrder(@WebParam(name="id") int orderId) throws DBException, RecordNotFound;
@WebResult(name="bytes")
public byte[] getPhoto(@WebParam(name="id") int productId) throws DBException, RecordNotFound;
public void savePhoto(@WebParam(name="id") int productId, @WebParam(name="bytes") byte[] bytes);
}
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>pl.alx.kjava</groupId>
<artifactId>Wielomodulowy</artifactId>
<version>1.0</version>
</parent>
<artifactId>wielomodulowy-soap_klient</artifactId>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>wielomodulowy-soap_api</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
......@@ -12,12 +12,6 @@
<dependencies>
<dependency>
<groupId>jakarta.xml.ws</groupId>
<artifactId>jakarta.xml.ws-api</artifactId>
<version>4.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>6.0.0</version>
......@@ -25,7 +19,7 @@
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>wielomodulowy-model</artifactId>
<artifactId>wielomodulowy-soap_api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
......
......@@ -3,8 +3,6 @@ package sklep.soap;
import java.math.BigDecimal;
import java.util.List;
import jakarta.jws.WebParam;
import jakarta.jws.WebResult;
import jakarta.jws.WebService;
import jakarta.xml.ws.soap.MTOM;
import sklep.db.CustomerDAO;
......@@ -17,38 +15,32 @@ import sklep.model.Customer;
import sklep.model.Order;
import sklep.model.Product;
@WebService
@MTOM
public class Sklep {
@WebService(endpointInterface = "sklep.soap.Sklep")
public class SklepImpl implements Sklep {
@WebResult(name="product")
public List<Product> readAll() throws DBException {
try(DBConnection db = DBConnection.open()) {
ProductDAO productDAO = db.productDAO();
return productDAO.readAll();
}
}
// @ResponseWrapper(localName = "wynikiWyszukiwania", targetNamespace = "http://soap.sklep/")
// @WebResult(name="product", targetNamespace = "http://soap.sklep/model")
@WebResult(name="product")
public List<Product> readByPrice(@WebParam(name="min") BigDecimal min, @WebParam(name="max") BigDecimal max) throws DBException {
public List<Product> readByPrice(BigDecimal min, BigDecimal max) throws DBException {
try(DBConnection db = DBConnection.open()) {
ProductDAO productDAO = db.productDAO();
return productDAO.findByPrice(min, max);
}
}
@WebResult(name="product")
public Product readOne(@WebParam(name="id") int productId) throws DBException, RecordNotFound {
public Product readOne(int productId) throws DBException, RecordNotFound {
try(DBConnection db = DBConnection.open()) {
ProductDAO productDAO = db.productDAO();
return productDAO.findById(productId);
}
}
public void saveProduct(@WebParam(name="product") Product product) throws DBException {
public void saveProduct(Product product) throws DBException {
try(DBConnection db = DBConnection.open()) {
ProductDAO productDAO = db.productDAO();
productDAO.save(product);
......@@ -56,29 +48,25 @@ public class Sklep {
}
}
@WebResult(name="customer")
public Customer oneCustomer(@WebParam(name="email") String email) throws DBException, RecordNotFound {
public Customer oneCustomer(String email) throws DBException, RecordNotFound {
try(DBConnection db = DBConnection.open()) {
CustomerDAO customerDAO = db.customerDAO();
return customerDAO.findByEmail(email);
}
}
@WebResult(name="order")
public Order oneOrder(@WebParam(name="id") int orderId) throws DBException, RecordNotFound {
public Order oneOrder(int orderId) throws DBException, RecordNotFound {
try(DBConnection db = DBConnection.open()) {
OrderDAO orderDAO = db.orderDAO();
return orderDAO.findById(orderId);
}
}
@WebResult(name="bytes")
public byte[] getPhoto(@WebParam(name="id") int productId) throws DBException, RecordNotFound {
public byte[] getPhoto(int productId) throws DBException, RecordNotFound {
return PhotoUtil.readBytes(productId);
}
public void savePhoto(@WebParam(name="id") int productId,
@WebParam(name="bytes") byte[] bytes) {
public void savePhoto(int productId, byte[] bytes) {
PhotoUtil.writeBytes(productId, bytes);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment