Skip to content

lucasmalara/soap-ws-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SOAP Web Service Example

Table Of Content

Project Details

Project Components

Components Description

  1. Annotation

    • YerbaMateExample - Custom annotation to annotate method that returns instance of YerbaMate.
  2. Configuration layer

    • MappingConfig - Bean declaration of ModelMapper.

    • WebServiceConfig - Configuration of Web Service.

  3. Endpoint

    • YerbaMateEndpoint - Web Service Endpoint declaration.
  4. Entity

    • YerbaMateEntity - Entity representation of YerbaMate.
  5. Repository layer

    • YerbaMateRepository - JPA Repository of YerbaMateEntity.
  6. Schema

    • Country - Enum of countries of origins of Yerba maté.
    • GetYerbaMateRequest - Anonymous complex type definition.
    • GetYerbaMateResponse - Anonymous complex type definition.
    • ObjectFactory - Produces instances of Java representation of XML content.
    • YerbaMate - DTO representation of Yerba maté.
    • YerbaMateType - Enum of produced types of Yerba maté.
  7. Service layer

    • YerbaMateService - YerbaMate Service definition.
    • YerbaMateServiceImpl - YerbaMate Service implementation - business logic.
  8. Utils

    • YerbaMateConvert - Map DTOs and entities to each other using ModelMapper.
    • YerbaMateExampleProcessor - Process usage of YerbaMateExample annotation with Java Reflections.
    • YerbaMateFactory - Produces prebuilt instances of YerbaMate.

Schema Definition

File yerba-mate.xsd:

    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
               xmlns:tns="http://localhost:8080/soap-demo"
               targetNamespace="http://localhost:8080/soap-demo"
               elementFormDefault="qualified">
    
        <xs:element name="getYerbaMateRequest">
            <xs:complexType>
                <xs:sequence>
                    <xs:element name="brand" type="xs:string"/>
                </xs:sequence>
            </xs:complexType>
        </xs:element>
    
        <xs:element name="getYerbaMateResponse">
            <xs:complexType>
                <xs:sequence>
                    <xs:element name="yerbaMate" type="tns:yerbaMate"/>
                </xs:sequence>
            </xs:complexType>
        </xs:element>
    
        <!-- PAYLOAD -->
        <xs:complexType name="yerbaMate">
            <xs:sequence>
                <xs:element name="brand" type="xs:string"/>
                <xs:element name="origin" type="tns:country"/>
                <xs:element name="type" type="tns:yerbaMateType"/>
            </xs:sequence>
        </xs:complexType>
    
        <xs:simpleType name="country">
            <xs:restriction base="xs:string">
                <xs:enumeration value="Argentina"/>
                <xs:enumeration value="Brazil"/>
                <xs:enumeration value="Paraguay"/>
            </xs:restriction>
        </xs:simpleType>
    
        <xs:simpleType name="yerbaMateType">
            <xs:restriction base="xs:string">
                <xs:enumeration value="elaborada"/>
                <xs:enumeration value="despalada"/>
            </xs:restriction>
        </xs:simpleType>
    </xs:schema>

Request Example

File request-example.xml:

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
                      xmlns:std="http://localhost:8080/soap-demo">
    
        <soapenv:Header/>
        <soapenv:Body>
            <std:getYerbaMateRequest>
                <std:brand>Pajarito Classic</std:brand>
            </std:getYerbaMateRequest>
        </soapenv:Body>
    
    </soapenv:Envelope>

Send request using curl:

    curl --location 'http://localhost:8080/soap-demo' --header 'Content-Type: text/xml' --data @./src/main/resources/request-example.xml

Response Example

    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
        <SOAP-ENV:Header/>
        <SOAP-ENV:Body>
            <ns2:getYerbaMateResponse xmlns:ns2="http://localhost:8080/soap-demo">
                <ns2:yerbaMate>
                    <ns2:brand>Pajarito Classic</ns2:brand>
                    <ns2:origin>Paraguay</ns2:origin>
                    <ns2:type>elaborada</ns2:type>
                </ns2:yerbaMate>
            </ns2:getYerbaMateResponse>
        </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>

Screenshots

Image contains H2 login page.

Image contains yerba-mate database structure

Dependencies

ArtifactId Version
Spring Boot Starter 3.2.0
Spring Boot Starter Data JPA 3.2.0
Spring Boot Starter Web Services 3.2.0
WSDL4J 1.6.3
Jaxb-API 2.3.1
H2 2.2.224
ModelMapper 3.2.0
Lombok 1.18.30

Author

@lucasmalara

About

Example of SOAP Web Service implementation in Java.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Languages