Skip to content

Airport. Java SOAP application, python client with tkinter GUI

Notifications You must be signed in to change notification settings

rzymski/SoapProject

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

89 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


Zalecane wersje Java 8, Payara 5.2022.5, SoapUi-4.6.4, baza danych H2 1.4.200, IDE Inteliji Ultimate


Zawartość REDME

  1. ✈️ Funkcjonalność
  2. 💻 Działanie serwera
  3. 📦 Instalacja
  4. 🔧 Konfiguracja serwera
  5. 📡 Modyfikowanie bazy danych
  6. 👀 Monitorowanie requestów
  7. 🐉 Konfiguracja klienta w pythonie
  8. 📁 Struktura projektu
  9. Wskazówki
  10. :godmode: WSDL

Funkcjonalność

System rezerwacji biletów lotniczych

  1. Baza lotów (Miasto od , Miasto do, dzień, godzina)
  2. Wyszukiwanie lotów
  3. Kupno biletu
  4. Odbiór potwierdzenia kupna w formacie PDF
  5. Sprawdzenie rezerwacji na podstawie podanego numeru

Działanie Serwera

Można sprawdzić działanie serwera w:

WSDL:

Tester Glassfisha:

Instrukcja instalacji

Linki do pobrania Payary 5.2022.5 i H2 1.4.200

Dodanie Payary do Inteliji: Edit configurations... -> + -> Glassfish server Local -> Configure ustawienie Servera Payara w Inteliji.png

Wymagane pluginy w Inteliji GlassFish, Maven i Maven Extension: File -> Settings -> Plugins Pluginy

Instrukcja konfiguracji serwera

Important

Ustawiamy ścieżke do naszej bazy danych w:

SoapProject/src/main/java/database/Configuration.java ${\textsf{\color{gold}@DataSourceDefinition}}$ 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

Ustawiamy ścieżke do obrazka, który ma być w pdf-ie w:

SoapProject/src/main/java/soap/service/AirportServerImpl.java ${\textsf{\color{red}generatePdf(Long reservationId)}}$ 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();
}

Ustawienie Javy 8 File -> Project Structure...: Project Structure

Maven Lifecycle wyczyszczenie i zbudowanie projektu: View -> Tool Windows -> Maven -> SoapProject -> Lifecycle i klikamy clean, a następnie package
Maven lifecycle clean and package

Konfiguracja Payary: Payara cz.1 Payara cz.2 Payara cz.3

Ustawienie/sprawdzenie połączenia z bazą danych przez Inteliji: View -> Tool Windows -> Database -> + -> Data Source -> H2 Polaczenie z baza danych przez Inteliji

Użycie konsoli Inteliji do modyfikowania bazy danych

Uruchomienie konsoli Inteliji

View -> Tool Windows -> Database -> wybieramy naszą baze danych np. airport -> QL -> Open Default Console

Tworzenie lotów w bazie za pomocą CSV:

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);

Instrukcja monitorowania requestów

Ustawienie SoapUi HTTP Proxy na porcie 8085: Ustawienie SoapUi HTTP Proxy na porcie 8085

Przykładowe działanie SoapUi HTTP Proxy na porcie 8085: Przykładowe działanie SoapUi HTTP Proxy na porcie 8085

Ustawienie tcpMonitor na porcie 8084: Ustawienie tcpMonitor-a na porcie 8084

Przykładowe działanie tcpMonitor na porcie 8084: Przykładowe działanie tcpMonitor-a na porcie 8084

Instrukcja konfiguracji klienta

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

Struktura projektu

Ogólna struktura całego projektu

.
├───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

Struktura serwera javy w SoapProject

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;
Loading

Struktura klienta pythona w pythonCLient

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];
Loading

Wskazówki użycia

Tip

Wskazówki

  1. ✅   Baza danych nie może być otwarta w tym samym momencie przez aplikacje i konsole Inteliji

WSDL

<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>
  1. 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.
  2. 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
  3. 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>
  4. 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>

About

Airport. Java SOAP application, python client with tkinter GUI

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published