├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── spring-ws-basic-authentication-httpclient ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── codenotfound │ │ │ └── ws │ │ │ ├── SpringWsApplication.java │ │ │ ├── client │ │ │ ├── ClientConfig.java │ │ │ └── TicketAgentClient.java │ │ │ └── endpoint │ │ │ ├── TicketAgentEndpoint.java │ │ │ └── WebServiceConfig.java │ └── resources │ │ ├── application.yml │ │ ├── logback.xml │ │ └── wsdl │ │ └── ticketagent.wsdl │ └── test │ └── java │ └── com │ └── codenotfound │ └── ws │ └── SpringWsApplicationTests.java ├── spring-ws-basic-authentication ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── codenotfound │ │ │ └── ws │ │ │ ├── SpringWsApplication.java │ │ │ ├── client │ │ │ ├── BasicAuthenticationUtil.java │ │ │ ├── ClientConfig.java │ │ │ └── TicketAgentClient.java │ │ │ └── endpoint │ │ │ ├── TicketAgentEndpoint.java │ │ │ └── WebServiceConfig.java │ └── resources │ │ ├── application.yml │ │ ├── logback.xml │ │ └── wsdl │ │ └── ticketagent.wsdl │ └── test │ └── java │ └── com │ └── codenotfound │ └── ws │ └── SpringWsApplicationTests.java ├── spring-ws-client-timeout ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── codenotfound │ │ │ └── ws │ │ │ ├── SpringWsApplication.java │ │ │ ├── client │ │ │ ├── ClientConfig.java │ │ │ ├── HttpUrlConnectionMessageSenderTimeout.java │ │ │ └── TicketAgentClient.java │ │ │ └── endpoint │ │ │ ├── TicketAgentEndpoint.java │ │ │ └── WebServiceConfig.java │ └── resources │ │ └── wsdl │ │ └── ticketagent.wsdl │ └── test │ └── java │ └── com │ └── codenotfound │ └── ws │ └── SpringWsApplicationTests.java ├── spring-ws-digital-signature ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── codenotfound │ │ │ └── ws │ │ │ ├── SpringWsApplication.java │ │ │ ├── client │ │ │ ├── ClientConfig.java │ │ │ └── TicketAgentClient.java │ │ │ └── endpoint │ │ │ ├── TicketAgentEndpoint.java │ │ │ └── WebServiceConfig.java │ └── resources │ │ ├── application.yml │ │ ├── jks │ │ ├── client-keystore.jks │ │ ├── client-public-key.cer │ │ ├── client-truststore.jks │ │ ├── server-keystore.jks │ │ ├── server-public-key.cer │ │ └── server-truststore.jks │ │ ├── logback.xml │ │ └── wsdl │ │ └── ticketagent.wsdl │ └── test │ └── java │ └── com │ └── codenotfound │ └── ws │ └── SpringWsApplicationTests.java ├── spring-ws-encryption ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── codenotfound │ │ │ └── ws │ │ │ ├── SpringWsApplication.java │ │ │ ├── client │ │ │ ├── ClientConfig.java │ │ │ └── TicketAgentClient.java │ │ │ └── endpoint │ │ │ ├── TicketAgentEndpoint.java │ │ │ └── WebServiceConfig.java │ └── resources │ │ ├── application.yml │ │ ├── jks │ │ ├── client-keystore.jks │ │ ├── client-public-key.cer │ │ ├── client-truststore.jks │ │ ├── server-keystore.jks │ │ ├── server-public-key.cer │ │ └── server-truststore.jks │ │ ├── logback.xml │ │ └── wsdl │ │ └── ticketagent.wsdl │ └── test │ └── java │ └── com │ └── codenotfound │ └── ws │ └── SpringWsApplicationTests.java ├── spring-ws-eureka ├── README.md ├── spring-boot-eureka-server │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── codenotfound │ │ │ └── eureka │ │ │ └── SpringBootEurekaServerApplication.java │ │ └── resources │ │ └── application.yml ├── spring-ws-ticketagent-client │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── codenotfound │ │ │ │ └── ws │ │ │ │ ├── SpringWsClientApplication.java │ │ │ │ └── client │ │ │ │ ├── ClientConfig.java │ │ │ │ └── TicketAgentClient.java │ │ └── resources │ │ │ └── wsdl │ │ │ └── ticketagent.wsdl │ │ └── test │ │ └── java │ │ └── com │ │ └── codenotfound │ │ └── ws │ │ └── SpringWsApplicationTests.java └── spring-ws-ticketagent-server │ ├── pom.xml │ └── src │ └── main │ ├── java │ └── com │ │ └── codenotfound │ │ └── ws │ │ ├── SpringWsServerApplication.java │ │ └── endpoint │ │ ├── TicketAgentEndpoint.java │ │ └── WebServiceConfig.java │ └── resources │ ├── application.yml │ └── wsdl │ └── ticketagent.wsdl ├── spring-ws-hello-world ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── codenotfound │ │ │ ├── SpringWsApplication.java │ │ │ └── ws │ │ │ ├── client │ │ │ ├── ClientConfig.java │ │ │ └── HelloWorldClient.java │ │ │ └── endpoint │ │ │ ├── HelloWorldEndpoint.java │ │ │ └── WebServiceConfig.java │ └── resources │ │ └── wsdl │ │ └── helloworld.wsdl │ └── test │ └── java │ └── com │ └── codenotfound │ └── SpringWsApplicationTests.java ├── spring-ws-https-httpclient ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── codenotfound │ │ │ └── ws │ │ │ ├── SpringWsApplication.java │ │ │ ├── client │ │ │ ├── ClientConfig.java │ │ │ └── TicketAgentClient.java │ │ │ └── endpoint │ │ │ ├── TicketAgentEndpoint.java │ │ │ └── WebServiceConfig.java │ └── resources │ │ ├── application.yml │ │ ├── jks │ │ ├── client-truststore.jks │ │ ├── server-keystore.jks │ │ └── server-public-key.cer │ │ ├── logback.xml │ │ └── wsdl │ │ └── ticketagent.wsdl │ └── test │ └── java │ └── com │ └── codenotfound │ └── ws │ └── SpringWsApplicationTests.java ├── spring-ws-https ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── codenotfound │ │ │ └── ws │ │ │ ├── SpringWsApplication.java │ │ │ ├── client │ │ │ ├── ClientConfig.java │ │ │ └── TicketAgentClient.java │ │ │ └── endpoint │ │ │ ├── TicketAgentEndpoint.java │ │ │ └── WebServiceConfig.java │ └── resources │ │ ├── application.yml │ │ ├── jks │ │ ├── client-truststore.jks │ │ ├── server-keystore.jks │ │ └── server-public-key.cer │ │ ├── logback.xml │ │ └── wsdl │ │ └── ticketagent.wsdl │ └── test │ └── java │ └── com │ └── codenotfound │ └── ws │ └── SpringWsApplicationTests.java ├── spring-ws-integration-test ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── codenotfound │ │ │ └── order │ │ │ ├── OrderApplication.java │ │ │ ├── client │ │ │ ├── ClientConfig.java │ │ │ └── CreateOrderClient.java │ │ │ └── endpoint │ │ │ ├── CreateOrderEndpoint.java │ │ │ └── WebServiceConfig.java │ └── resources │ │ ├── application.properties │ │ └── wsdl │ │ └── order.wsdl │ └── test │ ├── java │ └── com │ │ └── codenotfound │ │ └── order │ │ ├── client │ │ ├── CreateOrderClientIT.java │ │ ├── CreateOrderClientMockTest.java │ │ └── CreateOrderClientTest.java │ │ └── endpoint │ │ ├── CreateOrderEndpointMockTest.java │ │ └── CreateOrderEndpointTest.java │ └── resources │ ├── application.properties │ └── soapui │ └── order-soapui-project.xml ├── spring-ws-log-http-headers ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── codenotfound │ │ │ └── ws │ │ │ ├── SpringWsApplication.java │ │ │ ├── client │ │ │ ├── ClientConfig.java │ │ │ └── TicketAgentClient.java │ │ │ ├── endpoint │ │ │ ├── TicketAgentEndpoint.java │ │ │ └── WebServiceConfig.java │ │ │ └── interceptor │ │ │ ├── ByteArrayTransportOutputStream.java │ │ │ ├── HttpLoggingUtils.java │ │ │ ├── LogHttpHeaderClientInterceptor.java │ │ │ └── LogHttpHeaderEndpointInterceptor.java │ └── resources │ │ ├── application.yml │ │ ├── logback.xml │ │ └── wsdl │ │ └── ticketagent.wsdl │ └── test │ └── java │ └── com │ └── codenotfound │ └── ws │ └── SpringWsApplicationTests.java ├── spring-ws-mutual-authentication-httpclient ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── codenotfound │ │ │ └── ws │ │ │ ├── SpringWsApplication.java │ │ │ ├── client │ │ │ ├── ClientConfig.java │ │ │ └── TicketAgentClient.java │ │ │ └── endpoint │ │ │ ├── TicketAgentEndpoint.java │ │ │ └── WebServiceConfig.java │ └── resources │ │ ├── application.yml │ │ ├── jks │ │ ├── client-keystore.jks │ │ ├── client-public-key.cer │ │ ├── client-truststore.jks │ │ ├── server-keystore.jks │ │ ├── server-public-key.cer │ │ └── server-truststore.jks │ │ ├── logback.xml │ │ └── wsdl │ │ └── ticketagent.wsdl │ └── test │ └── java │ └── com │ └── codenotfound │ └── ws │ └── SpringWsApplicationTests.java ├── spring-ws-mutual-authentication ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── codenotfound │ │ │ └── ws │ │ │ ├── SpringWsApplication.java │ │ │ ├── client │ │ │ ├── ClientConfig.java │ │ │ └── TicketAgentClient.java │ │ │ └── endpoint │ │ │ ├── TicketAgentEndpoint.java │ │ │ └── WebServiceConfig.java │ └── resources │ │ ├── application.yml │ │ ├── jks │ │ ├── client-keystore.jks │ │ ├── client-public-key.cer │ │ ├── client-truststore.jks │ │ ├── server-keystore.jks │ │ ├── server-public-key.cer │ │ └── server-truststore.jks │ │ ├── logback.xml │ │ └── wsdl │ │ └── ticketagent.wsdl │ └── test │ └── java │ └── com │ └── codenotfound │ └── ws │ └── SpringWsApplicationTests.java ├── spring-ws-soap-header ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── codenotfound │ │ │ └── ws │ │ │ ├── SpringWsApplication.java │ │ │ ├── client │ │ │ ├── ClientConfig.java │ │ │ └── TicketAgentClient.java │ │ │ └── endpoint │ │ │ ├── TicketAgentEndpoint.java │ │ │ └── WebServiceConfig.java │ └── resources │ │ ├── application.yml │ │ ├── logback.xml │ │ └── wsdl │ │ └── ticketagent.wsdl │ └── test │ └── java │ └── com │ └── codenotfound │ └── ws │ ├── client │ └── TicketAgentClientTest.java │ └── endpoint │ └── TicketAgentEndpointTest.java ├── spring-ws-soapaction-header ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── codenotfound │ │ │ └── ws │ │ │ ├── SpringWsApplication.java │ │ │ ├── client │ │ │ ├── ClientConfig.java │ │ │ └── TicketAgentClient.java │ │ │ └── endpoint │ │ │ ├── TicketAgentEndpoint.java │ │ │ └── WebServiceConfig.java │ └── resources │ │ ├── application.yml │ │ ├── logback.xml │ │ └── wsdl │ │ └── ticketagent.wsdl │ └── test │ └── java │ └── com │ └── codenotfound │ └── ws │ ├── client │ ├── SoapActionMatcher.java │ └── TicketAgentClientTest.java │ └── endpoint │ ├── SoapActionCreator.java │ └── TicketAgentEndpointTest.java ├── spring-ws-stress-test ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── codenotfound │ │ │ └── order │ │ │ ├── OrderApplication.java │ │ │ ├── client │ │ │ ├── ClientConfig.java │ │ │ └── CreateOrderClient.java │ │ │ └── endpoint │ │ │ ├── CreateOrderEndpoint.java │ │ │ └── WebServiceConfig.java │ └── resources │ │ ├── application.properties │ │ └── wsdl │ │ └── order.wsdl │ └── test │ ├── java │ └── com │ │ └── codenotfound │ │ └── order │ │ ├── client │ │ ├── CreateOrderClientIT.java │ │ ├── CreateOrderClientMockTest.java │ │ └── CreateOrderClientTest.java │ │ └── endpoint │ │ ├── CreateOrderEndpointMockTest.java │ │ └── CreateOrderEndpointTest.java │ └── resources │ ├── application.properties │ ├── gatling │ ├── bodies │ │ └── order-request.xml │ └── scala │ │ └── OrderSimulation.scala │ └── soapui │ └── order-soapui-project.xml ├── spring-ws-test ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── codenotfound │ │ │ └── order │ │ │ ├── OrderApplication.java │ │ │ ├── client │ │ │ ├── ClientConfig.java │ │ │ └── CreateOrderClient.java │ │ │ └── endpoint │ │ │ ├── CreateOrderEndpoint.java │ │ │ └── WebServiceConfig.java │ └── resources │ │ ├── application.properties │ │ └── wsdl │ │ └── order.wsdl │ └── test │ ├── java │ └── com │ │ └── codenotfound │ │ └── order │ │ ├── client │ │ ├── CreateOrderClientIT.java │ │ ├── CreateOrderClientMockTest.java │ │ └── CreateOrderClientTest.java │ │ └── endpoint │ │ ├── CreateOrderEndpointMockTest.java │ │ └── CreateOrderEndpointTest.java │ └── resources │ ├── application.properties │ └── soapui │ └── order-soapui-project.xml ├── spring-ws-ticketagent ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── codenotfound │ │ │ └── ws │ │ │ ├── SpringWsApplication.java │ │ │ ├── client │ │ │ ├── ClientConfig.java │ │ │ └── TicketAgentClient.java │ │ │ └── endpoint │ │ │ ├── TicketAgentEndpoint.java │ │ │ └── WebServiceConfig.java │ └── resources │ │ └── wsdl │ │ └── ticketagent.wsdl │ └── test │ └── java │ └── com │ └── codenotfound │ └── ws │ └── SpringWsApplicationTests.java ├── spring-ws-timeout-httpclient ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── codenotfound │ │ │ └── ws │ │ │ ├── SpringWsApplication.java │ │ │ ├── client │ │ │ ├── ClientConfig.java │ │ │ └── TicketAgentClient.java │ │ │ └── endpoint │ │ │ ├── TicketAgentEndpoint.java │ │ │ └── WebServiceConfig.java │ └── resources │ │ ├── application.yml │ │ ├── logback.xml │ │ └── wsdl │ │ └── ticketagent.wsdl │ └── test │ └── java │ └── com │ └── codenotfound │ └── ws │ └── SpringWsApplicationTests.java ├── spring-ws-tolerant-reader ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── codenotfound │ │ │ └── ws │ │ │ ├── SpringWsApplication.java │ │ │ ├── client │ │ │ ├── ClientConfig.java │ │ │ └── OrderHistoryClient.java │ │ │ ├── endpoint │ │ │ ├── OrderHistoryEndpoint.java │ │ │ └── WebServiceConfig.java │ │ │ └── model │ │ │ ├── Order.java │ │ │ └── OrderHistory.java │ └── resources │ │ ├── application.yml │ │ ├── logback.xml │ │ └── wsdl │ │ └── orderhistory.wsdl │ └── test │ └── java │ └── com │ └── codenotfound │ └── ws │ ├── client │ └── OrderHistoryClientTest.java │ └── endpoint │ └── TicketAgentEndpointTest.java ├── spring-ws-unit-test ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── codenotfound │ │ │ └── order │ │ │ ├── OrderApplication.java │ │ │ ├── client │ │ │ ├── ClientConfig.java │ │ │ └── CreateOrderClient.java │ │ │ └── endpoint │ │ │ ├── CreateOrderEndpoint.java │ │ │ └── WebServiceConfig.java │ └── resources │ │ ├── application.properties │ │ └── wsdl │ │ └── order.wsdl │ └── test │ ├── java │ └── com │ │ └── codenotfound │ │ └── order │ │ ├── client │ │ ├── CreateOrderClientMockTest.java │ │ └── CreateOrderClientTest.java │ │ └── endpoint │ │ ├── CreateOrderEndpointMockTest.java │ │ └── CreateOrderEndpointTest.java │ └── resources │ └── application.properties └── spring-ws-wsdl-url-redirect ├── README.md ├── pom.xml └── src ├── main ├── java │ └── com │ │ └── codenotfound │ │ └── ws │ │ ├── SpringWsApplication.java │ │ ├── client │ │ ├── ClientConfig.java │ │ └── TicketAgentClient.java │ │ └── endpoint │ │ ├── QuestionMarkFilter.java │ │ ├── TicketAgentEndpoint.java │ │ └── WebServiceConfig.java └── resources │ ├── application.yml │ ├── logback.xml │ └── wsdl │ └── ticketagent.wsdl └── test └── java └── com └── codenotfound └── ws └── SpringWsApplicationTests.java /.gitignore: -------------------------------------------------------------------------------- 1 | ##Maven## 2 | target/ 3 | pom.xml.tag 4 | pom.xml.releaseBackup 5 | pom.xml.next 6 | release.properties 7 | 8 | ##Eclipse## 9 | .classpath 10 | .project 11 | .settings/ 12 | 13 | ##Logs## 14 | *.log 15 | *.log.* 16 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | sudo: false 3 | install: true 4 | 5 | jdk: 6 | - oraclejdk8 7 | 8 | addons: 9 | sonarqube: 10 | organization: "code-not-found-spring-ws" 11 | token: 12 | secure: $SONAR_TOKEN 13 | 14 | env: 15 | - PROJECT_DIR=spring-ws-basic-authentication-httpclient 16 | - PROJECT_DIR=spring-ws-basic-authentication 17 | - PROJECT_DIR=spring-ws-client-timeout 18 | - PROJECT_DIR=spring-ws-digital-signature 19 | - PROJECT_DIR=spring-ws-encryption 20 | - PROJECT_DIR=spring-ws-hello-world 21 | - PROJECT_DIR=spring-ws-https-httpclient 22 | - PROJECT_DIR=spring-ws-https 23 | - PROJECT_DIR=spring-ws-log-http-headers 24 | - PROJECT_DIR=spring-ws-mutual-authentication-httpclient 25 | - PROJECT_DIR=spring-ws-mutual-authentication 26 | - PROJECT_DIR=spring-ws-soapaction-header 27 | - PROJECT_DIR=spring-ws-soap-header 28 | - PROJECT_DIR=spring-ws-ticketagent 29 | - PROJECT_DIR=spring-ws-timeout-httpclient 30 | - PROJECT_DIR=spring-ws-tolerant-reader 31 | 32 | script: 33 | - cd $PROJECT_DIR 34 | - mvn test -B 35 | - mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent install sonar:sonar 36 | 37 | cache: 38 | directories: 39 | - $HOME/.m2/repository 40 | - $HOME/.sonar/cache 41 | 42 | notifications: 43 | email: false 44 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 code-not-found 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Spring WS Tutorials 2 | 3 | [![Build Status](https://travis-ci.org/code-not-found/spring-ws.svg?branch=master)](https://travis-ci.org/code-not-found/spring-ws) 4 | [![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE) 5 | 6 | This repository contains the source code for the spring-ws examples posted on [https://codenotfound.com/spring-ws-tutorials](https://codenotfound.com/spring-ws-tutorials) 7 | 8 | In case of questions or remarks please leave a comment in the respective blog post or open a GitHub issue. Thanks! 9 | -------------------------------------------------------------------------------- /spring-ws-basic-authentication-httpclient/README.md: -------------------------------------------------------------------------------- 1 | # spring-ws-basic-authentication-httpclient 2 | 3 | [![Quality Gate](https://sonarcloud.io/api/badges/gate?key=com.codenotfound:spring-ws-basic-authentication-httpclient)](https://sonarcloud.io/dashboard/index/com.codenotfound:spring-ws-basic-authentication-httpclient) 4 | 5 | A detailed step-by-step tutorial on how to configure basic authentication using Spring-WS and Spring Boot. 6 | 7 | [https://www.codenotfound.com/spring-ws-basic-authentication-example.html](https://www.codenotfound.com/spring-ws-basic-authentication-example.html) 8 | -------------------------------------------------------------------------------- /spring-ws-basic-authentication-httpclient/src/main/java/com/codenotfound/ws/SpringWsApplication.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringWsApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringWsApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spring-ws-basic-authentication-httpclient/src/main/java/com/codenotfound/ws/client/TicketAgentClient.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.client; 2 | 3 | import java.math.BigInteger; 4 | import java.util.List; 5 | 6 | import javax.xml.bind.JAXBElement; 7 | 8 | import org.example.ticketagent.ObjectFactory; 9 | import org.example.ticketagent.TFlightsResponse; 10 | import org.example.ticketagent.TListFlights; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.stereotype.Component; 13 | import org.springframework.ws.client.core.WebServiceTemplate; 14 | 15 | @Component 16 | public class TicketAgentClient { 17 | 18 | @Autowired 19 | private WebServiceTemplate webServiceTemplate; 20 | 21 | @SuppressWarnings("unchecked") 22 | public List listFlights() { 23 | ObjectFactory factory = new ObjectFactory(); 24 | TListFlights tListFlights = factory.createTListFlights(); 25 | 26 | JAXBElement request = factory.createListFlightsRequest(tListFlights); 27 | 28 | JAXBElement response = 29 | (JAXBElement) webServiceTemplate.marshalSendAndReceive(request); 30 | 31 | return response.getValue().getFlightNumber(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /spring-ws-basic-authentication-httpclient/src/main/java/com/codenotfound/ws/endpoint/TicketAgentEndpoint.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.endpoint; 2 | 3 | import java.math.BigInteger; 4 | 5 | import javax.xml.bind.JAXBElement; 6 | 7 | import org.example.ticketagent.ObjectFactory; 8 | import org.example.ticketagent.TFlightsResponse; 9 | import org.example.ticketagent.TListFlights; 10 | import org.springframework.ws.server.endpoint.annotation.Endpoint; 11 | import org.springframework.ws.server.endpoint.annotation.PayloadRoot; 12 | import org.springframework.ws.server.endpoint.annotation.RequestPayload; 13 | import org.springframework.ws.server.endpoint.annotation.ResponsePayload; 14 | 15 | @Endpoint 16 | public class TicketAgentEndpoint { 17 | 18 | @PayloadRoot(namespace = "http://example.org/TicketAgent.xsd", localPart = "listFlightsRequest") 19 | @ResponsePayload 20 | public JAXBElement listFlights( 21 | @RequestPayload JAXBElement request) { 22 | ObjectFactory factory = new ObjectFactory(); 23 | TFlightsResponse tFlightsResponse = factory.createTFlightsResponse(); 24 | tFlightsResponse.getFlightNumber().add(BigInteger.valueOf(101)); 25 | 26 | return factory.createListFlightsResponse(tFlightsResponse); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /spring-ws-basic-authentication-httpclient/src/main/java/com/codenotfound/ws/endpoint/WebServiceConfig.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.endpoint; 2 | 3 | import org.springframework.boot.web.servlet.ServletRegistrationBean; 4 | import org.springframework.context.ApplicationContext; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.core.io.ClassPathResource; 8 | import org.springframework.ws.config.annotation.EnableWs; 9 | import org.springframework.ws.config.annotation.WsConfigurerAdapter; 10 | import org.springframework.ws.transport.http.MessageDispatcherServlet; 11 | import org.springframework.ws.wsdl.wsdl11.SimpleWsdl11Definition; 12 | import org.springframework.ws.wsdl.wsdl11.Wsdl11Definition; 13 | 14 | @EnableWs 15 | @Configuration 16 | public class WebServiceConfig extends WsConfigurerAdapter { 17 | 18 | @Bean 19 | public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) { 20 | MessageDispatcherServlet servlet = new MessageDispatcherServlet(); 21 | servlet.setApplicationContext(applicationContext); 22 | 23 | return new ServletRegistrationBean(servlet, "/codenotfound/ws/*"); 24 | } 25 | 26 | @Bean(name = "ticketagent") 27 | public Wsdl11Definition defaultWsdl11Definition() { 28 | SimpleWsdl11Definition wsdl11Definition = new SimpleWsdl11Definition(); 29 | wsdl11Definition.setWsdl(new ClassPathResource("/wsdl/ticketagent.wsdl")); 30 | 31 | return wsdl11Definition; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /spring-ws-basic-authentication-httpclient/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | client: 2 | default-uri: http://localhost:9090/codenotfound/ws/helloworld 3 | user: 4 | name: codenotfound 5 | password: p455w0rd 6 | 7 | security: 8 | user: 9 | name: codenotfound 10 | password: p455w0rd 11 | 12 | server: 13 | port: 9090 14 | -------------------------------------------------------------------------------- /spring-ws-basic-authentication-httpclient/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /spring-ws-basic-authentication-httpclient/src/test/java/com/codenotfound/ws/SpringWsApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import java.math.BigInteger; 6 | import java.util.List; 7 | 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.boot.test.context.SpringBootTest; 12 | import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; 13 | import org.springframework.test.context.junit4.SpringRunner; 14 | 15 | import com.codenotfound.ws.client.TicketAgentClient; 16 | 17 | @RunWith(SpringRunner.class) 18 | @SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT) 19 | public class SpringWsApplicationTests { 20 | 21 | @Autowired 22 | private TicketAgentClient ticketAgentClient; 23 | 24 | @Test 25 | public void testListFlights() { 26 | List flights = ticketAgentClient.listFlights(); 27 | 28 | assertThat(flights.get(0)).isEqualTo(BigInteger.valueOf(101)); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /spring-ws-basic-authentication/README.md: -------------------------------------------------------------------------------- 1 | # spring-ws-basic-authentication 2 | 3 | [![Quality Gate](https://sonarcloud.io/api/badges/gate?key=com.codenotfound:spring-ws-basic-authentication)](https://sonarcloud.io/dashboard/index/com.codenotfound:spring-ws-basic-authentication) 4 | 5 | A sample project on how to configure basic authentication using Spring-WS and Spring Boot without using the Apache HttpClient. 6 | 7 | [https://www.codenotfound.com/spring-ws/](https://www.codenotfound.com/spring-ws/) 8 | -------------------------------------------------------------------------------- /spring-ws-basic-authentication/src/main/java/com/codenotfound/ws/SpringWsApplication.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringWsApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringWsApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spring-ws-basic-authentication/src/main/java/com/codenotfound/ws/client/BasicAuthenticationUtil.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.client; 2 | 3 | import java.util.Base64; 4 | 5 | public class BasicAuthenticationUtil { 6 | 7 | private BasicAuthenticationUtil() {} 8 | 9 | public static String generateBasicAutenticationHeader(String userName, String userPassword) { 10 | byte[] encodedBytes = Base64.getEncoder().encode((userName + ":" + userPassword).getBytes()); 11 | return "Basic " + new String(encodedBytes); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /spring-ws-basic-authentication/src/main/java/com/codenotfound/ws/client/ClientConfig.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.client; 2 | 3 | import org.springframework.beans.factory.annotation.Value; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.oxm.jaxb.Jaxb2Marshaller; 7 | import org.springframework.ws.client.core.WebServiceTemplate; 8 | 9 | @Configuration 10 | public class ClientConfig { 11 | 12 | @Value("${client.default-uri}") 13 | private String defaultUri; 14 | 15 | @Value("${client.user.name}") 16 | private String userName; 17 | 18 | @Value("${client.user.password}") 19 | private String userPassword; 20 | 21 | public String getUserName() { 22 | return userName; 23 | } 24 | 25 | public String getUserPassword() { 26 | return userPassword; 27 | } 28 | 29 | @Bean 30 | Jaxb2Marshaller jaxb2Marshaller() { 31 | Jaxb2Marshaller jaxb2Marshaller = new Jaxb2Marshaller(); 32 | jaxb2Marshaller.setContextPath("org.example.ticketagent"); 33 | 34 | return jaxb2Marshaller; 35 | } 36 | 37 | @Bean 38 | public WebServiceTemplate webServiceTemplate() { 39 | WebServiceTemplate webServiceTemplate = new WebServiceTemplate(); 40 | webServiceTemplate.setMarshaller(jaxb2Marshaller()); 41 | webServiceTemplate.setUnmarshaller(jaxb2Marshaller()); 42 | webServiceTemplate.setDefaultUri(defaultUri); 43 | 44 | return webServiceTemplate; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /spring-ws-basic-authentication/src/main/java/com/codenotfound/ws/client/TicketAgentClient.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.client; 2 | 3 | import java.math.BigInteger; 4 | import java.util.List; 5 | 6 | import javax.xml.bind.JAXBElement; 7 | 8 | import org.example.ticketagent.ObjectFactory; 9 | import org.example.ticketagent.TFlightsResponse; 10 | import org.example.ticketagent.TListFlights; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.stereotype.Component; 13 | import org.springframework.ws.WebServiceMessage; 14 | import org.springframework.ws.client.core.WebServiceMessageCallback; 15 | import org.springframework.ws.client.core.WebServiceTemplate; 16 | import org.springframework.ws.transport.context.TransportContext; 17 | import org.springframework.ws.transport.context.TransportContextHolder; 18 | import org.springframework.ws.transport.http.HttpUrlConnection; 19 | 20 | @Component 21 | public class TicketAgentClient { 22 | 23 | @Autowired 24 | private ClientConfig clientConfig; 25 | 26 | @Autowired 27 | private WebServiceTemplate webServiceTemplate; 28 | 29 | @SuppressWarnings("unchecked") 30 | public List listFlights() { 31 | ObjectFactory factory = new ObjectFactory(); 32 | TListFlights tListFlights = factory.createTListFlights(); 33 | 34 | JAXBElement request = factory.createListFlightsRequest(tListFlights); 35 | 36 | JAXBElement response = (JAXBElement) webServiceTemplate 37 | .marshalSendAndReceive(request, new WebServiceMessageCallback() { 38 | 39 | public void doWithMessage(WebServiceMessage message) { 40 | TransportContext context = TransportContextHolder.getTransportContext(); 41 | HttpUrlConnection connection = (HttpUrlConnection) context.getConnection(); 42 | connection.getConnection().addRequestProperty("Authorization", 43 | BasicAuthenticationUtil.generateBasicAutenticationHeader(clientConfig.getUserName(), 44 | clientConfig.getUserPassword())); 45 | } 46 | }); 47 | 48 | return response.getValue().getFlightNumber(); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /spring-ws-basic-authentication/src/main/java/com/codenotfound/ws/endpoint/TicketAgentEndpoint.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.endpoint; 2 | 3 | import java.math.BigInteger; 4 | 5 | import javax.xml.bind.JAXBElement; 6 | 7 | import org.example.ticketagent.ObjectFactory; 8 | import org.example.ticketagent.TFlightsResponse; 9 | import org.example.ticketagent.TListFlights; 10 | import org.springframework.ws.server.endpoint.annotation.Endpoint; 11 | import org.springframework.ws.server.endpoint.annotation.PayloadRoot; 12 | import org.springframework.ws.server.endpoint.annotation.RequestPayload; 13 | import org.springframework.ws.server.endpoint.annotation.ResponsePayload; 14 | 15 | @Endpoint 16 | public class TicketAgentEndpoint { 17 | 18 | @PayloadRoot(namespace = "http://example.org/TicketAgent.xsd", localPart = "listFlightsRequest") 19 | @ResponsePayload 20 | public JAXBElement listFlights( 21 | @RequestPayload JAXBElement request) { 22 | ObjectFactory factory = new ObjectFactory(); 23 | TFlightsResponse tFlightsResponse = factory.createTFlightsResponse(); 24 | tFlightsResponse.getFlightNumber().add(BigInteger.valueOf(101)); 25 | 26 | return factory.createListFlightsResponse(tFlightsResponse); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /spring-ws-basic-authentication/src/main/java/com/codenotfound/ws/endpoint/WebServiceConfig.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.endpoint; 2 | 3 | import org.springframework.boot.web.servlet.ServletRegistrationBean; 4 | import org.springframework.context.ApplicationContext; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.core.io.ClassPathResource; 8 | import org.springframework.ws.config.annotation.EnableWs; 9 | import org.springframework.ws.config.annotation.WsConfigurerAdapter; 10 | import org.springframework.ws.transport.http.MessageDispatcherServlet; 11 | import org.springframework.ws.wsdl.wsdl11.SimpleWsdl11Definition; 12 | import org.springframework.ws.wsdl.wsdl11.Wsdl11Definition; 13 | 14 | @EnableWs 15 | @Configuration 16 | public class WebServiceConfig extends WsConfigurerAdapter { 17 | 18 | @Bean 19 | public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) { 20 | MessageDispatcherServlet servlet = new MessageDispatcherServlet(); 21 | servlet.setApplicationContext(applicationContext); 22 | 23 | return new ServletRegistrationBean(servlet, "/codenotfound/ws/*"); 24 | } 25 | 26 | @Bean(name = "ticketagent") 27 | public Wsdl11Definition defaultWsdl11Definition() { 28 | SimpleWsdl11Definition wsdl11Definition = new SimpleWsdl11Definition(); 29 | wsdl11Definition.setWsdl(new ClassPathResource("/wsdl/ticketagent.wsdl")); 30 | 31 | return wsdl11Definition; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /spring-ws-basic-authentication/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | client: 2 | default-uri: http://localhost:9090/codenotfound/ws/helloworld 3 | user: 4 | name: codenotfound 5 | password: p455w0rd 6 | 7 | security: 8 | user: 9 | name: codenotfound 10 | password: p455w0rd 11 | 12 | server: 13 | port: 9090 14 | -------------------------------------------------------------------------------- /spring-ws-basic-authentication/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /spring-ws-basic-authentication/src/test/java/com/codenotfound/ws/SpringWsApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import java.math.BigInteger; 6 | import java.util.List; 7 | 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.boot.test.context.SpringBootTest; 12 | import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; 13 | import org.springframework.test.context.junit4.SpringRunner; 14 | 15 | import com.codenotfound.ws.client.TicketAgentClient; 16 | 17 | @RunWith(SpringRunner.class) 18 | @SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT) 19 | public class SpringWsApplicationTests { 20 | 21 | @Autowired 22 | private TicketAgentClient ticketAgentClient; 23 | 24 | @Test 25 | public void testListFlights() { 26 | List flights = ticketAgentClient.listFlights(); 27 | 28 | assertThat(flights.get(0)).isEqualTo(BigInteger.valueOf(101)); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /spring-ws-client-timeout/README.md: -------------------------------------------------------------------------------- 1 | # spring-ws-client-timeout 2 | 3 | [![Quality Gate](https://sonarcloud.io/api/badges/gate?key=com.codenotfound:spring-ws-client-timeout)](https://sonarcloud.io/dashboard/index/com.codenotfound:spring-ws-client-timeout) 4 | 5 | A sample project that illustrates how to configure a client timeout using Spring-WS and Spring Boot without using the Apache HttpClient. 6 | 7 | [https://www.codenotfound.com/spring-ws-client-timeout-example.html](https://www.codenotfound.com/spring-ws-client-timeout-example.html) 8 | -------------------------------------------------------------------------------- /spring-ws-client-timeout/src/main/java/com/codenotfound/ws/SpringWsApplication.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringWsApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringWsApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spring-ws-client-timeout/src/main/java/com/codenotfound/ws/client/ClientConfig.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.client; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.oxm.jaxb.Jaxb2Marshaller; 6 | import org.springframework.ws.client.core.WebServiceTemplate; 7 | 8 | @Configuration 9 | public class ClientConfig { 10 | 11 | @Bean 12 | Jaxb2Marshaller jaxb2Marshaller() { 13 | Jaxb2Marshaller jaxb2Marshaller = new Jaxb2Marshaller(); 14 | jaxb2Marshaller.setContextPath("org.example.ticketagent"); 15 | 16 | return jaxb2Marshaller; 17 | } 18 | 19 | @Bean 20 | public WebServiceTemplate webServiceTemplate() { 21 | WebServiceTemplate webServiceTemplate = new WebServiceTemplate(); 22 | webServiceTemplate.setMarshaller(jaxb2Marshaller()); 23 | webServiceTemplate.setUnmarshaller(jaxb2Marshaller()); 24 | webServiceTemplate.setDefaultUri( 25 | "http://localhost:8080/codenotfound/ws/helloworld"); 26 | webServiceTemplate 27 | .setMessageSender(httpUrlConnectionMessageSenderTimeout()); 28 | 29 | return webServiceTemplate; 30 | } 31 | 32 | @Bean 33 | public HttpUrlConnectionMessageSenderTimeout httpUrlConnectionMessageSenderTimeout() { 34 | HttpUrlConnectionMessageSenderTimeout httpUrlConnectionMessageSenderTimeout = 35 | new HttpUrlConnectionMessageSenderTimeout(); 36 | httpUrlConnectionMessageSenderTimeout.setTimeout(2000); 37 | 38 | return httpUrlConnectionMessageSenderTimeout; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /spring-ws-client-timeout/src/main/java/com/codenotfound/ws/client/HttpUrlConnectionMessageSenderTimeout.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.client; 2 | 3 | import java.io.IOException; 4 | import java.net.HttpURLConnection; 5 | 6 | import org.springframework.ws.transport.http.HttpTransportConstants; 7 | import org.springframework.ws.transport.http.HttpUrlConnectionMessageSender; 8 | 9 | public class HttpUrlConnectionMessageSenderTimeout 10 | extends HttpUrlConnectionMessageSender { 11 | 12 | private int timeout = 0; 13 | 14 | @Override 15 | protected void prepareConnection(HttpURLConnection connection) 16 | throws IOException { 17 | connection.setRequestMethod(HttpTransportConstants.METHOD_POST); 18 | connection.setUseCaches(false); 19 | connection.setDoInput(true); 20 | connection.setDoOutput(true); 21 | if (isAcceptGzipEncoding()) { 22 | connection.setRequestProperty( 23 | HttpTransportConstants.HEADER_ACCEPT_ENCODING, 24 | HttpTransportConstants.CONTENT_ENCODING_GZIP); 25 | } 26 | // timeout for creating a connection 27 | connection.setConnectTimeout(timeout); 28 | // when you have a connection, timeout the read blocks for 29 | connection.setReadTimeout(timeout); 30 | } 31 | 32 | public void setTimeout(int timeout) { 33 | this.timeout = timeout; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /spring-ws-client-timeout/src/main/java/com/codenotfound/ws/client/TicketAgentClient.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.client; 2 | 3 | import java.math.BigInteger; 4 | import java.util.List; 5 | 6 | import javax.xml.bind.JAXBElement; 7 | 8 | import org.example.ticketagent.ObjectFactory; 9 | import org.example.ticketagent.TFlightsResponse; 10 | import org.example.ticketagent.TListFlights; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.stereotype.Component; 13 | import org.springframework.ws.client.core.WebServiceTemplate; 14 | 15 | @Component 16 | public class TicketAgentClient { 17 | 18 | @Autowired 19 | private WebServiceTemplate webServiceTemplate; 20 | 21 | @SuppressWarnings("unchecked") 22 | public List listFlights() { 23 | ObjectFactory factory = new ObjectFactory(); 24 | TListFlights tListFlights = factory.createTListFlights(); 25 | 26 | JAXBElement request = 27 | factory.createListFlightsRequest(tListFlights); 28 | 29 | JAXBElement response = 30 | (JAXBElement) webServiceTemplate 31 | .marshalSendAndReceive(request); 32 | 33 | return response.getValue().getFlightNumber(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /spring-ws-client-timeout/src/main/java/com/codenotfound/ws/endpoint/TicketAgentEndpoint.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.endpoint; 2 | 3 | import java.math.BigInteger; 4 | 5 | import javax.xml.bind.JAXBElement; 6 | 7 | import org.example.ticketagent.ObjectFactory; 8 | import org.example.ticketagent.TFlightsResponse; 9 | import org.example.ticketagent.TListFlights; 10 | import org.springframework.ws.server.endpoint.annotation.Endpoint; 11 | import org.springframework.ws.server.endpoint.annotation.PayloadRoot; 12 | import org.springframework.ws.server.endpoint.annotation.RequestPayload; 13 | import org.springframework.ws.server.endpoint.annotation.ResponsePayload; 14 | 15 | @Endpoint 16 | public class TicketAgentEndpoint { 17 | 18 | @PayloadRoot(namespace = "http://example.org/TicketAgent.xsd", 19 | localPart = "listFlightsRequest") 20 | @ResponsePayload 21 | public JAXBElement listFlights( 22 | @RequestPayload JAXBElement request) 23 | throws InterruptedException { 24 | 25 | // sleep for 10 seconds so a timeout occurs 26 | Thread.sleep(10 * (long) 1000); 27 | 28 | ObjectFactory factory = new ObjectFactory(); 29 | TFlightsResponse tFlightsResponse = 30 | factory.createTFlightsResponse(); 31 | tFlightsResponse.getFlightNumber().add(BigInteger.valueOf(101)); 32 | 33 | return factory.createListFlightsResponse(tFlightsResponse); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /spring-ws-client-timeout/src/main/java/com/codenotfound/ws/endpoint/WebServiceConfig.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.endpoint; 2 | 3 | import org.springframework.boot.web.servlet.ServletRegistrationBean; 4 | import org.springframework.context.ApplicationContext; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.core.io.ClassPathResource; 8 | import org.springframework.ws.config.annotation.EnableWs; 9 | import org.springframework.ws.config.annotation.WsConfigurerAdapter; 10 | import org.springframework.ws.transport.http.MessageDispatcherServlet; 11 | import org.springframework.ws.wsdl.wsdl11.SimpleWsdl11Definition; 12 | import org.springframework.ws.wsdl.wsdl11.Wsdl11Definition; 13 | 14 | @EnableWs 15 | @Configuration 16 | public class WebServiceConfig extends WsConfigurerAdapter { 17 | 18 | @Bean 19 | public ServletRegistrationBean messageDispatcherServlet( 20 | ApplicationContext applicationContext) { 21 | MessageDispatcherServlet servlet = new MessageDispatcherServlet(); 22 | servlet.setApplicationContext(applicationContext); 23 | 24 | return new ServletRegistrationBean(servlet, "/codenotfound/ws/*"); 25 | } 26 | 27 | @Bean(name = "ticketagent") 28 | public Wsdl11Definition defaultWsdl11Definition() { 29 | SimpleWsdl11Definition wsdl11Definition = 30 | new SimpleWsdl11Definition(); 31 | wsdl11Definition 32 | .setWsdl(new ClassPathResource("/wsdl/ticketagent.wsdl")); 33 | 34 | return wsdl11Definition; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /spring-ws-client-timeout/src/test/java/com/codenotfound/ws/SpringWsApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | import static org.junit.Assert.fail; 5 | 6 | import org.junit.Test; 7 | import org.junit.runner.RunWith; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.boot.test.context.SpringBootTest; 10 | import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; 11 | import org.springframework.test.context.junit4.SpringRunner; 12 | 13 | import com.codenotfound.ws.client.TicketAgentClient; 14 | 15 | @RunWith(SpringRunner.class) 16 | @SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT) 17 | public class SpringWsApplicationTests { 18 | 19 | @Autowired 20 | private TicketAgentClient ticketAgentClient; 21 | 22 | @Test 23 | public void testListFlights() { 24 | try { 25 | ticketAgentClient.listFlights(); 26 | fail("Timeout exception not thrown"); 27 | } catch (Exception expectedException) { 28 | assertThat(expectedException.getMessage()) 29 | .contains("Read timed out"); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /spring-ws-digital-signature/README.md: -------------------------------------------------------------------------------- 1 | # spring-ws-digital-signature 2 | 3 | [![Quality Gate](https://sonarqube.com/api/badges/gate?key=com.codenotfound:spring-ws-digital-signature)](https://sonarqube.com/dashboard/index/com.codenotfound:spring-ws-digital-signature) 4 | 5 | A detailed step-by-step tutorial on how generate and validate a digital signature using Spring-WS and Spring Boot. 6 | 7 | [https://www.codenotfound.com/spring-ws-digital-signature-example.html](https://www.codenotfound.com/spring-ws-digital-signature-example.html) 8 | -------------------------------------------------------------------------------- /spring-ws-digital-signature/src/main/java/com/codenotfound/ws/SpringWsApplication.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringWsApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringWsApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spring-ws-digital-signature/src/main/java/com/codenotfound/ws/client/TicketAgentClient.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.client; 2 | 3 | import java.math.BigInteger; 4 | import java.util.List; 5 | 6 | import javax.xml.bind.JAXBElement; 7 | 8 | import org.example.ticketagent.ObjectFactory; 9 | import org.example.ticketagent.TFlightsResponse; 10 | import org.example.ticketagent.TListFlights; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.stereotype.Component; 13 | import org.springframework.ws.client.core.WebServiceTemplate; 14 | 15 | @Component 16 | public class TicketAgentClient { 17 | 18 | @Autowired 19 | private WebServiceTemplate webServiceTemplate; 20 | 21 | @SuppressWarnings("unchecked") 22 | public List listFlights() { 23 | 24 | ObjectFactory factory = new ObjectFactory(); 25 | TListFlights tListFlights = factory.createTListFlights(); 26 | 27 | JAXBElement request = factory.createListFlightsRequest(tListFlights); 28 | 29 | JAXBElement response = 30 | (JAXBElement) webServiceTemplate.marshalSendAndReceive(request); 31 | 32 | return response.getValue().getFlightNumber(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /spring-ws-digital-signature/src/main/java/com/codenotfound/ws/endpoint/TicketAgentEndpoint.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.endpoint; 2 | 3 | import java.math.BigInteger; 4 | 5 | import javax.xml.bind.JAXBElement; 6 | 7 | import org.example.ticketagent.ObjectFactory; 8 | import org.example.ticketagent.TFlightsResponse; 9 | import org.example.ticketagent.TListFlights; 10 | import org.springframework.ws.server.endpoint.annotation.Endpoint; 11 | import org.springframework.ws.server.endpoint.annotation.PayloadRoot; 12 | import org.springframework.ws.server.endpoint.annotation.RequestPayload; 13 | import org.springframework.ws.server.endpoint.annotation.ResponsePayload; 14 | 15 | @Endpoint 16 | public class TicketAgentEndpoint { 17 | 18 | @PayloadRoot(namespace = "http://example.org/TicketAgent.xsd", localPart = "listFlightsRequest") 19 | @ResponsePayload 20 | public JAXBElement listFlights( 21 | @RequestPayload JAXBElement request) { 22 | 23 | ObjectFactory factory = new ObjectFactory(); 24 | TFlightsResponse tFlightsResponse = factory.createTFlightsResponse(); 25 | tFlightsResponse.getFlightNumber().add(BigInteger.valueOf(101)); 26 | 27 | return factory.createListFlightsResponse(tFlightsResponse); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /spring-ws-digital-signature/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | client: 2 | default-uri: http://localhost:9090/codenotfound/ws/ticketagent 3 | signature: 4 | key-store: classpath:jks/client-keystore.jks 5 | key-store-password: client-keystore-p455w0rd 6 | key-alias: client-keypair 7 | key-password: client-key-p455w0rd 8 | trust-store: classpath:jks/client-truststore.jks 9 | trust-store-password: client-truststore-p455w0rd 10 | 11 | server: 12 | port: 9090 13 | signature: 14 | key-store: classpath:jks/server-keystore.jks 15 | key-store-password: server-keystore-p455w0rd 16 | key-alias: server-keypair 17 | key-password: server-key-p455w0rd 18 | trust-store: classpath:jks/server-truststore.jks 19 | trust-store-password: server-truststore-p455w0rd 20 | -------------------------------------------------------------------------------- /spring-ws-digital-signature/src/main/resources/jks/client-keystore.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-not-found/spring-ws/5d37e6987868b44b0fd162f8a2c836bd553d8132/spring-ws-digital-signature/src/main/resources/jks/client-keystore.jks -------------------------------------------------------------------------------- /spring-ws-digital-signature/src/main/resources/jks/client-public-key.cer: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-not-found/spring-ws/5d37e6987868b44b0fd162f8a2c836bd553d8132/spring-ws-digital-signature/src/main/resources/jks/client-public-key.cer -------------------------------------------------------------------------------- /spring-ws-digital-signature/src/main/resources/jks/client-truststore.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-not-found/spring-ws/5d37e6987868b44b0fd162f8a2c836bd553d8132/spring-ws-digital-signature/src/main/resources/jks/client-truststore.jks -------------------------------------------------------------------------------- /spring-ws-digital-signature/src/main/resources/jks/server-keystore.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-not-found/spring-ws/5d37e6987868b44b0fd162f8a2c836bd553d8132/spring-ws-digital-signature/src/main/resources/jks/server-keystore.jks -------------------------------------------------------------------------------- /spring-ws-digital-signature/src/main/resources/jks/server-public-key.cer: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-not-found/spring-ws/5d37e6987868b44b0fd162f8a2c836bd553d8132/spring-ws-digital-signature/src/main/resources/jks/server-public-key.cer -------------------------------------------------------------------------------- /spring-ws-digital-signature/src/main/resources/jks/server-truststore.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-not-found/spring-ws/5d37e6987868b44b0fd162f8a2c836bd553d8132/spring-ws-digital-signature/src/main/resources/jks/server-truststore.jks -------------------------------------------------------------------------------- /spring-ws-digital-signature/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /spring-ws-digital-signature/src/test/java/com/codenotfound/ws/SpringWsApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import java.math.BigInteger; 6 | import java.util.List; 7 | 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.boot.test.context.SpringBootTest; 12 | import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; 13 | import org.springframework.test.context.junit4.SpringRunner; 14 | 15 | import com.codenotfound.ws.client.TicketAgentClient; 16 | 17 | @RunWith(SpringRunner.class) 18 | @SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT) 19 | public class SpringWsApplicationTests { 20 | 21 | @Autowired 22 | private TicketAgentClient ticketAgentClient; 23 | 24 | @Test 25 | public void testListFlights() { 26 | List flights = ticketAgentClient.listFlights(); 27 | 28 | assertThat(flights.get(0)).isEqualTo(BigInteger.valueOf(101)); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /spring-ws-encryption/README.md: -------------------------------------------------------------------------------- 1 | # spring-ws-encryption 2 | 3 | [![Quality Gate](https://sonarqube.com/api/badges/gate?key=com.codenotfound:spring-ws-encryption)](https://sonarqube.com/dashboard/index/com.codenotfound:spring-ws-encryption) 4 | 5 | A detailed step-by-step tutorial on how to apply WS-Security encryption to a SOAP message using Spring-WS and Spring Boot. 6 | 7 | [https://www.codenotfound.com/spring-ws-encryption-example.html](https://www.codenotfound.com/spring-ws-encryption-example.html) 8 | -------------------------------------------------------------------------------- /spring-ws-encryption/src/main/java/com/codenotfound/ws/SpringWsApplication.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringWsApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringWsApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spring-ws-encryption/src/main/java/com/codenotfound/ws/client/TicketAgentClient.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.client; 2 | 3 | import java.math.BigInteger; 4 | import java.util.List; 5 | 6 | import javax.xml.bind.JAXBElement; 7 | 8 | import org.example.ticketagent.ObjectFactory; 9 | import org.example.ticketagent.TFlightsResponse; 10 | import org.example.ticketagent.TListFlights; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.stereotype.Component; 13 | import org.springframework.ws.client.core.WebServiceTemplate; 14 | 15 | @Component 16 | public class TicketAgentClient { 17 | 18 | @Autowired 19 | private WebServiceTemplate webServiceTemplate; 20 | 21 | @SuppressWarnings("unchecked") 22 | public List listFlights() { 23 | 24 | ObjectFactory factory = new ObjectFactory(); 25 | TListFlights tListFlights = factory.createTListFlights(); 26 | 27 | JAXBElement request = factory.createListFlightsRequest(tListFlights); 28 | 29 | JAXBElement response = 30 | (JAXBElement) webServiceTemplate.marshalSendAndReceive(request); 31 | 32 | return response.getValue().getFlightNumber(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /spring-ws-encryption/src/main/java/com/codenotfound/ws/endpoint/TicketAgentEndpoint.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.endpoint; 2 | 3 | import java.math.BigInteger; 4 | 5 | import javax.xml.bind.JAXBElement; 6 | 7 | import org.example.ticketagent.ObjectFactory; 8 | import org.example.ticketagent.TFlightsResponse; 9 | import org.example.ticketagent.TListFlights; 10 | import org.springframework.ws.server.endpoint.annotation.Endpoint; 11 | import org.springframework.ws.server.endpoint.annotation.PayloadRoot; 12 | import org.springframework.ws.server.endpoint.annotation.RequestPayload; 13 | import org.springframework.ws.server.endpoint.annotation.ResponsePayload; 14 | 15 | @Endpoint 16 | public class TicketAgentEndpoint { 17 | 18 | @PayloadRoot(namespace = "http://example.org/TicketAgent.xsd", localPart = "listFlightsRequest") 19 | @ResponsePayload 20 | public JAXBElement listFlights( 21 | @RequestPayload JAXBElement request) { 22 | 23 | ObjectFactory factory = new ObjectFactory(); 24 | TFlightsResponse tFlightsResponse = factory.createTFlightsResponse(); 25 | tFlightsResponse.getFlightNumber().add(BigInteger.valueOf(101)); 26 | 27 | return factory.createListFlightsResponse(tFlightsResponse); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /spring-ws-encryption/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | client: 2 | default-uri: http://localhost:9090/codenotfound/ws/ticketagent 3 | encrypt: 4 | trust-store: classpath:jks/client-truststore.jks 5 | trust-store-password: client-truststore-p455w0rd 6 | certificate-alias: server-public-key 7 | key-store: classpath:jks/client-keystore.jks 8 | key-store-password: client-keystore-p455w0rd 9 | key-password: client-key-p455w0rd 10 | 11 | 12 | server: 13 | port: 9090 14 | encrypt: 15 | key-store: classpath:jks/server-keystore.jks 16 | key-store-password: server-keystore-p455w0rd 17 | key-password: server-key-p455w0rd 18 | trust-store: classpath:jks/server-truststore.jks 19 | trust-store-password: server-truststore-p455w0rd 20 | certificate-alias: client-public-key 21 | -------------------------------------------------------------------------------- /spring-ws-encryption/src/main/resources/jks/client-keystore.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-not-found/spring-ws/5d37e6987868b44b0fd162f8a2c836bd553d8132/spring-ws-encryption/src/main/resources/jks/client-keystore.jks -------------------------------------------------------------------------------- /spring-ws-encryption/src/main/resources/jks/client-public-key.cer: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-not-found/spring-ws/5d37e6987868b44b0fd162f8a2c836bd553d8132/spring-ws-encryption/src/main/resources/jks/client-public-key.cer -------------------------------------------------------------------------------- /spring-ws-encryption/src/main/resources/jks/client-truststore.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-not-found/spring-ws/5d37e6987868b44b0fd162f8a2c836bd553d8132/spring-ws-encryption/src/main/resources/jks/client-truststore.jks -------------------------------------------------------------------------------- /spring-ws-encryption/src/main/resources/jks/server-keystore.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-not-found/spring-ws/5d37e6987868b44b0fd162f8a2c836bd553d8132/spring-ws-encryption/src/main/resources/jks/server-keystore.jks -------------------------------------------------------------------------------- /spring-ws-encryption/src/main/resources/jks/server-public-key.cer: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-not-found/spring-ws/5d37e6987868b44b0fd162f8a2c836bd553d8132/spring-ws-encryption/src/main/resources/jks/server-public-key.cer -------------------------------------------------------------------------------- /spring-ws-encryption/src/main/resources/jks/server-truststore.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-not-found/spring-ws/5d37e6987868b44b0fd162f8a2c836bd553d8132/spring-ws-encryption/src/main/resources/jks/server-truststore.jks -------------------------------------------------------------------------------- /spring-ws-encryption/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /spring-ws-encryption/src/test/java/com/codenotfound/ws/SpringWsApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import java.math.BigInteger; 6 | import java.util.List; 7 | 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.boot.test.context.SpringBootTest; 12 | import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; 13 | import org.springframework.test.context.junit4.SpringRunner; 14 | 15 | import com.codenotfound.ws.client.TicketAgentClient; 16 | 17 | @RunWith(SpringRunner.class) 18 | @SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT) 19 | public class SpringWsApplicationTests { 20 | 21 | @Autowired 22 | private TicketAgentClient ticketAgentClient; 23 | 24 | @Test 25 | public void testListFlights() { 26 | List flights = ticketAgentClient.listFlights(); 27 | 28 | assertThat(flights.get(0)).isEqualTo(BigInteger.valueOf(101)); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /spring-ws-eureka/README.md: -------------------------------------------------------------------------------- 1 | # spring-ws-eureka 2 | 3 | Spring WS UDDI Example in which we use Eureka to register a web service endpoint of a Ticket Agent server. First startup the spring-boot-eureka-server followed by spring-ws-ticketagent-server. Then run the test case in spring-ws-ticketagent-client. 4 | 5 | [https://www.codenotfound.com/spring-ws/](https://www.codenotfound.com/spring-ws/) 6 | -------------------------------------------------------------------------------- /spring-ws-eureka/spring-boot-eureka-server/src/main/java/com/codenotfound/eureka/SpringBootEurekaServerApplication.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.eureka; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; 6 | 7 | @SpringBootApplication 8 | @EnableEurekaServer 9 | public class SpringBootEurekaServerApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(SpringBootEurekaServerApplication.class, 13 | args); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /spring-ws-eureka/spring-boot-eureka-server/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8761 3 | 4 | eureka: 5 | instance: 6 | hostname: localhost 7 | client: 8 | registerWithEureka: false 9 | fetchRegistry: false 10 | -------------------------------------------------------------------------------- /spring-ws-eureka/spring-ws-ticketagent-client/src/main/java/com/codenotfound/ws/SpringWsClientApplication.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringWsClientApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringWsClientApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spring-ws-eureka/spring-ws-ticketagent-client/src/main/java/com/codenotfound/ws/client/ClientConfig.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.client; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.oxm.jaxb.Jaxb2Marshaller; 7 | import org.springframework.ws.client.core.WebServiceTemplate; 8 | 9 | import com.netflix.discovery.EurekaClient; 10 | 11 | @Configuration 12 | public class ClientConfig { 13 | 14 | @Autowired 15 | private EurekaClient discoveryClient; 16 | 17 | @Bean 18 | Jaxb2Marshaller jaxb2Marshaller() { 19 | Jaxb2Marshaller jaxb2Marshaller = new Jaxb2Marshaller(); 20 | jaxb2Marshaller.setContextPath("org.example.ticketagent"); 21 | 22 | return jaxb2Marshaller; 23 | } 24 | 25 | @Bean 26 | public WebServiceTemplate webServiceTemplate() { 27 | WebServiceTemplate webServiceTemplate = new WebServiceTemplate(); 28 | webServiceTemplate.setMarshaller(jaxb2Marshaller()); 29 | webServiceTemplate.setUnmarshaller(jaxb2Marshaller()); 30 | 31 | // set the host:port information fetched from Eureka 32 | webServiceTemplate.setDefaultUri( 33 | discoveryClient.getApplication("ticketagent-service") 34 | .getInstances().get(0).getHomePageUrl() 35 | + "/codenotfound/ws/helloworld"); 36 | 37 | return webServiceTemplate; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /spring-ws-eureka/spring-ws-ticketagent-client/src/main/java/com/codenotfound/ws/client/TicketAgentClient.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.client; 2 | 3 | import java.math.BigInteger; 4 | import java.util.List; 5 | 6 | import javax.xml.bind.JAXBElement; 7 | 8 | import org.example.ticketagent.ObjectFactory; 9 | import org.example.ticketagent.TFlightsResponse; 10 | import org.example.ticketagent.TListFlights; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.stereotype.Component; 13 | import org.springframework.ws.client.core.WebServiceTemplate; 14 | 15 | @Component 16 | public class TicketAgentClient { 17 | 18 | @Autowired 19 | private WebServiceTemplate webServiceTemplate; 20 | 21 | @SuppressWarnings("unchecked") 22 | public List listFlights() { 23 | ObjectFactory factory = new ObjectFactory(); 24 | TListFlights tListFlights = factory.createTListFlights(); 25 | 26 | JAXBElement request = 27 | factory.createListFlightsRequest(tListFlights); 28 | 29 | JAXBElement response = 30 | (JAXBElement) webServiceTemplate 31 | .marshalSendAndReceive(request); 32 | 33 | return response.getValue().getFlightNumber(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /spring-ws-eureka/spring-ws-ticketagent-client/src/test/java/com/codenotfound/ws/SpringWsApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import java.math.BigInteger; 6 | import java.util.List; 7 | 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.boot.test.context.SpringBootTest; 12 | import org.springframework.test.context.junit4.SpringRunner; 13 | 14 | import com.codenotfound.ws.client.TicketAgentClient; 15 | 16 | @RunWith(SpringRunner.class) 17 | @SpringBootTest 18 | public class SpringWsApplicationTests { 19 | 20 | @Autowired 21 | private TicketAgentClient ticketAgentClient; 22 | 23 | @Test 24 | public void testListFlights() { 25 | List flights = ticketAgentClient.listFlights(); 26 | 27 | assertThat(flights.get(0)).isEqualTo(BigInteger.valueOf(101)); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /spring-ws-eureka/spring-ws-ticketagent-server/src/main/java/com/codenotfound/ws/SpringWsServerApplication.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 6 | 7 | @SpringBootApplication 8 | @EnableEurekaClient 9 | public class SpringWsServerApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(SpringWsServerApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /spring-ws-eureka/spring-ws-ticketagent-server/src/main/java/com/codenotfound/ws/endpoint/TicketAgentEndpoint.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.endpoint; 2 | 3 | import java.math.BigInteger; 4 | 5 | import javax.xml.bind.JAXBElement; 6 | 7 | import org.example.ticketagent.ObjectFactory; 8 | import org.example.ticketagent.TFlightsResponse; 9 | import org.example.ticketagent.TListFlights; 10 | import org.springframework.ws.server.endpoint.annotation.Endpoint; 11 | import org.springframework.ws.server.endpoint.annotation.PayloadRoot; 12 | import org.springframework.ws.server.endpoint.annotation.RequestPayload; 13 | import org.springframework.ws.server.endpoint.annotation.ResponsePayload; 14 | 15 | @Endpoint 16 | public class TicketAgentEndpoint { 17 | 18 | @PayloadRoot(namespace = "http://example.org/TicketAgent.xsd", 19 | localPart = "listFlightsRequest") 20 | @ResponsePayload 21 | public JAXBElement listFlights( 22 | @RequestPayload JAXBElement request) { 23 | 24 | ObjectFactory factory = new ObjectFactory(); 25 | TFlightsResponse tFlightsResponse = 26 | factory.createTFlightsResponse(); 27 | tFlightsResponse.getFlightNumber().add(BigInteger.valueOf(101)); 28 | 29 | return factory.createListFlightsResponse(tFlightsResponse); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /spring-ws-eureka/spring-ws-ticketagent-server/src/main/java/com/codenotfound/ws/endpoint/WebServiceConfig.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.endpoint; 2 | 3 | import org.springframework.boot.web.servlet.ServletRegistrationBean; 4 | import org.springframework.context.ApplicationContext; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.core.io.ClassPathResource; 8 | import org.springframework.ws.config.annotation.EnableWs; 9 | import org.springframework.ws.config.annotation.WsConfigurerAdapter; 10 | import org.springframework.ws.transport.http.MessageDispatcherServlet; 11 | import org.springframework.ws.wsdl.wsdl11.SimpleWsdl11Definition; 12 | import org.springframework.ws.wsdl.wsdl11.Wsdl11Definition; 13 | 14 | @EnableWs 15 | @Configuration 16 | public class WebServiceConfig extends WsConfigurerAdapter { 17 | 18 | @Bean 19 | public ServletRegistrationBean messageDispatcherServlet( 20 | ApplicationContext applicationContext) { 21 | MessageDispatcherServlet servlet = new MessageDispatcherServlet(); 22 | servlet.setApplicationContext(applicationContext); 23 | 24 | return new ServletRegistrationBean(servlet, "/codenotfound/ws/*"); 25 | } 26 | 27 | @Bean(name = "ticketagent") 28 | public Wsdl11Definition defaultWsdl11Definition() { 29 | SimpleWsdl11Definition wsdl11Definition = 30 | new SimpleWsdl11Definition(); 31 | wsdl11Definition 32 | .setWsdl(new ClassPathResource("/wsdl/ticketagent.wsdl")); 33 | 34 | return wsdl11Definition; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /spring-ws-eureka/spring-ws-ticketagent-server/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | info: 2 | app: 3 | name: Spring WS TicketAgent Server 4 | version: 0.0.1-SNAPSHOT 5 | 6 | server: 7 | port: 9090 8 | 9 | spring: 10 | application: 11 | name: ticketagent-service 12 | eureka: 13 | client: 14 | healthcheck: 15 | enabled: true 16 | service-url: 17 | default-zone: http://localhost:8761/eureka/ 18 | instance: 19 | status-page-url-path: /actuator/info 20 | health-check-url-path: /actuator/health 21 | preferIpAddress: true 22 | -------------------------------------------------------------------------------- /spring-ws-hello-world/README.md: -------------------------------------------------------------------------------- 1 | # spring-ws-hello-world 2 | 3 | [![Sonarcloud Status](https://sonarcloud.io/api/project_badges/measure?project=com.codenotfound%3Aspring-ws-hello-world&metric=alert_status)](https://sonarcloud.io/dashboard?id=com.codenotfound%3Aspring-ws-hello-world) 4 | 5 | A detailed step-by-step tutorial on how to implement a web service using Spring-WS and Spring Boot. 6 | 7 | [https://codenotfound.com/spring-ws-example.html](https://codenotfound.com/spring-ws-example.html) 8 | -------------------------------------------------------------------------------- /spring-ws-hello-world/src/main/java/com/codenotfound/SpringWsApplication.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringWsApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringWsApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spring-ws-hello-world/src/main/java/com/codenotfound/ws/client/ClientConfig.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.client; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.oxm.jaxb.Jaxb2Marshaller; 6 | import org.springframework.ws.client.core.WebServiceTemplate; 7 | 8 | @Configuration 9 | public class ClientConfig { 10 | 11 | @Bean 12 | Jaxb2Marshaller jaxb2Marshaller() { 13 | Jaxb2Marshaller jaxb2Marshaller = new Jaxb2Marshaller(); 14 | jaxb2Marshaller 15 | .setContextPath("com.codenotfound.types.helloworld"); 16 | 17 | return jaxb2Marshaller; 18 | } 19 | 20 | @Bean 21 | public WebServiceTemplate webServiceTemplate() { 22 | WebServiceTemplate webServiceTemplate = new WebServiceTemplate(); 23 | webServiceTemplate.setMarshaller(jaxb2Marshaller()); 24 | webServiceTemplate.setUnmarshaller(jaxb2Marshaller()); 25 | webServiceTemplate.setDefaultUri( 26 | "http://localhost:8080/codenotfound/ws/helloworld"); 27 | 28 | return webServiceTemplate; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /spring-ws-hello-world/src/main/java/com/codenotfound/ws/client/HelloWorldClient.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.client; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Component; 7 | import org.springframework.ws.client.core.WebServiceTemplate; 8 | import com.codenotfound.types.helloworld.Greeting; 9 | import com.codenotfound.types.helloworld.ObjectFactory; 10 | import com.codenotfound.types.helloworld.Person; 11 | 12 | @Component 13 | public class HelloWorldClient { 14 | 15 | private static final Logger LOGGER = 16 | LoggerFactory.getLogger(HelloWorldClient.class); 17 | 18 | @Autowired 19 | private WebServiceTemplate webServiceTemplate; 20 | 21 | public String sayHello(String firstName, String lastName) { 22 | ObjectFactory factory = new ObjectFactory(); 23 | Person person = factory.createPerson(); 24 | 25 | person.setFirstName(firstName); 26 | person.setLastName(lastName); 27 | 28 | LOGGER.info("Client sending person[firstName={},lastName={}]", 29 | person.getFirstName(), person.getLastName()); 30 | 31 | Greeting greeting = 32 | (Greeting) webServiceTemplate.marshalSendAndReceive(person); 33 | 34 | LOGGER.info("Client received greeting='{}'", 35 | greeting.getGreeting()); 36 | return greeting.getGreeting(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /spring-ws-hello-world/src/main/java/com/codenotfound/ws/endpoint/HelloWorldEndpoint.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.endpoint; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.ws.server.endpoint.annotation.Endpoint; 6 | import org.springframework.ws.server.endpoint.annotation.PayloadRoot; 7 | import org.springframework.ws.server.endpoint.annotation.RequestPayload; 8 | import org.springframework.ws.server.endpoint.annotation.ResponsePayload; 9 | import com.codenotfound.types.helloworld.Greeting; 10 | import com.codenotfound.types.helloworld.ObjectFactory; 11 | import com.codenotfound.types.helloworld.Person; 12 | 13 | @Endpoint 14 | public class HelloWorldEndpoint { 15 | 16 | private static final Logger LOGGER = 17 | LoggerFactory.getLogger(HelloWorldEndpoint.class); 18 | 19 | @PayloadRoot( 20 | namespace = "http://codenotfound.com/types/helloworld", 21 | localPart = "person") 22 | @ResponsePayload 23 | public Greeting sayHello(@RequestPayload Person request) { 24 | LOGGER.info("Endpoint received person[firstName={},lastName={}]", 25 | request.getFirstName(), request.getLastName()); 26 | 27 | String greeting = "Hello " + request.getFirstName() + " " 28 | + request.getLastName() + "!"; 29 | 30 | ObjectFactory factory = new ObjectFactory(); 31 | Greeting response = factory.createGreeting(); 32 | response.setGreeting(greeting); 33 | 34 | LOGGER.info("Endpoint sending greeting='{}'", 35 | response.getGreeting()); 36 | return response; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /spring-ws-hello-world/src/main/java/com/codenotfound/ws/endpoint/WebServiceConfig.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.endpoint; 2 | 3 | import javax.servlet.Servlet; 4 | import org.springframework.boot.web.servlet.ServletRegistrationBean; 5 | import org.springframework.context.ApplicationContext; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | import org.springframework.core.io.ClassPathResource; 9 | import org.springframework.ws.config.annotation.EnableWs; 10 | import org.springframework.ws.config.annotation.WsConfigurerAdapter; 11 | import org.springframework.ws.transport.http.MessageDispatcherServlet; 12 | import org.springframework.ws.wsdl.wsdl11.SimpleWsdl11Definition; 13 | import org.springframework.ws.wsdl.wsdl11.Wsdl11Definition; 14 | 15 | @EnableWs 16 | @Configuration 17 | public class WebServiceConfig extends WsConfigurerAdapter { 18 | 19 | @Bean 20 | public ServletRegistrationBean messageDispatcherServlet( 21 | ApplicationContext applicationContext) { 22 | MessageDispatcherServlet servlet = 23 | new MessageDispatcherServlet(); 24 | servlet.setApplicationContext(applicationContext); 25 | 26 | return new ServletRegistrationBean<>(servlet, 27 | "/codenotfound/ws/*"); 28 | } 29 | 30 | @Bean(name = "helloworld") 31 | public Wsdl11Definition defaultWsdl11Definition() { 32 | SimpleWsdl11Definition wsdl11Definition = 33 | new SimpleWsdl11Definition(); 34 | wsdl11Definition 35 | .setWsdl(new ClassPathResource("/wsdl/helloworld.wsdl")); 36 | 37 | return wsdl11Definition; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /spring-ws-hello-world/src/test/java/com/codenotfound/SpringWsApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | import org.junit.Test; 5 | import org.junit.runner.RunWith; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.boot.test.context.SpringBootTest; 8 | import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; 9 | import org.springframework.test.context.junit4.SpringRunner; 10 | import com.codenotfound.ws.client.HelloWorldClient; 11 | 12 | @RunWith(SpringRunner.class) 13 | @SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT) 14 | public class SpringWsApplicationTests { 15 | 16 | @Autowired 17 | private HelloWorldClient helloWorldClient; 18 | 19 | @Test 20 | public void testSayHello() { 21 | assertThat(helloWorldClient.sayHello("John", "Doe")) 22 | .isEqualTo("Hello John Doe!"); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /spring-ws-https-httpclient/README.md: -------------------------------------------------------------------------------- 1 | # spring-ws-https-httpclient 2 | 3 | [![Quality Gate](https://sonarcloud.io/api/badges/gate?key=com.codenotfound:spring-ws-https-httpclient)](https://sonarcloud.io/dashboard/index/com.codenotfound:spring-ws-https-httpclient) 4 | 5 | A detailed step-by-step tutorial on how to setup HTTPS on client and server side using Spring-WS and Spring Boot. 6 | 7 | [https://www.codenotfound.com/spring-ws-https-client-server-example.html](https://www.codenotfound.com/spring-ws-https-client-server-example.html) 8 | -------------------------------------------------------------------------------- /spring-ws-https-httpclient/src/main/java/com/codenotfound/ws/SpringWsApplication.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringWsApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringWsApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spring-ws-https-httpclient/src/main/java/com/codenotfound/ws/client/TicketAgentClient.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.client; 2 | 3 | import java.math.BigInteger; 4 | import java.util.List; 5 | 6 | import javax.xml.bind.JAXBElement; 7 | 8 | import org.example.ticketagent.ObjectFactory; 9 | import org.example.ticketagent.TFlightsResponse; 10 | import org.example.ticketagent.TListFlights; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.stereotype.Component; 13 | import org.springframework.ws.client.core.WebServiceTemplate; 14 | 15 | @Component 16 | public class TicketAgentClient { 17 | 18 | @Autowired 19 | private WebServiceTemplate webServiceTemplate; 20 | 21 | @SuppressWarnings("unchecked") 22 | public List listFlights() { 23 | ObjectFactory factory = new ObjectFactory(); 24 | TListFlights tListFlights = factory.createTListFlights(); 25 | 26 | JAXBElement request = factory.createListFlightsRequest(tListFlights); 27 | 28 | JAXBElement response = 29 | (JAXBElement) webServiceTemplate.marshalSendAndReceive(request); 30 | 31 | return response.getValue().getFlightNumber(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /spring-ws-https-httpclient/src/main/java/com/codenotfound/ws/endpoint/TicketAgentEndpoint.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.endpoint; 2 | 3 | import java.math.BigInteger; 4 | 5 | import javax.xml.bind.JAXBElement; 6 | 7 | import org.example.ticketagent.ObjectFactory; 8 | import org.example.ticketagent.TFlightsResponse; 9 | import org.example.ticketagent.TListFlights; 10 | import org.springframework.ws.server.endpoint.annotation.Endpoint; 11 | import org.springframework.ws.server.endpoint.annotation.PayloadRoot; 12 | import org.springframework.ws.server.endpoint.annotation.RequestPayload; 13 | import org.springframework.ws.server.endpoint.annotation.ResponsePayload; 14 | 15 | @Endpoint 16 | public class TicketAgentEndpoint { 17 | 18 | @PayloadRoot(namespace = "http://example.org/TicketAgent.xsd", localPart = "listFlightsRequest") 19 | @ResponsePayload 20 | public JAXBElement listFlights( 21 | @RequestPayload JAXBElement request) { 22 | ObjectFactory factory = new ObjectFactory(); 23 | TFlightsResponse tFlightsResponse = factory.createTFlightsResponse(); 24 | tFlightsResponse.getFlightNumber().add(BigInteger.valueOf(101)); 25 | 26 | return factory.createListFlightsResponse(tFlightsResponse); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /spring-ws-https-httpclient/src/main/java/com/codenotfound/ws/endpoint/WebServiceConfig.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.endpoint; 2 | 3 | import org.springframework.boot.web.servlet.ServletRegistrationBean; 4 | import org.springframework.context.ApplicationContext; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.core.io.ClassPathResource; 8 | import org.springframework.ws.config.annotation.EnableWs; 9 | import org.springframework.ws.config.annotation.WsConfigurerAdapter; 10 | import org.springframework.ws.transport.http.MessageDispatcherServlet; 11 | import org.springframework.ws.wsdl.wsdl11.SimpleWsdl11Definition; 12 | import org.springframework.ws.wsdl.wsdl11.Wsdl11Definition; 13 | 14 | @EnableWs 15 | @Configuration 16 | public class WebServiceConfig extends WsConfigurerAdapter { 17 | 18 | @Bean 19 | public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) { 20 | MessageDispatcherServlet servlet = new MessageDispatcherServlet(); 21 | servlet.setApplicationContext(applicationContext); 22 | 23 | return new ServletRegistrationBean(servlet, "/codenotfound/ws/*"); 24 | } 25 | 26 | @Bean(name = "ticketagent") 27 | public Wsdl11Definition defaultWsdl11Definition() { 28 | SimpleWsdl11Definition wsdl11Definition = new SimpleWsdl11Definition(); 29 | wsdl11Definition.setWsdl(new ClassPathResource("/wsdl/ticketagent.wsdl")); 30 | 31 | return wsdl11Definition; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /spring-ws-https-httpclient/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | client: 2 | default-uri: https://localhost:9443/codenotfound/ws/ticketagent 3 | ssl: 4 | trust-store: classpath:jks/client-truststore.jks 5 | trust-store-password: client-truststore-p455w0rd 6 | 7 | server: 8 | port: 9443 9 | ssl: 10 | key-store: classpath:jks/server-keystore.jks 11 | key-store-password: server-keystore-p455w0rd 12 | key-alias: server-keypair 13 | key-password: server-key-p455w0rd 14 | -------------------------------------------------------------------------------- /spring-ws-https-httpclient/src/main/resources/jks/client-truststore.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-not-found/spring-ws/5d37e6987868b44b0fd162f8a2c836bd553d8132/spring-ws-https-httpclient/src/main/resources/jks/client-truststore.jks -------------------------------------------------------------------------------- /spring-ws-https-httpclient/src/main/resources/jks/server-keystore.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-not-found/spring-ws/5d37e6987868b44b0fd162f8a2c836bd553d8132/spring-ws-https-httpclient/src/main/resources/jks/server-keystore.jks -------------------------------------------------------------------------------- /spring-ws-https-httpclient/src/main/resources/jks/server-public-key.cer: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-not-found/spring-ws/5d37e6987868b44b0fd162f8a2c836bd553d8132/spring-ws-https-httpclient/src/main/resources/jks/server-public-key.cer -------------------------------------------------------------------------------- /spring-ws-https-httpclient/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /spring-ws-https-httpclient/src/test/java/com/codenotfound/ws/SpringWsApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import java.math.BigInteger; 6 | import java.util.List; 7 | 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.boot.test.context.SpringBootTest; 12 | import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; 13 | import org.springframework.test.context.junit4.SpringRunner; 14 | 15 | import com.codenotfound.ws.client.TicketAgentClient; 16 | 17 | @RunWith(SpringRunner.class) 18 | @SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT) 19 | public class SpringWsApplicationTests { 20 | 21 | @Autowired 22 | private TicketAgentClient ticketAgentClient; 23 | 24 | @Test 25 | public void testListFlights() { 26 | List flights = ticketAgentClient.listFlights(); 27 | 28 | assertThat(flights.get(0)).isEqualTo(BigInteger.valueOf(101)); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /spring-ws-https/README.md: -------------------------------------------------------------------------------- 1 | # spring-ws-https 2 | 3 | [![Quality Gate](https://sonarcloud.io/api/badges/gate?key=com.codenotfound:spring-ws-https)](https://sonarcloud.io/dashboard/index/com.codenotfound:spring-ws-https) 4 | 5 | A sample project on how to setup HTTPS on client and server side using Spring-WS and Spring Boot without using the Apache HttpClient. 6 | 7 | [https://www.codenotfound.com/spring-ws/](https://www.codenotfound.com/spring-ws/) 8 | -------------------------------------------------------------------------------- /spring-ws-https/src/main/java/com/codenotfound/ws/SpringWsApplication.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringWsApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringWsApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spring-ws-https/src/main/java/com/codenotfound/ws/client/TicketAgentClient.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.client; 2 | 3 | import java.math.BigInteger; 4 | import java.util.List; 5 | 6 | import javax.xml.bind.JAXBElement; 7 | 8 | import org.example.ticketagent.ObjectFactory; 9 | import org.example.ticketagent.TFlightsResponse; 10 | import org.example.ticketagent.TListFlights; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.stereotype.Component; 13 | import org.springframework.ws.client.core.WebServiceTemplate; 14 | 15 | @Component 16 | public class TicketAgentClient { 17 | 18 | @Autowired 19 | private WebServiceTemplate webServiceTemplate; 20 | 21 | @SuppressWarnings("unchecked") 22 | public List listFlights() { 23 | ObjectFactory factory = new ObjectFactory(); 24 | TListFlights tListFlights = factory.createTListFlights(); 25 | 26 | JAXBElement request = factory.createListFlightsRequest(tListFlights); 27 | 28 | JAXBElement response = 29 | (JAXBElement) webServiceTemplate.marshalSendAndReceive(request); 30 | 31 | return response.getValue().getFlightNumber(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /spring-ws-https/src/main/java/com/codenotfound/ws/endpoint/TicketAgentEndpoint.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.endpoint; 2 | 3 | import java.math.BigInteger; 4 | 5 | import javax.xml.bind.JAXBElement; 6 | 7 | import org.example.ticketagent.ObjectFactory; 8 | import org.example.ticketagent.TFlightsResponse; 9 | import org.example.ticketagent.TListFlights; 10 | import org.springframework.ws.server.endpoint.annotation.Endpoint; 11 | import org.springframework.ws.server.endpoint.annotation.PayloadRoot; 12 | import org.springframework.ws.server.endpoint.annotation.RequestPayload; 13 | import org.springframework.ws.server.endpoint.annotation.ResponsePayload; 14 | 15 | @Endpoint 16 | public class TicketAgentEndpoint { 17 | 18 | @PayloadRoot(namespace = "http://example.org/TicketAgent.xsd", localPart = "listFlightsRequest") 19 | @ResponsePayload 20 | public JAXBElement listFlights( 21 | @RequestPayload JAXBElement request) { 22 | ObjectFactory factory = new ObjectFactory(); 23 | TFlightsResponse tFlightsResponse = factory.createTFlightsResponse(); 24 | tFlightsResponse.getFlightNumber().add(BigInteger.valueOf(101)); 25 | 26 | return factory.createListFlightsResponse(tFlightsResponse); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /spring-ws-https/src/main/java/com/codenotfound/ws/endpoint/WebServiceConfig.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.endpoint; 2 | 3 | import org.springframework.boot.web.servlet.ServletRegistrationBean; 4 | import org.springframework.context.ApplicationContext; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.core.io.ClassPathResource; 8 | import org.springframework.ws.config.annotation.EnableWs; 9 | import org.springframework.ws.config.annotation.WsConfigurerAdapter; 10 | import org.springframework.ws.transport.http.MessageDispatcherServlet; 11 | import org.springframework.ws.wsdl.wsdl11.SimpleWsdl11Definition; 12 | import org.springframework.ws.wsdl.wsdl11.Wsdl11Definition; 13 | 14 | @EnableWs 15 | @Configuration 16 | public class WebServiceConfig extends WsConfigurerAdapter { 17 | 18 | @Bean 19 | public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) { 20 | MessageDispatcherServlet servlet = new MessageDispatcherServlet(); 21 | servlet.setApplicationContext(applicationContext); 22 | 23 | return new ServletRegistrationBean(servlet, "/codenotfound/ws/*"); 24 | } 25 | 26 | @Bean(name = "ticketagent") 27 | public Wsdl11Definition defaultWsdl11Definition() { 28 | SimpleWsdl11Definition wsdl11Definition = new SimpleWsdl11Definition(); 29 | wsdl11Definition.setWsdl(new ClassPathResource("/wsdl/ticketagent.wsdl")); 30 | 31 | return wsdl11Definition; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /spring-ws-https/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | client: 2 | default-uri: https://localhost:9443/codenotfound/ws/ticketagent 3 | ssl: 4 | trust-store: classpath:jks/client-truststore.jks 5 | trust-store-password: client-truststore-p455w0rd 6 | 7 | server: 8 | port: 9443 9 | ssl: 10 | key-store: classpath:jks/server-keystore.jks 11 | key-store-password: server-keystore-p455w0rd 12 | key-alias: server-keypair 13 | key-password: server-key-p455w0rd 14 | -------------------------------------------------------------------------------- /spring-ws-https/src/main/resources/jks/client-truststore.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-not-found/spring-ws/5d37e6987868b44b0fd162f8a2c836bd553d8132/spring-ws-https/src/main/resources/jks/client-truststore.jks -------------------------------------------------------------------------------- /spring-ws-https/src/main/resources/jks/server-keystore.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-not-found/spring-ws/5d37e6987868b44b0fd162f8a2c836bd553d8132/spring-ws-https/src/main/resources/jks/server-keystore.jks -------------------------------------------------------------------------------- /spring-ws-https/src/main/resources/jks/server-public-key.cer: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-not-found/spring-ws/5d37e6987868b44b0fd162f8a2c836bd553d8132/spring-ws-https/src/main/resources/jks/server-public-key.cer -------------------------------------------------------------------------------- /spring-ws-https/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /spring-ws-https/src/test/java/com/codenotfound/ws/SpringWsApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import java.math.BigInteger; 6 | import java.util.List; 7 | 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.boot.test.context.SpringBootTest; 12 | import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; 13 | import org.springframework.test.context.junit4.SpringRunner; 14 | 15 | import com.codenotfound.ws.client.TicketAgentClient; 16 | 17 | @RunWith(SpringRunner.class) 18 | @SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT) 19 | public class SpringWsApplicationTests { 20 | 21 | @Autowired 22 | private TicketAgentClient ticketAgentClient; 23 | 24 | @Test 25 | public void testListFlights() { 26 | List flights = ticketAgentClient.listFlights(); 27 | 28 | assertThat(flights.get(0)).isEqualTo(BigInteger.valueOf(101)); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /spring-ws-integration-test/src/main/java/com/codenotfound/order/OrderApplication.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.order; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class OrderApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(OrderApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spring-ws-integration-test/src/main/java/com/codenotfound/order/client/ClientConfig.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.order.client; 2 | 3 | import org.springframework.beans.factory.annotation.Value; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.oxm.jaxb.Jaxb2Marshaller; 7 | import org.springframework.ws.client.core.WebServiceTemplate; 8 | 9 | @Configuration 10 | public class ClientConfig { 11 | 12 | @Value("${order.address}") 13 | private String orderAddress; 14 | 15 | @Bean 16 | Jaxb2Marshaller jaxb2Marshaller() { 17 | 18 | Jaxb2Marshaller jaxb2Marshaller = new Jaxb2Marshaller(); 19 | jaxb2Marshaller.setContextPath("com.codenotfound.types.order"); 20 | return jaxb2Marshaller; 21 | } 22 | 23 | @Bean 24 | public WebServiceTemplate webServiceTemplate() { 25 | 26 | WebServiceTemplate webServiceTemplate = new WebServiceTemplate(); 27 | webServiceTemplate.setMarshaller(jaxb2Marshaller()); 28 | webServiceTemplate.setUnmarshaller(jaxb2Marshaller()); 29 | webServiceTemplate.setDefaultUri(orderAddress); 30 | 31 | return webServiceTemplate; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /spring-ws-integration-test/src/main/java/com/codenotfound/order/client/CreateOrderClient.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.order.client; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Component; 7 | import org.springframework.ws.client.core.WebServiceTemplate; 8 | 9 | import com.codenotfound.types.order.CustomerType; 10 | import com.codenotfound.types.order.LineItemsType; 11 | import com.codenotfound.types.order.ObjectFactory; 12 | import com.codenotfound.types.order.Order; 13 | import com.codenotfound.types.order.OrderConfirmation; 14 | 15 | @Component 16 | public class CreateOrderClient { 17 | 18 | private static final Logger LOGGER = LoggerFactory 19 | .getLogger(CreateOrderClient.class); 20 | 21 | @Autowired 22 | private WebServiceTemplate webServiceTemplate; 23 | 24 | public OrderConfirmation createOrder(CustomerType customer, 25 | LineItemsType lineItems) { 26 | 27 | ObjectFactory factory = new ObjectFactory(); 28 | Order order = factory.createOrder(); 29 | 30 | order.setCustomer(customer); 31 | order.setLineItems(lineItems); 32 | 33 | LOGGER.info( 34 | "Client sending order for Customer[firstName={},lastName={}]", 35 | customer.getFirstName(), customer.getLastName()); 36 | 37 | OrderConfirmation orderConfirmation = (OrderConfirmation) webServiceTemplate 38 | .marshalSendAndReceive(order); 39 | 40 | LOGGER.info("Client received orderConfirmationId='{}'", 41 | orderConfirmation.getConfirmationId()); 42 | return orderConfirmation; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /spring-ws-integration-test/src/main/java/com/codenotfound/order/endpoint/CreateOrderEndpoint.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.order.endpoint; 2 | 3 | import java.util.UUID; 4 | 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | import org.springframework.ws.server.endpoint.annotation.Endpoint; 8 | import org.springframework.ws.server.endpoint.annotation.PayloadRoot; 9 | import org.springframework.ws.server.endpoint.annotation.RequestPayload; 10 | import org.springframework.ws.server.endpoint.annotation.ResponsePayload; 11 | 12 | import com.codenotfound.types.order.ObjectFactory; 13 | import com.codenotfound.types.order.Order; 14 | import com.codenotfound.types.order.OrderConfirmation; 15 | 16 | @Endpoint 17 | public class CreateOrderEndpoint { 18 | 19 | private static final Logger LOGGER = LoggerFactory 20 | .getLogger(CreateOrderEndpoint.class); 21 | 22 | private static final String NAMESPACE_URI = "http://codenotfound.com/types/order"; 23 | 24 | @PayloadRoot(namespace = NAMESPACE_URI, localPart = "order") 25 | @ResponsePayload 26 | public OrderConfirmation createOrder(@RequestPayload Order request) { 27 | LOGGER.info( 28 | "Endpoint received order for Customer[firstName={},lastName={}]", 29 | request.getCustomer().getFirstName(), 30 | request.getCustomer().getLastName()); 31 | 32 | // process order 33 | 34 | ObjectFactory factory = new ObjectFactory(); 35 | OrderConfirmation response = factory.createOrderConfirmation(); 36 | response.setConfirmationId(UUID.randomUUID().toString()); 37 | 38 | LOGGER.info("Endpoint sending orderConfirmationId='{}'", 39 | response.getConfirmationId()); 40 | return response; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /spring-ws-integration-test/src/main/java/com/codenotfound/order/endpoint/WebServiceConfig.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.order.endpoint; 2 | 3 | import org.springframework.boot.web.servlet.ServletRegistrationBean; 4 | import org.springframework.context.ApplicationContext; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.core.io.ClassPathResource; 8 | import org.springframework.ws.config.annotation.EnableWs; 9 | import org.springframework.ws.config.annotation.WsConfigurerAdapter; 10 | import org.springframework.ws.transport.http.MessageDispatcherServlet; 11 | import org.springframework.ws.wsdl.wsdl11.SimpleWsdl11Definition; 12 | import org.springframework.ws.wsdl.wsdl11.Wsdl11Definition; 13 | 14 | @EnableWs 15 | @Configuration 16 | public class WebServiceConfig extends WsConfigurerAdapter { 17 | 18 | @Bean 19 | public ServletRegistrationBean messageDispatcherServlet( 20 | ApplicationContext applicationContext) { 21 | 22 | MessageDispatcherServlet servlet = new MessageDispatcherServlet(); 23 | servlet.setApplicationContext(applicationContext); 24 | 25 | return new ServletRegistrationBean(servlet, 26 | "/codenotfound/ws/*"); 27 | } 28 | 29 | @Bean(name = "order") 30 | public Wsdl11Definition defaultWsdl11Definition() { 31 | SimpleWsdl11Definition wsdl11Definition = new SimpleWsdl11Definition(); 32 | wsdl11Definition.setWsdl( 33 | new ClassPathResource("/wsdl/order.wsdl")); 34 | 35 | return wsdl11Definition; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /spring-ws-integration-test/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | # Address of the Order service 2 | order.address=http://localhost:9090/codenotfound/ws/order 3 | 4 | # Server HTTP port 5 | server.port=9090 6 | 7 | # Log file name. For instance `myapp.log` 8 | logging.file=spring-ws-test.log 9 | # Log levels severity mapping. For instance `logging.level.org.springframework=DEBUG` 10 | logging.level.org.springframework=INFO 11 | logging.level.com.codenotfound.order=INFO -------------------------------------------------------------------------------- /spring-ws-integration-test/src/test/java/com/codenotfound/order/client/CreateOrderClientIT.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.order.client; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import java.math.BigInteger; 6 | 7 | import org.junit.Before; 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.boot.test.context.SpringBootTest; 12 | import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; 13 | import org.springframework.test.context.junit4.SpringRunner; 14 | 15 | import com.codenotfound.types.order.CustomerType; 16 | import com.codenotfound.types.order.LineItemType; 17 | import com.codenotfound.types.order.LineItemsType; 18 | import com.codenotfound.types.order.ObjectFactory; 19 | import com.codenotfound.types.order.ProductType; 20 | 21 | @RunWith(SpringRunner.class) 22 | @SpringBootTest(webEnvironment = WebEnvironment.NONE) 23 | public class CreateOrderClientIT { 24 | 25 | @Autowired 26 | private CreateOrderClient createOrderClient; 27 | 28 | private CustomerType customer; 29 | private LineItemsType lineItems; 30 | 31 | @Before 32 | public void setUp() throws Exception { 33 | ObjectFactory factory = new ObjectFactory(); 34 | 35 | customer = factory.createCustomerType(); 36 | customer.setFirstName("John"); 37 | customer.setLastName("Doe"); 38 | 39 | ProductType product1 = factory.createProductType(); 40 | product1.setId("1"); 41 | 42 | LineItemType lineItem1 = factory.createLineItemType(); 43 | lineItem1.setProduct(product1); 44 | lineItem1.setQuantity(BigInteger.valueOf(2)); 45 | 46 | lineItems = factory.createLineItemsType(); 47 | lineItems.getLineItem().add(lineItem1); 48 | } 49 | 50 | @Test 51 | public void testCreateOrder() { 52 | assertThat(createOrderClient.createOrder(customer, lineItems) 53 | .getConfirmationId()).isEqualTo("gero et"); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /spring-ws-integration-test/src/test/java/com/codenotfound/order/endpoint/CreateOrderEndpointTest.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.order.endpoint; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import java.math.BigInteger; 6 | 7 | import org.junit.Before; 8 | import org.junit.Test; 9 | 10 | import com.codenotfound.order.endpoint.CreateOrderEndpoint; 11 | import com.codenotfound.types.order.CustomerType; 12 | import com.codenotfound.types.order.LineItemType; 13 | import com.codenotfound.types.order.LineItemsType; 14 | import com.codenotfound.types.order.ObjectFactory; 15 | import com.codenotfound.types.order.Order; 16 | import com.codenotfound.types.order.ProductType; 17 | 18 | public class CreateOrderEndpointTest { 19 | 20 | private CreateOrderEndpoint createOrderEndpoint = new CreateOrderEndpoint(); 21 | 22 | private Order order; 23 | 24 | @Before 25 | public void setUp() throws Exception { 26 | ObjectFactory factory = new ObjectFactory(); 27 | 28 | CustomerType customer = factory.createCustomerType(); 29 | customer.setFirstName("John"); 30 | customer.setLastName("Doe"); 31 | 32 | ProductType product1 = factory.createProductType(); 33 | product1.setId("1"); 34 | product1.setName("batman action figure"); 35 | 36 | LineItemType lineItem1 = factory.createLineItemType(); 37 | lineItem1.setProduct(product1); 38 | lineItem1.setQuantity(BigInteger.valueOf(1)); 39 | 40 | LineItemsType lineItems = factory.createLineItemsType(); 41 | lineItems.getLineItem().add(lineItem1); 42 | 43 | order = factory.createOrder(); 44 | order.setCustomer(customer); 45 | order.setLineItems(lineItems); 46 | } 47 | 48 | @Test 49 | public void testCreateOrder() { 50 | assertThat(createOrderEndpoint.createOrder(order) 51 | .getConfirmationId()).isNotBlank(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /spring-ws-integration-test/src/test/resources/application.properties: -------------------------------------------------------------------------------- 1 | # Address of the Order service 2 | order.address=http://localhost:9070/mockOrder_SoapBinding 3 | 4 | # server HTTP port 5 | server.port=9080 6 | 7 | # Log file name. For instance `myapp.log` 8 | logging.file=spring-ws-test-test.log 9 | # Log levels severity mapping. For instance `logging.level.org.springframework=DEBUG` 10 | logging.level.org.springframework=INFO 11 | logging.level.com.codenotfound.order=DEBUG -------------------------------------------------------------------------------- /spring-ws-log-http-headers/README.md: -------------------------------------------------------------------------------- 1 | # spring-ws-log-http-headers 2 | 3 | [![Quality Gate](https://sonarcloud.io/api/badges/gate?key=com.codenotfound:spring-ws-log-http-headers)](https://sonarcloud.io/dashboard/index/com.codenotfound:spring-ws-log-http-headers) 4 | 5 | A detailed step-by-step tutorial on how to log the client and server HTTP headers using Spring-WS and Spring Boot. 6 | 7 | [https://www.codenotfound.com/spring-ws-log-client-server-http-headers.html](https://www.codenotfound.com/spring-ws-log-client-server-http-headers.html) 8 | -------------------------------------------------------------------------------- /spring-ws-log-http-headers/src/main/java/com/codenotfound/ws/SpringWsApplication.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringWsApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringWsApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spring-ws-log-http-headers/src/main/java/com/codenotfound/ws/client/ClientConfig.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.client; 2 | 3 | import org.springframework.beans.factory.annotation.Value; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.oxm.jaxb.Jaxb2Marshaller; 7 | import org.springframework.ws.client.core.WebServiceTemplate; 8 | import org.springframework.ws.client.support.interceptor.ClientInterceptor; 9 | 10 | import com.codenotfound.ws.interceptor.LogHttpHeaderClientInterceptor; 11 | 12 | @Configuration 13 | public class ClientConfig { 14 | 15 | @Value("${client.default-uri}") 16 | private String defaultUri; 17 | 18 | @Bean 19 | Jaxb2Marshaller jaxb2Marshaller() { 20 | Jaxb2Marshaller jaxb2Marshaller = new Jaxb2Marshaller(); 21 | jaxb2Marshaller.setContextPath("org.example.ticketagent"); 22 | 23 | return jaxb2Marshaller; 24 | } 25 | 26 | @Bean 27 | public WebServiceTemplate webServiceTemplate() { 28 | WebServiceTemplate webServiceTemplate = new WebServiceTemplate(); 29 | webServiceTemplate.setMarshaller(jaxb2Marshaller()); 30 | webServiceTemplate.setUnmarshaller(jaxb2Marshaller()); 31 | webServiceTemplate.setDefaultUri(defaultUri); 32 | 33 | // register the LogHttpHeaderClientInterceptor 34 | ClientInterceptor[] interceptors = 35 | new ClientInterceptor[] {new LogHttpHeaderClientInterceptor()}; 36 | webServiceTemplate.setInterceptors(interceptors); 37 | 38 | return webServiceTemplate; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /spring-ws-log-http-headers/src/main/java/com/codenotfound/ws/client/TicketAgentClient.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.client; 2 | 3 | import java.math.BigInteger; 4 | import java.util.List; 5 | 6 | import javax.xml.bind.JAXBElement; 7 | 8 | import org.example.ticketagent.ObjectFactory; 9 | import org.example.ticketagent.TFlightsResponse; 10 | import org.example.ticketagent.TListFlights; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.stereotype.Component; 13 | import org.springframework.ws.client.core.WebServiceTemplate; 14 | 15 | @Component 16 | public class TicketAgentClient { 17 | 18 | @Autowired 19 | private WebServiceTemplate webServiceTemplate; 20 | 21 | @SuppressWarnings("unchecked") 22 | public List listFlights() { 23 | ObjectFactory factory = new ObjectFactory(); 24 | TListFlights tListFlights = factory.createTListFlights(); 25 | 26 | JAXBElement request = factory.createListFlightsRequest(tListFlights); 27 | 28 | JAXBElement response = 29 | (JAXBElement) webServiceTemplate.marshalSendAndReceive(request); 30 | 31 | return response.getValue().getFlightNumber(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /spring-ws-log-http-headers/src/main/java/com/codenotfound/ws/endpoint/TicketAgentEndpoint.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.endpoint; 2 | 3 | import java.math.BigInteger; 4 | 5 | import javax.xml.bind.JAXBElement; 6 | 7 | import org.example.ticketagent.ObjectFactory; 8 | import org.example.ticketagent.TFlightsResponse; 9 | import org.example.ticketagent.TListFlights; 10 | import org.springframework.ws.server.endpoint.annotation.Endpoint; 11 | import org.springframework.ws.server.endpoint.annotation.PayloadRoot; 12 | import org.springframework.ws.server.endpoint.annotation.RequestPayload; 13 | import org.springframework.ws.server.endpoint.annotation.ResponsePayload; 14 | 15 | @Endpoint 16 | public class TicketAgentEndpoint { 17 | 18 | @PayloadRoot(namespace = "http://example.org/TicketAgent.xsd", localPart = "listFlightsRequest") 19 | @ResponsePayload 20 | public JAXBElement listFlights( 21 | @RequestPayload JAXBElement request) { 22 | ObjectFactory factory = new ObjectFactory(); 23 | TFlightsResponse tFlightsResponse = factory.createTFlightsResponse(); 24 | tFlightsResponse.getFlightNumber().add(BigInteger.valueOf(101)); 25 | 26 | return factory.createListFlightsResponse(tFlightsResponse); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /spring-ws-log-http-headers/src/main/java/com/codenotfound/ws/endpoint/WebServiceConfig.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.endpoint; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.boot.web.servlet.ServletRegistrationBean; 6 | import org.springframework.context.ApplicationContext; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.context.annotation.Configuration; 9 | import org.springframework.core.io.ClassPathResource; 10 | import org.springframework.ws.config.annotation.EnableWs; 11 | import org.springframework.ws.config.annotation.WsConfigurerAdapter; 12 | import org.springframework.ws.server.EndpointInterceptor; 13 | import org.springframework.ws.transport.http.MessageDispatcherServlet; 14 | import org.springframework.ws.wsdl.wsdl11.SimpleWsdl11Definition; 15 | import org.springframework.ws.wsdl.wsdl11.Wsdl11Definition; 16 | 17 | import com.codenotfound.ws.interceptor.LogHttpHeaderEndpointInterceptor; 18 | 19 | @EnableWs 20 | @Configuration 21 | public class WebServiceConfig extends WsConfigurerAdapter { 22 | 23 | @Bean 24 | public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) { 25 | MessageDispatcherServlet servlet = new MessageDispatcherServlet(); 26 | servlet.setApplicationContext(applicationContext); 27 | 28 | return new ServletRegistrationBean(servlet, "/codenotfound/ws/*"); 29 | } 30 | 31 | @Bean(name = "ticketagent") 32 | public Wsdl11Definition defaultWsdl11Definition() { 33 | SimpleWsdl11Definition wsdl11Definition = new SimpleWsdl11Definition(); 34 | wsdl11Definition.setWsdl(new ClassPathResource("/wsdl/ticketagent.wsdl")); 35 | 36 | return wsdl11Definition; 37 | } 38 | 39 | @Override 40 | public void addInterceptors(List interceptors) { 41 | // register the LogHttpHeaderEndpointInterceptor 42 | interceptors.add(new LogHttpHeaderEndpointInterceptor()); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /spring-ws-log-http-headers/src/main/java/com/codenotfound/ws/interceptor/ByteArrayTransportOutputStream.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.interceptor; 2 | 3 | import java.io.ByteArrayOutputStream; 4 | import java.io.IOException; 5 | import java.io.OutputStream; 6 | 7 | import org.springframework.ws.transport.TransportOutputStream; 8 | 9 | public class ByteArrayTransportOutputStream extends TransportOutputStream { 10 | 11 | private static final String NEW_LINE = System.getProperty("line.separator"); 12 | 13 | private ByteArrayOutputStream byteArrayOutputStream; 14 | 15 | @Override 16 | public void addHeader(String name, String value) throws IOException { 17 | createOutputStream(); 18 | String header = name + ": " + value + NEW_LINE; 19 | byteArrayOutputStream.write(header.getBytes()); 20 | } 21 | 22 | @Override 23 | protected OutputStream createOutputStream() throws IOException { 24 | if (byteArrayOutputStream == null) { 25 | byteArrayOutputStream = new ByteArrayOutputStream(); 26 | } 27 | return byteArrayOutputStream; 28 | } 29 | 30 | public byte[] toByteArray() { 31 | return byteArrayOutputStream.toByteArray(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /spring-ws-log-http-headers/src/main/java/com/codenotfound/ws/interceptor/HttpLoggingUtils.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.interceptor; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.ws.WebServiceMessage; 6 | import org.springframework.xml.transform.TransformerObjectSupport; 7 | 8 | public class HttpLoggingUtils extends TransformerObjectSupport { 9 | 10 | private static final Logger LOGGER = LoggerFactory.getLogger(HttpLoggingUtils.class); 11 | 12 | private static final String NEW_LINE = System.getProperty("line.separator"); 13 | 14 | private HttpLoggingUtils() {} 15 | 16 | public static void logMessage(String id, WebServiceMessage webServiceMessage) { 17 | try { 18 | ByteArrayTransportOutputStream byteArrayTransportOutputStream = 19 | new ByteArrayTransportOutputStream(); 20 | webServiceMessage.writeTo(byteArrayTransportOutputStream); 21 | 22 | String httpMessage = new String(byteArrayTransportOutputStream.toByteArray()); 23 | LOGGER.info(NEW_LINE + "----------------------------" + NEW_LINE + id + NEW_LINE 24 | + "----------------------------" + NEW_LINE + httpMessage + NEW_LINE); 25 | } catch (Exception e) { 26 | LOGGER.error("Unable to log HTTP message.", e); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /spring-ws-log-http-headers/src/main/java/com/codenotfound/ws/interceptor/LogHttpHeaderClientInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.interceptor; 2 | 3 | import org.springframework.ws.client.WebServiceClientException; 4 | import org.springframework.ws.client.support.interceptor.ClientInterceptor; 5 | import org.springframework.ws.context.MessageContext; 6 | 7 | public class LogHttpHeaderClientInterceptor implements ClientInterceptor { 8 | 9 | @Override 10 | public void afterCompletion(MessageContext arg0, Exception arg1) 11 | throws WebServiceClientException { 12 | // No-op 13 | } 14 | 15 | @Override 16 | public boolean handleFault(MessageContext messageContext) throws WebServiceClientException { 17 | // No-op 18 | return true; 19 | } 20 | 21 | @Override 22 | public boolean handleRequest(MessageContext messageContext) throws WebServiceClientException { 23 | HttpLoggingUtils.logMessage("Client Request Message", messageContext.getRequest()); 24 | 25 | return true; 26 | } 27 | 28 | @Override 29 | public boolean handleResponse(MessageContext messageContext) throws WebServiceClientException { 30 | HttpLoggingUtils.logMessage("Client Response Message", messageContext.getResponse()); 31 | 32 | return true; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /spring-ws-log-http-headers/src/main/java/com/codenotfound/ws/interceptor/LogHttpHeaderEndpointInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.interceptor; 2 | 3 | import org.springframework.ws.context.MessageContext; 4 | import org.springframework.ws.server.EndpointInterceptor; 5 | 6 | public class LogHttpHeaderEndpointInterceptor implements EndpointInterceptor { 7 | 8 | @Override 9 | public void afterCompletion(MessageContext arg0, Object arg1, Exception arg2) throws Exception { 10 | // No-op 11 | } 12 | 13 | @Override 14 | public boolean handleFault(MessageContext messageContext, Object arg1) throws Exception { 15 | // No-op 16 | return true; 17 | } 18 | 19 | @Override 20 | public boolean handleRequest(MessageContext messageContext, Object arg1) throws Exception { 21 | HttpLoggingUtils.logMessage("Server Request Message", messageContext.getRequest()); 22 | 23 | return true; 24 | } 25 | 26 | @Override 27 | public boolean handleResponse(MessageContext messageContext, Object arg1) throws Exception { 28 | HttpLoggingUtils.logMessage("Server Response Message", messageContext.getResponse()); 29 | 30 | return true; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /spring-ws-log-http-headers/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | client: 2 | default-uri: http://localhost:9090/codenotfound/ws/helloworld 3 | 4 | server: 5 | port: 9090 6 | -------------------------------------------------------------------------------- /spring-ws-log-http-headers/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /spring-ws-log-http-headers/src/test/java/com/codenotfound/ws/SpringWsApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import java.math.BigInteger; 6 | import java.util.List; 7 | 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.boot.test.context.SpringBootTest; 12 | import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; 13 | import org.springframework.test.context.junit4.SpringRunner; 14 | 15 | import com.codenotfound.ws.client.TicketAgentClient; 16 | 17 | @RunWith(SpringRunner.class) 18 | @SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT) 19 | public class SpringWsApplicationTests { 20 | 21 | @Autowired 22 | private TicketAgentClient ticketAgentClient; 23 | 24 | @Test 25 | public void testListFlights() { 26 | List flights = ticketAgentClient.listFlights(); 27 | 28 | assertThat(flights.get(0)).isEqualTo(BigInteger.valueOf(101)); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /spring-ws-mutual-authentication-httpclient/README.md: -------------------------------------------------------------------------------- 1 | # spring-ws-mutual-authentication-httpclient 2 | 3 | [![Quality Gate](https://sonarcloud.io/api/badges/gate?key=com.codenotfound:spring-ws-mutual-authentication-httpclient)](https://sonarcloud.io/dashboard/index/com.codenotfound:spring-ws-mutual-authentication-httpclient) 4 | 5 | A detailed step-by-step tutorial on how setup mutual certificate authentication using Spring-WS and Spring Boot. 6 | 7 | [https://www.codenotfound.com/spring-ws-mutual-authentication-example.html](https://www.codenotfound.com/spring-ws-mutual-authentication-example.html) 8 | -------------------------------------------------------------------------------- /spring-ws-mutual-authentication-httpclient/src/main/java/com/codenotfound/ws/SpringWsApplication.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringWsApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringWsApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spring-ws-mutual-authentication-httpclient/src/main/java/com/codenotfound/ws/client/TicketAgentClient.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.client; 2 | 3 | import java.math.BigInteger; 4 | import java.util.List; 5 | 6 | import javax.xml.bind.JAXBElement; 7 | 8 | import org.example.ticketagent.ObjectFactory; 9 | import org.example.ticketagent.TFlightsResponse; 10 | import org.example.ticketagent.TListFlights; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.stereotype.Component; 13 | import org.springframework.ws.client.core.WebServiceTemplate; 14 | 15 | @Component 16 | public class TicketAgentClient { 17 | 18 | @Autowired 19 | private WebServiceTemplate webServiceTemplate; 20 | 21 | @SuppressWarnings("unchecked") 22 | public List listFlights() { 23 | 24 | ObjectFactory factory = new ObjectFactory(); 25 | TListFlights tListFlights = factory.createTListFlights(); 26 | 27 | JAXBElement request = factory.createListFlightsRequest(tListFlights); 28 | 29 | JAXBElement response = 30 | (JAXBElement) webServiceTemplate.marshalSendAndReceive(request); 31 | 32 | return response.getValue().getFlightNumber(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /spring-ws-mutual-authentication-httpclient/src/main/java/com/codenotfound/ws/endpoint/TicketAgentEndpoint.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.endpoint; 2 | 3 | import java.math.BigInteger; 4 | 5 | import javax.xml.bind.JAXBElement; 6 | 7 | import org.example.ticketagent.ObjectFactory; 8 | import org.example.ticketagent.TFlightsResponse; 9 | import org.example.ticketagent.TListFlights; 10 | import org.springframework.ws.server.endpoint.annotation.Endpoint; 11 | import org.springframework.ws.server.endpoint.annotation.PayloadRoot; 12 | import org.springframework.ws.server.endpoint.annotation.RequestPayload; 13 | import org.springframework.ws.server.endpoint.annotation.ResponsePayload; 14 | 15 | @Endpoint 16 | public class TicketAgentEndpoint { 17 | 18 | @PayloadRoot(namespace = "http://example.org/TicketAgent.xsd", localPart = "listFlightsRequest") 19 | @ResponsePayload 20 | public JAXBElement listFlights( 21 | @RequestPayload JAXBElement request) { 22 | 23 | ObjectFactory factory = new ObjectFactory(); 24 | TFlightsResponse tFlightsResponse = factory.createTFlightsResponse(); 25 | tFlightsResponse.getFlightNumber().add(BigInteger.valueOf(101)); 26 | 27 | return factory.createListFlightsResponse(tFlightsResponse); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /spring-ws-mutual-authentication-httpclient/src/main/java/com/codenotfound/ws/endpoint/WebServiceConfig.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.endpoint; 2 | 3 | import org.springframework.boot.web.servlet.ServletRegistrationBean; 4 | import org.springframework.context.ApplicationContext; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.core.io.ClassPathResource; 8 | import org.springframework.ws.config.annotation.EnableWs; 9 | import org.springframework.ws.config.annotation.WsConfigurerAdapter; 10 | import org.springframework.ws.transport.http.MessageDispatcherServlet; 11 | import org.springframework.ws.wsdl.wsdl11.SimpleWsdl11Definition; 12 | import org.springframework.ws.wsdl.wsdl11.Wsdl11Definition; 13 | 14 | @EnableWs 15 | @Configuration 16 | public class WebServiceConfig extends WsConfigurerAdapter { 17 | 18 | @Bean 19 | public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) { 20 | 21 | MessageDispatcherServlet servlet = new MessageDispatcherServlet(); 22 | servlet.setApplicationContext(applicationContext); 23 | 24 | return new ServletRegistrationBean(servlet, "/codenotfound/ws/*"); 25 | } 26 | 27 | @Bean(name = "ticketagent") 28 | public Wsdl11Definition defaultWsdl11Definition() { 29 | SimpleWsdl11Definition wsdl11Definition = new SimpleWsdl11Definition(); 30 | wsdl11Definition.setWsdl(new ClassPathResource("/wsdl/ticketagent.wsdl")); 31 | 32 | return wsdl11Definition; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /spring-ws-mutual-authentication-httpclient/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | client: 2 | default-uri: https://localhost:9443/codenotfound/ws/ticketagent 3 | ssl: 4 | key-store: classpath:jks/client-keystore.jks 5 | key-store-password: client-keystore-p455w0rd 6 | key-password: client-key-p455w0rd 7 | trust-store: classpath:jks/client-truststore.jks 8 | trust-store-password: client-truststore-p455w0rd 9 | 10 | server: 11 | port: 9443 12 | ssl: 13 | client-auth: need 14 | key-store: classpath:jks/server-keystore.jks 15 | key-store-password: server-keystore-p455w0rd 16 | key-alias: server-keypair 17 | key-password: server-key-p455w0rd 18 | trust-store: classpath:jks/server-truststore.jks 19 | trust-store-password: server-truststore-p455w0rd 20 | -------------------------------------------------------------------------------- /spring-ws-mutual-authentication-httpclient/src/main/resources/jks/client-keystore.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-not-found/spring-ws/5d37e6987868b44b0fd162f8a2c836bd553d8132/spring-ws-mutual-authentication-httpclient/src/main/resources/jks/client-keystore.jks -------------------------------------------------------------------------------- /spring-ws-mutual-authentication-httpclient/src/main/resources/jks/client-public-key.cer: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-not-found/spring-ws/5d37e6987868b44b0fd162f8a2c836bd553d8132/spring-ws-mutual-authentication-httpclient/src/main/resources/jks/client-public-key.cer -------------------------------------------------------------------------------- /spring-ws-mutual-authentication-httpclient/src/main/resources/jks/client-truststore.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-not-found/spring-ws/5d37e6987868b44b0fd162f8a2c836bd553d8132/spring-ws-mutual-authentication-httpclient/src/main/resources/jks/client-truststore.jks -------------------------------------------------------------------------------- /spring-ws-mutual-authentication-httpclient/src/main/resources/jks/server-keystore.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-not-found/spring-ws/5d37e6987868b44b0fd162f8a2c836bd553d8132/spring-ws-mutual-authentication-httpclient/src/main/resources/jks/server-keystore.jks -------------------------------------------------------------------------------- /spring-ws-mutual-authentication-httpclient/src/main/resources/jks/server-public-key.cer: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-not-found/spring-ws/5d37e6987868b44b0fd162f8a2c836bd553d8132/spring-ws-mutual-authentication-httpclient/src/main/resources/jks/server-public-key.cer -------------------------------------------------------------------------------- /spring-ws-mutual-authentication-httpclient/src/main/resources/jks/server-truststore.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-not-found/spring-ws/5d37e6987868b44b0fd162f8a2c836bd553d8132/spring-ws-mutual-authentication-httpclient/src/main/resources/jks/server-truststore.jks -------------------------------------------------------------------------------- /spring-ws-mutual-authentication-httpclient/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /spring-ws-mutual-authentication-httpclient/src/test/java/com/codenotfound/ws/SpringWsApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import java.math.BigInteger; 6 | import java.util.List; 7 | 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.boot.test.context.SpringBootTest; 12 | import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; 13 | import org.springframework.test.context.junit4.SpringRunner; 14 | 15 | import com.codenotfound.ws.client.TicketAgentClient; 16 | 17 | @RunWith(SpringRunner.class) 18 | @SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT) 19 | public class SpringWsApplicationTests { 20 | 21 | @Autowired 22 | private TicketAgentClient ticketAgentClient; 23 | 24 | @Test 25 | public void testListFlights() { 26 | List flights = ticketAgentClient.listFlights(); 27 | 28 | assertThat(flights.get(0)).isEqualTo(BigInteger.valueOf(101)); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /spring-ws-mutual-authentication/README.md: -------------------------------------------------------------------------------- 1 | # spring-ws-mutual-authentication 2 | 3 | [![Quality Gate](https://sonarcloud.io/api/badges/gate?key=com.codenotfound:spring-ws-mutual-authentication)](https://sonarcloud.io/dashboard/index/com.codenotfound:spring-ws-mutual-authentication) 4 | 5 | A sample project on how setup mutual certificate authentication using Spring-WS and Spring Boot without using the Apache HttpClient. 6 | 7 | [https://www.codenotfound.com/spring-ws/](https://www.codenotfound.com/spring-ws/) 8 | -------------------------------------------------------------------------------- /spring-ws-mutual-authentication/src/main/java/com/codenotfound/ws/SpringWsApplication.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringWsApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringWsApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spring-ws-mutual-authentication/src/main/java/com/codenotfound/ws/client/TicketAgentClient.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.client; 2 | 3 | import java.math.BigInteger; 4 | import java.util.List; 5 | 6 | import javax.xml.bind.JAXBElement; 7 | 8 | import org.example.ticketagent.ObjectFactory; 9 | import org.example.ticketagent.TFlightsResponse; 10 | import org.example.ticketagent.TListFlights; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.stereotype.Component; 13 | import org.springframework.ws.client.core.WebServiceTemplate; 14 | 15 | @Component 16 | public class TicketAgentClient { 17 | 18 | @Autowired 19 | private WebServiceTemplate webServiceTemplate; 20 | 21 | @SuppressWarnings("unchecked") 22 | public List listFlights() { 23 | 24 | ObjectFactory factory = new ObjectFactory(); 25 | TListFlights tListFlights = factory.createTListFlights(); 26 | 27 | JAXBElement request = factory.createListFlightsRequest(tListFlights); 28 | 29 | JAXBElement response = 30 | (JAXBElement) webServiceTemplate.marshalSendAndReceive(request); 31 | 32 | return response.getValue().getFlightNumber(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /spring-ws-mutual-authentication/src/main/java/com/codenotfound/ws/endpoint/TicketAgentEndpoint.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.endpoint; 2 | 3 | import java.math.BigInteger; 4 | 5 | import javax.xml.bind.JAXBElement; 6 | 7 | import org.example.ticketagent.ObjectFactory; 8 | import org.example.ticketagent.TFlightsResponse; 9 | import org.example.ticketagent.TListFlights; 10 | import org.springframework.ws.server.endpoint.annotation.Endpoint; 11 | import org.springframework.ws.server.endpoint.annotation.PayloadRoot; 12 | import org.springframework.ws.server.endpoint.annotation.RequestPayload; 13 | import org.springframework.ws.server.endpoint.annotation.ResponsePayload; 14 | 15 | @Endpoint 16 | public class TicketAgentEndpoint { 17 | 18 | @PayloadRoot(namespace = "http://example.org/TicketAgent.xsd", localPart = "listFlightsRequest") 19 | @ResponsePayload 20 | public JAXBElement listFlights( 21 | @RequestPayload JAXBElement request) { 22 | 23 | ObjectFactory factory = new ObjectFactory(); 24 | TFlightsResponse tFlightsResponse = factory.createTFlightsResponse(); 25 | tFlightsResponse.getFlightNumber().add(BigInteger.valueOf(101)); 26 | 27 | return factory.createListFlightsResponse(tFlightsResponse); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /spring-ws-mutual-authentication/src/main/java/com/codenotfound/ws/endpoint/WebServiceConfig.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.endpoint; 2 | 3 | import org.springframework.boot.web.servlet.ServletRegistrationBean; 4 | import org.springframework.context.ApplicationContext; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.core.io.ClassPathResource; 8 | import org.springframework.ws.config.annotation.EnableWs; 9 | import org.springframework.ws.config.annotation.WsConfigurerAdapter; 10 | import org.springframework.ws.transport.http.MessageDispatcherServlet; 11 | import org.springframework.ws.wsdl.wsdl11.SimpleWsdl11Definition; 12 | import org.springframework.ws.wsdl.wsdl11.Wsdl11Definition; 13 | 14 | @EnableWs 15 | @Configuration 16 | public class WebServiceConfig extends WsConfigurerAdapter { 17 | 18 | @Bean 19 | public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) { 20 | 21 | MessageDispatcherServlet servlet = new MessageDispatcherServlet(); 22 | servlet.setApplicationContext(applicationContext); 23 | 24 | return new ServletRegistrationBean(servlet, "/codenotfound/ws/*"); 25 | } 26 | 27 | @Bean(name = "ticketagent") 28 | public Wsdl11Definition defaultWsdl11Definition() { 29 | SimpleWsdl11Definition wsdl11Definition = new SimpleWsdl11Definition(); 30 | wsdl11Definition.setWsdl(new ClassPathResource("/wsdl/ticketagent.wsdl")); 31 | 32 | return wsdl11Definition; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /spring-ws-mutual-authentication/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | client: 2 | default-uri: https://localhost:9443/codenotfound/ws/ticketagent 3 | ssl: 4 | key-store: classpath:jks/client-keystore.jks 5 | key-store-password: client-keystore-p455w0rd 6 | key-password: client-key-p455w0rd 7 | trust-store: classpath:jks/client-truststore.jks 8 | trust-store-password: client-truststore-p455w0rd 9 | 10 | server: 11 | port: 9443 12 | ssl: 13 | client-auth: need 14 | key-store: classpath:jks/server-keystore.jks 15 | key-store-password: server-keystore-p455w0rd 16 | key-alias: server-keypair 17 | key-password: server-key-p455w0rd 18 | trust-store: classpath:jks/server-truststore.jks 19 | trust-store-password: server-truststore-p455w0rd 20 | -------------------------------------------------------------------------------- /spring-ws-mutual-authentication/src/main/resources/jks/client-keystore.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-not-found/spring-ws/5d37e6987868b44b0fd162f8a2c836bd553d8132/spring-ws-mutual-authentication/src/main/resources/jks/client-keystore.jks -------------------------------------------------------------------------------- /spring-ws-mutual-authentication/src/main/resources/jks/client-public-key.cer: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-not-found/spring-ws/5d37e6987868b44b0fd162f8a2c836bd553d8132/spring-ws-mutual-authentication/src/main/resources/jks/client-public-key.cer -------------------------------------------------------------------------------- /spring-ws-mutual-authentication/src/main/resources/jks/client-truststore.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-not-found/spring-ws/5d37e6987868b44b0fd162f8a2c836bd553d8132/spring-ws-mutual-authentication/src/main/resources/jks/client-truststore.jks -------------------------------------------------------------------------------- /spring-ws-mutual-authentication/src/main/resources/jks/server-keystore.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-not-found/spring-ws/5d37e6987868b44b0fd162f8a2c836bd553d8132/spring-ws-mutual-authentication/src/main/resources/jks/server-keystore.jks -------------------------------------------------------------------------------- /spring-ws-mutual-authentication/src/main/resources/jks/server-public-key.cer: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-not-found/spring-ws/5d37e6987868b44b0fd162f8a2c836bd553d8132/spring-ws-mutual-authentication/src/main/resources/jks/server-public-key.cer -------------------------------------------------------------------------------- /spring-ws-mutual-authentication/src/main/resources/jks/server-truststore.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-not-found/spring-ws/5d37e6987868b44b0fd162f8a2c836bd553d8132/spring-ws-mutual-authentication/src/main/resources/jks/server-truststore.jks -------------------------------------------------------------------------------- /spring-ws-mutual-authentication/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /spring-ws-mutual-authentication/src/test/java/com/codenotfound/ws/SpringWsApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import java.math.BigInteger; 6 | import java.util.List; 7 | 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.boot.test.context.SpringBootTest; 12 | import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; 13 | import org.springframework.test.context.junit4.SpringRunner; 14 | 15 | import com.codenotfound.ws.client.TicketAgentClient; 16 | 17 | @RunWith(SpringRunner.class) 18 | @SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT) 19 | public class SpringWsApplicationTests { 20 | 21 | @Autowired 22 | private TicketAgentClient ticketAgentClient; 23 | 24 | @Test 25 | public void testListFlights() { 26 | List flights = ticketAgentClient.listFlights(); 27 | 28 | assertThat(flights.get(0)).isEqualTo(BigInteger.valueOf(101)); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /spring-ws-soap-header/README.md: -------------------------------------------------------------------------------- 1 | # spring-ws-soap-header 2 | 3 | [![Quality Gate](https://sonarcloud.io/api/badges/gate?key=com.codenotfound:spring-ws-soap-header)](https://sonarcloud.io/dashboard/index/com.codenotfound:spring-ws-soap-header) 4 | 5 | A detailed step-by-step tutorial on how to set and get a SOAP header using Spring-WS and Spring Boot. 6 | 7 | [https://www.codenotfound.com/spring-ws/spring-ws-soap-header-example.html](https://www.codenotfound.com/spring-ws/spring-ws-soap-header-example.html) 8 | -------------------------------------------------------------------------------- /spring-ws-soap-header/src/main/java/com/codenotfound/ws/SpringWsApplication.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringWsApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringWsApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spring-ws-soap-header/src/main/java/com/codenotfound/ws/client/ClientConfig.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.client; 2 | 3 | import org.springframework.beans.factory.annotation.Value; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.oxm.jaxb.Jaxb2Marshaller; 7 | import org.springframework.ws.client.core.WebServiceTemplate; 8 | 9 | @Configuration 10 | public class ClientConfig { 11 | 12 | @Value("${client.default-uri}") 13 | private String defaultUri; 14 | 15 | @Bean 16 | Jaxb2Marshaller jaxb2Marshaller() { 17 | Jaxb2Marshaller jaxb2Marshaller = new Jaxb2Marshaller(); 18 | jaxb2Marshaller.setContextPath("org.example.ticketagent"); 19 | 20 | return jaxb2Marshaller; 21 | } 22 | 23 | @Bean 24 | public WebServiceTemplate webServiceTemplate() { 25 | WebServiceTemplate webServiceTemplate = new WebServiceTemplate(); 26 | webServiceTemplate.setMarshaller(jaxb2Marshaller()); 27 | webServiceTemplate.setUnmarshaller(jaxb2Marshaller()); 28 | webServiceTemplate.setDefaultUri(defaultUri); 29 | 30 | return webServiceTemplate; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /spring-ws-soap-header/src/main/java/com/codenotfound/ws/endpoint/WebServiceConfig.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.endpoint; 2 | 3 | import org.springframework.boot.web.servlet.ServletRegistrationBean; 4 | import org.springframework.context.ApplicationContext; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.core.io.ClassPathResource; 8 | import org.springframework.ws.config.annotation.EnableWs; 9 | import org.springframework.ws.config.annotation.WsConfigurerAdapter; 10 | import org.springframework.ws.transport.http.MessageDispatcherServlet; 11 | import org.springframework.ws.wsdl.wsdl11.SimpleWsdl11Definition; 12 | import org.springframework.ws.wsdl.wsdl11.Wsdl11Definition; 13 | 14 | @EnableWs 15 | @Configuration 16 | public class WebServiceConfig extends WsConfigurerAdapter { 17 | 18 | @Bean 19 | public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) { 20 | MessageDispatcherServlet servlet = new MessageDispatcherServlet(); 21 | servlet.setApplicationContext(applicationContext); 22 | 23 | return new ServletRegistrationBean(servlet, "/codenotfound/ws/*"); 24 | } 25 | 26 | @Bean(name = "ticketagent") 27 | public Wsdl11Definition defaultWsdl11Definition() { 28 | SimpleWsdl11Definition wsdl11Definition = new SimpleWsdl11Definition(); 29 | wsdl11Definition.setWsdl(new ClassPathResource("/wsdl/ticketagent.wsdl")); 30 | 31 | return wsdl11Definition; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /spring-ws-soap-header/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | client: 2 | default-uri: http://localhost:9090/codenotfound/ws/helloworld 3 | 4 | server: 5 | port: 9090 6 | -------------------------------------------------------------------------------- /spring-ws-soap-header/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /spring-ws-soapaction-header/README.md: -------------------------------------------------------------------------------- 1 | # spring-ws-soapaction-header 2 | 3 | [![Quality Gate](https://sonarcloud.io/api/badges/gate?key=com.codenotfound:spring-ws-soapaction-header)](https://sonarcloud.io/dashboard/index/com.codenotfound:spring-ws-soapaction-header) 4 | 5 | A detailed step-by-step tutorial on how to set the SOAPAction header using Spring-WS and Spring Boot. 6 | 7 | [https://www.codenotfound.com/spring-ws-soapaction-header-example.html](https://www.codenotfound.com/spring-ws-soapaction-header-example.html) 8 | -------------------------------------------------------------------------------- /spring-ws-soapaction-header/src/main/java/com/codenotfound/ws/SpringWsApplication.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringWsApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringWsApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spring-ws-soapaction-header/src/main/java/com/codenotfound/ws/client/ClientConfig.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.client; 2 | 3 | import org.springframework.beans.factory.annotation.Value; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.oxm.jaxb.Jaxb2Marshaller; 7 | import org.springframework.ws.client.core.WebServiceTemplate; 8 | 9 | @Configuration 10 | public class ClientConfig { 11 | 12 | @Value("${client.default-uri}") 13 | private String defaultUri; 14 | 15 | @Bean 16 | Jaxb2Marshaller jaxb2Marshaller() { 17 | Jaxb2Marshaller jaxb2Marshaller = new Jaxb2Marshaller(); 18 | jaxb2Marshaller.setContextPath("org.example.ticketagent"); 19 | 20 | return jaxb2Marshaller; 21 | } 22 | 23 | @Bean 24 | public WebServiceTemplate webServiceTemplate() { 25 | WebServiceTemplate webServiceTemplate = new WebServiceTemplate(); 26 | webServiceTemplate.setMarshaller(jaxb2Marshaller()); 27 | webServiceTemplate.setUnmarshaller(jaxb2Marshaller()); 28 | webServiceTemplate.setDefaultUri(defaultUri); 29 | 30 | return webServiceTemplate; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /spring-ws-soapaction-header/src/main/java/com/codenotfound/ws/client/TicketAgentClient.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.client; 2 | 3 | import java.math.BigInteger; 4 | import java.util.List; 5 | 6 | import javax.xml.bind.JAXBElement; 7 | 8 | import org.example.ticketagent.ObjectFactory; 9 | import org.example.ticketagent.TFlightsResponse; 10 | import org.example.ticketagent.TListFlights; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.stereotype.Component; 13 | import org.springframework.ws.client.core.WebServiceTemplate; 14 | import org.springframework.ws.soap.client.core.SoapActionCallback; 15 | 16 | @Component 17 | public class TicketAgentClient { 18 | 19 | @Autowired 20 | private WebServiceTemplate webServiceTemplate; 21 | 22 | @SuppressWarnings("unchecked") 23 | public List listFlights() { 24 | ObjectFactory factory = new ObjectFactory(); 25 | TListFlights tListFlights = factory.createTListFlights(); 26 | 27 | JAXBElement request = factory.createListFlightsRequest(tListFlights); 28 | 29 | // use SoapActionCallback to add the SOAPAction 30 | JAXBElement response = 31 | (JAXBElement) webServiceTemplate.marshalSendAndReceive(request, 32 | new SoapActionCallback("http://example.com/TicketAgent/listFlights")); 33 | 34 | return response.getValue().getFlightNumber(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /spring-ws-soapaction-header/src/main/java/com/codenotfound/ws/endpoint/TicketAgentEndpoint.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.endpoint; 2 | 3 | import java.math.BigInteger; 4 | 5 | import javax.xml.bind.JAXBElement; 6 | 7 | import org.example.ticketagent.ObjectFactory; 8 | import org.example.ticketagent.TFlightsResponse; 9 | import org.example.ticketagent.TListFlights; 10 | import org.slf4j.Logger; 11 | import org.slf4j.LoggerFactory; 12 | import org.springframework.ws.WebServiceMessage; 13 | import org.springframework.ws.context.MessageContext; 14 | import org.springframework.ws.server.endpoint.annotation.Endpoint; 15 | import org.springframework.ws.server.endpoint.annotation.RequestPayload; 16 | import org.springframework.ws.server.endpoint.annotation.ResponsePayload; 17 | import org.springframework.ws.soap.SoapMessage; 18 | import org.springframework.ws.soap.server.endpoint.annotation.SoapAction; 19 | 20 | @Endpoint 21 | public class TicketAgentEndpoint { 22 | 23 | private static final Logger LOGGER = LoggerFactory.getLogger(TicketAgentEndpoint.class); 24 | 25 | // map a message to this endpoint based on the SOAPAction 26 | @SoapAction(value = "http://example.com/TicketAgent/listFlights") 27 | @ResponsePayload 28 | public JAXBElement listFlights( 29 | @RequestPayload JAXBElement request, MessageContext messageContext) { 30 | // access the SOAPAction value 31 | WebServiceMessage webServiceMessage = messageContext.getRequest(); 32 | SoapMessage soapMessage = (SoapMessage) webServiceMessage; 33 | LOGGER.info("SOAPAction header: {}", soapMessage.getSoapAction()); 34 | 35 | ObjectFactory factory = new ObjectFactory(); 36 | TFlightsResponse tFlightsResponse = factory.createTFlightsResponse(); 37 | tFlightsResponse.getFlightNumber().add(BigInteger.valueOf(101)); 38 | 39 | return factory.createListFlightsResponse(tFlightsResponse); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /spring-ws-soapaction-header/src/main/java/com/codenotfound/ws/endpoint/WebServiceConfig.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.endpoint; 2 | 3 | import org.springframework.boot.web.servlet.ServletRegistrationBean; 4 | import org.springframework.context.ApplicationContext; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.core.io.ClassPathResource; 8 | import org.springframework.ws.config.annotation.EnableWs; 9 | import org.springframework.ws.config.annotation.WsConfigurerAdapter; 10 | import org.springframework.ws.transport.http.MessageDispatcherServlet; 11 | import org.springframework.ws.wsdl.wsdl11.SimpleWsdl11Definition; 12 | import org.springframework.ws.wsdl.wsdl11.Wsdl11Definition; 13 | 14 | @EnableWs 15 | @Configuration 16 | public class WebServiceConfig extends WsConfigurerAdapter { 17 | 18 | @Bean 19 | public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) { 20 | MessageDispatcherServlet servlet = new MessageDispatcherServlet(); 21 | servlet.setApplicationContext(applicationContext); 22 | 23 | return new ServletRegistrationBean(servlet, "/codenotfound/ws/*"); 24 | } 25 | 26 | @Bean(name = "ticketagent") 27 | public Wsdl11Definition defaultWsdl11Definition() { 28 | SimpleWsdl11Definition wsdl11Definition = new SimpleWsdl11Definition(); 29 | wsdl11Definition.setWsdl(new ClassPathResource("/wsdl/ticketagent.wsdl")); 30 | 31 | return wsdl11Definition; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /spring-ws-soapaction-header/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | client: 2 | default-uri: http://localhost:9090/codenotfound/ws/helloworld 3 | 4 | server: 5 | port: 9090 6 | -------------------------------------------------------------------------------- /spring-ws-soapaction-header/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /spring-ws-soapaction-header/src/test/java/com/codenotfound/ws/client/SoapActionMatcher.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.client; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import java.io.IOException; 6 | import java.net.URI; 7 | 8 | import org.springframework.ws.WebServiceMessage; 9 | import org.springframework.ws.soap.SoapMessage; 10 | import org.springframework.ws.soap.support.SoapUtils; 11 | import org.springframework.ws.test.client.RequestMatcher; 12 | 13 | public class SoapActionMatcher implements RequestMatcher { 14 | 15 | private final String expectedSoapAction; 16 | 17 | public SoapActionMatcher(String expectedSoapAction) { 18 | this.expectedSoapAction = SoapUtils.escapeAction(expectedSoapAction); 19 | } 20 | 21 | @Override 22 | public void match(URI uri, WebServiceMessage webServiceMessage) 23 | throws IOException, AssertionError { 24 | assertThat(webServiceMessage).isInstanceOf(SoapMessage.class); 25 | 26 | SoapMessage soapMessage = (SoapMessage) webServiceMessage; 27 | assertThat(soapMessage.getSoapAction()).isEqualTo(expectedSoapAction); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /spring-ws-soapaction-header/src/test/java/com/codenotfound/ws/endpoint/SoapActionCreator.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.endpoint; 2 | 3 | import java.io.IOException; 4 | 5 | import javax.xml.transform.Source; 6 | 7 | import org.springframework.ws.WebServiceMessage; 8 | import org.springframework.ws.WebServiceMessageFactory; 9 | import org.springframework.ws.soap.SoapMessage; 10 | import org.springframework.ws.test.server.RequestCreator; 11 | import org.springframework.ws.test.support.creator.PayloadMessageCreator; 12 | 13 | public class SoapActionCreator implements RequestCreator { 14 | 15 | private final Source payload; 16 | 17 | private final String soapAction; 18 | 19 | public SoapActionCreator(Source payload, String soapAction) { 20 | this.payload = payload; 21 | this.soapAction = soapAction; 22 | } 23 | 24 | @Override 25 | public WebServiceMessage createRequest(WebServiceMessageFactory webServiceMessageFactory) 26 | throws IOException { 27 | WebServiceMessage webServiceMessage = 28 | new PayloadMessageCreator(payload).createMessage(webServiceMessageFactory); 29 | 30 | SoapMessage soapMessage = (SoapMessage) webServiceMessage; 31 | soapMessage.setSoapAction(soapAction); 32 | 33 | return webServiceMessage; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /spring-ws-soapaction-header/src/test/java/com/codenotfound/ws/endpoint/TicketAgentEndpointTest.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.endpoint; 2 | 3 | import static org.springframework.ws.test.server.ResponseMatchers.payload; 4 | 5 | import javax.xml.transform.Source; 6 | 7 | import org.junit.Before; 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.boot.test.context.SpringBootTest; 12 | import org.springframework.context.ApplicationContext; 13 | import org.springframework.test.context.junit4.SpringRunner; 14 | import org.springframework.ws.test.server.MockWebServiceClient; 15 | import org.springframework.xml.transform.StringSource; 16 | 17 | @RunWith(SpringRunner.class) 18 | @SpringBootTest 19 | public class TicketAgentEndpointTest { 20 | 21 | @Autowired 22 | private ApplicationContext applicationContext; 23 | 24 | private MockWebServiceClient mockClient; 25 | 26 | @Before 27 | public void createClient() { 28 | mockClient = MockWebServiceClient.createClient(applicationContext); 29 | } 30 | 31 | @Test 32 | public void testListFlights() { 33 | Source requestPayload = 34 | new StringSource("" 35 | + ""); 36 | 37 | Source responsePayload = 38 | new StringSource("" 39 | + "101" + ""); 40 | 41 | mockClient 42 | .sendRequest( 43 | new SoapActionCreator(requestPayload, "http://example.com/TicketAgent/listFlights")) 44 | .andExpect(payload(responsePayload)); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /spring-ws-stress-test/src/main/java/com/codenotfound/order/OrderApplication.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.order; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class OrderApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(OrderApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spring-ws-stress-test/src/main/java/com/codenotfound/order/client/ClientConfig.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.order.client; 2 | 3 | import org.springframework.beans.factory.annotation.Value; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.oxm.jaxb.Jaxb2Marshaller; 7 | import org.springframework.ws.client.core.WebServiceTemplate; 8 | 9 | @Configuration 10 | public class ClientConfig { 11 | 12 | @Value("${order.address}") 13 | private String orderAddress; 14 | 15 | @Bean 16 | Jaxb2Marshaller jaxb2Marshaller() { 17 | 18 | Jaxb2Marshaller jaxb2Marshaller = new Jaxb2Marshaller(); 19 | jaxb2Marshaller.setContextPath("com.codenotfound.types.order"); 20 | return jaxb2Marshaller; 21 | } 22 | 23 | @Bean 24 | public WebServiceTemplate webServiceTemplate() { 25 | 26 | WebServiceTemplate webServiceTemplate = new WebServiceTemplate(); 27 | webServiceTemplate.setMarshaller(jaxb2Marshaller()); 28 | webServiceTemplate.setUnmarshaller(jaxb2Marshaller()); 29 | webServiceTemplate.setDefaultUri(orderAddress); 30 | 31 | return webServiceTemplate; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /spring-ws-stress-test/src/main/java/com/codenotfound/order/client/CreateOrderClient.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.order.client; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Component; 7 | import org.springframework.ws.client.core.WebServiceTemplate; 8 | 9 | import com.codenotfound.types.order.CustomerType; 10 | import com.codenotfound.types.order.LineItemsType; 11 | import com.codenotfound.types.order.ObjectFactory; 12 | import com.codenotfound.types.order.Order; 13 | import com.codenotfound.types.order.OrderConfirmation; 14 | 15 | @Component 16 | public class CreateOrderClient { 17 | 18 | private static final Logger LOGGER = LoggerFactory 19 | .getLogger(CreateOrderClient.class); 20 | 21 | @Autowired 22 | private WebServiceTemplate webServiceTemplate; 23 | 24 | public OrderConfirmation createOrder(CustomerType customer, 25 | LineItemsType lineItems) { 26 | 27 | ObjectFactory factory = new ObjectFactory(); 28 | Order order = factory.createOrder(); 29 | 30 | order.setCustomer(customer); 31 | order.setLineItems(lineItems); 32 | 33 | LOGGER.info( 34 | "Client sending order for Customer[firstName={},lastName={}]", 35 | customer.getFirstName(), customer.getLastName()); 36 | 37 | OrderConfirmation orderConfirmation = (OrderConfirmation) webServiceTemplate 38 | .marshalSendAndReceive(order); 39 | 40 | LOGGER.info("Client received orderConfirmationId='{}'", 41 | orderConfirmation.getConfirmationId()); 42 | return orderConfirmation; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /spring-ws-stress-test/src/main/java/com/codenotfound/order/endpoint/CreateOrderEndpoint.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.order.endpoint; 2 | 3 | import java.util.UUID; 4 | 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | import org.springframework.ws.server.endpoint.annotation.Endpoint; 8 | import org.springframework.ws.server.endpoint.annotation.PayloadRoot; 9 | import org.springframework.ws.server.endpoint.annotation.RequestPayload; 10 | import org.springframework.ws.server.endpoint.annotation.ResponsePayload; 11 | 12 | import com.codenotfound.types.order.ObjectFactory; 13 | import com.codenotfound.types.order.Order; 14 | import com.codenotfound.types.order.OrderConfirmation; 15 | 16 | @Endpoint 17 | public class CreateOrderEndpoint { 18 | 19 | private static final Logger LOGGER = LoggerFactory 20 | .getLogger(CreateOrderEndpoint.class); 21 | 22 | private static final String NAMESPACE_URI = "http://codenotfound.com/types/order"; 23 | 24 | @PayloadRoot(namespace = NAMESPACE_URI, localPart = "order") 25 | @ResponsePayload 26 | public OrderConfirmation createOrder(@RequestPayload Order request) { 27 | LOGGER.info( 28 | "Endpoint received order for Customer[firstName={},lastName={}]", 29 | request.getCustomer().getFirstName(), 30 | request.getCustomer().getLastName()); 31 | 32 | // process order 33 | 34 | ObjectFactory factory = new ObjectFactory(); 35 | OrderConfirmation response = factory.createOrderConfirmation(); 36 | response.setConfirmationId(UUID.randomUUID().toString()); 37 | 38 | LOGGER.info("Endpoint sending orderConfirmationId='{}'", 39 | response.getConfirmationId()); 40 | return response; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /spring-ws-stress-test/src/main/java/com/codenotfound/order/endpoint/WebServiceConfig.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.order.endpoint; 2 | 3 | import org.springframework.boot.web.servlet.ServletRegistrationBean; 4 | import org.springframework.context.ApplicationContext; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.core.io.ClassPathResource; 8 | import org.springframework.ws.config.annotation.EnableWs; 9 | import org.springframework.ws.config.annotation.WsConfigurerAdapter; 10 | import org.springframework.ws.transport.http.MessageDispatcherServlet; 11 | import org.springframework.ws.wsdl.wsdl11.SimpleWsdl11Definition; 12 | import org.springframework.ws.wsdl.wsdl11.Wsdl11Definition; 13 | 14 | @EnableWs 15 | @Configuration 16 | public class WebServiceConfig extends WsConfigurerAdapter { 17 | 18 | @Bean 19 | public ServletRegistrationBean messageDispatcherServlet( 20 | ApplicationContext applicationContext) { 21 | 22 | MessageDispatcherServlet servlet = new MessageDispatcherServlet(); 23 | servlet.setApplicationContext(applicationContext); 24 | 25 | return new ServletRegistrationBean(servlet, 26 | "/codenotfound/ws/*"); 27 | } 28 | 29 | @Bean(name = "order") 30 | public Wsdl11Definition defaultWsdl11Definition() { 31 | SimpleWsdl11Definition wsdl11Definition = new SimpleWsdl11Definition(); 32 | wsdl11Definition.setWsdl( 33 | new ClassPathResource("/wsdl/order.wsdl")); 34 | 35 | return wsdl11Definition; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /spring-ws-stress-test/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | # Address of the Order service 2 | order.address=http://localhost:9090/codenotfound/ws/order 3 | 4 | # Server HTTP port 5 | server.port=9090 6 | 7 | # Log file name. For instance `myapp.log` 8 | logging.file=spring-ws-test.log 9 | # Log levels severity mapping. For instance `logging.level.org.springframework=DEBUG` 10 | logging.level.org.springframework=INFO 11 | logging.level.com.codenotfound.order=INFO -------------------------------------------------------------------------------- /spring-ws-stress-test/src/test/java/com/codenotfound/order/client/CreateOrderClientIT.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.order.client; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import java.math.BigInteger; 6 | 7 | import org.junit.Before; 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.boot.test.context.SpringBootTest; 12 | import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; 13 | import org.springframework.test.context.junit4.SpringRunner; 14 | 15 | import com.codenotfound.types.order.CustomerType; 16 | import com.codenotfound.types.order.LineItemType; 17 | import com.codenotfound.types.order.LineItemsType; 18 | import com.codenotfound.types.order.ObjectFactory; 19 | import com.codenotfound.types.order.ProductType; 20 | 21 | @RunWith(SpringRunner.class) 22 | @SpringBootTest(webEnvironment = WebEnvironment.NONE) 23 | public class CreateOrderClientIT { 24 | 25 | @Autowired 26 | private CreateOrderClient createOrderClient; 27 | 28 | private CustomerType customer; 29 | private LineItemsType lineItems; 30 | 31 | @Before 32 | public void setUp() throws Exception { 33 | ObjectFactory factory = new ObjectFactory(); 34 | 35 | customer = factory.createCustomerType(); 36 | customer.setFirstName("John"); 37 | customer.setLastName("Doe"); 38 | 39 | ProductType product1 = factory.createProductType(); 40 | product1.setId("1"); 41 | 42 | LineItemType lineItem1 = factory.createLineItemType(); 43 | lineItem1.setProduct(product1); 44 | lineItem1.setQuantity(BigInteger.valueOf(2)); 45 | 46 | lineItems = factory.createLineItemsType(); 47 | lineItems.getLineItem().add(lineItem1); 48 | } 49 | 50 | @Test 51 | public void testCreateOrder() { 52 | assertThat(createOrderClient.createOrder(customer, lineItems) 53 | .getConfirmationId()).isEqualTo("gero et"); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /spring-ws-stress-test/src/test/java/com/codenotfound/order/endpoint/CreateOrderEndpointTest.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.order.endpoint; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import java.math.BigInteger; 6 | 7 | import org.junit.Before; 8 | import org.junit.Test; 9 | 10 | import com.codenotfound.order.endpoint.CreateOrderEndpoint; 11 | import com.codenotfound.types.order.CustomerType; 12 | import com.codenotfound.types.order.LineItemType; 13 | import com.codenotfound.types.order.LineItemsType; 14 | import com.codenotfound.types.order.ObjectFactory; 15 | import com.codenotfound.types.order.Order; 16 | import com.codenotfound.types.order.ProductType; 17 | 18 | public class CreateOrderEndpointTest { 19 | 20 | private CreateOrderEndpoint createOrderEndpoint = new CreateOrderEndpoint(); 21 | 22 | private Order order; 23 | 24 | @Before 25 | public void setUp() throws Exception { 26 | ObjectFactory factory = new ObjectFactory(); 27 | 28 | CustomerType customer = factory.createCustomerType(); 29 | customer.setFirstName("John"); 30 | customer.setLastName("Doe"); 31 | 32 | ProductType product1 = factory.createProductType(); 33 | product1.setId("1"); 34 | product1.setName("batman action figure"); 35 | 36 | LineItemType lineItem1 = factory.createLineItemType(); 37 | lineItem1.setProduct(product1); 38 | lineItem1.setQuantity(BigInteger.valueOf(1)); 39 | 40 | LineItemsType lineItems = factory.createLineItemsType(); 41 | lineItems.getLineItem().add(lineItem1); 42 | 43 | order = factory.createOrder(); 44 | order.setCustomer(customer); 45 | order.setLineItems(lineItems); 46 | } 47 | 48 | @Test 49 | public void testCreateOrder() { 50 | assertThat(createOrderEndpoint.createOrder(order) 51 | .getConfirmationId()).isNotBlank(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /spring-ws-stress-test/src/test/resources/application.properties: -------------------------------------------------------------------------------- 1 | # Address of the Order service 2 | order.address=http://localhost:9070/mockOrder_SoapBinding 3 | 4 | # server HTTP port 5 | server.port=9080 6 | 7 | # Log file name. For instance `myapp.log` 8 | logging.file=spring-ws-test-test.log 9 | # Log levels severity mapping. For instance `logging.level.org.springframework=DEBUG` 10 | logging.level.org.springframework=INFO 11 | logging.level.com.codenotfound.order=DEBUG -------------------------------------------------------------------------------- /spring-ws-stress-test/src/test/resources/gatling/bodies/order-request.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | gero et 7 | sonoras imperio 8 | quae divum incedo 9 | verrantque per auras 10 | per auras 11 | circum claustra 12 | nimborum in 13 | 14 | 15 | 16 | 17 | 18 | foedere certo 19 | profundum quippe ferant 20 | et carcere 21 | 22 | 100 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /spring-ws-stress-test/src/test/resources/gatling/scala/OrderSimulation.scala: -------------------------------------------------------------------------------- 1 | package com.codenotfound.order 2 | 3 | import io.gatling.core.Predef._ 4 | import io.gatling.http.Predef._ 5 | import scala.concurrent.duration._ 6 | 7 | class BasicSimulation extends Simulation { 8 | 9 | val httpConf = http 10 | .baseURL("http://localhost:9090") 11 | .contentTypeHeader("text/xml") 12 | 13 | val scn = scenario("Call Order Web Service").during(1 minutes) { 14 | exec(http("createOrder") 15 | .post("/codenotfound/ws/order") 16 | .body(RawFileBody("order-request.xml"))) 17 | } 18 | 19 | setUp( 20 | scn.inject(rampUsers(10) over(1 minutes)) 21 | .protocols(httpConf)) 22 | .maxDuration(2 minutes) 23 | } -------------------------------------------------------------------------------- /spring-ws-test/src/main/java/com/codenotfound/order/OrderApplication.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.order; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class OrderApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(OrderApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spring-ws-test/src/main/java/com/codenotfound/order/client/ClientConfig.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.order.client; 2 | 3 | import org.springframework.beans.factory.annotation.Value; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.oxm.jaxb.Jaxb2Marshaller; 7 | import org.springframework.ws.client.core.WebServiceTemplate; 8 | 9 | @Configuration 10 | public class ClientConfig { 11 | 12 | @Value("${order.address}") 13 | private String orderAddress; 14 | 15 | @Bean 16 | Jaxb2Marshaller jaxb2Marshaller() { 17 | 18 | Jaxb2Marshaller jaxb2Marshaller = new Jaxb2Marshaller(); 19 | jaxb2Marshaller.setContextPath("com.codenotfound.types.order"); 20 | return jaxb2Marshaller; 21 | } 22 | 23 | @Bean 24 | public WebServiceTemplate webServiceTemplate() { 25 | 26 | WebServiceTemplate webServiceTemplate = new WebServiceTemplate(); 27 | webServiceTemplate.setMarshaller(jaxb2Marshaller()); 28 | webServiceTemplate.setUnmarshaller(jaxb2Marshaller()); 29 | webServiceTemplate.setDefaultUri(orderAddress); 30 | 31 | return webServiceTemplate; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /spring-ws-test/src/main/java/com/codenotfound/order/client/CreateOrderClient.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.order.client; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Component; 7 | import org.springframework.ws.client.core.WebServiceTemplate; 8 | 9 | import com.codenotfound.types.order.CustomerType; 10 | import com.codenotfound.types.order.LineItemsType; 11 | import com.codenotfound.types.order.ObjectFactory; 12 | import com.codenotfound.types.order.Order; 13 | import com.codenotfound.types.order.OrderConfirmation; 14 | 15 | @Component 16 | public class CreateOrderClient { 17 | 18 | private static final Logger LOGGER = LoggerFactory 19 | .getLogger(CreateOrderClient.class); 20 | 21 | @Autowired 22 | private WebServiceTemplate webServiceTemplate; 23 | 24 | public OrderConfirmation createOrder(CustomerType customer, 25 | LineItemsType lineItems) { 26 | 27 | ObjectFactory factory = new ObjectFactory(); 28 | Order order = factory.createOrder(); 29 | 30 | order.setCustomer(customer); 31 | order.setLineItems(lineItems); 32 | 33 | LOGGER.info( 34 | "Client sending order for Customer[firstName={},lastName={}]", 35 | customer.getFirstName(), customer.getLastName()); 36 | 37 | OrderConfirmation orderConfirmation = (OrderConfirmation) webServiceTemplate 38 | .marshalSendAndReceive(order); 39 | 40 | LOGGER.info("Client received orderConfirmationId='{}'", 41 | orderConfirmation.getConfirmationId()); 42 | return orderConfirmation; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /spring-ws-test/src/main/java/com/codenotfound/order/endpoint/CreateOrderEndpoint.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.order.endpoint; 2 | 3 | import java.util.UUID; 4 | 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | import org.springframework.ws.server.endpoint.annotation.Endpoint; 8 | import org.springframework.ws.server.endpoint.annotation.PayloadRoot; 9 | import org.springframework.ws.server.endpoint.annotation.RequestPayload; 10 | import org.springframework.ws.server.endpoint.annotation.ResponsePayload; 11 | 12 | import com.codenotfound.types.order.ObjectFactory; 13 | import com.codenotfound.types.order.Order; 14 | import com.codenotfound.types.order.OrderConfirmation; 15 | 16 | @Endpoint 17 | public class CreateOrderEndpoint { 18 | 19 | private static final Logger LOGGER = LoggerFactory 20 | .getLogger(CreateOrderEndpoint.class); 21 | 22 | private static final String NAMESPACE_URI = "http://codenotfound.com/types/order"; 23 | 24 | @PayloadRoot(namespace = NAMESPACE_URI, localPart = "order") 25 | @ResponsePayload 26 | public OrderConfirmation createOrder(@RequestPayload Order request) { 27 | LOGGER.info( 28 | "Endpoint received order for Customer[firstName={},lastName={}]", 29 | request.getCustomer().getFirstName(), 30 | request.getCustomer().getLastName()); 31 | 32 | // process order 33 | 34 | ObjectFactory factory = new ObjectFactory(); 35 | OrderConfirmation response = factory.createOrderConfirmation(); 36 | response.setConfirmationId(UUID.randomUUID().toString()); 37 | 38 | LOGGER.info("Endpoint sending orderConfirmationId='{}'", 39 | response.getConfirmationId()); 40 | return response; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /spring-ws-test/src/main/java/com/codenotfound/order/endpoint/WebServiceConfig.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.order.endpoint; 2 | 3 | import org.springframework.boot.web.servlet.ServletRegistrationBean; 4 | import org.springframework.context.ApplicationContext; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.core.io.ClassPathResource; 8 | import org.springframework.ws.config.annotation.EnableWs; 9 | import org.springframework.ws.config.annotation.WsConfigurerAdapter; 10 | import org.springframework.ws.transport.http.MessageDispatcherServlet; 11 | import org.springframework.ws.wsdl.wsdl11.SimpleWsdl11Definition; 12 | import org.springframework.ws.wsdl.wsdl11.Wsdl11Definition; 13 | 14 | @EnableWs 15 | @Configuration 16 | public class WebServiceConfig extends WsConfigurerAdapter { 17 | 18 | @Bean 19 | public ServletRegistrationBean messageDispatcherServlet( 20 | ApplicationContext applicationContext) { 21 | 22 | MessageDispatcherServlet servlet = new MessageDispatcherServlet(); 23 | servlet.setApplicationContext(applicationContext); 24 | 25 | return new ServletRegistrationBean(servlet, 26 | "/codenotfound/ws/*"); 27 | } 28 | 29 | @Bean(name = "order") 30 | public Wsdl11Definition defaultWsdl11Definition() { 31 | SimpleWsdl11Definition wsdl11Definition = new SimpleWsdl11Definition(); 32 | wsdl11Definition.setWsdl( 33 | new ClassPathResource("/wsdl/order.wsdl")); 34 | 35 | return wsdl11Definition; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /spring-ws-test/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | # Address of the Order service 2 | order.address=http://localhost:9090/codenotfound/ws/order 3 | 4 | # Server HTTP port 5 | server.port=9090 6 | 7 | # Log file name. For instance `myapp.log` 8 | logging.file=spring-ws-test.log 9 | # Log levels severity mapping. For instance `logging.level.org.springframework=DEBUG` 10 | logging.level.org.springframework=INFO 11 | logging.level.com.codenotfound.order=INFO -------------------------------------------------------------------------------- /spring-ws-test/src/test/java/com/codenotfound/order/client/CreateOrderClientIT.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.order.client; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import java.math.BigInteger; 6 | 7 | import org.junit.Before; 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.boot.test.context.SpringBootTest; 12 | import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; 13 | import org.springframework.test.context.junit4.SpringRunner; 14 | 15 | import com.codenotfound.types.order.CustomerType; 16 | import com.codenotfound.types.order.LineItemType; 17 | import com.codenotfound.types.order.LineItemsType; 18 | import com.codenotfound.types.order.ObjectFactory; 19 | import com.codenotfound.types.order.ProductType; 20 | 21 | @RunWith(SpringRunner.class) 22 | @SpringBootTest(webEnvironment = WebEnvironment.NONE) 23 | public class CreateOrderClientIT { 24 | 25 | @Autowired 26 | private CreateOrderClient createOrderClient; 27 | 28 | private CustomerType customer; 29 | private LineItemsType lineItems; 30 | 31 | @Before 32 | public void setUp() throws Exception { 33 | ObjectFactory factory = new ObjectFactory(); 34 | 35 | customer = factory.createCustomerType(); 36 | customer.setFirstName("John"); 37 | customer.setLastName("Doe"); 38 | 39 | ProductType product1 = factory.createProductType(); 40 | product1.setId("1"); 41 | 42 | LineItemType lineItem1 = factory.createLineItemType(); 43 | lineItem1.setProduct(product1); 44 | lineItem1.setQuantity(BigInteger.valueOf(2)); 45 | 46 | lineItems = factory.createLineItemsType(); 47 | lineItems.getLineItem().add(lineItem1); 48 | } 49 | 50 | @Test 51 | public void testCreateOrder() { 52 | assertThat(createOrderClient.createOrder(customer, lineItems) 53 | .getConfirmationId()).isEqualTo("gero et"); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /spring-ws-test/src/test/java/com/codenotfound/order/endpoint/CreateOrderEndpointTest.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.order.endpoint; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import java.math.BigInteger; 6 | 7 | import org.junit.Before; 8 | import org.junit.Test; 9 | 10 | import com.codenotfound.order.endpoint.CreateOrderEndpoint; 11 | import com.codenotfound.types.order.CustomerType; 12 | import com.codenotfound.types.order.LineItemType; 13 | import com.codenotfound.types.order.LineItemsType; 14 | import com.codenotfound.types.order.ObjectFactory; 15 | import com.codenotfound.types.order.Order; 16 | import com.codenotfound.types.order.ProductType; 17 | 18 | public class CreateOrderEndpointTest { 19 | 20 | private CreateOrderEndpoint createOrderEndpoint = new CreateOrderEndpoint(); 21 | 22 | private Order order; 23 | 24 | @Before 25 | public void setUp() throws Exception { 26 | ObjectFactory factory = new ObjectFactory(); 27 | 28 | CustomerType customer = factory.createCustomerType(); 29 | customer.setFirstName("John"); 30 | customer.setLastName("Doe"); 31 | 32 | ProductType product1 = factory.createProductType(); 33 | product1.setId("1"); 34 | product1.setName("batman action figure"); 35 | 36 | LineItemType lineItem1 = factory.createLineItemType(); 37 | lineItem1.setProduct(product1); 38 | lineItem1.setQuantity(BigInteger.valueOf(1)); 39 | 40 | LineItemsType lineItems = factory.createLineItemsType(); 41 | lineItems.getLineItem().add(lineItem1); 42 | 43 | order = factory.createOrder(); 44 | order.setCustomer(customer); 45 | order.setLineItems(lineItems); 46 | } 47 | 48 | @Test 49 | public void testCreateOrder() { 50 | assertThat(createOrderEndpoint.createOrder(order) 51 | .getConfirmationId()).isNotBlank(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /spring-ws-test/src/test/resources/application.properties: -------------------------------------------------------------------------------- 1 | # Address of the Order service 2 | order.address=http://localhost:9070/mockOrder_SoapBinding 3 | 4 | # server HTTP port 5 | server.port=9080 6 | 7 | # Log file name. For instance `myapp.log` 8 | logging.file=spring-ws-test-test.log 9 | # Log levels severity mapping. For instance `logging.level.org.springframework=DEBUG` 10 | logging.level.org.springframework=INFO 11 | logging.level.com.codenotfound.order=DEBUG -------------------------------------------------------------------------------- /spring-ws-ticketagent/README.md: -------------------------------------------------------------------------------- 1 | # spring-ws-ticketagent 2 | 3 | [![Quality Gate](https://sonarcloud.io/api/badges/gate?key=com.codenotfound:spring-ws-ticketagent)](https://sonarcloud.io/dashboard/index/com.codenotfound:spring-ws-ticketagent) 4 | 5 | Spring-WS Ticket Agent project based on the TicketAgent.wsdl example from the [W3C WSDL 1.1 specification](https://www.w3.org/TR/wsdl11elementidentifiers/#Iri-ref-ex). 6 | 7 | [https://www.codenotfound.com/spring-ws/](https://www.codenotfound.com/spring-ws/) 8 | -------------------------------------------------------------------------------- /spring-ws-ticketagent/src/main/java/com/codenotfound/ws/SpringWsApplication.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringWsApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringWsApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spring-ws-ticketagent/src/main/java/com/codenotfound/ws/client/ClientConfig.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.client; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.oxm.jaxb.Jaxb2Marshaller; 6 | import org.springframework.ws.client.core.WebServiceTemplate; 7 | 8 | @Configuration 9 | public class ClientConfig { 10 | 11 | @Bean 12 | Jaxb2Marshaller jaxb2Marshaller() { 13 | Jaxb2Marshaller jaxb2Marshaller = new Jaxb2Marshaller(); 14 | jaxb2Marshaller.setContextPath("org.example.ticketagent"); 15 | 16 | return jaxb2Marshaller; 17 | } 18 | 19 | @Bean 20 | public WebServiceTemplate webServiceTemplate() { 21 | WebServiceTemplate webServiceTemplate = new WebServiceTemplate(); 22 | webServiceTemplate.setMarshaller(jaxb2Marshaller()); 23 | webServiceTemplate.setUnmarshaller(jaxb2Marshaller()); 24 | webServiceTemplate.setDefaultUri( 25 | "http://localhost:8080/codenotfound/ws/helloworld"); 26 | 27 | return webServiceTemplate; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /spring-ws-ticketagent/src/main/java/com/codenotfound/ws/client/TicketAgentClient.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.client; 2 | 3 | import java.math.BigInteger; 4 | import java.util.List; 5 | 6 | import javax.xml.bind.JAXBElement; 7 | 8 | import org.example.ticketagent.ObjectFactory; 9 | import org.example.ticketagent.TFlightsResponse; 10 | import org.example.ticketagent.TListFlights; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.stereotype.Component; 13 | import org.springframework.ws.client.core.WebServiceTemplate; 14 | 15 | @Component 16 | public class TicketAgentClient { 17 | 18 | @Autowired 19 | private WebServiceTemplate webServiceTemplate; 20 | 21 | @SuppressWarnings("unchecked") 22 | public List listFlights() { 23 | ObjectFactory factory = new ObjectFactory(); 24 | TListFlights tListFlights = factory.createTListFlights(); 25 | 26 | JAXBElement request = 27 | factory.createListFlightsRequest(tListFlights); 28 | 29 | JAXBElement response = 30 | (JAXBElement) webServiceTemplate 31 | .marshalSendAndReceive(request); 32 | 33 | return response.getValue().getFlightNumber(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /spring-ws-ticketagent/src/main/java/com/codenotfound/ws/endpoint/TicketAgentEndpoint.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.endpoint; 2 | 3 | import java.math.BigInteger; 4 | 5 | import javax.xml.bind.JAXBElement; 6 | 7 | import org.example.ticketagent.ObjectFactory; 8 | import org.example.ticketagent.TFlightsResponse; 9 | import org.example.ticketagent.TListFlights; 10 | import org.springframework.ws.server.endpoint.annotation.Endpoint; 11 | import org.springframework.ws.server.endpoint.annotation.PayloadRoot; 12 | import org.springframework.ws.server.endpoint.annotation.RequestPayload; 13 | import org.springframework.ws.server.endpoint.annotation.ResponsePayload; 14 | 15 | @Endpoint 16 | public class TicketAgentEndpoint { 17 | 18 | @PayloadRoot(namespace = "http://example.org/TicketAgent.xsd", 19 | localPart = "listFlightsRequest") 20 | @ResponsePayload 21 | public JAXBElement listFlights( 22 | @RequestPayload JAXBElement request) { 23 | 24 | ObjectFactory factory = new ObjectFactory(); 25 | TFlightsResponse tFlightsResponse = 26 | factory.createTFlightsResponse(); 27 | tFlightsResponse.getFlightNumber().add(BigInteger.valueOf(101)); 28 | 29 | return factory.createListFlightsResponse(tFlightsResponse); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /spring-ws-ticketagent/src/main/java/com/codenotfound/ws/endpoint/WebServiceConfig.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.endpoint; 2 | 3 | import org.springframework.boot.web.servlet.ServletRegistrationBean; 4 | import org.springframework.context.ApplicationContext; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.core.io.ClassPathResource; 8 | import org.springframework.ws.config.annotation.EnableWs; 9 | import org.springframework.ws.config.annotation.WsConfigurerAdapter; 10 | import org.springframework.ws.transport.http.MessageDispatcherServlet; 11 | import org.springframework.ws.wsdl.wsdl11.SimpleWsdl11Definition; 12 | import org.springframework.ws.wsdl.wsdl11.Wsdl11Definition; 13 | 14 | @EnableWs 15 | @Configuration 16 | public class WebServiceConfig extends WsConfigurerAdapter { 17 | 18 | @Bean 19 | public ServletRegistrationBean messageDispatcherServlet( 20 | ApplicationContext applicationContext) { 21 | MessageDispatcherServlet servlet = new MessageDispatcherServlet(); 22 | servlet.setApplicationContext(applicationContext); 23 | 24 | return new ServletRegistrationBean(servlet, "/codenotfound/ws/*"); 25 | } 26 | 27 | @Bean(name = "ticketagent") 28 | public Wsdl11Definition defaultWsdl11Definition() { 29 | SimpleWsdl11Definition wsdl11Definition = 30 | new SimpleWsdl11Definition(); 31 | wsdl11Definition 32 | .setWsdl(new ClassPathResource("/wsdl/ticketagent.wsdl")); 33 | 34 | return wsdl11Definition; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /spring-ws-ticketagent/src/test/java/com/codenotfound/ws/SpringWsApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import java.math.BigInteger; 6 | import java.util.List; 7 | 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.boot.test.context.SpringBootTest; 12 | import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; 13 | import org.springframework.test.context.junit4.SpringRunner; 14 | 15 | import com.codenotfound.ws.client.TicketAgentClient; 16 | 17 | @RunWith(SpringRunner.class) 18 | @SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT) 19 | public class SpringWsApplicationTests { 20 | 21 | @Autowired 22 | private TicketAgentClient ticketAgentClient; 23 | 24 | @Test 25 | public void testListFlights() { 26 | List flights = ticketAgentClient.listFlights(); 27 | 28 | assertThat(flights.get(0)).isEqualTo(BigInteger.valueOf(101)); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /spring-ws-timeout-httpclient/README.md: -------------------------------------------------------------------------------- 1 | # spring-ws-timeout-httpclient 2 | 3 | [![Quality Gate](https://sonarcloud.io/api/badges/gate?key=com.codenotfound:spring-ws-timeout-httpclient)](https://sonarcloud.io/dashboard/index/com.codenotfound:spring-ws-timeout-httpclient) 4 | 5 | A detailed step-by-step tutorial on how to set a client timeout using Spring-WS and Spring Boot. 6 | 7 | [https://www.codenotfound.com/spring-ws-client-timeout-example.html](https://www.codenotfound.com/spring-ws-client-timeout-example.html) 8 | -------------------------------------------------------------------------------- /spring-ws-timeout-httpclient/src/main/java/com/codenotfound/ws/SpringWsApplication.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringWsApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringWsApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spring-ws-timeout-httpclient/src/main/java/com/codenotfound/ws/client/ClientConfig.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.client; 2 | 3 | import org.springframework.beans.factory.annotation.Value; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.oxm.jaxb.Jaxb2Marshaller; 7 | import org.springframework.ws.client.core.WebServiceTemplate; 8 | import org.springframework.ws.transport.WebServiceMessageSender; 9 | import org.springframework.ws.transport.http.HttpComponentsMessageSender; 10 | 11 | @Configuration 12 | public class ClientConfig { 13 | 14 | @Value("${client.default-uri}") 15 | private String defaultUri; 16 | 17 | @Value("${client.timeout}") 18 | private int timeout; 19 | 20 | @Bean 21 | Jaxb2Marshaller jaxb2Marshaller() { 22 | Jaxb2Marshaller jaxb2Marshaller = new Jaxb2Marshaller(); 23 | jaxb2Marshaller.setContextPath("org.example.ticketagent"); 24 | 25 | return jaxb2Marshaller; 26 | } 27 | 28 | @Bean 29 | public WebServiceTemplate webServiceTemplate() { 30 | WebServiceTemplate webServiceTemplate = new WebServiceTemplate(); 31 | webServiceTemplate.setMarshaller(jaxb2Marshaller()); 32 | webServiceTemplate.setUnmarshaller(jaxb2Marshaller()); 33 | webServiceTemplate.setDefaultUri(defaultUri); 34 | webServiceTemplate.setMessageSender(webServiceMessageSender()); 35 | 36 | return webServiceTemplate; 37 | } 38 | 39 | @Bean 40 | public WebServiceMessageSender webServiceMessageSender() { 41 | HttpComponentsMessageSender httpComponentsMessageSender = new HttpComponentsMessageSender(); 42 | // timeout for creating a connection 43 | httpComponentsMessageSender.setConnectionTimeout(timeout); 44 | // when you have a connection, timeout the read blocks for 45 | httpComponentsMessageSender.setReadTimeout(timeout); 46 | 47 | return httpComponentsMessageSender; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /spring-ws-timeout-httpclient/src/main/java/com/codenotfound/ws/client/TicketAgentClient.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.client; 2 | 3 | import java.math.BigInteger; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | import javax.xml.bind.JAXBElement; 8 | 9 | import org.example.ticketagent.ObjectFactory; 10 | import org.example.ticketagent.TFlightsResponse; 11 | import org.example.ticketagent.TListFlights; 12 | import org.slf4j.Logger; 13 | import org.slf4j.LoggerFactory; 14 | import org.springframework.beans.factory.annotation.Autowired; 15 | import org.springframework.stereotype.Component; 16 | import org.springframework.ws.client.core.WebServiceTemplate; 17 | 18 | @Component 19 | public class TicketAgentClient { 20 | 21 | private static final Logger LOGGER = LoggerFactory.getLogger(TicketAgentClient.class); 22 | 23 | @Autowired 24 | private WebServiceTemplate webServiceTemplate; 25 | 26 | @SuppressWarnings("unchecked") 27 | public List listFlights() { 28 | ObjectFactory factory = new ObjectFactory(); 29 | TListFlights tListFlights = factory.createTListFlights(); 30 | 31 | JAXBElement request = factory.createListFlightsRequest(tListFlights); 32 | JAXBElement response = null; 33 | 34 | try { 35 | response = (JAXBElement) webServiceTemplate.marshalSendAndReceive(request); 36 | return response.getValue().getFlightNumber(); 37 | } catch (Exception e) { 38 | LOGGER.error(e.getMessage()); 39 | // TODO handle the exception 40 | return new ArrayList<>(); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /spring-ws-timeout-httpclient/src/main/java/com/codenotfound/ws/endpoint/TicketAgentEndpoint.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.endpoint; 2 | 3 | import java.math.BigInteger; 4 | 5 | import javax.xml.bind.JAXBElement; 6 | 7 | import org.example.ticketagent.ObjectFactory; 8 | import org.example.ticketagent.TFlightsResponse; 9 | import org.example.ticketagent.TListFlights; 10 | import org.springframework.ws.server.endpoint.annotation.Endpoint; 11 | import org.springframework.ws.server.endpoint.annotation.PayloadRoot; 12 | import org.springframework.ws.server.endpoint.annotation.RequestPayload; 13 | import org.springframework.ws.server.endpoint.annotation.ResponsePayload; 14 | 15 | @Endpoint 16 | public class TicketAgentEndpoint { 17 | 18 | @PayloadRoot(namespace = "http://example.org/TicketAgent.xsd", localPart = "listFlightsRequest") 19 | @ResponsePayload 20 | public JAXBElement listFlights( 21 | @RequestPayload JAXBElement request) throws InterruptedException { 22 | 23 | // sleep for 10 seconds so a timeout occurs 24 | Thread.sleep(10 * 1000); 25 | 26 | ObjectFactory factory = new ObjectFactory(); 27 | TFlightsResponse tFlightsResponse = factory.createTFlightsResponse(); 28 | tFlightsResponse.getFlightNumber().add(BigInteger.valueOf(101)); 29 | 30 | return factory.createListFlightsResponse(tFlightsResponse); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /spring-ws-timeout-httpclient/src/main/java/com/codenotfound/ws/endpoint/WebServiceConfig.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.endpoint; 2 | 3 | import org.springframework.boot.web.servlet.ServletRegistrationBean; 4 | import org.springframework.context.ApplicationContext; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.core.io.ClassPathResource; 8 | import org.springframework.ws.config.annotation.EnableWs; 9 | import org.springframework.ws.config.annotation.WsConfigurerAdapter; 10 | import org.springframework.ws.transport.http.MessageDispatcherServlet; 11 | import org.springframework.ws.wsdl.wsdl11.SimpleWsdl11Definition; 12 | import org.springframework.ws.wsdl.wsdl11.Wsdl11Definition; 13 | 14 | @EnableWs 15 | @Configuration 16 | public class WebServiceConfig extends WsConfigurerAdapter { 17 | 18 | @Bean 19 | public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) { 20 | MessageDispatcherServlet servlet = new MessageDispatcherServlet(); 21 | servlet.setApplicationContext(applicationContext); 22 | 23 | return new ServletRegistrationBean(servlet, "/codenotfound/ws/*"); 24 | } 25 | 26 | @Bean(name = "ticketagent") 27 | public Wsdl11Definition defaultWsdl11Definition() { 28 | SimpleWsdl11Definition wsdl11Definition = new SimpleWsdl11Definition(); 29 | wsdl11Definition.setWsdl(new ClassPathResource("/wsdl/ticketagent.wsdl")); 30 | 31 | return wsdl11Definition; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /spring-ws-timeout-httpclient/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | client: 2 | default-uri: http://localhost:9090/codenotfound/ws/helloworld 3 | timeout: 2000 4 | 5 | server: 6 | port: 9090 7 | -------------------------------------------------------------------------------- /spring-ws-timeout-httpclient/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /spring-ws-timeout-httpclient/src/test/java/com/codenotfound/ws/SpringWsApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import java.math.BigInteger; 6 | import java.util.List; 7 | 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.boot.test.context.SpringBootTest; 12 | import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; 13 | import org.springframework.test.context.junit4.SpringRunner; 14 | 15 | import com.codenotfound.ws.client.TicketAgentClient; 16 | 17 | @RunWith(SpringRunner.class) 18 | @SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT) 19 | public class SpringWsApplicationTests { 20 | 21 | @Autowired 22 | private TicketAgentClient ticketAgentClient; 23 | 24 | @Test 25 | public void testListFlights() { 26 | List flights = ticketAgentClient.listFlights(); 27 | 28 | assertThat(flights.size()).isEqualTo(0); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /spring-ws-tolerant-reader/README.md: -------------------------------------------------------------------------------- 1 | # spring-ws-tolerant-reader 2 | 3 | [![Quality Gate](https://sonarcloud.io/api/badges/gate?key=com.codenotfound:spring-ws-tolerant-reader)](https://sonarcloud.io/dashboard/index/com.codenotfound:spring-ws-tolerant-reader) 4 | 5 | A detailed step-by-step tutorial on how to implement a soap tolerant reader using Spring-WS and Spring Boot. 6 | 7 | [https://www.codenotfound.com/spring-ws-soap-tolerant-reader-example.html](https://www.codenotfound.com/spring-ws-soap-tolerant-reader-example.html) 8 | -------------------------------------------------------------------------------- /spring-ws-tolerant-reader/src/main/java/com/codenotfound/ws/SpringWsApplication.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringWsApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringWsApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spring-ws-tolerant-reader/src/main/java/com/codenotfound/ws/client/ClientConfig.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.client; 2 | 3 | import org.springframework.beans.factory.annotation.Value; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.oxm.jaxb.Jaxb2Marshaller; 7 | import org.springframework.ws.client.core.WebServiceTemplate; 8 | import org.springframework.xml.xpath.XPathExpression; 9 | import org.springframework.xml.xpath.XPathExpressionFactory; 10 | 11 | @Configuration 12 | public class ClientConfig { 13 | 14 | @Value("${client.default-uri}") 15 | private String defaultUri; 16 | 17 | @Value("${client.xpath.order}") 18 | private String orderXPath; 19 | 20 | @Value("${client.xpath.order-id}") 21 | private String orderIdXPath; 22 | 23 | @Bean 24 | public XPathExpression orderXPath() { 25 | return XPathExpressionFactory.createXPathExpression(orderXPath); 26 | } 27 | 28 | @Bean 29 | public XPathExpression orderIdXPath() { 30 | return XPathExpressionFactory.createXPathExpression(orderIdXPath); 31 | } 32 | 33 | @Bean 34 | Jaxb2Marshaller jaxb2Marshaller() { 35 | Jaxb2Marshaller jaxb2Marshaller = new Jaxb2Marshaller(); 36 | jaxb2Marshaller.setContextPath("com.codenotfound.types.orderhistory"); 37 | 38 | return jaxb2Marshaller; 39 | } 40 | 41 | @Bean 42 | public WebServiceTemplate webServiceTemplate() { 43 | WebServiceTemplate webServiceTemplate = new WebServiceTemplate(); 44 | webServiceTemplate.setMarshaller(jaxb2Marshaller()); 45 | webServiceTemplate.setUnmarshaller(jaxb2Marshaller()); 46 | webServiceTemplate.setDefaultUri(defaultUri); 47 | 48 | return webServiceTemplate; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /spring-ws-tolerant-reader/src/main/java/com/codenotfound/ws/endpoint/WebServiceConfig.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.endpoint; 2 | 3 | import org.springframework.boot.web.servlet.ServletRegistrationBean; 4 | import org.springframework.context.ApplicationContext; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.core.io.ClassPathResource; 8 | import org.springframework.ws.config.annotation.EnableWs; 9 | import org.springframework.ws.config.annotation.WsConfigurerAdapter; 10 | import org.springframework.ws.transport.http.MessageDispatcherServlet; 11 | import org.springframework.ws.wsdl.wsdl11.SimpleWsdl11Definition; 12 | import org.springframework.ws.wsdl.wsdl11.Wsdl11Definition; 13 | 14 | @EnableWs 15 | @Configuration 16 | public class WebServiceConfig extends WsConfigurerAdapter { 17 | 18 | @Bean 19 | public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) { 20 | 21 | MessageDispatcherServlet servlet = new MessageDispatcherServlet(); 22 | servlet.setApplicationContext(applicationContext); 23 | 24 | return new ServletRegistrationBean(servlet, "/codenotfound/ws/*"); 25 | } 26 | 27 | @Bean(name = "orderhistory") 28 | public Wsdl11Definition defaultWsdl11Definition() { 29 | SimpleWsdl11Definition wsdl11Definition = new SimpleWsdl11Definition(); 30 | wsdl11Definition.setWsdl(new ClassPathResource("/wsdl/orderhistory.wsdl")); 31 | 32 | return wsdl11Definition; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /spring-ws-tolerant-reader/src/main/java/com/codenotfound/ws/model/Order.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.model; 2 | 3 | public class Order { 4 | 5 | private String orderId; 6 | 7 | public Order(String orderId) { 8 | this.orderId = orderId; 9 | } 10 | 11 | public String getOrderId() { 12 | return orderId; 13 | } 14 | 15 | public void setOrderId(String orderId) { 16 | this.orderId = orderId; 17 | } 18 | 19 | @Override 20 | public String toString() { 21 | return "Order[orderId=" + orderId + "]"; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /spring-ws-tolerant-reader/src/main/java/com/codenotfound/ws/model/OrderHistory.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.model; 2 | 3 | import java.util.List; 4 | 5 | public class OrderHistory { 6 | 7 | private List orders; 8 | 9 | public List getOrders() { 10 | return orders; 11 | } 12 | 13 | public void setOrders(List orders) { 14 | this.orders = orders; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /spring-ws-tolerant-reader/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | client: 2 | default-uri: http://localhost:9090/codenotfound/ws/orderhistory 3 | xpath: 4 | order: //*[local-name()='order'] 5 | order-id: .//*[local-name()='orderId'] 6 | 7 | server: 8 | port: 9090 9 | -------------------------------------------------------------------------------- /spring-ws-tolerant-reader/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /spring-ws-unit-test/src/main/java/com/codenotfound/order/OrderApplication.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.order; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class OrderApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(OrderApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spring-ws-unit-test/src/main/java/com/codenotfound/order/client/ClientConfig.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.order.client; 2 | 3 | import org.springframework.beans.factory.annotation.Value; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.oxm.jaxb.Jaxb2Marshaller; 7 | import org.springframework.ws.client.core.WebServiceTemplate; 8 | 9 | @Configuration 10 | public class ClientConfig { 11 | 12 | @Value("${order.address}") 13 | private String orderAddress; 14 | 15 | @Bean 16 | Jaxb2Marshaller jaxb2Marshaller() { 17 | 18 | Jaxb2Marshaller jaxb2Marshaller = new Jaxb2Marshaller(); 19 | jaxb2Marshaller.setContextPath("com.codenotfound.types.order"); 20 | return jaxb2Marshaller; 21 | } 22 | 23 | @Bean 24 | public WebServiceTemplate webServiceTemplate() { 25 | 26 | WebServiceTemplate webServiceTemplate = new WebServiceTemplate(); 27 | webServiceTemplate.setMarshaller(jaxb2Marshaller()); 28 | webServiceTemplate.setUnmarshaller(jaxb2Marshaller()); 29 | webServiceTemplate.setDefaultUri(orderAddress); 30 | 31 | return webServiceTemplate; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /spring-ws-unit-test/src/main/java/com/codenotfound/order/client/CreateOrderClient.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.order.client; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Component; 7 | import org.springframework.ws.client.core.WebServiceTemplate; 8 | 9 | import com.codenotfound.types.order.CustomerType; 10 | import com.codenotfound.types.order.LineItemsType; 11 | import com.codenotfound.types.order.ObjectFactory; 12 | import com.codenotfound.types.order.Order; 13 | import com.codenotfound.types.order.OrderConfirmation; 14 | 15 | @Component 16 | public class CreateOrderClient { 17 | 18 | private static final Logger LOGGER = LoggerFactory 19 | .getLogger(CreateOrderClient.class); 20 | 21 | @Autowired 22 | private WebServiceTemplate webServiceTemplate; 23 | 24 | public OrderConfirmation createOrder(CustomerType customer, 25 | LineItemsType lineItems) { 26 | 27 | ObjectFactory factory = new ObjectFactory(); 28 | Order order = factory.createOrder(); 29 | 30 | order.setCustomer(customer); 31 | order.setLineItems(lineItems); 32 | 33 | LOGGER.info( 34 | "Client sending order for Customer[firstName={},lastName={}]", 35 | customer.getFirstName(), customer.getLastName()); 36 | 37 | OrderConfirmation orderConfirmation = (OrderConfirmation) webServiceTemplate 38 | .marshalSendAndReceive(order); 39 | 40 | LOGGER.info("Client received orderConfirmationId='{}'", 41 | orderConfirmation.getConfirmationId()); 42 | return orderConfirmation; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /spring-ws-unit-test/src/main/java/com/codenotfound/order/endpoint/CreateOrderEndpoint.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.order.endpoint; 2 | 3 | import java.util.UUID; 4 | 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | import org.springframework.ws.server.endpoint.annotation.Endpoint; 8 | import org.springframework.ws.server.endpoint.annotation.PayloadRoot; 9 | import org.springframework.ws.server.endpoint.annotation.RequestPayload; 10 | import org.springframework.ws.server.endpoint.annotation.ResponsePayload; 11 | 12 | import com.codenotfound.types.order.ObjectFactory; 13 | import com.codenotfound.types.order.Order; 14 | import com.codenotfound.types.order.OrderConfirmation; 15 | 16 | @Endpoint 17 | public class CreateOrderEndpoint { 18 | 19 | private static final Logger LOGGER = LoggerFactory 20 | .getLogger(CreateOrderEndpoint.class); 21 | 22 | private static final String NAMESPACE_URI = "http://codenotfound.com/types/order"; 23 | 24 | @PayloadRoot(namespace = NAMESPACE_URI, localPart = "order") 25 | @ResponsePayload 26 | public OrderConfirmation createOrder(@RequestPayload Order request) { 27 | LOGGER.info( 28 | "Endpoint received order for Customer[firstName={},lastName={}]", 29 | request.getCustomer().getFirstName(), 30 | request.getCustomer().getLastName()); 31 | 32 | // process order 33 | 34 | ObjectFactory factory = new ObjectFactory(); 35 | OrderConfirmation response = factory.createOrderConfirmation(); 36 | response.setConfirmationId(UUID.randomUUID().toString()); 37 | 38 | LOGGER.info("Endpoint sending orderConfirmationId='{}'", 39 | response.getConfirmationId()); 40 | return response; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /spring-ws-unit-test/src/main/java/com/codenotfound/order/endpoint/WebServiceConfig.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.order.endpoint; 2 | 3 | import org.springframework.boot.web.servlet.ServletRegistrationBean; 4 | import org.springframework.context.ApplicationContext; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.core.io.ClassPathResource; 8 | import org.springframework.ws.config.annotation.EnableWs; 9 | import org.springframework.ws.config.annotation.WsConfigurerAdapter; 10 | import org.springframework.ws.transport.http.MessageDispatcherServlet; 11 | import org.springframework.ws.wsdl.wsdl11.SimpleWsdl11Definition; 12 | import org.springframework.ws.wsdl.wsdl11.Wsdl11Definition; 13 | 14 | @EnableWs 15 | @Configuration 16 | public class WebServiceConfig extends WsConfigurerAdapter { 17 | 18 | @Bean 19 | public ServletRegistrationBean messageDispatcherServlet( 20 | ApplicationContext applicationContext) { 21 | 22 | MessageDispatcherServlet servlet = new MessageDispatcherServlet(); 23 | servlet.setApplicationContext(applicationContext); 24 | 25 | return new ServletRegistrationBean(servlet, 26 | "/codenotfound/ws/*"); 27 | } 28 | 29 | @Bean(name = "order") 30 | public Wsdl11Definition defaultWsdl11Definition() { 31 | SimpleWsdl11Definition wsdl11Definition = new SimpleWsdl11Definition(); 32 | wsdl11Definition.setWsdl( 33 | new ClassPathResource("/wsdl/order.wsdl")); 34 | 35 | return wsdl11Definition; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /spring-ws-unit-test/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | # Address of the Order service 2 | order.address=http://localhost:9090/codenotfound/ws/order 3 | 4 | # Server HTTP port 5 | server.port=9090 6 | 7 | # Log file name. For instance `myapp.log` 8 | logging.file=spring-ws-unit-test.log 9 | # Log levels severity mapping. For instance `logging.level.org.springframework=DEBUG` 10 | logging.level.org.springframework=INFO 11 | logging.level.com.codenotfound.order=INFO -------------------------------------------------------------------------------- /spring-ws-unit-test/src/test/java/com/codenotfound/order/endpoint/CreateOrderEndpointTest.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.order.endpoint; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import java.math.BigInteger; 6 | 7 | import org.junit.Before; 8 | import org.junit.Test; 9 | 10 | import com.codenotfound.order.endpoint.CreateOrderEndpoint; 11 | import com.codenotfound.types.order.CustomerType; 12 | import com.codenotfound.types.order.LineItemType; 13 | import com.codenotfound.types.order.LineItemsType; 14 | import com.codenotfound.types.order.ObjectFactory; 15 | import com.codenotfound.types.order.Order; 16 | import com.codenotfound.types.order.ProductType; 17 | 18 | public class CreateOrderEndpointTest { 19 | 20 | private CreateOrderEndpoint createOrderEndpoint = new CreateOrderEndpoint(); 21 | 22 | private Order order; 23 | 24 | @Before 25 | public void setUp() throws Exception { 26 | ObjectFactory factory = new ObjectFactory(); 27 | 28 | CustomerType customer = factory.createCustomerType(); 29 | customer.setFirstName("John"); 30 | customer.setLastName("Doe"); 31 | 32 | ProductType product1 = factory.createProductType(); 33 | product1.setId("1"); 34 | product1.setName("batman action figure"); 35 | 36 | LineItemType lineItem1 = factory.createLineItemType(); 37 | lineItem1.setProduct(product1); 38 | lineItem1.setQuantity(BigInteger.valueOf(1)); 39 | 40 | LineItemsType lineItems = factory.createLineItemsType(); 41 | lineItems.getLineItem().add(lineItem1); 42 | 43 | order = factory.createOrder(); 44 | order.setCustomer(customer); 45 | order.setLineItems(lineItems); 46 | } 47 | 48 | @Test 49 | public void testCreateOrder() { 50 | assertThat(createOrderEndpoint.createOrder(order) 51 | .getConfirmationId()).isNotBlank(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /spring-ws-unit-test/src/test/resources/application.properties: -------------------------------------------------------------------------------- 1 | # Address of the Order service 2 | order.address=http://localhost:9080/codenotfound/ws/order 3 | 4 | # Server HTTP port 5 | server.port=9080 6 | 7 | # Log file name. For instance `myapp.log` 8 | logging.file=spring-ws-unit-test-test.log 9 | # Log levels severity mapping. For instance `logging.level.org.springframework=DEBUG` 10 | logging.level.org.springframework=INFO 11 | logging.level.com.codenotfound.order=DEBUG -------------------------------------------------------------------------------- /spring-ws-wsdl-url-redirect/README.md: -------------------------------------------------------------------------------- 1 | # spring-ws-wsdl-url-redirect 2 | 3 | [https://www.codenotfound.com/spring-ws/](https://www.codenotfound.com/spring-ws/) 4 | -------------------------------------------------------------------------------- /spring-ws-wsdl-url-redirect/src/main/java/com/codenotfound/ws/SpringWsApplication.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringWsApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringWsApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spring-ws-wsdl-url-redirect/src/main/java/com/codenotfound/ws/client/ClientConfig.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.client; 2 | 3 | import org.springframework.beans.factory.annotation.Value; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.oxm.jaxb.Jaxb2Marshaller; 7 | import org.springframework.ws.client.core.WebServiceTemplate; 8 | 9 | @Configuration 10 | public class ClientConfig { 11 | 12 | @Value("${client.default-uri}") 13 | private String defaultUri; 14 | 15 | @Bean 16 | Jaxb2Marshaller jaxb2Marshaller() { 17 | 18 | Jaxb2Marshaller jaxb2Marshaller = new Jaxb2Marshaller(); 19 | jaxb2Marshaller.setContextPath("org.example.ticketagent"); 20 | return jaxb2Marshaller; 21 | } 22 | 23 | @Bean 24 | public WebServiceTemplate webServiceTemplate() { 25 | 26 | WebServiceTemplate webServiceTemplate = new WebServiceTemplate(); 27 | webServiceTemplate.setMarshaller(jaxb2Marshaller()); 28 | webServiceTemplate.setUnmarshaller(jaxb2Marshaller()); 29 | webServiceTemplate.setDefaultUri(defaultUri); 30 | 31 | return webServiceTemplate; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /spring-ws-wsdl-url-redirect/src/main/java/com/codenotfound/ws/client/TicketAgentClient.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.client; 2 | 3 | import java.math.BigInteger; 4 | import java.util.List; 5 | 6 | import javax.xml.bind.JAXBElement; 7 | 8 | import org.example.ticketagent.ObjectFactory; 9 | import org.example.ticketagent.TFlightsResponse; 10 | import org.example.ticketagent.TListFlights; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.stereotype.Component; 13 | import org.springframework.ws.client.core.WebServiceTemplate; 14 | 15 | @Component 16 | public class TicketAgentClient { 17 | 18 | @Autowired 19 | private WebServiceTemplate webServiceTemplate; 20 | 21 | @SuppressWarnings("unchecked") 22 | public List listFlights() { 23 | 24 | ObjectFactory factory = new ObjectFactory(); 25 | TListFlights tListFlights = factory.createTListFlights(); 26 | 27 | JAXBElement request = factory.createListFlightsRequest(tListFlights); 28 | 29 | JAXBElement response = 30 | (JAXBElement) webServiceTemplate.marshalSendAndReceive(request); 31 | 32 | return response.getValue().getFlightNumber(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /spring-ws-wsdl-url-redirect/src/main/java/com/codenotfound/ws/endpoint/QuestionMarkFilter.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.endpoint; 2 | 3 | import java.io.IOException; 4 | 5 | import javax.servlet.Filter; 6 | import javax.servlet.FilterChain; 7 | import javax.servlet.FilterConfig; 8 | import javax.servlet.ServletException; 9 | import javax.servlet.ServletRequest; 10 | import javax.servlet.ServletResponse; 11 | import javax.servlet.http.HttpServletRequest; 12 | import javax.servlet.http.HttpServletResponse; 13 | 14 | import org.springframework.stereotype.Component; 15 | 16 | @Component 17 | public class QuestionMarkFilter implements Filter { 18 | 19 | @Override 20 | public void doFilter(ServletRequest servletRequest, 21 | ServletResponse servletResponse, FilterChain chain) 22 | throws IOException, ServletException { 23 | HttpServletRequest httpServletRequest = 24 | (HttpServletRequest) servletRequest; 25 | HttpServletResponse httpServletResponse = 26 | (HttpServletResponse) servletResponse; 27 | 28 | if (httpServletRequest.getQueryString() != null 29 | && httpServletRequest.getQueryString().toLowerCase() 30 | .endsWith("wsdl")) { 31 | // redirect 32 | httpServletResponse 33 | .sendRedirect(httpServletRequest.getContextPath() 34 | + "/codenotfound/ws/ticketagent.wsdl"); 35 | } else { 36 | // do nothing 37 | chain.doFilter(servletRequest, servletResponse); 38 | } 39 | } 40 | 41 | @Override 42 | public void init(FilterConfig filterConfig) { 43 | // empty 44 | } 45 | 46 | @Override 47 | public void destroy() { 48 | // empty 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /spring-ws-wsdl-url-redirect/src/main/java/com/codenotfound/ws/endpoint/TicketAgentEndpoint.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.endpoint; 2 | 3 | import java.math.BigInteger; 4 | 5 | import javax.xml.bind.JAXBElement; 6 | 7 | import org.example.ticketagent.ObjectFactory; 8 | import org.example.ticketagent.TFlightsResponse; 9 | import org.example.ticketagent.TListFlights; 10 | import org.springframework.ws.server.endpoint.annotation.Endpoint; 11 | import org.springframework.ws.server.endpoint.annotation.PayloadRoot; 12 | import org.springframework.ws.server.endpoint.annotation.RequestPayload; 13 | import org.springframework.ws.server.endpoint.annotation.ResponsePayload; 14 | 15 | @Endpoint 16 | public class TicketAgentEndpoint { 17 | 18 | @PayloadRoot(namespace = "http://example.org/TicketAgent.xsd", localPart = "listFlightsRequest") 19 | @ResponsePayload 20 | public JAXBElement listFlights( 21 | @RequestPayload JAXBElement request) { 22 | 23 | ObjectFactory factory = new ObjectFactory(); 24 | TFlightsResponse tFlightsResponse = factory.createTFlightsResponse(); 25 | tFlightsResponse.getFlightNumber().add(BigInteger.valueOf(101)); 26 | 27 | return factory.createListFlightsResponse(tFlightsResponse); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /spring-ws-wsdl-url-redirect/src/main/java/com/codenotfound/ws/endpoint/WebServiceConfig.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws.endpoint; 2 | 3 | import org.springframework.boot.web.servlet.ServletRegistrationBean; 4 | import org.springframework.context.ApplicationContext; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.core.io.ClassPathResource; 8 | import org.springframework.ws.config.annotation.EnableWs; 9 | import org.springframework.ws.config.annotation.WsConfigurerAdapter; 10 | import org.springframework.ws.transport.http.MessageDispatcherServlet; 11 | import org.springframework.ws.wsdl.wsdl11.SimpleWsdl11Definition; 12 | import org.springframework.ws.wsdl.wsdl11.Wsdl11Definition; 13 | 14 | @EnableWs 15 | @Configuration 16 | public class WebServiceConfig extends WsConfigurerAdapter { 17 | 18 | @Bean 19 | public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) { 20 | 21 | MessageDispatcherServlet servlet = new MessageDispatcherServlet(); 22 | servlet.setApplicationContext(applicationContext); 23 | 24 | return new ServletRegistrationBean(servlet, "/codenotfound/ws/*"); 25 | } 26 | 27 | @Bean(name = "ticketagent") 28 | public Wsdl11Definition defaultWsdl11Definition() { 29 | SimpleWsdl11Definition wsdl11Definition = new SimpleWsdl11Definition(); 30 | wsdl11Definition.setWsdl(new ClassPathResource("/wsdl/ticketagent.wsdl")); 31 | 32 | return wsdl11Definition; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /spring-ws-wsdl-url-redirect/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | client: 2 | default-uri: http://localhost:9090/codenotfound/ws/helloworld 3 | 4 | server: 5 | port: 9090 6 | -------------------------------------------------------------------------------- /spring-ws-wsdl-url-redirect/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /spring-ws-wsdl-url-redirect/src/test/java/com/codenotfound/ws/SpringWsApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.ws; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import java.math.BigInteger; 6 | import java.util.List; 7 | 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.boot.test.context.SpringBootTest; 12 | import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; 13 | import org.springframework.test.context.junit4.SpringRunner; 14 | 15 | import com.codenotfound.ws.client.TicketAgentClient; 16 | 17 | @RunWith(SpringRunner.class) 18 | @SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT) 19 | public class SpringWsApplicationTests { 20 | 21 | @Autowired 22 | private TicketAgentClient ticketAgentClient; 23 | 24 | @Test 25 | public void testListFlights() { 26 | List flights = ticketAgentClient.listFlights(); 27 | 28 | assertThat(flights.get(0)).isEqualTo(BigInteger.valueOf(101)); 29 | } 30 | } 31 | --------------------------------------------------------------------------------