Zalecane wersje Java 8, Payara 5.2022.5, SoapUi-4.6.4, baza danych H2 1.4.200, IDE Inteliji Ultimate
✈️ Funkcjonalność- 💻 Działanie serwera
- 📦 Instalacja
- 🔧 Konfiguracja serwera
- 📡 Modyfikowanie bazy danych
- 👀 Monitorowanie requestów
- 🐉 Konfiguracja klienta w pythonie
- 📁 Struktura projektu
- ✅ Wskazówki
- WSDL
System rezerwacji biletów lotniczych
- Baza lotów (Miasto od , Miasto do, dzień, godzina)
- Wyszukiwanie lotów
- Kupno biletu
- Odbiór potwierdzenia kupna w formacie PDF
- Sprawdzenie rezerwacji na podstawie podanego numeru
Można sprawdzić działanie serwera w:
WSDL:
Tester Glassfisha:
Linki do pobrania Payary 5.2022.5 i H2 1.4.200
- Serwer Payara 5.2022.5: Payara 5.2022.5
- Baza danych H2 1.4.200: H2 1.4.200
Important
SoapProject/src/main/java/database/Configuration.java url
Kod @DataSourceDefinition
zawierający url do bazy danych
@DataSourceDefinition(
name = "java:global/SoapProjectDataSource",
className = "org.h2.jdbcx.JdbcDataSource",
url = "jdbc:h2:file:yourPath/SoapProject/SoapProject/airport",
minPoolSize = 1,
initialPoolSize = 1,
user = "sa",
password = ""
)
@FacesConfig
@Singleton
@Startup
public class Configuration {
Note
SoapProject/src/main/java/soap/service/AirportServerImpl.java imagePath
Kod generatePdf
zawierający url do pliku obrazka
@Override
public byte[] generatePdf(Long reservationId) throws IOException {
FlightReservationDTO res = checkFlightReservation(reservationId);
if (res == null) {
throw new RecordNotFoundException("No reservation with ID: " + reservationId);
}
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
PdfGenerator pdfGenerator = new PdfGenerator(byteArrayOutputStream, res);
pdfGenerator.setHeaderFooter("Potwierdzenie rezerwacji biletu", "Super linie lotnicze sp. z o.o.");
String imagePath = "youPath\\SoapProject\\screens\\plane.png";
pdfGenerator.setImage(imagePath);
pdfGenerator.generate();
return byteArrayOutputStream.toByteArray();
}
View -> Tool Windows -> Database -> wybieramy naszą baze danych np. airport -> QL -> Open Default Console
INSERT INTO Flight (ID, FLIGHTCODE, DEPARTUREAIRPORT, DEPARTURETIME, DESTINATIONAIRPORT, ARRIVALTIME, CREATEDATE, UPDATEDATE, CAPACITY, OCCUPIEDSEATS)
SELECT *
FROM CSVREAD('D:/programowanie/java/rsi/SoapProject/createDatabaseCSV/flights.csv', null);
Przechodzimy w konsoli do folderu pythonClient
Tworzymy wirtualne środowisko
python -m venv venv
Aktywujemy wirtualne środowisko
.\venv\Scripts\activate
Instalujemy wszystkie potrzebne biblioteki z pliku requirements.txt
pip install -r .\requirements.txt
.
├───createDatabaseCSV
│ └───pythonScriptToCreateCSV
├───pdfs
├───pythonClient
├───screens
├───SoapProject
│ └───src
│ └───main
│ ├───java
│ │ ├───database
│ │ │ ├───adapter
│ │ │ ├───dao
│ │ │ ├───dto
│ │ │ ├───exceptions
│ │ │ ├───model
│ │ │ └───service
│ │ ├───pdfGenerator
│ │ └───soap
│ │ ├───handler
│ │ └───service
│ ├───resources
│ │ └───META-INF
│ └───webapp
│ └───WEB-INF
└───tcpMonitor
SoapProject
│ airport.mv.db
│ pom.xml
└───src
└───main
├───java
│ ├───database
│ │ │ Configuration.java
│ │ ├───adapter
│ │ │ LocalDateTimeAdapter.java
│ │ ├───dao
│ │ │ AbstractDao.java
│ │ │ AbstractDaoJpaImpl.java
│ │ │ FlightDao.java
│ │ │ FlightDaoImpl.java
│ │ │ FlightReservationDao.java
│ │ │ FlightReservationDaoImpl.java
│ │ │ UserDao.java
│ │ │ UserDaoImpl.java
│ │ │ UserGroupDao.java
│ │ │ UserGroupDaoImpl.java
│ │ ├───dto
│ │ │ FlightDTO.java
│ │ │ FlightReservationDTO.java
│ │ ├───exceptions
│ │ │ NotEnoughDataException.java
│ │ │ RecordNotFoundException.java
│ │ │ UserNotFoundException.java
│ │ ├───model
│ │ │ AbstractModel.java
│ │ │ Flight.java
│ │ │ FlightReservation.java
│ │ │ User.java
│ │ │ UserGroup.java
│ │ └───service
│ │ FlightReservationService.java
│ │ FlightReservationServiceImpl.java
│ │ FlightService.java
│ │ FlightServiceImpl.java
│ │ UserService.java
│ │ UserServiceImpl.java
│ ├───pdfGenerator
│ │ HeaderFooterEventHandler.java
│ │ PdfGenerator.java
│ └───soap
│ ├───handler
│ │ LoginHandler.java
│ └───service
│ AirportServer.java
│ AirportServerImpl.java
├───resources
│ │ loginHandler.xml
│ └───META-INF
│ persistence.xml
└───webapp
│ index.xhtml
└───WEB-INF
web.xml
graph TD;
A[SoapProject]-->B[src];
A[SoapProject]-->C[(airport.mv.db)];
B-->M[main];
M-->J[java];
M-->R[resources];
M-->W[webapp];
J-->D[database];
D-->model;
D-->dao;
D-->SD[service];
D-->adapter;
D-->dto;
D-->exceptions;
J-->pdfGenerator;
J-->S[soap];
S-->handler;
S-->SS[service];
R-->META-INF;
W-->WEB-INF;
pythonCLient
client.py
interface.py
logic.py
main.py
graph TD;
A[pythonClient]-->M[main.py];
A-->I[interface.py];
A-->L[logic.py];
A-->C[client.py];
Tip
Wskazówki
- ✅ Baza danych nie może być otwarta w tym samym momencie przez aplikacje i konsole Inteliji
<definitions targetNamespace="http://service.soap/" name="AirportServerImplService">
<wsp:Policy wsu:Id="AirportServerImplPortBinding_MTOM_Policy-AirportServerImplPortBinding_MTOM_Policy">
<ns1:OptimizedMimeSerialization wsp:Optional="true"/>
</wsp:Policy>
<types>
<xsd:schema>
<xsd:import namespace="http://service.soap/" schemaLocation="http://localhost:8080/SoapProject/AirportServerImplService?xsd=1"/>
</xsd:schema>
</types>
<message name="echo">
<part name="parameters" element="tns:echo"/>
</message>
<message name="echoResponse">
<part name="parameters" element="tns:echoResponse"/>
</message>
<message name="getFlightsData">
<part name="parameters" element="tns:getFlightsData"/>
</message>
<message name="getFlightsDataResponse">
<part name="parameters" element="tns:getFlightsDataResponse"/>
</message>
<message name="getFlightById">
<part name="parameters" element="tns:getFlightById"/>
</message>
<message name="getFlightByIdResponse">
<part name="parameters" element="tns:getFlightByIdResponse"/>
</message>
<message name="generatePdf">
<part name="parameters" element="tns:generatePdf"/>
</message>
<message name="generatePdfResponse">
<part name="parameters" element="tns:generatePdfResponse"/>
</message>
<message name="IOException">
<part name="fault" element="tns:IOException"/>
</message>
<message name="reserveFlight">
<part name="parameters" element="tns:reserveFlight"/>
</message>
<message name="reserveFlightResponse">
<part name="parameters" element="tns:reserveFlightResponse"/>
</message>
<message name="createUser">
<part name="parameters" element="tns:createUser"/>
</message>
<message name="createUserResponse">
<part name="parameters" element="tns:createUserResponse"/>
</message>
<message name="getFlightAvailableSeats">
<part name="parameters" element="tns:getFlightAvailableSeats"/>
</message>
<message name="getFlightAvailableSeatsResponse">
<part name="parameters" element="tns:getFlightAvailableSeatsResponse"/>
</message>
<message name="findAvailableAirports">
<part name="parameters" element="tns:findAvailableAirports"/>
</message>
<message name="findAvailableAirportsResponse">
<part name="parameters" element="tns:findAvailableAirportsResponse"/>
</message>
<message name="checkFlightReservation">
<part name="parameters" element="tns:checkFlightReservation"/>
</message>
<message name="checkFlightReservationResponse">
<part name="parameters" element="tns:checkFlightReservationResponse"/>
</message>
<message name="cancelFlightReservation">
<part name="parameters" element="tns:cancelFlightReservation"/>
</message>
<message name="cancelFlightReservationResponse">
<part name="parameters" element="tns:cancelFlightReservationResponse"/>
</message>
<message name="getUserReservations">
<part name="parameters" element="tns:getUserReservations"/>
</message>
<message name="getUserReservationsResponse">
<part name="parameters" element="tns:getUserReservationsResponse"/>
</message>
<message name="getAllFlightsWithParameters">
<part name="parameters" element="tns:getAllFlightsWithParameters"/>
</message>
<message name="getAllFlightsWithParametersResponse">
<part name="parameters" element="tns:getAllFlightsWithParametersResponse"/>
</message>
<message name="cancelUserReservationInConcreteFlight">
<part name="parameters" element="tns:cancelUserReservationInConcreteFlight"/>
</message>
<message name="cancelUserReservationInConcreteFlightResponse">
<part name="parameters" element="tns:cancelUserReservationInConcreteFlightResponse"/>
</message>
<portType name="AirportServer">
<operation name="echo">
<input wsam:Action="http://service.soap/AirportServer/echoRequest" message="tns:echo"/>
<output wsam:Action="http://service.soap/AirportServer/echoResponse" message="tns:echoResponse"/>
</operation>
<operation name="getFlightsData">
<input wsam:Action="http://service.soap/AirportServer/getFlightsDataRequest" message="tns:getFlightsData"/>
<output wsam:Action="http://service.soap/AirportServer/getFlightsDataResponse" message="tns:getFlightsDataResponse"/>
</operation>
<operation name="getFlightById">
<input wsam:Action="http://service.soap/AirportServer/getFlightByIdRequest" message="tns:getFlightById"/>
<output wsam:Action="http://service.soap/AirportServer/getFlightByIdResponse" message="tns:getFlightByIdResponse"/>
</operation>
<operation name="generatePdf">
<input wsam:Action="http://service.soap/AirportServer/generatePdfRequest" message="tns:generatePdf"/>
<output wsam:Action="http://service.soap/AirportServer/generatePdfResponse" message="tns:generatePdfResponse"/>
<fault message="tns:IOException" name="IOException" wsam:Action="http://service.soap/AirportServer/generatePdf/Fault/IOException"/>
</operation>
<operation name="reserveFlight">
<input wsam:Action="http://service.soap/AirportServer/reserveFlightRequest" message="tns:reserveFlight"/>
<output wsam:Action="http://service.soap/AirportServer/reserveFlightResponse" message="tns:reserveFlightResponse"/>
</operation>
<operation name="createUser">
<input wsam:Action="http://service.soap/AirportServer/createUserRequest" message="tns:createUser"/>
<output wsam:Action="http://service.soap/AirportServer/createUserResponse" message="tns:createUserResponse"/>
</operation>
<operation name="getFlightAvailableSeats">
<input wsam:Action="http://service.soap/AirportServer/getFlightAvailableSeatsRequest" message="tns:getFlightAvailableSeats"/>
<output wsam:Action="http://service.soap/AirportServer/getFlightAvailableSeatsResponse" message="tns:getFlightAvailableSeatsResponse"/>
</operation>
<operation name="findAvailableAirports">
<input wsam:Action="http://service.soap/AirportServer/findAvailableAirportsRequest" message="tns:findAvailableAirports"/>
<output wsam:Action="http://service.soap/AirportServer/findAvailableAirportsResponse" message="tns:findAvailableAirportsResponse"/>
</operation>
<operation name="checkFlightReservation">
<input wsam:Action="http://service.soap/AirportServer/checkFlightReservationRequest" message="tns:checkFlightReservation"/>
<output wsam:Action="http://service.soap/AirportServer/checkFlightReservationResponse" message="tns:checkFlightReservationResponse"/>
</operation>
<operation name="cancelFlightReservation">
<input wsam:Action="http://service.soap/AirportServer/cancelFlightReservationRequest" message="tns:cancelFlightReservation"/>
<output wsam:Action="http://service.soap/AirportServer/cancelFlightReservationResponse" message="tns:cancelFlightReservationResponse"/>
</operation>
<operation name="getUserReservations">
<input wsam:Action="http://service.soap/AirportServer/getUserReservationsRequest" message="tns:getUserReservations"/>
<output wsam:Action="http://service.soap/AirportServer/getUserReservationsResponse" message="tns:getUserReservationsResponse"/>
</operation>
<operation name="getAllFlightsWithParameters">
<input wsam:Action="http://service.soap/AirportServer/getAllFlightsWithParametersRequest" message="tns:getAllFlightsWithParameters"/>
<output wsam:Action="http://service.soap/AirportServer/getAllFlightsWithParametersResponse" message="tns:getAllFlightsWithParametersResponse"/>
</operation>
<operation name="cancelUserReservationInConcreteFlight">
<input wsam:Action="http://service.soap/AirportServer/cancelUserReservationInConcreteFlightRequest" message="tns:cancelUserReservationInConcreteFlight"/>
<output wsam:Action="http://service.soap/AirportServer/cancelUserReservationInConcreteFlightResponse" message="tns:cancelUserReservationInConcreteFlightResponse"/>
</operation>
</portType>
<binding name="AirportServerImplPortBinding" type="tns:AirportServer">
<wsp:PolicyReference URI="#AirportServerImplPortBinding_MTOM_Policy-AirportServerImplPortBinding_MTOM_Policy"/>
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="echo">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
<operation name="getFlightsData">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
<operation name="getFlightById">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
<operation name="generatePdf">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
<fault name="IOException">
<soap:fault name="IOException" use="literal"/>
</fault>
</operation>
<operation name="reserveFlight">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
<operation name="createUser">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
<operation name="getFlightAvailableSeats">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
<operation name="findAvailableAirports">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
<operation name="checkFlightReservation">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
<operation name="cancelFlightReservation">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
<operation name="getUserReservations">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
<operation name="getAllFlightsWithParameters">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
<operation name="cancelUserReservationInConcreteFlight">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="AirportServerImplService">
<port name="AirportServerImplPort" binding="tns:AirportServerImplPortBinding">
<soap:address location="http://localhost:8080/SoapProject/AirportServerImplService"/>
</port>
</service>
</definitions>
- Opis Web serwisu
echo
- Operacja przyjmuje stringa i zwraca komunikat z serwera wraz z tym samym stringiem. echo można również wykorzystać do sprawdzenia poprawności logowania, jeśli umieści się w nagłówku wartości do "username" i "password", echo zwraca w Soap nagłówku usernameValidation wartość bool.
- Opisz szczegółowy
- Dane wejściowe
- text - dowolny string
- oprcjonalny nagłówek "username" i "password"
- Dane wyjściowe
- text - wiadomość z serwera "Serwer zwraca otrzymany text: " + text z parametru
- soap nagłówek "usernameValidation" z wartością bool
- Dane wejściowe
- Przykładowy komunikat wysłany do usługi:
POST http://localhost:8080/SoapProject/AirportServerImplService HTTP/1.1 Host: localhost:8080 User-Agent: Zeep/4.2.1 (www.python-zeep.org) Accept-Encoding: gzip, deflate Accept: */* Connection: keep-alive SOAPAction: "" Content-Type: text/xml; charset=utf-8 Content-Length: 564 username: user password: admin <soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/"> <soap-env:Header xmlns:wsa="http://www.w3.org/2005/08/addressing"> <wsa:Action>http://service.soap/AirportServer/echoRequest</wsa:Action> <wsa:MessageID>urn:uuid:9f36bcac-4fc3-461a-a62c-af66bee2918e</wsa:MessageID> <wsa:To>http://localhost:8080/SoapProject/AirportServerImplService</wsa:To> </soap-env:Header> <soap-env:Body> <ns0:echo xmlns:ns0="http://service.soap/"> <arg0>Check if user is correct</arg0> </ns0:echo> </soap-env:Body> </soap-env:Envelope>
- Przykładowy komunikat zwrócony z usługi:
HTTP/1.1 200 OK Server: Payara Server 5.2022.5 #badassfish X-Powered-By: Servlet/4.0 JSP/2.3 (Payara Server 5.2022.5 #badassfish Java/Oracle Corporation/1.8) Content-Type: text/xml; charset=utf-8 Transfer-Encoding: chunked X-Frame-Options: SAMEORIGIN <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> <SOAP-ENV:Header> <usernameValidation SOAP-ENV:actor="http://schemas.xmlsoap.org/soap/actor/next" xmlns="http://localhost:8080/SoapProject/AirportServerImplService">true</usernameValidation> </SOAP-ENV:Header> <S:Body xmlns:ns2="http://service.soap/"> <ns2:echoResponse> <return>Serwer zwraca otrzymany text: Check if user is correct</return> </ns2:echoResponse> </S:Body> </S:Envelope>