├── .gitignore ├── LICENSE ├── README.md ├── pom.xml ├── step10_simple_app_with_cxf-spring-boot-starter ├── pom.xml └── src │ ├── main │ ├── java │ │ └── de │ │ │ └── jonashackt │ │ │ └── tutorial │ │ │ ├── SimpleBootCxfApplication.java │ │ │ ├── common │ │ │ └── CustomIds.java │ │ │ ├── configuration │ │ │ └── SimpleBootCxfConfiguration.java │ │ │ ├── controller │ │ │ └── WeatherServiceController.java │ │ │ ├── endpoint │ │ │ └── WeatherServiceEndpoint.java │ │ │ ├── transformation │ │ │ └── GetCityForecastByZIPOutMapper.java │ │ │ └── xmlvalidation │ │ │ └── WeatherFaultBuilder.java │ └── resources │ │ ├── application.properties │ │ ├── logback-spring.xml │ │ └── service-api-definition │ │ ├── Weather-Schemes │ │ ├── w3c-xmlmime-definition.xsd │ │ ├── weather-datatypes.xsd │ │ ├── weather-exception.xsd │ │ └── weather-general.xsd │ │ ├── Weather1.0.wsdl │ │ └── Weather1.0.xsd │ └── test │ ├── java │ └── de │ │ └── jonashackt │ │ └── tutorial │ │ ├── SimpleBootCxfSystemTestApplication.java │ │ ├── SimpleBootCxfSystemTestConfiguration.java │ │ ├── endpoint │ │ └── WeatherServiceXmlFileSystemTest.java │ │ └── xmlvalidation │ │ └── WeatherServiceXmlErrorSystemTest.java │ └── resources │ └── requests │ ├── GetCityForecastByZIPTest.xml │ └── xmlerrors │ ├── xmlErrorNotXmlSchemeCompliantRootElementTest.xml │ ├── xmlErrorNotXmlSchemeCompliantUnderRootElementTest.xml │ ├── xmlErrorSoapBodyTagMissingBracketTest.xml │ ├── xmlErrorSoapEnvelopeTagMissingBracketTest.xml │ ├── xmlErrorSoapHeaderMissingSlash.xml │ ├── xmlErrorSoapHeaderTagMissingBracketTest.xml │ ├── xmlErrorXMLHeaderDefinitionMissingBracket.xml │ └── xmlErrorXMLTagNotClosedInsideBodyTest.xml ├── step1_simple_springboot_app_with_cxf ├── pom.xml └── src │ ├── main │ ├── java │ │ └── de │ │ │ └── jonashackt │ │ │ └── tutorial │ │ │ └── SimpleBootCxfApplication.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── de │ └── jonashackt │ └── tutorial │ └── SimpleBootCxfApplicationTests.java ├── step2_wsdl_2_java_maven ├── pom.xml └── src │ ├── main │ ├── java │ │ └── de │ │ │ └── jonashackt │ │ │ └── tutorial │ │ │ └── SimpleBootCxfApplication.java │ └── resources │ │ ├── application.properties │ │ └── service-api-definition │ │ ├── Weather-Schemes │ │ ├── w3c-xmlmime-definition.xsd │ │ ├── weather-datatypes.xsd │ │ ├── weather-exception.xsd │ │ └── weather-general.xsd │ │ ├── Weather1.0.wsdl │ │ └── Weather1.0.xsd │ └── test │ └── java │ └── de │ └── jonashackt │ └── tutorial │ └── SimpleBootCxfApplicationTests.java ├── step3_jaxws-endpoint-cxf-spring-boot-orig-wsdl ├── pom.xml └── src │ ├── main │ ├── java │ │ └── de │ │ │ └── jonashackt │ │ │ └── tutorial │ │ │ ├── SimpleBootCxfApplication.java │ │ │ ├── configuration │ │ │ └── WebServiceConfiguration.java │ │ │ └── endpoint │ │ │ └── WeatherServiceEndpoint.java │ └── resources │ │ ├── application.properties │ │ └── service-api-definition │ │ ├── Weather-Schemes │ │ ├── w3c-xmlmime-definition.xsd │ │ ├── weather-datatypes.xsd │ │ ├── weather-exception.xsd │ │ └── weather-general.xsd │ │ ├── Weather1.0.wsdl │ │ └── Weather1.0.xsd │ └── test │ └── java │ └── de │ └── jonashackt │ └── tutorial │ └── SimpleBootCxfApplicationTests.java ├── step3_jaxws-endpoint-cxf-spring-boot ├── pom.xml └── src │ ├── main │ ├── java │ │ └── de │ │ │ └── jonashackt │ │ │ └── tutorial │ │ │ ├── SimpleBootCxfApplication.java │ │ │ ├── configuration │ │ │ └── WebServiceConfiguration.java │ │ │ └── endpoint │ │ │ └── WeatherServiceEndpoint.java │ └── resources │ │ ├── application.properties │ │ └── service-api-definition │ │ ├── Weather-Schemes │ │ ├── w3c-xmlmime-definition.xsd │ │ ├── weather-datatypes.xsd │ │ ├── weather-exception.xsd │ │ └── weather-general.xsd │ │ ├── Weather1.0.wsdl │ │ └── Weather1.0.xsd │ └── test │ └── java │ └── de │ └── jonashackt │ └── tutorial │ └── SimpleBootCxfApplicationTests.java ├── step4_test ├── pom.xml └── src │ ├── main │ ├── java │ │ └── de │ │ │ └── jonashackt │ │ │ └── tutorial │ │ │ ├── SimpleBootCxfApplication.java │ │ │ ├── configuration │ │ │ ├── ApplicationConfiguration.java │ │ │ └── WebServiceConfiguration.java │ │ │ ├── controller │ │ │ └── WeatherServiceController.java │ │ │ ├── endpoint │ │ │ └── WeatherServiceEndpoint.java │ │ │ └── transformation │ │ │ └── GetCityForecastByZIPOutMapper.java │ └── resources │ │ ├── application.properties │ │ └── service-api-definition │ │ ├── Weather-Schemes │ │ ├── w3c-xmlmime-definition.xsd │ │ ├── weather-datatypes.xsd │ │ ├── weather-exception.xsd │ │ └── weather-general.xsd │ │ ├── Weather1.0.wsdl │ │ └── Weather1.0.xsd │ └── test │ ├── java │ └── de │ │ └── jonashackt │ │ └── tutorial │ │ ├── ApplicationTestConfiguration.java │ │ ├── SimpleBootCxfSystemTestApplication.java │ │ ├── WebServiceIntegrationTestConfiguration.java │ │ ├── WebServiceSystemTestConfiguration.java │ │ ├── endpoint │ │ ├── WeatherServiceIntegrationTest.java │ │ ├── WeatherServiceSystemTest.java │ │ ├── WeatherServiceTest.java │ │ └── WeatherServiceXmlFileSystemTest.java │ │ └── utils │ │ ├── TestHelper.java │ │ ├── XmlUtils.java │ │ └── XmlUtilsException.java │ └── resources │ └── requests │ └── GetCityForecastByZIPTest.xml ├── step5_custom-soap-fault ├── pom.xml └── src │ ├── main │ ├── java │ │ └── de │ │ │ └── jonashackt │ │ │ └── tutorial │ │ │ ├── SimpleBootCxfApplication.java │ │ │ ├── common │ │ │ ├── FaultConst.java │ │ │ ├── InternalBusinessException.java │ │ │ └── XmlUtils.java │ │ │ ├── configuration │ │ │ ├── ApplicationConfiguration.java │ │ │ ├── WebServiceConfiguration.java │ │ │ └── customsoapfaults │ │ │ │ ├── CustomSoapFaultInterceptor.java │ │ │ │ └── WeatherSoapFaultHelper.java │ │ │ ├── controller │ │ │ └── WeatherServiceController.java │ │ │ ├── endpoint │ │ │ └── WeatherServiceEndpoint.java │ │ │ ├── logging │ │ │ └── SoapFrameworkLogger.java │ │ │ └── transformation │ │ │ ├── GetCityForecastByZIPOutMapper.java │ │ │ └── WeatherOutError.java │ └── resources │ │ ├── application.properties │ │ └── service-api-definition │ │ ├── Weather-Schemes │ │ ├── w3c-xmlmime-definition.xsd │ │ ├── weather-datatypes.xsd │ │ ├── weather-exception.xsd │ │ └── weather-general.xsd │ │ ├── Weather1.0.wsdl │ │ └── Weather1.0.xsd │ └── test │ ├── java │ └── de │ │ └── jonashackt │ │ └── tutorial │ │ ├── ApplicationTestConfiguration.java │ │ ├── SimpleBootCxfSystemTestApplication.java │ │ ├── WebServiceIntegrationTestConfiguration.java │ │ ├── WebServiceSystemTestConfiguration.java │ │ ├── endpoint │ │ ├── WeatherServiceIntegrationTest.java │ │ ├── WeatherServiceSystemTest.java │ │ ├── WeatherServiceTest.java │ │ ├── WeatherServiceXmlErrorSystemTest.java │ │ └── WeatherServiceXmlFileSystemTest.java │ │ └── utils │ │ ├── SoapRawClient.java │ │ ├── SoapRawClientResponse.java │ │ └── TestHelper.java │ └── resources │ └── requests │ ├── GetCityForecastByZIPTest.xml │ └── xmlerrors │ ├── xmlErrorNotXmlSchemeCompliantRootElementTest.xml │ ├── xmlErrorNotXmlSchemeCompliantUnderRootElementTest.xml │ ├── xmlErrorSoapBodyTagMissingBracketTest.xml │ ├── xmlErrorSoapEnvelopeTagMissingBracketTest.xml │ ├── xmlErrorSoapHeaderMissingSlash.xml │ ├── xmlErrorSoapHeaderTagMissingBracketTest.xml │ ├── xmlErrorXMLHeaderDefinitionMissingBracket.xml │ └── xmlErrorXMLTagNotClosedInsideBodyTest.xml ├── step6_soap_message_logging ├── pom.xml └── src │ ├── main │ ├── java │ │ └── de │ │ │ └── jonashackt │ │ │ └── tutorial │ │ │ ├── SimpleBootCxfApplication.java │ │ │ ├── configuration │ │ │ ├── ApplicationConfiguration.java │ │ │ └── WebServiceConfiguration.java │ │ │ ├── controller │ │ │ └── WeatherServiceController.java │ │ │ ├── endpoint │ │ │ └── WeatherServiceEndpoint.java │ │ │ └── transformation │ │ │ └── GetCityForecastByZIPOutMapper.java │ └── resources │ │ ├── META-INF │ │ └── cxf │ │ │ └── org.apache.cxf.Logger │ │ ├── application.properties │ │ ├── logback-spring.xml │ │ └── service-api-definition │ │ ├── Weather-Schemes │ │ ├── w3c-xmlmime-definition.xsd │ │ ├── weather-datatypes.xsd │ │ ├── weather-exception.xsd │ │ └── weather-general.xsd │ │ ├── Weather1.0.wsdl │ │ └── Weather1.0.xsd │ └── test │ ├── java │ └── de │ │ └── jonashackt │ │ └── tutorial │ │ ├── ApplicationTestConfiguration.java │ │ ├── SimpleBootCxfSystemTestApplication.java │ │ ├── WebServiceIntegrationTestConfiguration.java │ │ ├── WebServiceSystemTestConfiguration.java │ │ ├── endpoint │ │ ├── WeatherServiceIntegrationTest.java │ │ ├── WeatherServiceSystemTest.java │ │ ├── WeatherServiceTest.java │ │ └── WeatherServiceXmlFileSystemTest.java │ │ └── utils │ │ ├── TestHelper.java │ │ ├── XmlUtils.java │ │ └── XmlUtilsException.java │ └── resources │ └── requests │ └── GetCityForecastByZIPTest.xml ├── step7_soap_message_logging_payload_only ├── pom.xml └── src │ ├── main │ ├── java │ │ └── de │ │ │ └── jonashackt │ │ │ └── tutorial │ │ │ ├── SimpleBootCxfApplication.java │ │ │ ├── configuration │ │ │ ├── ApplicationConfiguration.java │ │ │ └── WebServiceConfiguration.java │ │ │ ├── controller │ │ │ └── WeatherServiceController.java │ │ │ ├── endpoint │ │ │ └── WeatherServiceEndpoint.java │ │ │ ├── soapmsglogging │ │ │ ├── LoggingInInterceptorXmlOnly.java │ │ │ └── LoggingOutInterceptorXmlOnly.java │ │ │ └── transformation │ │ │ └── GetCityForecastByZIPOutMapper.java │ └── resources │ │ ├── META-INF │ │ └── cxf │ │ │ └── org.apache.cxf.Logger │ │ ├── application.properties │ │ ├── logback-spring.xml │ │ └── service-api-definition │ │ ├── Weather-Schemes │ │ ├── w3c-xmlmime-definition.xsd │ │ ├── weather-datatypes.xsd │ │ ├── weather-exception.xsd │ │ └── weather-general.xsd │ │ ├── Weather1.0.wsdl │ │ └── Weather1.0.xsd │ └── test │ ├── java │ └── de │ │ └── jonashackt │ │ └── tutorial │ │ ├── ApplicationTestConfiguration.java │ │ ├── SimpleBootCxfSystemTestApplication.java │ │ ├── WebServiceIntegrationTestConfiguration.java │ │ ├── WebServiceSystemTestConfiguration.java │ │ ├── endpoint │ │ ├── WeatherServiceIntegrationTest.java │ │ ├── WeatherServiceSystemTest.java │ │ ├── WeatherServiceTest.java │ │ └── WeatherServiceXmlFileSystemTest.java │ │ └── utils │ │ ├── TestHelper.java │ │ ├── XmlUtils.java │ │ └── XmlUtilsException.java │ └── resources │ └── requests │ └── GetCityForecastByZIPTest.xml ├── step8_logging_into_elasticstack ├── pom.xml └── src │ ├── main │ ├── java │ │ └── de │ │ │ └── jonashackt │ │ │ └── tutorial │ │ │ ├── SimpleBootCxfApplication.java │ │ │ ├── configuration │ │ │ ├── ApplicationConfiguration.java │ │ │ └── WebServiceConfiguration.java │ │ │ ├── controller │ │ │ └── WeatherServiceController.java │ │ │ ├── endpoint │ │ │ └── WeatherServiceEndpoint.java │ │ │ ├── soapmsglogging │ │ │ ├── LoggingInInterceptorXmlOnly.java │ │ │ └── LoggingOutInterceptorXmlOnly.java │ │ │ └── transformation │ │ │ └── GetCityForecastByZIPOutMapper.java │ └── resources │ │ ├── META-INF │ │ └── cxf │ │ │ └── org.apache.cxf.Logger │ │ ├── application.properties │ │ ├── logback-spring.xml │ │ └── service-api-definition │ │ ├── Weather-Schemes │ │ ├── w3c-xmlmime-definition.xsd │ │ ├── weather-datatypes.xsd │ │ ├── weather-exception.xsd │ │ └── weather-general.xsd │ │ ├── Weather1.0.wsdl │ │ └── Weather1.0.xsd │ └── test │ ├── java │ └── de │ │ └── jonashackt │ │ └── tutorial │ │ ├── ApplicationTestConfiguration.java │ │ ├── SimpleBootCxfSystemTestApplication.java │ │ ├── WebServiceIntegrationTestConfiguration.java │ │ ├── WebServiceSystemTestConfiguration.java │ │ ├── endpoint │ │ ├── WeatherServiceIntegrationTest.java │ │ ├── WeatherServiceSystemTest.java │ │ ├── WeatherServiceTest.java │ │ └── WeatherServiceXmlFileSystemTest.java │ │ └── utils │ │ ├── TestHelper.java │ │ ├── XmlUtils.java │ │ └── XmlUtilsException.java │ └── resources │ └── requests │ └── GetCityForecastByZIPTest.xml └── step9_soap_message_logging_into_custom_elasticsearch_field ├── pom.xml └── src ├── main ├── java │ └── de │ │ └── jonashackt │ │ └── tutorial │ │ ├── SimpleBootCxfApplication.java │ │ ├── configuration │ │ ├── ApplicationConfiguration.java │ │ └── WebServiceConfiguration.java │ │ ├── controller │ │ └── WeatherServiceController.java │ │ ├── endpoint │ │ └── WeatherServiceEndpoint.java │ │ ├── soapmsglogging │ │ ├── LogCorrelationFilter.java │ │ ├── SoapMsgToMdcExtractionLoggingInInterceptor.java │ │ └── SoapMsgToMdcExtractionLoggingOutInterceptor.java │ │ └── transformation │ │ └── GetCityForecastByZIPOutMapper.java └── resources │ ├── META-INF │ └── cxf │ │ └── org.apache.cxf.Logger │ ├── application.properties │ ├── logback-spring.xml │ └── service-api-definition │ ├── Weather-Schemes │ ├── w3c-xmlmime-definition.xsd │ ├── weather-datatypes.xsd │ ├── weather-exception.xsd │ └── weather-general.xsd │ ├── Weather1.0.wsdl │ └── Weather1.0.xsd └── test ├── java └── de │ └── jonashackt │ └── tutorial │ ├── ApplicationTestConfiguration.java │ ├── SimpleBootCxfSystemTestApplication.java │ ├── WebServiceIntegrationTestConfiguration.java │ ├── WebServiceSystemTestConfiguration.java │ ├── endpoint │ ├── WeatherServiceIntegrationTest.java │ ├── WeatherServiceSystemTest.java │ ├── WeatherServiceTest.java │ └── WeatherServiceXmlFileSystemTest.java │ └── utils │ ├── TestHelper.java │ ├── XmlUtils.java │ └── XmlUtilsException.java └── resources └── requests └── GetCityForecastByZIPTest.xml /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | 3 | # Package Files # 4 | *.jar 5 | *.war 6 | *.ear 7 | 8 | # Eclipse # 9 | .settings 10 | .project 11 | .classpath 12 | .studio 13 | target 14 | 15 | # Apple # 16 | .DS_Store 17 | 18 | # Intellij # 19 | .idea 20 | *.iml 21 | *.log 22 | 23 | # logback 24 | logback.out.xml -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Jonas Hecht 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 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | de.jonashackt.tutorial 7 | build-all-tutorial-projects 8 | 0.0.1-SNAPSHOT 9 | pom 10 | 11 | 12 | step1_simple_springboot_app_with_cxf 13 | step2_wsdl_2_java_maven 14 | step3_jaxws-endpoint-cxf-spring-boot 15 | step3_jaxws-endpoint-cxf-spring-boot-orig-wsdl 16 | step4_test 17 | step5_custom-soap-fault 18 | step6_soap_message_logging 19 | step7_soap_message_logging_payload_only 20 | step8_logging_into_elasticstack 21 | step9_soap_message_logging_into_custom_elasticsearch_field 22 | step10_simple_app_with_cxf-spring-boot-starter 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /step10_simple_app_with_cxf-spring-boot-starter/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | de.jonashackt.tutorial 7 | step10_simple_app_with_cxf-spring-boot-starter 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | 12 | org.springframework.boot 13 | spring-boot-starter-parent 14 | 1.4.1.RELEASE 15 | 16 | 17 | 18 | 19 | UTF-8 20 | UTF-8 21 | 1.8 22 | 24 | 1.1.6 25 | 26 | 27 | 28 | 29 | de.codecentric 30 | cxf-spring-boot-starter 31 | 1.0.7.RELEASE 32 | 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-starter-test 37 | test 38 | 39 | 40 | 41 | 42 | 43 | 44 | org.springframework.boot 45 | spring-boot-maven-plugin 46 | 47 | 48 | de.codecentric 49 | cxf-spring-boot-starter-maven-plugin 50 | 1.0.7.RELEASE 51 | 52 | 53 | 54 | generate 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /step10_simple_app_with_cxf-spring-boot-starter/src/main/java/de/jonashackt/tutorial/SimpleBootCxfApplication.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SimpleBootCxfApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SimpleBootCxfApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /step10_simple_app_with_cxf-spring-boot-starter/src/main/java/de/jonashackt/tutorial/common/CustomIds.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.common; 2 | 3 | /** 4 | * Custom Ids and Messages for WeatherException-Detail 5 | */ 6 | public enum CustomIds { 7 | 8 | EVERYTHING_FINE("01", "The Weather-Call was successfully processed by the backend."), 9 | NON_XML_COMPLIANT("71", "XML-Scheme-validiation failed."), 10 | COMPLETE_USELESS_XML("72", "Syntactically incorrect XML."), 11 | SOMETHING_ELSE_WENT_TERRIBLY_WRONG("99", "Backend processing failed."); 12 | 13 | private String id; 14 | private String message; 15 | 16 | private CustomIds(String id, String text) { 17 | this.id = id; 18 | this.message = text; 19 | } 20 | 21 | public String getMessage() { 22 | return message; 23 | } 24 | 25 | public String getId() { 26 | return id; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /step10_simple_app_with_cxf-spring-boot-starter/src/main/java/de/jonashackt/tutorial/configuration/SimpleBootCxfConfiguration.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.configuration; 2 | 3 | import de.codecentric.cxf.xmlvalidation.CustomFaultBuilder; 4 | import de.codecentric.namespace.weatherservice.Weather; 5 | import de.codecentric.namespace.weatherservice.WeatherService; 6 | import de.jonashackt.tutorial.endpoint.WeatherServiceEndpoint; 7 | import de.jonashackt.tutorial.xmlvalidation.WeatherFaultBuilder; 8 | import org.apache.cxf.bus.spring.SpringBus; 9 | import org.apache.cxf.jaxws.EndpointImpl; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.context.annotation.Bean; 12 | import org.springframework.context.annotation.Configuration; 13 | 14 | import javax.xml.ws.Endpoint; 15 | 16 | @Configuration 17 | public class SimpleBootCxfConfiguration { 18 | 19 | public static final String SERVICE_URL = "/WeatherSoapService_1.0"; 20 | 21 | @Autowired 22 | private SpringBus springBus; 23 | 24 | @Bean 25 | public WeatherService weatherService() { 26 | return new WeatherServiceEndpoint(); 27 | } 28 | 29 | @Bean 30 | public Endpoint endpoint() { 31 | EndpointImpl endpoint = new EndpointImpl(springBus, weatherService()); 32 | endpoint.setServiceName(weatherClient().getServiceName()); 33 | endpoint.setWsdlLocation(weatherClient().getWSDLDocumentLocation().toString()); 34 | endpoint.publish(SERVICE_URL); 35 | return endpoint; 36 | } 37 | 38 | @Bean 39 | public Weather weatherClient() { 40 | return new Weather(); 41 | } 42 | 43 | @Bean 44 | public CustomFaultBuilder weatherFaultBuilder() { 45 | return new WeatherFaultBuilder(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /step10_simple_app_with_cxf-spring-boot-starter/src/main/java/de/jonashackt/tutorial/controller/WeatherServiceController.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.controller; 2 | 3 | import de.codecentric.namespace.weatherservice.general.ForecastRequest; 4 | import de.codecentric.namespace.weatherservice.general.ForecastReturn; 5 | import de.jonashackt.tutorial.transformation.GetCityForecastByZIPOutMapper; 6 | import org.springframework.stereotype.Controller; 7 | 8 | /* 9 | * Example-Controller: 10 | * This Class would be responsible for Mapping from Request to internal Datamodel (and backwards), 11 | * for calling Backend-Services and handling Backend-Exceptions 12 | * So it decouples the WSDL-generated Classes from the internal Classes - for when the former changes, 13 | * nothing or only the mapping has to be changed 14 | */ 15 | @Controller 16 | public class WeatherServiceController { 17 | 18 | public ForecastReturn getCityForecastByZIP(ForecastRequest forecastRequest) { 19 | /* 20 | * We leave out inbound transformation, plausibility-checking, logging, backend-calls e.g. 21 | * for the moment 22 | */ 23 | return GetCityForecastByZIPOutMapper.mapGeneralOutlook2Forecast(); 24 | } 25 | 26 | /* 27 | * Other Methods would follow here... 28 | */ 29 | //public WeatherReturn getCityWeatherByZIP(ForecastRequest forecastRequest) throws BusinessException {} 30 | 31 | //public WeatherInformationReturn getWeatherInformation(String zip) throws BusinessException {} 32 | } 33 | -------------------------------------------------------------------------------- /step10_simple_app_with_cxf-spring-boot-starter/src/main/java/de/jonashackt/tutorial/endpoint/WeatherServiceEndpoint.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.endpoint; 2 | 3 | import de.codecentric.namespace.weatherservice.WeatherException; 4 | import de.codecentric.namespace.weatherservice.WeatherService; 5 | import de.codecentric.namespace.weatherservice.general.ForecastRequest; 6 | import de.codecentric.namespace.weatherservice.general.ForecastReturn; 7 | import de.codecentric.namespace.weatherservice.general.WeatherInformationReturn; 8 | import de.codecentric.namespace.weatherservice.general.WeatherReturn; 9 | import de.jonashackt.tutorial.controller.WeatherServiceController; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | 12 | 13 | public class WeatherServiceEndpoint implements WeatherService { 14 | 15 | @Autowired 16 | private WeatherServiceController weatherServiceController; 17 | 18 | @Override 19 | public ForecastReturn getCityForecastByZIP(ForecastRequest forecastRequest) throws WeatherException { 20 | return weatherServiceController.getCityForecastByZIP(forecastRequest); 21 | } 22 | 23 | @Override 24 | public WeatherInformationReturn getWeatherInformation(String zip) 25 | throws WeatherException { 26 | // TODO Auto-generated method stub 27 | return null; 28 | } 29 | 30 | @Override 31 | public WeatherReturn getCityWeatherByZIP(ForecastRequest forecastRequest) 32 | throws WeatherException { 33 | // TODO Auto-generated method stub 34 | return null; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /step10_simple_app_with_cxf-spring-boot-starter/src/main/java/de/jonashackt/tutorial/xmlvalidation/WeatherFaultBuilder.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.xmlvalidation; 2 | 3 | import de.codecentric.cxf.common.FaultType; 4 | import de.codecentric.cxf.xmlvalidation.CustomFaultBuilder; 5 | import de.codecentric.namespace.weatherservice.exception.WeatherException; 6 | import de.jonashackt.tutorial.common.CustomIds; 7 | import org.springframework.stereotype.Component; 8 | 9 | @Component 10 | public class WeatherFaultBuilder implements CustomFaultBuilder { 11 | 12 | private de.codecentric.namespace.weatherservice.exception.ObjectFactory objectFactoryDatatypes = new de.codecentric.namespace.weatherservice.exception.ObjectFactory(); 13 | 14 | @Override 15 | public String createCustomFaultMessage(FaultType faultType) { 16 | if(FaultType.SCHEME_VALIDATION_ERROR.equals(faultType)) { 17 | return CustomIds.NON_XML_COMPLIANT.getMessage(); 18 | } 19 | else if(FaultType.SYNTACTICALLY_INCORRECT_XML_ERROR.equals(faultType)) { 20 | return CustomIds.COMPLETE_USELESS_XML.getMessage(); 21 | } 22 | else { 23 | return CustomIds.SOMETHING_ELSE_WENT_TERRIBLY_WRONG.getMessage(); 24 | } 25 | } 26 | 27 | @Override 28 | public WeatherException createCustomFaultDetail(String originalFaultMessage, FaultType faultType) { 29 | // Build SOAP-Fault detail 30 | WeatherException weatherException = objectFactoryDatatypes.createWeatherException(); 31 | weatherException.setBigBusinessErrorCausingMoneyLoss(true); 32 | setIdBasedUponFaultContent(faultType, weatherException); 33 | weatherException.setExceptionDetails(originalFaultMessage); 34 | weatherException.setUuid("ExtremeRandomNumber"); 35 | return weatherException; 36 | } 37 | 38 | private void setIdBasedUponFaultContent(FaultType faultType, WeatherException weatherException) { 39 | if(FaultType.SCHEME_VALIDATION_ERROR.equals(faultType)) { 40 | weatherException.setBusinessErrorId(CustomIds.NON_XML_COMPLIANT.getId()); 41 | } 42 | else if(FaultType.SYNTACTICALLY_INCORRECT_XML_ERROR.equals(faultType)) { 43 | weatherException.setBusinessErrorId(CustomIds.COMPLETE_USELESS_XML.getId()); 44 | } 45 | else { 46 | weatherException.setBusinessErrorId(CustomIds.SOMETHING_ELSE_WENT_TERRIBLY_WRONG.getId()); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /step10_simple_app_with_cxf-spring-boot-starter/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | #soap.service.base.url=/my-custom-api 2 | cxf.servicelist.title=Extremely customized List-Title 3 | soap.messages.logging=true 4 | soap.messages.extract=true -------------------------------------------------------------------------------- /step10_simple_app_with_cxf-spring-boot-starter/src/main/resources/logback-spring.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | localhost:5000 12 | 13 | 14 | true 15 | {"service_name":"WeatherService 1.0"} 16 | 17 | log-msg 18 | 19 | 20 | 5 minutes 21 | 22 | 23 | 24 | weather-service.log 25 | true 26 | 27 | %-4relative [%thread] %-5level %logger{35} - %msg%n 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /step10_simple_app_with_cxf-spring-boot-starter/src/main/resources/service-api-definition/Weather-Schemes/w3c-xmlmime-definition.xsd: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /step10_simple_app_with_cxf-spring-boot-starter/src/main/resources/service-api-definition/Weather-Schemes/weather-exception.xsd: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /step10_simple_app_with_cxf-spring-boot-starter/src/main/resources/service-api-definition/Weather1.0.xsd: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 12 | 13 | 15 | 16 | -------------------------------------------------------------------------------- /step10_simple_app_with_cxf-spring-boot-starter/src/test/java/de/jonashackt/tutorial/SimpleBootCxfSystemTestApplication.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.context.annotation.Import; 5 | 6 | @Configuration 7 | @Import({ 8 | SimpleBootCxfSystemTestConfiguration.class, 9 | SimpleBootCxfApplication.class 10 | }) 11 | public class SimpleBootCxfSystemTestApplication { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /step10_simple_app_with_cxf-spring-boot-starter/src/test/java/de/jonashackt/tutorial/SimpleBootCxfSystemTestConfiguration.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial; 2 | 3 | import de.codecentric.cxf.common.BootStarterCxfException; 4 | import de.codecentric.cxf.configuration.CxfAutoConfiguration; 5 | import de.codecentric.cxf.soaprawclient.SoapRawClient; 6 | import de.codecentric.namespace.weatherservice.WeatherService; 7 | import de.jonashackt.tutorial.configuration.SimpleBootCxfConfiguration; 8 | import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.context.annotation.Bean; 11 | import org.springframework.context.annotation.Configuration; 12 | 13 | @Configuration 14 | public class SimpleBootCxfSystemTestConfiguration { 15 | 16 | @Autowired 17 | private CxfAutoConfiguration cxfAutoConfiguration; 18 | 19 | @Bean 20 | public WeatherService weatherServiceSystemTestClient() { 21 | JaxWsProxyFactoryBean jaxWsProxyFactory = new JaxWsProxyFactoryBean(); 22 | jaxWsProxyFactory.setServiceClass(WeatherService.class); 23 | jaxWsProxyFactory.setAddress("http://localhost:8090" + cxfAutoConfiguration.getBaseUrl() + SimpleBootCxfConfiguration.SERVICE_URL); 24 | return (WeatherService) jaxWsProxyFactory.create(); 25 | } 26 | 27 | @Bean 28 | public SoapRawClient soapRawClient() throws BootStarterCxfException { 29 | return new SoapRawClient(buildUrl(), WeatherService.class); 30 | } 31 | 32 | private String buildUrl() { 33 | // return something like http://localhost:8084/soap-api/WeatherSoapService 34 | return "http://localhost:8087" 35 | + cxfAutoConfiguration.getBaseUrl() 36 | + SimpleBootCxfConfiguration.SERVICE_URL; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /step10_simple_app_with_cxf-spring-boot-starter/src/test/java/de/jonashackt/tutorial/endpoint/WeatherServiceXmlFileSystemTest.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.endpoint; 2 | 3 | import de.codecentric.cxf.common.BootStarterCxfException; 4 | import de.codecentric.cxf.common.XmlUtils; 5 | import de.codecentric.namespace.weatherservice.WeatherException; 6 | import de.codecentric.namespace.weatherservice.WeatherService; 7 | import de.codecentric.namespace.weatherservice.general.ForecastReturn; 8 | import de.codecentric.namespace.weatherservice.general.GetCityForecastByZIP; 9 | import de.jonashackt.tutorial.SimpleBootCxfSystemTestApplication; 10 | import org.junit.Test; 11 | import org.junit.runner.RunWith; 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | import org.springframework.beans.factory.annotation.Value; 14 | import org.springframework.boot.test.context.SpringBootTest; 15 | import org.springframework.core.io.Resource; 16 | import org.springframework.test.context.junit4.SpringRunner; 17 | 18 | import java.io.IOException; 19 | 20 | import static org.junit.Assert.assertEquals; 21 | import static org.junit.Assert.assertNotNull; 22 | 23 | @RunWith(SpringRunner.class) 24 | @SpringBootTest( 25 | classes=SimpleBootCxfSystemTestApplication.class, 26 | webEnvironment= SpringBootTest.WebEnvironment.DEFINED_PORT, 27 | properties = {"server.port=8090"} 28 | ) 29 | public class WeatherServiceXmlFileSystemTest { 30 | 31 | @Autowired 32 | private WeatherService weatherServiceSystemTestClient; 33 | 34 | @Value(value="classpath:requests/GetCityForecastByZIPTest.xml") 35 | private Resource getCityForecastByZIPTestXml; 36 | 37 | @Test 38 | public void getCityForecastByZIP() throws WeatherException, IOException, BootStarterCxfException { 39 | // Given 40 | GetCityForecastByZIP getCityForecastByZIP = XmlUtils.readSoapMessageFromStreamAndUnmarshallBody2Object(getCityForecastByZIPTestXml.getInputStream(), GetCityForecastByZIP.class); 41 | 42 | // When 43 | ForecastReturn forecastReturn = weatherServiceSystemTestClient.getCityForecastByZIP(getCityForecastByZIP.getForecastRequest()); 44 | 45 | // Then 46 | assertNotNull(forecastReturn); 47 | assertEquals(true, forecastReturn.isSuccess()); 48 | assertEquals("Weimar", forecastReturn.getCity()); 49 | assertEquals("22%", forecastReturn.getForecastResult().getForecast().get(0).getProbabilityOfPrecipiation().getDaytime()); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /step10_simple_app_with_cxf-spring-boot-starter/src/test/resources/requests/GetCityForecastByZIPTest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 99425 8 | bluewhite 9 | ForecastBasic 10 | 11 | 30 12 | 5000 13 | Paypal 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /step10_simple_app_with_cxf-spring-boot-starter/src/test/resources/requests/xmlerrors/xmlErrorNotXmlSchemeCompliantRootElementTest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 99425 7 | 8 | 9 | -------------------------------------------------------------------------------- /step10_simple_app_with_cxf-spring-boot-starter/src/test/resources/requests/xmlerrors/xmlErrorNotXmlSchemeCompliantUnderRootElementTest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 99425 7 | 8 | 9 | -------------------------------------------------------------------------------- /step10_simple_app_with_cxf-spring-boot-starter/src/test/resources/requests/xmlerrors/xmlErrorSoapBodyTagMissingBracketTest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | -------------------------------------------------------------------------------- /step10_simple_app_with_cxf-spring-boot-starter/src/test/resources/requests/xmlerrors/xmlErrorSoapEnvelopeTagMissingBracketTest.xml: -------------------------------------------------------------------------------- 1 | 2 | soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:gen="http://www.codecentric.de/namespace/weatherservice/general"> 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /step10_simple_app_with_cxf-spring-boot-starter/src/test/resources/requests/xmlerrors/xmlErrorSoapHeaderMissingSlash.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /step10_simple_app_with_cxf-spring-boot-starter/src/test/resources/requests/xmlerrors/xmlErrorSoapHeaderTagMissingBracketTest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /step10_simple_app_with_cxf-spring-boot-starter/src/test/resources/requests/xmlerrors/xmlErrorXMLHeaderDefinitionMissingBracket.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /step10_simple_app_with_cxf-spring-boot-starter/src/test/resources/requests/xmlerrors/xmlErrorXMLTagNotClosedInsideBodyTest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | notRelevantHere /> 6 | 7 | -------------------------------------------------------------------------------- /step1_simple_springboot_app_with_cxf/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | de.jonashackt.tutorial 7 | step1_simple_springboot_app_with_cxf 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | step1_simple_springboot_app_with_cxf 12 | step1_simple_springboot_app_with_cxf 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.3.3.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | 1.8 24 | 3.1.6 25 | 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-devtools 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-web 35 | 36 | 37 | 38 | 39 | org.apache.cxf 40 | cxf-rt-frontend-jaxws 41 | ${cxf.version} 42 | 43 | 44 | org.apache.cxf 45 | cxf-rt-transports-http 46 | ${cxf.version} 47 | 48 | 49 | 50 | org.springframework.boot 51 | spring-boot-starter-test 52 | test 53 | 54 | 55 | 56 | 57 | 58 | 59 | org.springframework.boot 60 | spring-boot-maven-plugin 61 | 62 | 63 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /step1_simple_springboot_app_with_cxf/src/main/java/de/jonashackt/tutorial/SimpleBootCxfApplication.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial; 2 | 3 | import org.apache.cxf.Bus; 4 | import org.apache.cxf.bus.spring.SpringBus; 5 | import org.apache.cxf.transport.servlet.CXFServlet; 6 | import org.springframework.boot.SpringApplication; 7 | import org.springframework.boot.autoconfigure.SpringBootApplication; 8 | import org.springframework.boot.context.embedded.ServletRegistrationBean; 9 | import org.springframework.context.annotation.Bean; 10 | 11 | @SpringBootApplication 12 | public class SimpleBootCxfApplication { 13 | 14 | public static void main(String[] args) { 15 | SpringApplication.run(SimpleBootCxfApplication.class, args); 16 | } 17 | 18 | @Bean 19 | public ServletRegistrationBean cxfServlet() { 20 | return new ServletRegistrationBean(new CXFServlet(), "/soap-api/*"); 21 | } 22 | 23 | @Bean(name = Bus.DEFAULT_BUS_ID) 24 | public SpringBus springBus() { 25 | return new SpringBus(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /step1_simple_springboot_app_with_cxf/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jonashackt/tutorial-soap-spring-boot-cxf/3960f26a558a84e4c40474336c115942e528d135/step1_simple_springboot_app_with_cxf/src/main/resources/application.properties -------------------------------------------------------------------------------- /step1_simple_springboot_app_with_cxf/src/test/java/de/jonashackt/tutorial/SimpleBootCxfApplicationTests.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.test.context.web.WebAppConfiguration; 6 | import org.springframework.boot.test.SpringApplicationConfiguration; 7 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 8 | 9 | @RunWith(SpringJUnit4ClassRunner.class) 10 | @SpringApplicationConfiguration(classes = SimpleBootCxfApplication.class) 11 | @WebAppConfiguration 12 | public class SimpleBootCxfApplicationTests { 13 | 14 | @Test 15 | public void contextLoads() { 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /step2_wsdl_2_java_maven/src/main/java/de/jonashackt/tutorial/SimpleBootCxfApplication.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial; 2 | 3 | import org.apache.cxf.Bus; 4 | import org.apache.cxf.bus.spring.SpringBus; 5 | import org.apache.cxf.transport.servlet.CXFServlet; 6 | import org.springframework.boot.SpringApplication; 7 | import org.springframework.boot.autoconfigure.SpringBootApplication; 8 | import org.springframework.boot.context.embedded.ServletRegistrationBean; 9 | import org.springframework.context.annotation.Bean; 10 | 11 | @SpringBootApplication 12 | public class SimpleBootCxfApplication { 13 | 14 | public static void main(String[] args) { 15 | SpringApplication.run(SimpleBootCxfApplication.class, args); 16 | } 17 | 18 | @Bean 19 | public ServletRegistrationBean cxfServlet() { 20 | return new ServletRegistrationBean(new CXFServlet(), "/soap-api/*"); 21 | } 22 | 23 | @Bean(name = Bus.DEFAULT_BUS_ID) 24 | public SpringBus springBus() { 25 | return new SpringBus(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /step2_wsdl_2_java_maven/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jonashackt/tutorial-soap-spring-boot-cxf/3960f26a558a84e4c40474336c115942e528d135/step2_wsdl_2_java_maven/src/main/resources/application.properties -------------------------------------------------------------------------------- /step2_wsdl_2_java_maven/src/main/resources/service-api-definition/Weather-Schemes/w3c-xmlmime-definition.xsd: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /step2_wsdl_2_java_maven/src/main/resources/service-api-definition/Weather-Schemes/weather-exception.xsd: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /step2_wsdl_2_java_maven/src/main/resources/service-api-definition/Weather1.0.xsd: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 12 | 13 | 15 | 16 | -------------------------------------------------------------------------------- /step2_wsdl_2_java_maven/src/test/java/de/jonashackt/tutorial/SimpleBootCxfApplicationTests.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.test.context.web.WebAppConfiguration; 6 | import org.springframework.boot.test.SpringApplicationConfiguration; 7 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 8 | 9 | @RunWith(SpringJUnit4ClassRunner.class) 10 | @SpringApplicationConfiguration(classes = SimpleBootCxfApplication.class) 11 | @WebAppConfiguration 12 | public class SimpleBootCxfApplicationTests { 13 | 14 | @Test 15 | public void contextLoads() { 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /step3_jaxws-endpoint-cxf-spring-boot-orig-wsdl/src/main/java/de/jonashackt/tutorial/SimpleBootCxfApplication.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.context.annotation.ComponentScan; 6 | 7 | @SpringBootApplication 8 | @ComponentScan("de.jonashackt.tutorial") 9 | public class SimpleBootCxfApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(SimpleBootCxfApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /step3_jaxws-endpoint-cxf-spring-boot-orig-wsdl/src/main/java/de/jonashackt/tutorial/configuration/WebServiceConfiguration.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.configuration; 2 | 3 | import javax.xml.ws.Endpoint; 4 | 5 | import org.apache.cxf.Bus; 6 | import org.apache.cxf.bus.spring.SpringBus; 7 | import org.apache.cxf.jaxws.EndpointImpl; 8 | import org.apache.cxf.transport.servlet.CXFServlet; 9 | import org.springframework.boot.context.embedded.ServletRegistrationBean; 10 | import org.springframework.context.annotation.Bean; 11 | import org.springframework.context.annotation.Configuration; 12 | 13 | import de.codecentric.namespace.weatherservice.Weather; 14 | import de.codecentric.namespace.weatherservice.WeatherService; 15 | import de.jonashackt.tutorial.endpoint.WeatherServiceEndpoint; 16 | 17 | @Configuration 18 | public class WebServiceConfiguration { 19 | 20 | @Bean 21 | public ServletRegistrationBean cxfServlet() { 22 | return new ServletRegistrationBean(new CXFServlet(), "/soap-api/*"); 23 | } 24 | 25 | @Bean(name = Bus.DEFAULT_BUS_ID) 26 | public SpringBus springBus() { 27 | return new SpringBus(); 28 | } 29 | 30 | @Bean 31 | public WeatherService weatherService() { 32 | return new WeatherServiceEndpoint(); 33 | } 34 | 35 | @Bean 36 | public Endpoint endpoint() { 37 | EndpointImpl endpoint = new EndpointImpl(springBus(), weatherService()); 38 | // CXF JAX-WS implementation relies on the correct ServiceName as QName-Object with 39 | // the name-Attribute´s text and the targetNamespace 40 | // "http://www.codecentric.de/namespace/weatherservice/" 41 | // Also the WSDLLocation must be set 42 | endpoint.setServiceName(weather().getServiceName()); 43 | endpoint.setWsdlLocation(weather().getWSDLDocumentLocation().toString()); 44 | endpoint.publish("/WeatherSoapService_1.0"); 45 | return endpoint; 46 | } 47 | 48 | @Bean 49 | public Weather weather() { 50 | // Needed for correct ServiceName & WSDLLocation to publish contract first incl. original WSDL 51 | return new Weather(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /step3_jaxws-endpoint-cxf-spring-boot-orig-wsdl/src/main/java/de/jonashackt/tutorial/endpoint/WeatherServiceEndpoint.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.endpoint; 2 | 3 | import de.codecentric.namespace.weatherservice.WeatherException; 4 | import de.codecentric.namespace.weatherservice.WeatherService; 5 | import de.codecentric.namespace.weatherservice.general.ForecastRequest; 6 | import de.codecentric.namespace.weatherservice.general.ForecastReturn; 7 | import de.codecentric.namespace.weatherservice.general.WeatherInformationReturn; 8 | import de.codecentric.namespace.weatherservice.general.WeatherReturn; 9 | 10 | public class WeatherServiceEndpoint implements WeatherService { 11 | 12 | @Override 13 | public ForecastReturn getCityForecastByZIP(ForecastRequest forecastRequest) 14 | throws WeatherException { 15 | // TODO Auto-generated method stub 16 | return null; 17 | } 18 | 19 | @Override 20 | public WeatherInformationReturn getWeatherInformation(String zip) 21 | throws WeatherException { 22 | // TODO Auto-generated method stub 23 | return null; 24 | } 25 | 26 | @Override 27 | public WeatherReturn getCityWeatherByZIP(ForecastRequest forecastRequest) 28 | throws WeatherException { 29 | // TODO Auto-generated method stub 30 | return null; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /step3_jaxws-endpoint-cxf-spring-boot-orig-wsdl/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jonashackt/tutorial-soap-spring-boot-cxf/3960f26a558a84e4c40474336c115942e528d135/step3_jaxws-endpoint-cxf-spring-boot-orig-wsdl/src/main/resources/application.properties -------------------------------------------------------------------------------- /step3_jaxws-endpoint-cxf-spring-boot-orig-wsdl/src/main/resources/service-api-definition/Weather-Schemes/w3c-xmlmime-definition.xsd: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /step3_jaxws-endpoint-cxf-spring-boot-orig-wsdl/src/main/resources/service-api-definition/Weather-Schemes/weather-exception.xsd: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /step3_jaxws-endpoint-cxf-spring-boot-orig-wsdl/src/main/resources/service-api-definition/Weather1.0.xsd: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 12 | 13 | 15 | 16 | -------------------------------------------------------------------------------- /step3_jaxws-endpoint-cxf-spring-boot-orig-wsdl/src/test/java/de/jonashackt/tutorial/SimpleBootCxfApplicationTests.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.test.context.web.WebAppConfiguration; 6 | import org.springframework.boot.test.SpringApplicationConfiguration; 7 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 8 | 9 | @RunWith(SpringJUnit4ClassRunner.class) 10 | @SpringApplicationConfiguration(classes = SimpleBootCxfApplication.class) 11 | @WebAppConfiguration 12 | public class SimpleBootCxfApplicationTests { 13 | 14 | @Test 15 | public void contextLoads() { 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /step3_jaxws-endpoint-cxf-spring-boot/src/main/java/de/jonashackt/tutorial/SimpleBootCxfApplication.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.context.annotation.ComponentScan; 6 | 7 | @SpringBootApplication 8 | @ComponentScan("de.jonashackt.tutorial") 9 | public class SimpleBootCxfApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(SimpleBootCxfApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /step3_jaxws-endpoint-cxf-spring-boot/src/main/java/de/jonashackt/tutorial/configuration/WebServiceConfiguration.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.configuration; 2 | 3 | import javax.xml.ws.Endpoint; 4 | 5 | import org.apache.cxf.Bus; 6 | import org.apache.cxf.bus.spring.SpringBus; 7 | import org.apache.cxf.jaxws.EndpointImpl; 8 | import org.apache.cxf.transport.servlet.CXFServlet; 9 | import org.springframework.boot.context.embedded.ServletRegistrationBean; 10 | import org.springframework.context.annotation.Bean; 11 | import org.springframework.context.annotation.Configuration; 12 | 13 | import de.codecentric.namespace.weatherservice.WeatherService; 14 | import de.jonashackt.tutorial.endpoint.WeatherServiceEndpoint; 15 | 16 | @Configuration 17 | public class WebServiceConfiguration { 18 | 19 | @Bean 20 | public ServletRegistrationBean cxfServlet() { 21 | return new ServletRegistrationBean(new CXFServlet(), "/soap-api/*"); 22 | } 23 | 24 | @Bean(name = Bus.DEFAULT_BUS_ID) 25 | public SpringBus springBus() { 26 | return new SpringBus(); 27 | } 28 | 29 | @Bean 30 | public WeatherService weatherService() { 31 | return new WeatherServiceEndpoint(); 32 | } 33 | 34 | @Bean 35 | public Endpoint endpoint() { 36 | EndpointImpl endpoint = new EndpointImpl(springBus(), weatherService()); 37 | endpoint.publish("/WeatherSoapService_1.0"); 38 | endpoint.setWsdlLocation("Weather1.0.wsdl"); 39 | return endpoint; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /step3_jaxws-endpoint-cxf-spring-boot/src/main/java/de/jonashackt/tutorial/endpoint/WeatherServiceEndpoint.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.endpoint; 2 | 3 | import de.codecentric.namespace.weatherservice.WeatherException; 4 | import de.codecentric.namespace.weatherservice.WeatherService; 5 | import de.codecentric.namespace.weatherservice.general.ForecastRequest; 6 | import de.codecentric.namespace.weatherservice.general.ForecastReturn; 7 | import de.codecentric.namespace.weatherservice.general.WeatherInformationReturn; 8 | import de.codecentric.namespace.weatherservice.general.WeatherReturn; 9 | 10 | public class WeatherServiceEndpoint implements WeatherService { 11 | 12 | @Override 13 | public ForecastReturn getCityForecastByZIP(ForecastRequest forecastRequest) 14 | throws WeatherException { 15 | // TODO Auto-generated method stub 16 | return null; 17 | } 18 | 19 | @Override 20 | public WeatherInformationReturn getWeatherInformation(String zip) 21 | throws WeatherException { 22 | // TODO Auto-generated method stub 23 | return null; 24 | } 25 | 26 | @Override 27 | public WeatherReturn getCityWeatherByZIP(ForecastRequest forecastRequest) 28 | throws WeatherException { 29 | // TODO Auto-generated method stub 30 | return null; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /step3_jaxws-endpoint-cxf-spring-boot/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jonashackt/tutorial-soap-spring-boot-cxf/3960f26a558a84e4c40474336c115942e528d135/step3_jaxws-endpoint-cxf-spring-boot/src/main/resources/application.properties -------------------------------------------------------------------------------- /step3_jaxws-endpoint-cxf-spring-boot/src/main/resources/service-api-definition/Weather-Schemes/w3c-xmlmime-definition.xsd: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /step3_jaxws-endpoint-cxf-spring-boot/src/main/resources/service-api-definition/Weather-Schemes/weather-exception.xsd: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /step3_jaxws-endpoint-cxf-spring-boot/src/main/resources/service-api-definition/Weather1.0.xsd: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 12 | 13 | 15 | 16 | -------------------------------------------------------------------------------- /step3_jaxws-endpoint-cxf-spring-boot/src/test/java/de/jonashackt/tutorial/SimpleBootCxfApplicationTests.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.test.context.web.WebAppConfiguration; 6 | import org.springframework.boot.test.SpringApplicationConfiguration; 7 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 8 | 9 | @RunWith(SpringJUnit4ClassRunner.class) 10 | @SpringApplicationConfiguration(classes = SimpleBootCxfApplication.class) 11 | @WebAppConfiguration 12 | public class SimpleBootCxfApplicationTests { 13 | 14 | @Test 15 | public void contextLoads() { 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /step4_test/src/main/java/de/jonashackt/tutorial/SimpleBootCxfApplication.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.context.annotation.ComponentScan; 6 | 7 | @SpringBootApplication 8 | @ComponentScan("de.jonashackt.tutorial") 9 | public class SimpleBootCxfApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(SimpleBootCxfApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /step4_test/src/main/java/de/jonashackt/tutorial/configuration/ApplicationConfiguration.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.configuration; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | 6 | import de.jonashackt.tutorial.controller.WeatherServiceController; 7 | 8 | 9 | @Configuration 10 | public class ApplicationConfiguration { 11 | 12 | @Bean 13 | public WeatherServiceController weatherServiceController() { 14 | return new WeatherServiceController(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /step4_test/src/main/java/de/jonashackt/tutorial/configuration/WebServiceConfiguration.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.configuration; 2 | 3 | import javax.xml.ws.Endpoint; 4 | 5 | import org.apache.cxf.Bus; 6 | import org.apache.cxf.bus.spring.SpringBus; 7 | import org.apache.cxf.jaxws.EndpointImpl; 8 | import org.apache.cxf.transport.servlet.CXFServlet; 9 | import org.springframework.boot.context.embedded.ServletRegistrationBean; 10 | import org.springframework.context.annotation.Bean; 11 | import org.springframework.context.annotation.Configuration; 12 | 13 | import de.codecentric.namespace.weatherservice.Weather; 14 | import de.codecentric.namespace.weatherservice.WeatherService; 15 | import de.jonashackt.tutorial.endpoint.WeatherServiceEndpoint; 16 | 17 | @Configuration 18 | public class WebServiceConfiguration { 19 | 20 | public static final String BASE_URL = "/soap-api"; 21 | public static final String SERVICE_URL = "/WeatherSoapService_1.0"; 22 | 23 | @Bean 24 | public ServletRegistrationBean cxfServlet() { 25 | return new ServletRegistrationBean(new CXFServlet(), BASE_URL + "/*"); 26 | } 27 | 28 | @Bean(name = Bus.DEFAULT_BUS_ID) 29 | public SpringBus springBus() { 30 | return new SpringBus(); 31 | } 32 | 33 | @Bean 34 | public WeatherService weatherService() { 35 | return new WeatherServiceEndpoint(); 36 | } 37 | 38 | @Bean 39 | public Endpoint endpoint() { 40 | EndpointImpl endpoint = new EndpointImpl(springBus(), weatherService()); 41 | // CXF JAX-WS implementation relies on the correct ServiceName as QName-Object with 42 | // the name-Attribute´s text and the targetNamespace 43 | // "http://www.codecentric.de/namespace/weatherservice/" 44 | // Also the WSDLLocation must be set 45 | endpoint.setServiceName(weather().getServiceName()); 46 | endpoint.setWsdlLocation(weather().getWSDLDocumentLocation().toString()); 47 | endpoint.publish(SERVICE_URL); 48 | return endpoint; 49 | } 50 | 51 | @Bean 52 | public Weather weather() { 53 | // Needed for correct ServiceName & WSDLLocation to publish contract first incl. original WSDL 54 | return new Weather(); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /step4_test/src/main/java/de/jonashackt/tutorial/controller/WeatherServiceController.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.controller; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | import de.codecentric.namespace.weatherservice.general.ForecastRequest; 6 | import de.codecentric.namespace.weatherservice.general.ForecastReturn; 7 | import de.jonashackt.tutorial.transformation.GetCityForecastByZIPOutMapper; 8 | 9 | /* 10 | * Example-Controller: 11 | * This Class would be responsible for Mapping from Request to internal Datamodel (and backwards), 12 | * for calling Backend-Services and handling Backend-Exceptions 13 | * So it decouples the WSDL-generated Classes from the internal Classes - for when the former changes, 14 | * nothing or only the mapping has to be changed 15 | */ 16 | @Component 17 | public class WeatherServiceController { 18 | 19 | public ForecastReturn getCityForecastByZIP(ForecastRequest forecastRequest) { 20 | /* 21 | * We leave out inbound transformation, plausibility-checking, logging, backend-calls e.g. 22 | * for the moment 23 | */ 24 | return GetCityForecastByZIPOutMapper.mapGeneralOutlook2Forecast(); 25 | } 26 | 27 | /* 28 | * Other Methods would follow here... 29 | */ 30 | //public WeatherReturn getCityWeatherByZIP(ForecastRequest forecastRequest) throws BusinessException {} 31 | 32 | //public WeatherInformationReturn getWeatherInformation(String zip) throws BusinessException {} 33 | } 34 | -------------------------------------------------------------------------------- /step4_test/src/main/java/de/jonashackt/tutorial/endpoint/WeatherServiceEndpoint.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.endpoint; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | 5 | import de.codecentric.namespace.weatherservice.WeatherException; 6 | import de.codecentric.namespace.weatherservice.WeatherService; 7 | import de.codecentric.namespace.weatherservice.general.ForecastRequest; 8 | import de.codecentric.namespace.weatherservice.general.ForecastReturn; 9 | import de.codecentric.namespace.weatherservice.general.WeatherInformationReturn; 10 | import de.codecentric.namespace.weatherservice.general.WeatherReturn; 11 | import de.jonashackt.tutorial.controller.WeatherServiceController; 12 | 13 | 14 | public class WeatherServiceEndpoint implements WeatherService { 15 | 16 | @Autowired 17 | private WeatherServiceController weatherServiceController; 18 | 19 | @Override 20 | public ForecastReturn getCityForecastByZIP(ForecastRequest forecastRequest) throws WeatherException { 21 | return weatherServiceController.getCityForecastByZIP(forecastRequest); 22 | } 23 | 24 | @Override 25 | public WeatherInformationReturn getWeatherInformation(String zip) 26 | throws WeatherException { 27 | // TODO Auto-generated method stub 28 | return null; 29 | } 30 | 31 | @Override 32 | public WeatherReturn getCityWeatherByZIP(ForecastRequest forecastRequest) 33 | throws WeatherException { 34 | // TODO Auto-generated method stub 35 | return null; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /step4_test/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jonashackt/tutorial-soap-spring-boot-cxf/3960f26a558a84e4c40474336c115942e528d135/step4_test/src/main/resources/application.properties -------------------------------------------------------------------------------- /step4_test/src/main/resources/service-api-definition/Weather-Schemes/w3c-xmlmime-definition.xsd: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /step4_test/src/main/resources/service-api-definition/Weather-Schemes/weather-exception.xsd: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /step4_test/src/main/resources/service-api-definition/Weather1.0.xsd: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 12 | 13 | 15 | 16 | -------------------------------------------------------------------------------- /step4_test/src/test/java/de/jonashackt/tutorial/ApplicationTestConfiguration.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.context.annotation.Import; 6 | 7 | import de.codecentric.namespace.weatherservice.WeatherService; 8 | import de.jonashackt.tutorial.configuration.ApplicationConfiguration; 9 | import de.jonashackt.tutorial.endpoint.WeatherServiceEndpoint; 10 | 11 | @Configuration 12 | @Import(ApplicationConfiguration.class) 13 | public class ApplicationTestConfiguration { 14 | 15 | @Bean 16 | public WeatherService weatherService() { 17 | return new WeatherServiceEndpoint(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /step4_test/src/test/java/de/jonashackt/tutorial/SimpleBootCxfSystemTestApplication.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.context.annotation.Import; 6 | 7 | @SpringBootApplication 8 | @Import(WebServiceSystemTestConfiguration.class) 9 | public class SimpleBootCxfSystemTestApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(SimpleBootCxfSystemTestApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /step4_test/src/test/java/de/jonashackt/tutorial/WebServiceIntegrationTestConfiguration.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial; 2 | 3 | import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | import de.codecentric.namespace.weatherservice.WeatherService; 8 | import de.jonashackt.tutorial.configuration.WebServiceConfiguration; 9 | 10 | @Configuration 11 | public class WebServiceIntegrationTestConfiguration { 12 | 13 | @Bean 14 | public WeatherService weatherServiceIntegrationTestClient() { 15 | JaxWsProxyFactoryBean jaxWsProxyFactory = new JaxWsProxyFactoryBean(); 16 | jaxWsProxyFactory.setServiceClass(WeatherService.class); 17 | jaxWsProxyFactory.setAddress("http://localhost:8080" + WebServiceConfiguration.BASE_URL + WebServiceConfiguration.SERVICE_URL); 18 | return (WeatherService) jaxWsProxyFactory.create(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /step4_test/src/test/java/de/jonashackt/tutorial/WebServiceSystemTestConfiguration.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial; 2 | 3 | import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | import de.codecentric.namespace.weatherservice.WeatherService; 8 | import de.jonashackt.tutorial.configuration.WebServiceConfiguration; 9 | 10 | @Configuration 11 | public class WebServiceSystemTestConfiguration { 12 | 13 | @Bean 14 | public WeatherService weatherServiceSystemTestClient() { 15 | JaxWsProxyFactoryBean jaxWsProxyFactory = new JaxWsProxyFactoryBean(); 16 | jaxWsProxyFactory.setServiceClass(WeatherService.class); 17 | jaxWsProxyFactory.setAddress("http://localhost:8090" + WebServiceConfiguration.BASE_URL + WebServiceConfiguration.SERVICE_URL); 18 | return (WeatherService) jaxWsProxyFactory.create(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /step4_test/src/test/java/de/jonashackt/tutorial/endpoint/WeatherServiceIntegrationTest.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.endpoint; 2 | 3 | import static de.jonashackt.tutorial.utils.TestHelper.generateDummyRequest; 4 | import static org.junit.Assert.assertEquals; 5 | import static org.junit.Assert.assertNotNull; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.test.context.ContextConfiguration; 11 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 12 | 13 | import de.codecentric.namespace.weatherservice.WeatherException; 14 | import de.codecentric.namespace.weatherservice.WeatherService; 15 | import de.codecentric.namespace.weatherservice.general.ForecastRequest; 16 | import de.codecentric.namespace.weatherservice.general.ForecastReturn; 17 | import de.jonashackt.tutorial.WebServiceIntegrationTestConfiguration; 18 | 19 | @RunWith(SpringJUnit4ClassRunner.class) 20 | @ContextConfiguration(classes=WebServiceIntegrationTestConfiguration.class) 21 | public class WeatherServiceIntegrationTest { 22 | 23 | @Autowired 24 | private WeatherService weatherServiceIntegrationTestClient; 25 | 26 | @Test 27 | public void getCityForecastByZIP() throws WeatherException { 28 | // Given 29 | ForecastRequest forecastRequest = generateDummyRequest(); 30 | 31 | // When 32 | ForecastReturn forecastReturn = weatherServiceIntegrationTestClient.getCityForecastByZIP(forecastRequest); 33 | 34 | // Then 35 | assertNotNull(forecastReturn); 36 | assertEquals(true, forecastReturn.isSuccess()); 37 | assertEquals("Weimar", forecastReturn.getCity()); 38 | assertEquals("22%", forecastReturn.getForecastResult().getForecast().get(0).getProbabilityOfPrecipiation().getDaytime()); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /step4_test/src/test/java/de/jonashackt/tutorial/endpoint/WeatherServiceSystemTest.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.endpoint; 2 | 3 | import static de.jonashackt.tutorial.utils.TestHelper.generateDummyRequest; 4 | import static org.junit.Assert.assertEquals; 5 | import static org.junit.Assert.assertNotNull; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.boot.test.SpringApplicationConfiguration; 11 | import org.springframework.boot.test.WebIntegrationTest; 12 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 13 | 14 | import de.codecentric.namespace.weatherservice.WeatherException; 15 | import de.codecentric.namespace.weatherservice.WeatherService; 16 | import de.codecentric.namespace.weatherservice.general.ForecastRequest; 17 | import de.codecentric.namespace.weatherservice.general.ForecastReturn; 18 | import de.jonashackt.tutorial.SimpleBootCxfSystemTestApplication; 19 | 20 | @RunWith(SpringJUnit4ClassRunner.class) 21 | @SpringApplicationConfiguration(classes=SimpleBootCxfSystemTestApplication.class) 22 | @WebIntegrationTest("server.port:8090") 23 | public class WeatherServiceSystemTest { 24 | 25 | @Autowired 26 | private WeatherService weatherServiceSystemTestClient; 27 | 28 | @Test 29 | public void getCityForecastByZIP() throws WeatherException { 30 | // Given 31 | ForecastRequest forecastRequest = generateDummyRequest(); 32 | 33 | // When 34 | ForecastReturn forecastReturn = weatherServiceSystemTestClient.getCityForecastByZIP(forecastRequest); 35 | 36 | // Then 37 | assertNotNull(forecastReturn); 38 | assertEquals(true, forecastReturn.isSuccess()); 39 | assertEquals("Weimar", forecastReturn.getCity()); 40 | assertEquals("22%", forecastReturn.getForecastResult().getForecast().get(0).getProbabilityOfPrecipiation().getDaytime()); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /step4_test/src/test/java/de/jonashackt/tutorial/endpoint/WeatherServiceTest.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.endpoint; 2 | 3 | import static de.jonashackt.tutorial.utils.TestHelper.generateDummyRequest; 4 | import static org.junit.Assert.assertEquals; 5 | import static org.junit.Assert.assertNotNull; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.test.context.ContextConfiguration; 11 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 12 | 13 | import de.codecentric.namespace.weatherservice.WeatherException; 14 | import de.codecentric.namespace.weatherservice.general.ForecastRequest; 15 | import de.codecentric.namespace.weatherservice.general.ForecastReturn; 16 | import de.jonashackt.tutorial.ApplicationTestConfiguration; 17 | 18 | @RunWith(SpringJUnit4ClassRunner.class) 19 | @ContextConfiguration(classes=ApplicationTestConfiguration.class) 20 | public class WeatherServiceTest { 21 | 22 | @Autowired 23 | private WeatherServiceEndpoint weatherServiceEndpoint; 24 | 25 | @Test 26 | public void getCityForecastByZIP() throws WeatherException { 27 | // Given 28 | ForecastRequest forecastRequest = generateDummyRequest(); 29 | 30 | // When 31 | ForecastReturn forecastReturn = weatherServiceEndpoint.getCityForecastByZIP(forecastRequest); 32 | 33 | // Then 34 | assertNotNull(forecastReturn); 35 | assertEquals(true, forecastReturn.isSuccess()); 36 | assertEquals("Weimar", forecastReturn.getCity()); 37 | assertEquals("22%", forecastReturn.getForecastResult().getForecast().get(0).getProbabilityOfPrecipiation().getDaytime()); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /step4_test/src/test/java/de/jonashackt/tutorial/endpoint/WeatherServiceXmlFileSystemTest.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.endpoint; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | import static org.junit.Assert.assertNotNull; 5 | 6 | import java.io.IOException; 7 | 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.beans.factory.annotation.Value; 12 | import org.springframework.boot.test.SpringApplicationConfiguration; 13 | import org.springframework.boot.test.WebIntegrationTest; 14 | import org.springframework.core.io.Resource; 15 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 16 | 17 | import de.codecentric.namespace.weatherservice.WeatherException; 18 | import de.codecentric.namespace.weatherservice.WeatherService; 19 | import de.codecentric.namespace.weatherservice.general.ForecastReturn; 20 | import de.codecentric.namespace.weatherservice.general.GetCityForecastByZIP; 21 | import de.jonashackt.tutorial.SimpleBootCxfSystemTestApplication; 22 | import de.jonashackt.tutorial.utils.XmlUtilsException; 23 | import de.jonashackt.tutorial.utils.XmlUtils; 24 | 25 | @RunWith(SpringJUnit4ClassRunner.class) 26 | @SpringApplicationConfiguration(classes=SimpleBootCxfSystemTestApplication.class) 27 | @WebIntegrationTest("server.port:8090") 28 | public class WeatherServiceXmlFileSystemTest { 29 | 30 | @Autowired 31 | private WeatherService weatherServiceSystemTestClient; 32 | 33 | @Value(value="classpath:requests/GetCityForecastByZIPTest.xml") 34 | private Resource getCityForecastByZIPTestXml; 35 | 36 | @Test 37 | public void getCityForecastByZIP() throws WeatherException, XmlUtilsException, IOException { 38 | // Given 39 | GetCityForecastByZIP getCityForecastByZIP = XmlUtils.readSoapMessageFromStreamAndUnmarshallBody2Object(getCityForecastByZIPTestXml.getInputStream(), GetCityForecastByZIP.class); 40 | 41 | // When 42 | ForecastReturn forecastReturn = weatherServiceSystemTestClient.getCityForecastByZIP(getCityForecastByZIP.getForecastRequest()); 43 | 44 | // Then 45 | assertNotNull(forecastReturn); 46 | assertEquals(true, forecastReturn.isSuccess()); 47 | assertEquals("Weimar", forecastReturn.getCity()); 48 | assertEquals("22%", forecastReturn.getForecastResult().getForecast().get(0).getProbabilityOfPrecipiation().getDaytime()); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /step4_test/src/test/java/de/jonashackt/tutorial/utils/TestHelper.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.utils; 2 | 3 | import de.codecentric.namespace.weatherservice.datatypes.ProductName; 4 | import de.codecentric.namespace.weatherservice.general.ForecastCustomer; 5 | import de.codecentric.namespace.weatherservice.general.ForecastRequest; 6 | 7 | public class TestHelper { 8 | 9 | public static ForecastRequest generateDummyRequest() { 10 | ForecastRequest forecastRequest = new ForecastRequest(); 11 | forecastRequest.setZIP("99425"); 12 | forecastRequest.setFlagcolor("blackblue"); 13 | forecastRequest.setProductName(ProductName.FORECAST_BASIC); 14 | ForecastCustomer customer = new ForecastCustomer(); 15 | customer.setAge(67); 16 | customer.setContribution(500); 17 | customer.setMethodOfPayment("Bitcoin"); 18 | forecastRequest.setForecastCustomer(customer); 19 | return forecastRequest; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /step4_test/src/test/java/de/jonashackt/tutorial/utils/XmlUtilsException.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.utils; 2 | 3 | public class XmlUtilsException extends Exception { 4 | private static final long serialVersionUID = 1L; 5 | 6 | public XmlUtilsException(Throwable cause) { 7 | super(cause); 8 | } 9 | 10 | public XmlUtilsException(String message, Throwable cause) { 11 | super(message, cause); 12 | } 13 | 14 | public XmlUtilsException(String message) { 15 | super(message); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /step4_test/src/test/resources/requests/GetCityForecastByZIPTest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 99425 8 | bluewhite 9 | ForecastBasic 10 | 11 | 30 12 | 5000 13 | Paypal 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /step5_custom-soap-fault/src/main/java/de/jonashackt/tutorial/SimpleBootCxfApplication.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.context.annotation.ComponentScan; 6 | 7 | @SpringBootApplication 8 | @ComponentScan("de.jonashackt.tutorial") 9 | public class SimpleBootCxfApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(SimpleBootCxfApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /step5_custom-soap-fault/src/main/java/de/jonashackt/tutorial/common/FaultConst.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.common; 2 | 3 | /** 4 | * Ids and Messages for generation of SoapFaults according to WeatherException 5 | */ 6 | public enum FaultConst { 7 | 8 | SUCCESSFULL_PROCESSING("01", "The Weather-Call was successfully processed by the backend."), 9 | SCHEME_VALIDATION_ERROR("07", "XML-Scheme-validiation failed."), 10 | SYNTACTICALLY_INCORRECT_XML_ERROR("08", "Syntactically incorrect XML."), 11 | BACKEND_PROCESSING_FAILED("04", "Backend processing failed."); 12 | 13 | private String id; 14 | private String message; 15 | 16 | private FaultConst(String id, String text) { 17 | this.id = id; 18 | this.message = text; 19 | } 20 | 21 | public String getMessage() { 22 | return message; 23 | } 24 | 25 | public String getId() { 26 | return id; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /step5_custom-soap-fault/src/main/java/de/jonashackt/tutorial/common/InternalBusinessException.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.common; 2 | 3 | public class InternalBusinessException extends Exception { 4 | private static final long serialVersionUID = 1L; 5 | 6 | public InternalBusinessException(Throwable cause) { 7 | super(cause); 8 | } 9 | 10 | public InternalBusinessException(String message, Throwable cause) { 11 | super(message, cause); 12 | } 13 | 14 | public InternalBusinessException(String message) { 15 | super(message); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /step5_custom-soap-fault/src/main/java/de/jonashackt/tutorial/configuration/ApplicationConfiguration.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.configuration; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | 6 | import de.jonashackt.tutorial.controller.WeatherServiceController; 7 | 8 | 9 | @Configuration 10 | public class ApplicationConfiguration { 11 | 12 | @Bean 13 | public WeatherServiceController weatherServiceController() { 14 | return new WeatherServiceController(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /step5_custom-soap-fault/src/main/java/de/jonashackt/tutorial/configuration/customsoapfaults/WeatherSoapFaultHelper.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.configuration.customsoapfaults; 2 | 3 | import org.apache.cxf.binding.soap.SoapMessage; 4 | import org.apache.cxf.interceptor.Fault; 5 | import org.w3c.dom.Document; 6 | import org.w3c.dom.Element; 7 | 8 | import de.jonashackt.tutorial.common.FaultConst; 9 | import de.jonashackt.tutorial.common.XmlUtils; 10 | import de.jonashackt.tutorial.logging.SoapFrameworkLogger; 11 | import de.jonashackt.tutorial.transformation.WeatherOutError; 12 | 13 | public final class WeatherSoapFaultHelper { 14 | 15 | // private Constructor for Utility-Class 16 | private WeatherSoapFaultHelper() {}; 17 | 18 | private static final SoapFrameworkLogger LOG = SoapFrameworkLogger.getLogger(WeatherSoapFaultHelper.class); 19 | 20 | public static void buildWeatherFaultAndSet2SoapMessage(SoapMessage message, FaultConst faultContent) { 21 | Fault exceptionFault = (Fault) message.getContent(Exception.class); 22 | String originalFaultMessage = exceptionFault.getMessage(); 23 | exceptionFault.setMessage(faultContent.getMessage()); 24 | exceptionFault.setDetail(createFaultDetailWithWeatherException(originalFaultMessage, faultContent)); 25 | message.setContent(Exception.class, exceptionFault); 26 | } 27 | 28 | private static Element createFaultDetailWithWeatherException(String originalFaultMessage, FaultConst faultContent) { 29 | Element weatherExceptionElementAppended = null; 30 | try { 31 | Document weatherExcecption = XmlUtils.marhallJaxbElementIntoDocument(WeatherOutError.createWeatherException(faultContent, originalFaultMessage)); 32 | // As the Root-Element is deleted while adding the WeatherException to the Fault-Details, we have to use a Workaround: 33 | // we append it to a new Element, which then gets deleted again 34 | weatherExceptionElementAppended = XmlUtils.appendAsChildElement2NewElement(weatherExcecption); 35 | } catch (Exception exception) { 36 | LOG.failedToBuildWeatherServiceCompliantSoapFaultDetails(exception); 37 | // We don´t want an Exception in the Exceptionhandling 38 | } 39 | return weatherExceptionElementAppended; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /step5_custom-soap-fault/src/main/java/de/jonashackt/tutorial/controller/WeatherServiceController.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.controller; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | import de.codecentric.namespace.weatherservice.general.ForecastRequest; 6 | import de.codecentric.namespace.weatherservice.general.ForecastReturn; 7 | import de.jonashackt.tutorial.transformation.GetCityForecastByZIPOutMapper; 8 | 9 | /* 10 | * Example-Controller: 11 | * This Class would be responsible for Mapping from Request to internal Datamodel (and backwards), 12 | * for calling Backend-Services and handling Backend-Exceptions 13 | * So it decouples the WSDL-generated Classes from the internal Classes - for when the former changes, 14 | * nothing or only the mapping has to be changed 15 | */ 16 | @Component 17 | public class WeatherServiceController { 18 | 19 | public ForecastReturn getCityForecastByZIP(ForecastRequest forecastRequest) { 20 | /* 21 | * We leave out inbound transformation, plausibility-checking, logging, backend-calls e.g. 22 | * for the moment 23 | */ 24 | return GetCityForecastByZIPOutMapper.mapGeneralOutlook2Forecast(); 25 | } 26 | 27 | /* 28 | * Other Methods would follow here... 29 | */ 30 | //public WeatherReturn getCityWeatherByZIP(ForecastRequest forecastRequest) throws BusinessException {} 31 | 32 | //public WeatherInformationReturn getWeatherInformation(String zip) throws BusinessException {} 33 | } 34 | -------------------------------------------------------------------------------- /step5_custom-soap-fault/src/main/java/de/jonashackt/tutorial/endpoint/WeatherServiceEndpoint.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.endpoint; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | 5 | import de.codecentric.namespace.weatherservice.WeatherException; 6 | import de.codecentric.namespace.weatherservice.WeatherService; 7 | import de.codecentric.namespace.weatherservice.general.ForecastRequest; 8 | import de.codecentric.namespace.weatherservice.general.ForecastReturn; 9 | import de.codecentric.namespace.weatherservice.general.WeatherInformationReturn; 10 | import de.codecentric.namespace.weatherservice.general.WeatherReturn; 11 | import de.jonashackt.tutorial.controller.WeatherServiceController; 12 | 13 | 14 | public class WeatherServiceEndpoint implements WeatherService { 15 | 16 | @Autowired 17 | private WeatherServiceController weatherServiceController; 18 | 19 | @Override 20 | public ForecastReturn getCityForecastByZIP(ForecastRequest forecastRequest) throws WeatherException { 21 | return weatherServiceController.getCityForecastByZIP(forecastRequest); 22 | } 23 | 24 | @Override 25 | public WeatherInformationReturn getWeatherInformation(String zip) 26 | throws WeatherException { 27 | // TODO Auto-generated method stub 28 | return null; 29 | } 30 | 31 | @Override 32 | public WeatherReturn getCityWeatherByZIP(ForecastRequest forecastRequest) 33 | throws WeatherException { 34 | // TODO Auto-generated method stub 35 | return null; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /step5_custom-soap-fault/src/main/java/de/jonashackt/tutorial/logging/SoapFrameworkLogger.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.logging; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | 6 | import de.jonashackt.tutorial.common.FaultConst; 7 | 8 | public class SoapFrameworkLogger { 9 | 10 | private Logger delegateLogger; 11 | 12 | private SoapFrameworkLogger() {}; 13 | 14 | public static SoapFrameworkLogger getLogger(Class class2LogFor) { 15 | SoapFrameworkLogger frameworkLogger = new SoapFrameworkLogger(); 16 | frameworkLogger.delegateLogger = LoggerFactory.getLogger(class2LogFor); 17 | return frameworkLogger; 18 | } 19 | 20 | /* 21 | * Errors - 9xx 22 | */ 23 | public void errorAccuredInBackendProcessing(Throwable cause) { 24 | logError("901", "An Error accured in backend-processing: {}", cause.getMessage()); 25 | } 26 | 27 | public void failedToBuildWeatherServiceCompliantSoapFaultDetails(Throwable cause) { 28 | logError("902", "Failed to build Weather-compliant SoapFault-details: {}\nStacktrace: {}", cause.getMessage(), cause.getStackTrace()); 29 | } 30 | 31 | public void schemaValidationError(FaultConst error, String faultMessage) { 32 | logDebug("903", error.getMessage() + ": {}", faultMessage); 33 | } 34 | 35 | 36 | /* 37 | * Logger-Methods - only private, to use just inside this class 38 | */ 39 | 40 | private void logDebug(String id, String messageTemplate, Object... parameters) { 41 | String msg = formatMessage(id, messageTemplate); 42 | delegateLogger.debug(msg, parameters); 43 | } 44 | 45 | private void logError(String id, String messageTemplate, Object... parameters) { 46 | String msg = formatMessage(id, messageTemplate); 47 | delegateLogger.error(msg, parameters); 48 | } 49 | 50 | private String formatMessage(String id, String messageTemplate) { 51 | return id + " >>> " + messageTemplate; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /step5_custom-soap-fault/src/main/java/de/jonashackt/tutorial/transformation/WeatherOutError.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.transformation; 2 | 3 | import de.codecentric.namespace.weatherservice.exception.WeatherException; 4 | import de.jonashackt.tutorial.common.FaultConst; 5 | 6 | 7 | 8 | public final class WeatherOutError { 9 | 10 | private WeatherOutError() { 11 | // private Constructor for Utility-Class 12 | }; 13 | 14 | private static final de.codecentric.namespace.weatherservice.exception.ObjectFactory objectFactoryDatatypes = new de.codecentric.namespace.weatherservice.exception.ObjectFactory(); 15 | 16 | public static WeatherException createWeatherException(FaultConst faultContent, String originalFaultMessage) { 17 | // Build SOAP-Fault detail 18 | WeatherException weatherException = objectFactoryDatatypes.createWeatherException(); 19 | weatherException.setBigBusinessErrorCausingMoneyLoss(true); 20 | weatherException.setBusinessErrorId(faultContent.getId()); 21 | weatherException.setExceptionDetails(originalFaultMessage); 22 | weatherException.setUuid("ExtremeRandomNumber"); 23 | return weatherException; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /step5_custom-soap-fault/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jonashackt/tutorial-soap-spring-boot-cxf/3960f26a558a84e4c40474336c115942e528d135/step5_custom-soap-fault/src/main/resources/application.properties -------------------------------------------------------------------------------- /step5_custom-soap-fault/src/main/resources/service-api-definition/Weather-Schemes/w3c-xmlmime-definition.xsd: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /step5_custom-soap-fault/src/main/resources/service-api-definition/Weather-Schemes/weather-exception.xsd: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /step5_custom-soap-fault/src/main/resources/service-api-definition/Weather1.0.xsd: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 12 | 13 | 15 | 16 | -------------------------------------------------------------------------------- /step5_custom-soap-fault/src/test/java/de/jonashackt/tutorial/ApplicationTestConfiguration.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.context.annotation.Import; 6 | 7 | import de.codecentric.namespace.weatherservice.WeatherService; 8 | import de.jonashackt.tutorial.configuration.ApplicationConfiguration; 9 | import de.jonashackt.tutorial.endpoint.WeatherServiceEndpoint; 10 | 11 | @Configuration 12 | @Import(ApplicationConfiguration.class) 13 | public class ApplicationTestConfiguration { 14 | 15 | @Bean 16 | public WeatherService weatherService() { 17 | return new WeatherServiceEndpoint(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /step5_custom-soap-fault/src/test/java/de/jonashackt/tutorial/SimpleBootCxfSystemTestApplication.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.context.annotation.Import; 6 | 7 | @SpringBootApplication 8 | @Import(WebServiceSystemTestConfiguration.class) 9 | public class SimpleBootCxfSystemTestApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(SimpleBootCxfSystemTestApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /step5_custom-soap-fault/src/test/java/de/jonashackt/tutorial/WebServiceIntegrationTestConfiguration.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial; 2 | 3 | import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | import de.codecentric.namespace.weatherservice.WeatherService; 8 | import de.jonashackt.tutorial.configuration.WebServiceConfiguration; 9 | 10 | @Configuration 11 | public class WebServiceIntegrationTestConfiguration { 12 | 13 | @Bean 14 | public WeatherService weatherServiceIntegrationTestClient() { 15 | JaxWsProxyFactoryBean jaxWsProxyFactory = new JaxWsProxyFactoryBean(); 16 | jaxWsProxyFactory.setServiceClass(WeatherService.class); 17 | jaxWsProxyFactory.setAddress("http://localhost:8080" + WebServiceConfiguration.BASE_URL + WebServiceConfiguration.SERVICE_URL); 18 | return (WeatherService) jaxWsProxyFactory.create(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /step5_custom-soap-fault/src/test/java/de/jonashackt/tutorial/WebServiceSystemTestConfiguration.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial; 2 | 3 | import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | import de.codecentric.namespace.weatherservice.WeatherService; 8 | import de.jonashackt.tutorial.common.InternalBusinessException; 9 | import de.jonashackt.tutorial.configuration.WebServiceConfiguration; 10 | import de.jonashackt.tutorial.utils.SoapRawClient; 11 | 12 | @Configuration 13 | public class WebServiceSystemTestConfiguration { 14 | 15 | private String webServiceUrl = "http://localhost:8090" + WebServiceConfiguration.BASE_URL + WebServiceConfiguration.SERVICE_URL; 16 | 17 | @Bean 18 | public WeatherService weatherServiceSystemTestClient() { 19 | JaxWsProxyFactoryBean jaxWsProxyFactory = new JaxWsProxyFactoryBean(); 20 | jaxWsProxyFactory.setServiceClass(WeatherService.class); 21 | jaxWsProxyFactory.setAddress(webServiceUrl); 22 | return (WeatherService) jaxWsProxyFactory.create(); 23 | } 24 | 25 | @Bean 26 | public SoapRawClient soapRawClient() throws InternalBusinessException { 27 | return new SoapRawClient(webServiceUrl, WeatherService.class); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /step5_custom-soap-fault/src/test/java/de/jonashackt/tutorial/endpoint/WeatherServiceIntegrationTest.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.endpoint; 2 | 3 | import static de.jonashackt.tutorial.utils.TestHelper.generateDummyRequest; 4 | import static org.junit.Assert.assertEquals; 5 | import static org.junit.Assert.assertNotNull; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.test.context.ContextConfiguration; 11 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 12 | 13 | import de.codecentric.namespace.weatherservice.WeatherException; 14 | import de.codecentric.namespace.weatherservice.WeatherService; 15 | import de.codecentric.namespace.weatherservice.general.ForecastRequest; 16 | import de.codecentric.namespace.weatherservice.general.ForecastReturn; 17 | import de.jonashackt.tutorial.WebServiceIntegrationTestConfiguration; 18 | 19 | @RunWith(SpringJUnit4ClassRunner.class) 20 | @ContextConfiguration(classes=WebServiceIntegrationTestConfiguration.class) 21 | public class WeatherServiceIntegrationTest { 22 | 23 | @Autowired 24 | private WeatherService weatherServiceIntegrationTestClient; 25 | 26 | @Test 27 | public void getCityForecastByZIP() throws WeatherException { 28 | // Given 29 | ForecastRequest forecastRequest = generateDummyRequest(); 30 | 31 | // When 32 | ForecastReturn forecastReturn = weatherServiceIntegrationTestClient.getCityForecastByZIP(forecastRequest); 33 | 34 | // Then 35 | assertNotNull(forecastReturn); 36 | assertEquals(true, forecastReturn.isSuccess()); 37 | assertEquals("Weimar", forecastReturn.getCity()); 38 | assertEquals("22%", forecastReturn.getForecastResult().getForecast().get(0).getProbabilityOfPrecipiation().getDaytime()); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /step5_custom-soap-fault/src/test/java/de/jonashackt/tutorial/endpoint/WeatherServiceSystemTest.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.endpoint; 2 | 3 | import static de.jonashackt.tutorial.utils.TestHelper.generateDummyRequest; 4 | import static org.junit.Assert.assertEquals; 5 | import static org.junit.Assert.assertNotNull; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.boot.test.SpringApplicationConfiguration; 11 | import org.springframework.boot.test.WebIntegrationTest; 12 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 13 | 14 | import de.codecentric.namespace.weatherservice.WeatherException; 15 | import de.codecentric.namespace.weatherservice.WeatherService; 16 | import de.codecentric.namespace.weatherservice.general.ForecastRequest; 17 | import de.codecentric.namespace.weatherservice.general.ForecastReturn; 18 | import de.jonashackt.tutorial.SimpleBootCxfSystemTestApplication; 19 | 20 | @RunWith(SpringJUnit4ClassRunner.class) 21 | @SpringApplicationConfiguration(classes=SimpleBootCxfSystemTestApplication.class) 22 | @WebIntegrationTest("server.port:8090") 23 | public class WeatherServiceSystemTest { 24 | 25 | @Autowired 26 | private WeatherService weatherServiceSystemTestClient; 27 | 28 | @Test 29 | public void getCityForecastByZIP() throws WeatherException { 30 | // Given 31 | ForecastRequest forecastRequest = generateDummyRequest(); 32 | 33 | // When 34 | ForecastReturn forecastReturn = weatherServiceSystemTestClient.getCityForecastByZIP(forecastRequest); 35 | 36 | // Then 37 | assertNotNull(forecastReturn); 38 | assertEquals(true, forecastReturn.isSuccess()); 39 | assertEquals("Weimar", forecastReturn.getCity()); 40 | assertEquals("22%", forecastReturn.getForecastResult().getForecast().get(0).getProbabilityOfPrecipiation().getDaytime()); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /step5_custom-soap-fault/src/test/java/de/jonashackt/tutorial/endpoint/WeatherServiceTest.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.endpoint; 2 | 3 | import static de.jonashackt.tutorial.utils.TestHelper.generateDummyRequest; 4 | import static org.junit.Assert.assertEquals; 5 | import static org.junit.Assert.assertNotNull; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.test.context.ContextConfiguration; 11 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 12 | 13 | import de.codecentric.namespace.weatherservice.WeatherException; 14 | import de.codecentric.namespace.weatherservice.general.ForecastRequest; 15 | import de.codecentric.namespace.weatherservice.general.ForecastReturn; 16 | import de.jonashackt.tutorial.ApplicationTestConfiguration; 17 | 18 | @RunWith(SpringJUnit4ClassRunner.class) 19 | @ContextConfiguration(classes=ApplicationTestConfiguration.class) 20 | public class WeatherServiceTest { 21 | 22 | @Autowired 23 | private WeatherServiceEndpoint weatherServiceEndpoint; 24 | 25 | @Test 26 | public void getCityForecastByZIP() throws WeatherException { 27 | // Given 28 | ForecastRequest forecastRequest = generateDummyRequest(); 29 | 30 | // When 31 | ForecastReturn forecastReturn = weatherServiceEndpoint.getCityForecastByZIP(forecastRequest); 32 | 33 | // Then 34 | assertNotNull(forecastReturn); 35 | assertEquals(true, forecastReturn.isSuccess()); 36 | assertEquals("Weimar", forecastReturn.getCity()); 37 | assertEquals("22%", forecastReturn.getForecastResult().getForecast().get(0).getProbabilityOfPrecipiation().getDaytime()); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /step5_custom-soap-fault/src/test/java/de/jonashackt/tutorial/utils/SoapRawClient.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.utils; 2 | 3 | import java.io.InputStream; 4 | 5 | import org.apache.http.Consts; 6 | import org.apache.http.HttpResponse; 7 | import org.apache.http.client.fluent.Request; 8 | import org.apache.http.client.fluent.Response; 9 | import org.apache.http.entity.ContentType; 10 | import org.slf4j.Logger; 11 | import org.slf4j.LoggerFactory; 12 | import org.springframework.stereotype.Component; 13 | 14 | import de.jonashackt.tutorial.common.InternalBusinessException; 15 | import de.jonashackt.tutorial.common.XmlUtils; 16 | 17 | @Component 18 | public class SoapRawClient { 19 | 20 | private static final Logger LOGGER = LoggerFactory.getLogger(SoapRawClient.class); 21 | private String soapAction; 22 | 23 | private String soapServiceUrl; 24 | 25 | public SoapRawClient(String soapServiceUrl, Class jaxWsServiceInterfaceClass) throws InternalBusinessException { 26 | this.soapAction = XmlUtils.getSoapActionFromJaxWsServiceInterface(jaxWsServiceInterfaceClass); 27 | this.soapServiceUrl = soapServiceUrl; 28 | } 29 | 30 | public SoapRawClientResponse callSoapService(InputStream xmlFile) throws InternalBusinessException { 31 | SoapRawClientResponse rawSoapResponse = new SoapRawClientResponse(); 32 | 33 | LOGGER.debug("Calling SoapService with POST on Apache HTTP-Client and configured URL: {}", soapServiceUrl); 34 | 35 | try { 36 | Response httpResponseContainer = Request 37 | .Post(soapServiceUrl) 38 | .bodyStream(xmlFile, contentTypeTextXmlUtf8()) 39 | .addHeader("SOAPAction", "\"" + soapAction + "\"") 40 | .execute(); 41 | 42 | HttpResponse httpResponse = httpResponseContainer.returnResponse(); 43 | rawSoapResponse.setHttpStatusCode(httpResponse.getStatusLine().getStatusCode()); 44 | rawSoapResponse.setHttpResponseBody(XmlUtils.parseFileStream2Document(httpResponse.getEntity().getContent())); 45 | 46 | } catch (Exception exception) { 47 | throw new InternalBusinessException("Some Error accured while trying to Call SoapService for test: " + exception.getMessage()); 48 | } 49 | return rawSoapResponse; 50 | } 51 | 52 | private ContentType contentTypeTextXmlUtf8() { 53 | return ContentType.create(ContentType.TEXT_XML.getMimeType(), Consts.UTF_8); 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /step5_custom-soap-fault/src/test/java/de/jonashackt/tutorial/utils/SoapRawClientResponse.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.utils; 2 | 3 | import org.w3c.dom.Document; 4 | import org.w3c.dom.Node; 5 | 6 | import de.jonashackt.tutorial.common.InternalBusinessException; 7 | import de.jonashackt.tutorial.common.XmlUtils; 8 | 9 | public class SoapRawClientResponse { 10 | 11 | private int httpStatusCode; 12 | private Document httpResponseBody; 13 | 14 | public int getHttpStatusCode() { 15 | return httpStatusCode; 16 | } 17 | public void setHttpStatusCode(int httpStatusCode) { 18 | this.httpStatusCode = httpStatusCode; 19 | } 20 | public Document getHttpResponseBody() { 21 | return httpResponseBody; 22 | } 23 | public void setHttpResponseBody(Document httpResponseBody) { 24 | this.httpResponseBody = httpResponseBody; 25 | } 26 | 27 | public Node getElementByNameWithNamespace(String namespaceUrl, String elementName) { 28 | return httpResponseBody.getElementsByTagNameNS(namespaceUrl, elementName).item(0); 29 | } 30 | 31 | public String getElementValueByName(String elementName) { 32 | Node node = httpResponseBody.getElementsByTagName(elementName).item(0); 33 | return node.getNodeValue(); 34 | } 35 | 36 | public String getFaultstringValue() { 37 | Node fault = getElementByNameWithNamespace("http://schemas.xmlsoap.org/soap/envelope/", "Fault"); 38 | // The second Node (with List-Nr. 1) is the 39 | Node faultstring = fault.getChildNodes().item(1); 40 | return faultstring.getTextContent(); 41 | } 42 | 43 | public T getUnmarshalledObjectFromSoapMessage(Class jaxbClass) throws InternalBusinessException { 44 | return XmlUtils.getUnmarshalledObjectFromSoapMessage(httpResponseBody, jaxbClass); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /step5_custom-soap-fault/src/test/java/de/jonashackt/tutorial/utils/TestHelper.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.utils; 2 | 3 | import de.codecentric.namespace.weatherservice.datatypes.ProductName; 4 | import de.codecentric.namespace.weatherservice.general.ForecastCustomer; 5 | import de.codecentric.namespace.weatherservice.general.ForecastRequest; 6 | 7 | public class TestHelper { 8 | 9 | public static ForecastRequest generateDummyRequest() { 10 | ForecastRequest forecastRequest = new ForecastRequest(); 11 | forecastRequest.setZIP("99425"); 12 | forecastRequest.setFlagcolor("blackblue"); 13 | forecastRequest.setProductName(ProductName.FORECAST_BASIC); 14 | ForecastCustomer customer = new ForecastCustomer(); 15 | customer.setAge(67); 16 | customer.setContribution(500); 17 | customer.setMethodOfPayment("Bitcoin"); 18 | forecastRequest.setForecastCustomer(customer); 19 | return forecastRequest; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /step5_custom-soap-fault/src/test/resources/requests/GetCityForecastByZIPTest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 99425 8 | bluewhite 9 | ForecastBasic 10 | 11 | 30 12 | 5000 13 | Paypal 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /step5_custom-soap-fault/src/test/resources/requests/xmlerrors/xmlErrorNotXmlSchemeCompliantRootElementTest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 99425 7 | 8 | 9 | -------------------------------------------------------------------------------- /step5_custom-soap-fault/src/test/resources/requests/xmlerrors/xmlErrorNotXmlSchemeCompliantUnderRootElementTest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 99425 7 | 8 | 9 | -------------------------------------------------------------------------------- /step5_custom-soap-fault/src/test/resources/requests/xmlerrors/xmlErrorSoapBodyTagMissingBracketTest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | -------------------------------------------------------------------------------- /step5_custom-soap-fault/src/test/resources/requests/xmlerrors/xmlErrorSoapEnvelopeTagMissingBracketTest.xml: -------------------------------------------------------------------------------- 1 | 2 | soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:gen="http://www.codecentric.de/namespace/weatherservice/general"> 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /step5_custom-soap-fault/src/test/resources/requests/xmlerrors/xmlErrorSoapHeaderMissingSlash.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /step5_custom-soap-fault/src/test/resources/requests/xmlerrors/xmlErrorSoapHeaderTagMissingBracketTest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /step5_custom-soap-fault/src/test/resources/requests/xmlerrors/xmlErrorXMLHeaderDefinitionMissingBracket.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /step5_custom-soap-fault/src/test/resources/requests/xmlerrors/xmlErrorXMLTagNotClosedInsideBodyTest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | notRelevantHere /> 6 | 7 | -------------------------------------------------------------------------------- /step6_soap_message_logging/src/main/java/de/jonashackt/tutorial/SimpleBootCxfApplication.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.context.annotation.ComponentScan; 6 | 7 | @SpringBootApplication 8 | @ComponentScan("de.jonashackt.tutorial") 9 | public class SimpleBootCxfApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(SimpleBootCxfApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /step6_soap_message_logging/src/main/java/de/jonashackt/tutorial/configuration/ApplicationConfiguration.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.configuration; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | 6 | import de.jonashackt.tutorial.controller.WeatherServiceController; 7 | 8 | 9 | @Configuration 10 | public class ApplicationConfiguration { 11 | 12 | @Bean 13 | public WeatherServiceController weatherServiceController() { 14 | return new WeatherServiceController(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /step6_soap_message_logging/src/main/java/de/jonashackt/tutorial/controller/WeatherServiceController.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.controller; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | import de.codecentric.namespace.weatherservice.general.ForecastRequest; 6 | import de.codecentric.namespace.weatherservice.general.ForecastReturn; 7 | import de.jonashackt.tutorial.transformation.GetCityForecastByZIPOutMapper; 8 | 9 | /* 10 | * Example-Controller: 11 | * This Class would be responsible for Mapping from Request to internal Datamodel (and backwards), 12 | * for calling Backend-Services and handling Backend-Exceptions 13 | * So it decouples the WSDL-generated Classes from the internal Classes - for when the former changes, 14 | * nothing or only the mapping has to be changed 15 | */ 16 | @Component 17 | public class WeatherServiceController { 18 | 19 | public ForecastReturn getCityForecastByZIP(ForecastRequest forecastRequest) { 20 | /* 21 | * We leave out inbound transformation, plausibility-checking, logging, backend-calls e.g. 22 | * for the moment 23 | */ 24 | return GetCityForecastByZIPOutMapper.mapGeneralOutlook2Forecast(); 25 | } 26 | 27 | /* 28 | * Other Methods would follow here... 29 | */ 30 | //public WeatherReturn getCityWeatherByZIP(ForecastRequest forecastRequest) throws BusinessException {} 31 | 32 | //public WeatherInformationReturn getWeatherInformation(String zip) throws BusinessException {} 33 | } 34 | -------------------------------------------------------------------------------- /step6_soap_message_logging/src/main/java/de/jonashackt/tutorial/endpoint/WeatherServiceEndpoint.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.endpoint; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | 5 | import de.codecentric.namespace.weatherservice.WeatherException; 6 | import de.codecentric.namespace.weatherservice.WeatherService; 7 | import de.codecentric.namespace.weatherservice.general.ForecastRequest; 8 | import de.codecentric.namespace.weatherservice.general.ForecastReturn; 9 | import de.codecentric.namespace.weatherservice.general.WeatherInformationReturn; 10 | import de.codecentric.namespace.weatherservice.general.WeatherReturn; 11 | import de.jonashackt.tutorial.controller.WeatherServiceController; 12 | 13 | 14 | public class WeatherServiceEndpoint implements WeatherService { 15 | 16 | @Autowired 17 | private WeatherServiceController weatherServiceController; 18 | 19 | @Override 20 | public ForecastReturn getCityForecastByZIP(ForecastRequest forecastRequest) throws WeatherException { 21 | return weatherServiceController.getCityForecastByZIP(forecastRequest); 22 | } 23 | 24 | @Override 25 | public WeatherInformationReturn getWeatherInformation(String zip) 26 | throws WeatherException { 27 | // TODO Auto-generated method stub 28 | return null; 29 | } 30 | 31 | @Override 32 | public WeatherReturn getCityWeatherByZIP(ForecastRequest forecastRequest) 33 | throws WeatherException { 34 | // TODO Auto-generated method stub 35 | return null; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /step6_soap_message_logging/src/main/resources/META-INF/cxf/org.apache.cxf.Logger: -------------------------------------------------------------------------------- 1 | org.apache.cxf.common.logging.Slf4jLogger -------------------------------------------------------------------------------- /step6_soap_message_logging/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jonashackt/tutorial-soap-spring-boot-cxf/3960f26a558a84e4c40474336c115942e528d135/step6_soap_message_logging/src/main/resources/application.properties -------------------------------------------------------------------------------- /step6_soap_message_logging/src/main/resources/logback-spring.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | weather-service.log 10 | true 11 | 12 | %-4relative [%thread] %-5level %logger{35} - %msg%n 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /step6_soap_message_logging/src/main/resources/service-api-definition/Weather-Schemes/w3c-xmlmime-definition.xsd: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /step6_soap_message_logging/src/main/resources/service-api-definition/Weather-Schemes/weather-exception.xsd: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /step6_soap_message_logging/src/main/resources/service-api-definition/Weather1.0.xsd: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 12 | 13 | 15 | 16 | -------------------------------------------------------------------------------- /step6_soap_message_logging/src/test/java/de/jonashackt/tutorial/ApplicationTestConfiguration.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.context.annotation.Import; 6 | 7 | import de.codecentric.namespace.weatherservice.WeatherService; 8 | import de.jonashackt.tutorial.configuration.ApplicationConfiguration; 9 | import de.jonashackt.tutorial.endpoint.WeatherServiceEndpoint; 10 | 11 | @Configuration 12 | @Import(ApplicationConfiguration.class) 13 | public class ApplicationTestConfiguration { 14 | 15 | @Bean 16 | public WeatherService weatherService() { 17 | return new WeatherServiceEndpoint(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /step6_soap_message_logging/src/test/java/de/jonashackt/tutorial/SimpleBootCxfSystemTestApplication.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.context.annotation.Import; 6 | 7 | @SpringBootApplication 8 | @Import(WebServiceSystemTestConfiguration.class) 9 | public class SimpleBootCxfSystemTestApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(SimpleBootCxfSystemTestApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /step6_soap_message_logging/src/test/java/de/jonashackt/tutorial/WebServiceIntegrationTestConfiguration.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial; 2 | 3 | import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | import de.codecentric.namespace.weatherservice.WeatherService; 8 | import de.jonashackt.tutorial.configuration.WebServiceConfiguration; 9 | 10 | @Configuration 11 | public class WebServiceIntegrationTestConfiguration { 12 | 13 | @Bean 14 | public WeatherService weatherServiceIntegrationTestClient() { 15 | JaxWsProxyFactoryBean jaxWsProxyFactory = new JaxWsProxyFactoryBean(); 16 | jaxWsProxyFactory.setServiceClass(WeatherService.class); 17 | jaxWsProxyFactory.setAddress("http://localhost:8080" + WebServiceConfiguration.BASE_URL + WebServiceConfiguration.SERVICE_URL); 18 | return (WeatherService) jaxWsProxyFactory.create(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /step6_soap_message_logging/src/test/java/de/jonashackt/tutorial/WebServiceSystemTestConfiguration.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial; 2 | 3 | import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | import de.codecentric.namespace.weatherservice.WeatherService; 8 | import de.jonashackt.tutorial.configuration.WebServiceConfiguration; 9 | 10 | @Configuration 11 | public class WebServiceSystemTestConfiguration { 12 | 13 | @Bean 14 | public WeatherService weatherServiceSystemTestClient() { 15 | JaxWsProxyFactoryBean jaxWsProxyFactory = new JaxWsProxyFactoryBean(); 16 | jaxWsProxyFactory.setServiceClass(WeatherService.class); 17 | jaxWsProxyFactory.setAddress("http://localhost:8090" + WebServiceConfiguration.BASE_URL + WebServiceConfiguration.SERVICE_URL); 18 | return (WeatherService) jaxWsProxyFactory.create(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /step6_soap_message_logging/src/test/java/de/jonashackt/tutorial/endpoint/WeatherServiceIntegrationTest.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.endpoint; 2 | 3 | import static de.jonashackt.tutorial.utils.TestHelper.generateDummyRequest; 4 | import static org.junit.Assert.assertEquals; 5 | import static org.junit.Assert.assertNotNull; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.test.context.ContextConfiguration; 11 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 12 | 13 | import de.codecentric.namespace.weatherservice.WeatherException; 14 | import de.codecentric.namespace.weatherservice.WeatherService; 15 | import de.codecentric.namespace.weatherservice.general.ForecastRequest; 16 | import de.codecentric.namespace.weatherservice.general.ForecastReturn; 17 | import de.jonashackt.tutorial.WebServiceIntegrationTestConfiguration; 18 | 19 | @RunWith(SpringJUnit4ClassRunner.class) 20 | @ContextConfiguration(classes=WebServiceIntegrationTestConfiguration.class) 21 | public class WeatherServiceIntegrationTest { 22 | 23 | @Autowired 24 | private WeatherService weatherServiceIntegrationTestClient; 25 | 26 | @Test 27 | public void getCityForecastByZIP() throws WeatherException { 28 | // Given 29 | ForecastRequest forecastRequest = generateDummyRequest(); 30 | 31 | // When 32 | ForecastReturn forecastReturn = weatherServiceIntegrationTestClient.getCityForecastByZIP(forecastRequest); 33 | 34 | // Then 35 | assertNotNull(forecastReturn); 36 | assertEquals(true, forecastReturn.isSuccess()); 37 | assertEquals("Weimar", forecastReturn.getCity()); 38 | assertEquals("22%", forecastReturn.getForecastResult().getForecast().get(0).getProbabilityOfPrecipiation().getDaytime()); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /step6_soap_message_logging/src/test/java/de/jonashackt/tutorial/endpoint/WeatherServiceSystemTest.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.endpoint; 2 | 3 | import static de.jonashackt.tutorial.utils.TestHelper.generateDummyRequest; 4 | import static org.junit.Assert.assertEquals; 5 | import static org.junit.Assert.assertNotNull; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.boot.test.SpringApplicationConfiguration; 11 | import org.springframework.boot.test.WebIntegrationTest; 12 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 13 | 14 | import de.codecentric.namespace.weatherservice.WeatherException; 15 | import de.codecentric.namespace.weatherservice.WeatherService; 16 | import de.codecentric.namespace.weatherservice.general.ForecastRequest; 17 | import de.codecentric.namespace.weatherservice.general.ForecastReturn; 18 | import de.jonashackt.tutorial.SimpleBootCxfSystemTestApplication; 19 | 20 | @RunWith(SpringJUnit4ClassRunner.class) 21 | @SpringApplicationConfiguration(classes=SimpleBootCxfSystemTestApplication.class) 22 | @WebIntegrationTest("server.port:8090") 23 | public class WeatherServiceSystemTest { 24 | 25 | @Autowired 26 | private WeatherService weatherServiceSystemTestClient; 27 | 28 | @Test 29 | public void getCityForecastByZIP() throws WeatherException { 30 | // Given 31 | ForecastRequest forecastRequest = generateDummyRequest(); 32 | 33 | // When 34 | ForecastReturn forecastReturn = weatherServiceSystemTestClient.getCityForecastByZIP(forecastRequest); 35 | 36 | // Then 37 | assertNotNull(forecastReturn); 38 | assertEquals(true, forecastReturn.isSuccess()); 39 | assertEquals("Weimar", forecastReturn.getCity()); 40 | assertEquals("22%", forecastReturn.getForecastResult().getForecast().get(0).getProbabilityOfPrecipiation().getDaytime()); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /step6_soap_message_logging/src/test/java/de/jonashackt/tutorial/endpoint/WeatherServiceTest.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.endpoint; 2 | 3 | import static de.jonashackt.tutorial.utils.TestHelper.generateDummyRequest; 4 | import static org.junit.Assert.assertEquals; 5 | import static org.junit.Assert.assertNotNull; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.test.context.ContextConfiguration; 11 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 12 | 13 | import de.codecentric.namespace.weatherservice.WeatherException; 14 | import de.codecentric.namespace.weatherservice.general.ForecastRequest; 15 | import de.codecentric.namespace.weatherservice.general.ForecastReturn; 16 | import de.jonashackt.tutorial.ApplicationTestConfiguration; 17 | 18 | @RunWith(SpringJUnit4ClassRunner.class) 19 | @ContextConfiguration(classes=ApplicationTestConfiguration.class) 20 | public class WeatherServiceTest { 21 | 22 | @Autowired 23 | private WeatherServiceEndpoint weatherServiceEndpoint; 24 | 25 | @Test 26 | public void getCityForecastByZIP() throws WeatherException { 27 | // Given 28 | ForecastRequest forecastRequest = generateDummyRequest(); 29 | 30 | // When 31 | ForecastReturn forecastReturn = weatherServiceEndpoint.getCityForecastByZIP(forecastRequest); 32 | 33 | // Then 34 | assertNotNull(forecastReturn); 35 | assertEquals(true, forecastReturn.isSuccess()); 36 | assertEquals("Weimar", forecastReturn.getCity()); 37 | assertEquals("22%", forecastReturn.getForecastResult().getForecast().get(0).getProbabilityOfPrecipiation().getDaytime()); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /step6_soap_message_logging/src/test/java/de/jonashackt/tutorial/endpoint/WeatherServiceXmlFileSystemTest.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.endpoint; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | import static org.junit.Assert.assertNotNull; 5 | 6 | import java.io.IOException; 7 | 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.beans.factory.annotation.Value; 12 | import org.springframework.boot.test.SpringApplicationConfiguration; 13 | import org.springframework.boot.test.WebIntegrationTest; 14 | import org.springframework.core.io.Resource; 15 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 16 | 17 | import de.codecentric.namespace.weatherservice.WeatherException; 18 | import de.codecentric.namespace.weatherservice.WeatherService; 19 | import de.codecentric.namespace.weatherservice.general.ForecastReturn; 20 | import de.codecentric.namespace.weatherservice.general.GetCityForecastByZIP; 21 | import de.jonashackt.tutorial.SimpleBootCxfSystemTestApplication; 22 | import de.jonashackt.tutorial.utils.XmlUtilsException; 23 | import de.jonashackt.tutorial.utils.XmlUtils; 24 | 25 | @RunWith(SpringJUnit4ClassRunner.class) 26 | @SpringApplicationConfiguration(classes=SimpleBootCxfSystemTestApplication.class) 27 | @WebIntegrationTest("server.port:8090") 28 | public class WeatherServiceXmlFileSystemTest { 29 | 30 | @Autowired 31 | private WeatherService weatherServiceSystemTestClient; 32 | 33 | @Value(value="classpath:requests/GetCityForecastByZIPTest.xml") 34 | private Resource getCityForecastByZIPTestXml; 35 | 36 | @Test 37 | public void getCityForecastByZIP() throws WeatherException, XmlUtilsException, IOException { 38 | // Given 39 | GetCityForecastByZIP getCityForecastByZIP = XmlUtils.readSoapMessageFromStreamAndUnmarshallBody2Object(getCityForecastByZIPTestXml.getInputStream(), GetCityForecastByZIP.class); 40 | 41 | // When 42 | ForecastReturn forecastReturn = weatherServiceSystemTestClient.getCityForecastByZIP(getCityForecastByZIP.getForecastRequest()); 43 | 44 | // Then 45 | assertNotNull(forecastReturn); 46 | assertEquals(true, forecastReturn.isSuccess()); 47 | assertEquals("Weimar", forecastReturn.getCity()); 48 | assertEquals("22%", forecastReturn.getForecastResult().getForecast().get(0).getProbabilityOfPrecipiation().getDaytime()); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /step6_soap_message_logging/src/test/java/de/jonashackt/tutorial/utils/TestHelper.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.utils; 2 | 3 | import de.codecentric.namespace.weatherservice.datatypes.ProductName; 4 | import de.codecentric.namespace.weatherservice.general.ForecastCustomer; 5 | import de.codecentric.namespace.weatherservice.general.ForecastRequest; 6 | 7 | public class TestHelper { 8 | 9 | public static ForecastRequest generateDummyRequest() { 10 | ForecastRequest forecastRequest = new ForecastRequest(); 11 | forecastRequest.setZIP("99425"); 12 | forecastRequest.setFlagcolor("blackblue"); 13 | forecastRequest.setProductName(ProductName.FORECAST_BASIC); 14 | ForecastCustomer customer = new ForecastCustomer(); 15 | customer.setAge(67); 16 | customer.setContribution(500); 17 | customer.setMethodOfPayment("Bitcoin"); 18 | forecastRequest.setForecastCustomer(customer); 19 | return forecastRequest; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /step6_soap_message_logging/src/test/java/de/jonashackt/tutorial/utils/XmlUtilsException.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.utils; 2 | 3 | public class XmlUtilsException extends Exception { 4 | private static final long serialVersionUID = 1L; 5 | 6 | public XmlUtilsException(Throwable cause) { 7 | super(cause); 8 | } 9 | 10 | public XmlUtilsException(String message, Throwable cause) { 11 | super(message, cause); 12 | } 13 | 14 | public XmlUtilsException(String message) { 15 | super(message); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /step6_soap_message_logging/src/test/resources/requests/GetCityForecastByZIPTest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 99425 8 | bluewhite 9 | ForecastBasic 10 | 11 | 30 12 | 5000 13 | Paypal 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /step7_soap_message_logging_payload_only/src/main/java/de/jonashackt/tutorial/SimpleBootCxfApplication.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.context.annotation.ComponentScan; 6 | 7 | @SpringBootApplication 8 | @ComponentScan("de.jonashackt.tutorial") 9 | public class SimpleBootCxfApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(SimpleBootCxfApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /step7_soap_message_logging_payload_only/src/main/java/de/jonashackt/tutorial/configuration/ApplicationConfiguration.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.configuration; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | 6 | import de.jonashackt.tutorial.controller.WeatherServiceController; 7 | 8 | 9 | @Configuration 10 | public class ApplicationConfiguration { 11 | 12 | @Bean 13 | public WeatherServiceController weatherServiceController() { 14 | return new WeatherServiceController(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /step7_soap_message_logging_payload_only/src/main/java/de/jonashackt/tutorial/controller/WeatherServiceController.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.controller; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | import de.codecentric.namespace.weatherservice.general.ForecastRequest; 6 | import de.codecentric.namespace.weatherservice.general.ForecastReturn; 7 | import de.jonashackt.tutorial.transformation.GetCityForecastByZIPOutMapper; 8 | 9 | /* 10 | * Example-Controller: 11 | * This Class would be responsible for Mapping from Request to internal Datamodel (and backwards), 12 | * for calling Backend-Services and handling Backend-Exceptions 13 | * So it decouples the WSDL-generated Classes from the internal Classes - for when the former changes, 14 | * nothing or only the mapping has to be changed 15 | */ 16 | @Component 17 | public class WeatherServiceController { 18 | 19 | public ForecastReturn getCityForecastByZIP(ForecastRequest forecastRequest) { 20 | /* 21 | * We leave out inbound transformation, plausibility-checking, logging, backend-calls e.g. 22 | * for the moment 23 | */ 24 | return GetCityForecastByZIPOutMapper.mapGeneralOutlook2Forecast(); 25 | } 26 | 27 | /* 28 | * Other Methods would follow here... 29 | */ 30 | //public WeatherReturn getCityWeatherByZIP(ForecastRequest forecastRequest) throws BusinessException {} 31 | 32 | //public WeatherInformationReturn getWeatherInformation(String zip) throws BusinessException {} 33 | } 34 | -------------------------------------------------------------------------------- /step7_soap_message_logging_payload_only/src/main/java/de/jonashackt/tutorial/endpoint/WeatherServiceEndpoint.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.endpoint; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | 5 | import de.codecentric.namespace.weatherservice.WeatherException; 6 | import de.codecentric.namespace.weatherservice.WeatherService; 7 | import de.codecentric.namespace.weatherservice.general.ForecastRequest; 8 | import de.codecentric.namespace.weatherservice.general.ForecastReturn; 9 | import de.codecentric.namespace.weatherservice.general.WeatherInformationReturn; 10 | import de.codecentric.namespace.weatherservice.general.WeatherReturn; 11 | import de.jonashackt.tutorial.controller.WeatherServiceController; 12 | 13 | 14 | public class WeatherServiceEndpoint implements WeatherService { 15 | 16 | @Autowired 17 | private WeatherServiceController weatherServiceController; 18 | 19 | @Override 20 | public ForecastReturn getCityForecastByZIP(ForecastRequest forecastRequest) throws WeatherException { 21 | return weatherServiceController.getCityForecastByZIP(forecastRequest); 22 | } 23 | 24 | @Override 25 | public WeatherInformationReturn getWeatherInformation(String zip) 26 | throws WeatherException { 27 | // TODO Auto-generated method stub 28 | return null; 29 | } 30 | 31 | @Override 32 | public WeatherReturn getCityWeatherByZIP(ForecastRequest forecastRequest) 33 | throws WeatherException { 34 | // TODO Auto-generated method stub 35 | return null; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /step7_soap_message_logging_payload_only/src/main/java/de/jonashackt/tutorial/soapmsglogging/LoggingInInterceptorXmlOnly.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.soapmsglogging; 2 | 3 | import org.apache.cxf.interceptor.LoggingInInterceptor; 4 | import org.apache.cxf.interceptor.LoggingMessage; 5 | 6 | public class LoggingInInterceptorXmlOnly extends LoggingInInterceptor { 7 | 8 | @Override 9 | protected String formatLoggingMessage(LoggingMessage loggingMessage) { 10 | StringBuilder buffer = new StringBuilder(); 11 | buffer.append("Inbound Message:\n"); 12 | 13 | // Only write the Payload (SOAP-Xml) to Logger 14 | if (loggingMessage.getPayload().length() > 0) { 15 | buffer.append(loggingMessage.getPayload()); 16 | } 17 | return buffer.toString(); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /step7_soap_message_logging_payload_only/src/main/java/de/jonashackt/tutorial/soapmsglogging/LoggingOutInterceptorXmlOnly.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.soapmsglogging; 2 | 3 | import org.apache.cxf.interceptor.LoggingMessage; 4 | import org.apache.cxf.interceptor.LoggingOutInterceptor; 5 | 6 | public class LoggingOutInterceptorXmlOnly extends LoggingOutInterceptor { 7 | 8 | @Override 9 | protected String formatLoggingMessage(LoggingMessage loggingMessage) { 10 | StringBuilder buffer = new StringBuilder(); 11 | buffer.append("Outbound Message:\n"); 12 | 13 | // Only write the Payload (SOAP-Xml) to Logger 14 | if (loggingMessage.getPayload().length() > 0) { 15 | buffer.append(loggingMessage.getPayload()); 16 | } 17 | return buffer.toString(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /step7_soap_message_logging_payload_only/src/main/resources/META-INF/cxf/org.apache.cxf.Logger: -------------------------------------------------------------------------------- 1 | org.apache.cxf.common.logging.Slf4jLogger -------------------------------------------------------------------------------- /step7_soap_message_logging_payload_only/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jonashackt/tutorial-soap-spring-boot-cxf/3960f26a558a84e4c40474336c115942e528d135/step7_soap_message_logging_payload_only/src/main/resources/application.properties -------------------------------------------------------------------------------- /step7_soap_message_logging_payload_only/src/main/resources/logback-spring.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | weather-service.log 10 | true 11 | 12 | %-4relative [%thread] %-5level %logger{35} - %msg%n 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /step7_soap_message_logging_payload_only/src/main/resources/service-api-definition/Weather-Schemes/w3c-xmlmime-definition.xsd: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /step7_soap_message_logging_payload_only/src/main/resources/service-api-definition/Weather-Schemes/weather-exception.xsd: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /step7_soap_message_logging_payload_only/src/main/resources/service-api-definition/Weather1.0.xsd: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 12 | 13 | 15 | 16 | -------------------------------------------------------------------------------- /step7_soap_message_logging_payload_only/src/test/java/de/jonashackt/tutorial/ApplicationTestConfiguration.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.context.annotation.Import; 6 | 7 | import de.codecentric.namespace.weatherservice.WeatherService; 8 | import de.jonashackt.tutorial.configuration.ApplicationConfiguration; 9 | import de.jonashackt.tutorial.endpoint.WeatherServiceEndpoint; 10 | 11 | @Configuration 12 | @Import(ApplicationConfiguration.class) 13 | public class ApplicationTestConfiguration { 14 | 15 | @Bean 16 | public WeatherService weatherService() { 17 | return new WeatherServiceEndpoint(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /step7_soap_message_logging_payload_only/src/test/java/de/jonashackt/tutorial/SimpleBootCxfSystemTestApplication.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.context.annotation.Import; 6 | 7 | @SpringBootApplication 8 | @Import(WebServiceSystemTestConfiguration.class) 9 | public class SimpleBootCxfSystemTestApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(SimpleBootCxfSystemTestApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /step7_soap_message_logging_payload_only/src/test/java/de/jonashackt/tutorial/WebServiceIntegrationTestConfiguration.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial; 2 | 3 | import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | import de.codecentric.namespace.weatherservice.WeatherService; 8 | import de.jonashackt.tutorial.configuration.WebServiceConfiguration; 9 | 10 | @Configuration 11 | public class WebServiceIntegrationTestConfiguration { 12 | 13 | @Bean 14 | public WeatherService weatherServiceIntegrationTestClient() { 15 | JaxWsProxyFactoryBean jaxWsProxyFactory = new JaxWsProxyFactoryBean(); 16 | jaxWsProxyFactory.setServiceClass(WeatherService.class); 17 | jaxWsProxyFactory.setAddress("http://localhost:8080" + WebServiceConfiguration.BASE_URL + WebServiceConfiguration.SERVICE_URL); 18 | return (WeatherService) jaxWsProxyFactory.create(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /step7_soap_message_logging_payload_only/src/test/java/de/jonashackt/tutorial/WebServiceSystemTestConfiguration.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial; 2 | 3 | import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | import de.codecentric.namespace.weatherservice.WeatherService; 8 | import de.jonashackt.tutorial.configuration.WebServiceConfiguration; 9 | 10 | @Configuration 11 | public class WebServiceSystemTestConfiguration { 12 | 13 | @Bean 14 | public WeatherService weatherServiceSystemTestClient() { 15 | JaxWsProxyFactoryBean jaxWsProxyFactory = new JaxWsProxyFactoryBean(); 16 | jaxWsProxyFactory.setServiceClass(WeatherService.class); 17 | jaxWsProxyFactory.setAddress("http://localhost:8090" + WebServiceConfiguration.BASE_URL + WebServiceConfiguration.SERVICE_URL); 18 | return (WeatherService) jaxWsProxyFactory.create(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /step7_soap_message_logging_payload_only/src/test/java/de/jonashackt/tutorial/endpoint/WeatherServiceIntegrationTest.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.endpoint; 2 | 3 | import static de.jonashackt.tutorial.utils.TestHelper.generateDummyRequest; 4 | import static org.junit.Assert.assertEquals; 5 | import static org.junit.Assert.assertNotNull; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.test.context.ContextConfiguration; 11 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 12 | 13 | import de.codecentric.namespace.weatherservice.WeatherException; 14 | import de.codecentric.namespace.weatherservice.WeatherService; 15 | import de.codecentric.namespace.weatherservice.general.ForecastRequest; 16 | import de.codecentric.namespace.weatherservice.general.ForecastReturn; 17 | import de.jonashackt.tutorial.WebServiceIntegrationTestConfiguration; 18 | 19 | @RunWith(SpringJUnit4ClassRunner.class) 20 | @ContextConfiguration(classes=WebServiceIntegrationTestConfiguration.class) 21 | public class WeatherServiceIntegrationTest { 22 | 23 | @Autowired 24 | private WeatherService weatherServiceIntegrationTestClient; 25 | 26 | @Test 27 | public void getCityForecastByZIP() throws WeatherException { 28 | // Given 29 | ForecastRequest forecastRequest = generateDummyRequest(); 30 | 31 | // When 32 | ForecastReturn forecastReturn = weatherServiceIntegrationTestClient.getCityForecastByZIP(forecastRequest); 33 | 34 | // Then 35 | assertNotNull(forecastReturn); 36 | assertEquals(true, forecastReturn.isSuccess()); 37 | assertEquals("Weimar", forecastReturn.getCity()); 38 | assertEquals("22%", forecastReturn.getForecastResult().getForecast().get(0).getProbabilityOfPrecipiation().getDaytime()); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /step7_soap_message_logging_payload_only/src/test/java/de/jonashackt/tutorial/endpoint/WeatherServiceSystemTest.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.endpoint; 2 | 3 | import static de.jonashackt.tutorial.utils.TestHelper.generateDummyRequest; 4 | import static org.junit.Assert.assertEquals; 5 | import static org.junit.Assert.assertNotNull; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.boot.test.SpringApplicationConfiguration; 11 | import org.springframework.boot.test.WebIntegrationTest; 12 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 13 | 14 | import de.codecentric.namespace.weatherservice.WeatherException; 15 | import de.codecentric.namespace.weatherservice.WeatherService; 16 | import de.codecentric.namespace.weatherservice.general.ForecastRequest; 17 | import de.codecentric.namespace.weatherservice.general.ForecastReturn; 18 | import de.jonashackt.tutorial.SimpleBootCxfSystemTestApplication; 19 | 20 | @RunWith(SpringJUnit4ClassRunner.class) 21 | @SpringApplicationConfiguration(classes=SimpleBootCxfSystemTestApplication.class) 22 | @WebIntegrationTest("server.port:8090") 23 | public class WeatherServiceSystemTest { 24 | 25 | @Autowired 26 | private WeatherService weatherServiceSystemTestClient; 27 | 28 | @Test 29 | public void getCityForecastByZIP() throws WeatherException { 30 | // Given 31 | ForecastRequest forecastRequest = generateDummyRequest(); 32 | 33 | // When 34 | ForecastReturn forecastReturn = weatherServiceSystemTestClient.getCityForecastByZIP(forecastRequest); 35 | 36 | // Then 37 | assertNotNull(forecastReturn); 38 | assertEquals(true, forecastReturn.isSuccess()); 39 | assertEquals("Weimar", forecastReturn.getCity()); 40 | assertEquals("22%", forecastReturn.getForecastResult().getForecast().get(0).getProbabilityOfPrecipiation().getDaytime()); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /step7_soap_message_logging_payload_only/src/test/java/de/jonashackt/tutorial/endpoint/WeatherServiceTest.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.endpoint; 2 | 3 | import static de.jonashackt.tutorial.utils.TestHelper.generateDummyRequest; 4 | import static org.junit.Assert.assertEquals; 5 | import static org.junit.Assert.assertNotNull; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.test.context.ContextConfiguration; 11 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 12 | 13 | import de.codecentric.namespace.weatherservice.WeatherException; 14 | import de.codecentric.namespace.weatherservice.general.ForecastRequest; 15 | import de.codecentric.namespace.weatherservice.general.ForecastReturn; 16 | import de.jonashackt.tutorial.ApplicationTestConfiguration; 17 | 18 | @RunWith(SpringJUnit4ClassRunner.class) 19 | @ContextConfiguration(classes=ApplicationTestConfiguration.class) 20 | public class WeatherServiceTest { 21 | 22 | @Autowired 23 | private WeatherServiceEndpoint weatherServiceEndpoint; 24 | 25 | @Test 26 | public void getCityForecastByZIP() throws WeatherException { 27 | // Given 28 | ForecastRequest forecastRequest = generateDummyRequest(); 29 | 30 | // When 31 | ForecastReturn forecastReturn = weatherServiceEndpoint.getCityForecastByZIP(forecastRequest); 32 | 33 | // Then 34 | assertNotNull(forecastReturn); 35 | assertEquals(true, forecastReturn.isSuccess()); 36 | assertEquals("Weimar", forecastReturn.getCity()); 37 | assertEquals("22%", forecastReturn.getForecastResult().getForecast().get(0).getProbabilityOfPrecipiation().getDaytime()); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /step7_soap_message_logging_payload_only/src/test/java/de/jonashackt/tutorial/utils/TestHelper.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.utils; 2 | 3 | import de.codecentric.namespace.weatherservice.datatypes.ProductName; 4 | import de.codecentric.namespace.weatherservice.general.ForecastCustomer; 5 | import de.codecentric.namespace.weatherservice.general.ForecastRequest; 6 | 7 | public class TestHelper { 8 | 9 | public static ForecastRequest generateDummyRequest() { 10 | ForecastRequest forecastRequest = new ForecastRequest(); 11 | forecastRequest.setZIP("99425"); 12 | forecastRequest.setFlagcolor("blackblue"); 13 | forecastRequest.setProductName(ProductName.FORECAST_BASIC); 14 | ForecastCustomer customer = new ForecastCustomer(); 15 | customer.setAge(67); 16 | customer.setContribution(500); 17 | customer.setMethodOfPayment("Bitcoin"); 18 | forecastRequest.setForecastCustomer(customer); 19 | return forecastRequest; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /step7_soap_message_logging_payload_only/src/test/java/de/jonashackt/tutorial/utils/XmlUtilsException.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.utils; 2 | 3 | public class XmlUtilsException extends Exception { 4 | private static final long serialVersionUID = 1L; 5 | 6 | public XmlUtilsException(Throwable cause) { 7 | super(cause); 8 | } 9 | 10 | public XmlUtilsException(String message, Throwable cause) { 11 | super(message, cause); 12 | } 13 | 14 | public XmlUtilsException(String message) { 15 | super(message); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /step7_soap_message_logging_payload_only/src/test/resources/requests/GetCityForecastByZIPTest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 99425 8 | bluewhite 9 | ForecastBasic 10 | 11 | 30 12 | 5000 13 | Paypal 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /step8_logging_into_elasticstack/src/main/java/de/jonashackt/tutorial/SimpleBootCxfApplication.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.context.annotation.ComponentScan; 6 | 7 | @SpringBootApplication 8 | @ComponentScan("de.jonashackt.tutorial") 9 | public class SimpleBootCxfApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(SimpleBootCxfApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /step8_logging_into_elasticstack/src/main/java/de/jonashackt/tutorial/configuration/ApplicationConfiguration.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.configuration; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | 6 | import de.jonashackt.tutorial.controller.WeatherServiceController; 7 | 8 | 9 | @Configuration 10 | public class ApplicationConfiguration { 11 | 12 | @Bean 13 | public WeatherServiceController weatherServiceController() { 14 | return new WeatherServiceController(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /step8_logging_into_elasticstack/src/main/java/de/jonashackt/tutorial/controller/WeatherServiceController.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.controller; 2 | 3 | import de.codecentric.namespace.weatherservice.general.ForecastRequest; 4 | import de.codecentric.namespace.weatherservice.general.ForecastReturn; 5 | import de.jonashackt.tutorial.transformation.GetCityForecastByZIPOutMapper; 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | import org.springframework.stereotype.Component; 9 | 10 | /* 11 | * Example-Controller: 12 | * This Class would be responsible for Mapping from Request to internal Datamodel (and backwards), 13 | * for calling Backend-Services and handling Backend-Exceptions 14 | * So it decouples the WSDL-generated Classes from the internal Classes - for when the former changes, 15 | * nothing or only the mapping has to be changed 16 | */ 17 | @Component 18 | public class WeatherServiceController { 19 | 20 | private static final Logger LOG = LoggerFactory.getLogger(WeatherServiceController.class); 21 | 22 | public ForecastReturn getCityForecastByZIP(ForecastRequest forecastRequest) { 23 | /* 24 | * We leave out inbound transformation, plausibility-checking, logging, backend-calls e.g. 25 | * for the moment 26 | * 27 | * Just some Log-Statements here :) 28 | */ 29 | LOG.info("Starting inbound transformation into internal datamodel"); 30 | 31 | LOG.info("Checking plausibility of data"); 32 | 33 | LOG.info("Calling Backend No. 1"); 34 | 35 | LOG.info("Calling Backend No. 2"); 36 | 37 | LOG.info("Starting outbound transformation into external datamodel"); 38 | 39 | return GetCityForecastByZIPOutMapper.mapGeneralOutlook2Forecast(); 40 | } 41 | 42 | /* 43 | * Other Methods would follow here... 44 | */ 45 | //public WeatherReturn getCityWeatherByZIP(ForecastRequest forecastRequest) throws BusinessException {} 46 | 47 | //public WeatherInformationReturn getWeatherInformation(String zip) throws BusinessException {} 48 | } 49 | -------------------------------------------------------------------------------- /step8_logging_into_elasticstack/src/main/java/de/jonashackt/tutorial/endpoint/WeatherServiceEndpoint.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.endpoint; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | 7 | import de.codecentric.namespace.weatherservice.WeatherException; 8 | import de.codecentric.namespace.weatherservice.WeatherService; 9 | import de.codecentric.namespace.weatherservice.general.ForecastRequest; 10 | import de.codecentric.namespace.weatherservice.general.ForecastReturn; 11 | import de.codecentric.namespace.weatherservice.general.WeatherInformationReturn; 12 | import de.codecentric.namespace.weatherservice.general.WeatherReturn; 13 | import de.jonashackt.tutorial.controller.WeatherServiceController; 14 | 15 | 16 | public class WeatherServiceEndpoint implements WeatherService { 17 | 18 | private static final Logger LOG = LoggerFactory.getLogger(WeatherServiceEndpoint.class); 19 | 20 | @Autowired 21 | private WeatherServiceController weatherServiceController; 22 | 23 | @Override 24 | public ForecastReturn getCityForecastByZIP(ForecastRequest forecastRequest) throws WeatherException { 25 | LOG.debug("Method getCityForecastByZIP() was called. Processing the Request in the backend"); 26 | 27 | return weatherServiceController.getCityForecastByZIP(forecastRequest); 28 | } 29 | 30 | @Override 31 | public WeatherInformationReturn getWeatherInformation(String zip) throws WeatherException { 32 | // TODO Auto-generated method stub 33 | return null; 34 | } 35 | 36 | @Override 37 | public WeatherReturn getCityWeatherByZIP(ForecastRequest forecastRequest) throws WeatherException { 38 | // TODO Auto-generated method stub 39 | return null; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /step8_logging_into_elasticstack/src/main/java/de/jonashackt/tutorial/soapmsglogging/LoggingInInterceptorXmlOnly.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.soapmsglogging; 2 | 3 | import org.apache.cxf.interceptor.LoggingInInterceptor; 4 | import org.apache.cxf.interceptor.LoggingMessage; 5 | 6 | public class LoggingInInterceptorXmlOnly extends LoggingInInterceptor { 7 | 8 | @Override 9 | protected String formatLoggingMessage(LoggingMessage loggingMessage) { 10 | StringBuilder buffer = new StringBuilder(); 11 | buffer.append("Inbound Message:\n"); 12 | 13 | // Only write the Payload (SOAP-Xml) to Logger 14 | if (loggingMessage.getPayload().length() > 0) { 15 | buffer.append(loggingMessage.getPayload()); 16 | } 17 | return buffer.toString(); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /step8_logging_into_elasticstack/src/main/java/de/jonashackt/tutorial/soapmsglogging/LoggingOutInterceptorXmlOnly.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.soapmsglogging; 2 | 3 | import org.apache.cxf.interceptor.LoggingMessage; 4 | import org.apache.cxf.interceptor.LoggingOutInterceptor; 5 | 6 | public class LoggingOutInterceptorXmlOnly extends LoggingOutInterceptor { 7 | 8 | @Override 9 | protected String formatLoggingMessage(LoggingMessage loggingMessage) { 10 | StringBuilder buffer = new StringBuilder(); 11 | buffer.append("Outbound Message:\n"); 12 | 13 | // Only write the Payload (SOAP-Xml) to Logger 14 | if (loggingMessage.getPayload().length() > 0) { 15 | buffer.append(loggingMessage.getPayload()); 16 | } 17 | return buffer.toString(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /step8_logging_into_elasticstack/src/main/resources/META-INF/cxf/org.apache.cxf.Logger: -------------------------------------------------------------------------------- 1 | org.apache.cxf.common.logging.Slf4jLogger -------------------------------------------------------------------------------- /step8_logging_into_elasticstack/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jonashackt/tutorial-soap-spring-boot-cxf/3960f26a558a84e4c40474336c115942e528d135/step8_logging_into_elasticstack/src/main/resources/application.properties -------------------------------------------------------------------------------- /step8_logging_into_elasticstack/src/main/resources/logback-spring.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 192.168.99.100:5000 12 | 13 | 14 | {"service_name":"WeatherService 1.0"} 15 | 16 | log_msg 17 | 18 | 19 | 5 minutes 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /step8_logging_into_elasticstack/src/main/resources/service-api-definition/Weather-Schemes/w3c-xmlmime-definition.xsd: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /step8_logging_into_elasticstack/src/main/resources/service-api-definition/Weather-Schemes/weather-exception.xsd: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /step8_logging_into_elasticstack/src/main/resources/service-api-definition/Weather1.0.xsd: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 12 | 13 | 15 | 16 | -------------------------------------------------------------------------------- /step8_logging_into_elasticstack/src/test/java/de/jonashackt/tutorial/ApplicationTestConfiguration.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.context.annotation.Import; 6 | 7 | import de.codecentric.namespace.weatherservice.WeatherService; 8 | import de.jonashackt.tutorial.configuration.ApplicationConfiguration; 9 | import de.jonashackt.tutorial.endpoint.WeatherServiceEndpoint; 10 | 11 | @Configuration 12 | @Import(ApplicationConfiguration.class) 13 | public class ApplicationTestConfiguration { 14 | 15 | @Bean 16 | public WeatherService weatherService() { 17 | return new WeatherServiceEndpoint(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /step8_logging_into_elasticstack/src/test/java/de/jonashackt/tutorial/SimpleBootCxfSystemTestApplication.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.context.annotation.Import; 6 | 7 | @SpringBootApplication 8 | @Import(WebServiceSystemTestConfiguration.class) 9 | public class SimpleBootCxfSystemTestApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(SimpleBootCxfSystemTestApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /step8_logging_into_elasticstack/src/test/java/de/jonashackt/tutorial/WebServiceIntegrationTestConfiguration.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial; 2 | 3 | import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | import de.codecentric.namespace.weatherservice.WeatherService; 8 | import de.jonashackt.tutorial.configuration.WebServiceConfiguration; 9 | 10 | @Configuration 11 | public class WebServiceIntegrationTestConfiguration { 12 | 13 | @Bean 14 | public WeatherService weatherServiceIntegrationTestClient() { 15 | JaxWsProxyFactoryBean jaxWsProxyFactory = new JaxWsProxyFactoryBean(); 16 | jaxWsProxyFactory.setServiceClass(WeatherService.class); 17 | jaxWsProxyFactory.setAddress("http://localhost:8080" + WebServiceConfiguration.BASE_URL + WebServiceConfiguration.SERVICE_URL); 18 | return (WeatherService) jaxWsProxyFactory.create(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /step8_logging_into_elasticstack/src/test/java/de/jonashackt/tutorial/WebServiceSystemTestConfiguration.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial; 2 | 3 | import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | import de.codecentric.namespace.weatherservice.WeatherService; 8 | import de.jonashackt.tutorial.configuration.WebServiceConfiguration; 9 | 10 | @Configuration 11 | public class WebServiceSystemTestConfiguration { 12 | 13 | @Bean 14 | public WeatherService weatherServiceSystemTestClient() { 15 | JaxWsProxyFactoryBean jaxWsProxyFactory = new JaxWsProxyFactoryBean(); 16 | jaxWsProxyFactory.setServiceClass(WeatherService.class); 17 | jaxWsProxyFactory.setAddress("http://localhost:8090" + WebServiceConfiguration.BASE_URL + WebServiceConfiguration.SERVICE_URL); 18 | return (WeatherService) jaxWsProxyFactory.create(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /step8_logging_into_elasticstack/src/test/java/de/jonashackt/tutorial/endpoint/WeatherServiceIntegrationTest.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.endpoint; 2 | 3 | import static de.jonashackt.tutorial.utils.TestHelper.generateDummyRequest; 4 | import static org.junit.Assert.assertEquals; 5 | import static org.junit.Assert.assertNotNull; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.test.context.ContextConfiguration; 11 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 12 | 13 | import de.codecentric.namespace.weatherservice.WeatherException; 14 | import de.codecentric.namespace.weatherservice.WeatherService; 15 | import de.codecentric.namespace.weatherservice.general.ForecastRequest; 16 | import de.codecentric.namespace.weatherservice.general.ForecastReturn; 17 | import de.jonashackt.tutorial.WebServiceIntegrationTestConfiguration; 18 | 19 | @RunWith(SpringJUnit4ClassRunner.class) 20 | @ContextConfiguration(classes=WebServiceIntegrationTestConfiguration.class) 21 | public class WeatherServiceIntegrationTest { 22 | 23 | @Autowired 24 | private WeatherService weatherServiceIntegrationTestClient; 25 | 26 | @Test 27 | public void getCityForecastByZIP() throws WeatherException { 28 | // Given 29 | ForecastRequest forecastRequest = generateDummyRequest(); 30 | 31 | // When 32 | ForecastReturn forecastReturn = weatherServiceIntegrationTestClient.getCityForecastByZIP(forecastRequest); 33 | 34 | // Then 35 | assertNotNull(forecastReturn); 36 | assertEquals(true, forecastReturn.isSuccess()); 37 | assertEquals("Weimar", forecastReturn.getCity()); 38 | assertEquals("22%", forecastReturn.getForecastResult().getForecast().get(0).getProbabilityOfPrecipiation().getDaytime()); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /step8_logging_into_elasticstack/src/test/java/de/jonashackt/tutorial/endpoint/WeatherServiceSystemTest.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.endpoint; 2 | 3 | import static de.jonashackt.tutorial.utils.TestHelper.generateDummyRequest; 4 | import static org.junit.Assert.assertEquals; 5 | import static org.junit.Assert.assertNotNull; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.boot.test.SpringApplicationConfiguration; 11 | import org.springframework.boot.test.WebIntegrationTest; 12 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 13 | 14 | import de.codecentric.namespace.weatherservice.WeatherException; 15 | import de.codecentric.namespace.weatherservice.WeatherService; 16 | import de.codecentric.namespace.weatherservice.general.ForecastRequest; 17 | import de.codecentric.namespace.weatherservice.general.ForecastReturn; 18 | import de.jonashackt.tutorial.SimpleBootCxfSystemTestApplication; 19 | 20 | @RunWith(SpringJUnit4ClassRunner.class) 21 | @SpringApplicationConfiguration(classes=SimpleBootCxfSystemTestApplication.class) 22 | @WebIntegrationTest("server.port:8090") 23 | public class WeatherServiceSystemTest { 24 | 25 | @Autowired 26 | private WeatherService weatherServiceSystemTestClient; 27 | 28 | @Test 29 | public void getCityForecastByZIP() throws WeatherException { 30 | // Given 31 | ForecastRequest forecastRequest = generateDummyRequest(); 32 | 33 | // When 34 | ForecastReturn forecastReturn = weatherServiceSystemTestClient.getCityForecastByZIP(forecastRequest); 35 | 36 | // Then 37 | assertNotNull(forecastReturn); 38 | assertEquals(true, forecastReturn.isSuccess()); 39 | assertEquals("Weimar", forecastReturn.getCity()); 40 | assertEquals("22%", forecastReturn.getForecastResult().getForecast().get(0).getProbabilityOfPrecipiation().getDaytime()); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /step8_logging_into_elasticstack/src/test/java/de/jonashackt/tutorial/endpoint/WeatherServiceTest.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.endpoint; 2 | 3 | import static de.jonashackt.tutorial.utils.TestHelper.generateDummyRequest; 4 | import static org.junit.Assert.assertEquals; 5 | import static org.junit.Assert.assertNotNull; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.test.context.ContextConfiguration; 11 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 12 | 13 | import de.codecentric.namespace.weatherservice.WeatherException; 14 | import de.codecentric.namespace.weatherservice.general.ForecastRequest; 15 | import de.codecentric.namespace.weatherservice.general.ForecastReturn; 16 | import de.jonashackt.tutorial.ApplicationTestConfiguration; 17 | 18 | @RunWith(SpringJUnit4ClassRunner.class) 19 | @ContextConfiguration(classes=ApplicationTestConfiguration.class) 20 | public class WeatherServiceTest { 21 | 22 | @Autowired 23 | private WeatherServiceEndpoint weatherServiceEndpoint; 24 | 25 | @Test 26 | public void getCityForecastByZIP() throws WeatherException { 27 | // Given 28 | ForecastRequest forecastRequest = generateDummyRequest(); 29 | 30 | // When 31 | ForecastReturn forecastReturn = weatherServiceEndpoint.getCityForecastByZIP(forecastRequest); 32 | 33 | // Then 34 | assertNotNull(forecastReturn); 35 | assertEquals(true, forecastReturn.isSuccess()); 36 | assertEquals("Weimar", forecastReturn.getCity()); 37 | assertEquals("22%", forecastReturn.getForecastResult().getForecast().get(0).getProbabilityOfPrecipiation().getDaytime()); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /step8_logging_into_elasticstack/src/test/java/de/jonashackt/tutorial/endpoint/WeatherServiceXmlFileSystemTest.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.endpoint; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | import static org.junit.Assert.assertNotNull; 5 | 6 | import java.io.IOException; 7 | 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.beans.factory.annotation.Value; 12 | import org.springframework.boot.test.SpringApplicationConfiguration; 13 | import org.springframework.boot.test.WebIntegrationTest; 14 | import org.springframework.core.io.Resource; 15 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 16 | 17 | import de.codecentric.namespace.weatherservice.WeatherException; 18 | import de.codecentric.namespace.weatherservice.WeatherService; 19 | import de.codecentric.namespace.weatherservice.general.ForecastReturn; 20 | import de.codecentric.namespace.weatherservice.general.GetCityForecastByZIP; 21 | import de.jonashackt.tutorial.SimpleBootCxfSystemTestApplication; 22 | import de.jonashackt.tutorial.utils.XmlUtilsException; 23 | import de.jonashackt.tutorial.utils.XmlUtils; 24 | 25 | @RunWith(SpringJUnit4ClassRunner.class) 26 | @SpringApplicationConfiguration(classes=SimpleBootCxfSystemTestApplication.class) 27 | @WebIntegrationTest("server.port:8090") 28 | public class WeatherServiceXmlFileSystemTest { 29 | 30 | @Autowired 31 | private WeatherService weatherServiceSystemTestClient; 32 | 33 | @Value(value="classpath:requests/GetCityForecastByZIPTest.xml") 34 | private Resource getCityForecastByZIPTestXml; 35 | 36 | @Test 37 | public void getCityForecastByZIP() throws WeatherException, XmlUtilsException, IOException { 38 | // Given 39 | GetCityForecastByZIP getCityForecastByZIP = XmlUtils.readSoapMessageFromStreamAndUnmarshallBody2Object(getCityForecastByZIPTestXml.getInputStream(), GetCityForecastByZIP.class); 40 | 41 | // When 42 | ForecastReturn forecastReturn = weatherServiceSystemTestClient.getCityForecastByZIP(getCityForecastByZIP.getForecastRequest()); 43 | 44 | // Then 45 | assertNotNull(forecastReturn); 46 | assertEquals(true, forecastReturn.isSuccess()); 47 | assertEquals("Weimar", forecastReturn.getCity()); 48 | assertEquals("22%", forecastReturn.getForecastResult().getForecast().get(0).getProbabilityOfPrecipiation().getDaytime()); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /step8_logging_into_elasticstack/src/test/java/de/jonashackt/tutorial/utils/TestHelper.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.utils; 2 | 3 | import de.codecentric.namespace.weatherservice.datatypes.ProductName; 4 | import de.codecentric.namespace.weatherservice.general.ForecastCustomer; 5 | import de.codecentric.namespace.weatherservice.general.ForecastRequest; 6 | 7 | public class TestHelper { 8 | 9 | public static ForecastRequest generateDummyRequest() { 10 | ForecastRequest forecastRequest = new ForecastRequest(); 11 | forecastRequest.setZIP("99425"); 12 | forecastRequest.setFlagcolor("blackblue"); 13 | forecastRequest.setProductName(ProductName.FORECAST_BASIC); 14 | ForecastCustomer customer = new ForecastCustomer(); 15 | customer.setAge(67); 16 | customer.setContribution(500); 17 | customer.setMethodOfPayment("Bitcoin"); 18 | forecastRequest.setForecastCustomer(customer); 19 | return forecastRequest; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /step8_logging_into_elasticstack/src/test/java/de/jonashackt/tutorial/utils/XmlUtilsException.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.utils; 2 | 3 | public class XmlUtilsException extends Exception { 4 | private static final long serialVersionUID = 1L; 5 | 6 | public XmlUtilsException(Throwable cause) { 7 | super(cause); 8 | } 9 | 10 | public XmlUtilsException(String message, Throwable cause) { 11 | super(message, cause); 12 | } 13 | 14 | public XmlUtilsException(String message) { 15 | super(message); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /step8_logging_into_elasticstack/src/test/resources/requests/GetCityForecastByZIPTest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 99425 8 | bluewhite 9 | ForecastBasic 10 | 11 | 30 12 | 5000 13 | Paypal 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /step9_soap_message_logging_into_custom_elasticsearch_field/src/main/java/de/jonashackt/tutorial/SimpleBootCxfApplication.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.context.annotation.ComponentScan; 6 | 7 | @SpringBootApplication 8 | @ComponentScan("de.jonashackt.tutorial") 9 | public class SimpleBootCxfApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(SimpleBootCxfApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /step9_soap_message_logging_into_custom_elasticsearch_field/src/main/java/de/jonashackt/tutorial/configuration/ApplicationConfiguration.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.configuration; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | 6 | import de.jonashackt.tutorial.controller.WeatherServiceController; 7 | 8 | 9 | @Configuration 10 | public class ApplicationConfiguration { 11 | 12 | @Bean 13 | public WeatherServiceController weatherServiceController() { 14 | return new WeatherServiceController(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /step9_soap_message_logging_into_custom_elasticsearch_field/src/main/java/de/jonashackt/tutorial/controller/WeatherServiceController.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.controller; 2 | 3 | import de.codecentric.namespace.weatherservice.general.ForecastRequest; 4 | import de.codecentric.namespace.weatherservice.general.ForecastReturn; 5 | import de.jonashackt.tutorial.transformation.GetCityForecastByZIPOutMapper; 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | import org.springframework.stereotype.Component; 9 | 10 | /* 11 | * Example-Controller: 12 | * This Class would be responsible for Mapping from Request to internal Datamodel (and backwards), 13 | * for calling Backend-Services and handling Backend-Exceptions 14 | * So it decouples the WSDL-generated Classes from the internal Classes - for when the former changes, 15 | * nothing or only the mapping has to be changed 16 | */ 17 | @Component 18 | public class WeatherServiceController { 19 | 20 | private static final Logger LOG = LoggerFactory.getLogger(WeatherServiceController.class); 21 | 22 | public ForecastReturn getCityForecastByZIP(ForecastRequest forecastRequest) { 23 | /* 24 | * We leave out inbound transformation, plausibility-checking, logging, backend-calls e.g. 25 | * for the moment 26 | * 27 | * Just some Log-Statements here :) 28 | */ 29 | LOG.info("Starting inbound transformation into internal datamodel"); 30 | 31 | LOG.info("Checking plausibility of data"); 32 | 33 | LOG.info("Calling Backend No. 1"); 34 | 35 | LOG.info("Calling Backend No. 2"); 36 | 37 | LOG.info("Starting outbound transformation into external datamodel"); 38 | 39 | return GetCityForecastByZIPOutMapper.mapGeneralOutlook2Forecast(); 40 | } 41 | 42 | /* 43 | * Other Methods would follow here... 44 | */ 45 | //public WeatherReturn getCityWeatherByZIP(ForecastRequest forecastRequest) throws BusinessException {} 46 | 47 | //public WeatherInformationReturn getWeatherInformation(String zip) throws BusinessException {} 48 | } 49 | -------------------------------------------------------------------------------- /step9_soap_message_logging_into_custom_elasticsearch_field/src/main/java/de/jonashackt/tutorial/endpoint/WeatherServiceEndpoint.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.endpoint; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | 7 | import de.codecentric.namespace.weatherservice.WeatherException; 8 | import de.codecentric.namespace.weatherservice.WeatherService; 9 | import de.codecentric.namespace.weatherservice.general.ForecastRequest; 10 | import de.codecentric.namespace.weatherservice.general.ForecastReturn; 11 | import de.codecentric.namespace.weatherservice.general.WeatherInformationReturn; 12 | import de.codecentric.namespace.weatherservice.general.WeatherReturn; 13 | import de.jonashackt.tutorial.controller.WeatherServiceController; 14 | 15 | 16 | public class WeatherServiceEndpoint implements WeatherService { 17 | 18 | private static final Logger LOG = LoggerFactory.getLogger(WeatherServiceEndpoint.class); 19 | 20 | @Autowired 21 | private WeatherServiceController weatherServiceController; 22 | 23 | @Override 24 | public ForecastReturn getCityForecastByZIP(ForecastRequest forecastRequest) throws WeatherException { 25 | LOG.debug("Method getCityForecastByZIP() was called. Processing the Request in the backend"); 26 | 27 | return weatherServiceController.getCityForecastByZIP(forecastRequest); 28 | } 29 | 30 | @Override 31 | public WeatherInformationReturn getWeatherInformation(String zip) throws WeatherException { 32 | // TODO Auto-generated method stub 33 | return null; 34 | } 35 | 36 | @Override 37 | public WeatherReturn getCityWeatherByZIP(ForecastRequest forecastRequest) throws WeatherException { 38 | // TODO Auto-generated method stub 39 | return null; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /step9_soap_message_logging_into_custom_elasticsearch_field/src/main/java/de/jonashackt/tutorial/soapmsglogging/LogCorrelationFilter.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.soapmsglogging; 2 | 3 | import org.slf4j.MDC; 4 | 5 | import javax.servlet.*; 6 | import java.io.IOException; 7 | import java.util.UUID; 8 | 9 | public class LogCorrelationFilter implements Filter { 10 | 11 | private static final String SERVICE_CALL_ID_KEY = "service-call-id"; 12 | 13 | @Override 14 | public void init(FilterConfig filterConfig) throws ServletException {} 15 | 16 | @Override 17 | public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { 18 | // Put an unique-Logging-Id to the logback Mapped Diagnostic Context to correlate 19 | // against one Customer-Request, see http://logback.qos.ch/manual/mdc.html 20 | MDC.put(SERVICE_CALL_ID_KEY, UUID.randomUUID().toString()); 21 | try { 22 | chain.doFilter(request, response); 23 | } finally { 24 | // finally remove unique-Logging-Id, so that it could´nt be accidentally 25 | // reused for another Consumer-Request 26 | MDC.remove(SERVICE_CALL_ID_KEY); 27 | } 28 | } 29 | 30 | @Override 31 | public void destroy() {} 32 | 33 | } 34 | -------------------------------------------------------------------------------- /step9_soap_message_logging_into_custom_elasticsearch_field/src/main/java/de/jonashackt/tutorial/soapmsglogging/SoapMsgToMdcExtractionLoggingInInterceptor.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.soapmsglogging; 2 | 3 | import org.apache.cxf.interceptor.LoggingInInterceptor; 4 | import org.apache.cxf.interceptor.LoggingMessage; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | 8 | import static net.logstash.logback.marker.Markers.append; 9 | 10 | public class SoapMsgToMdcExtractionLoggingInInterceptor extends LoggingInInterceptor { 11 | 12 | private static final Logger LOG = LoggerFactory.getLogger(SoapMsgToMdcExtractionLoggingInInterceptor.class); 13 | private static final String SOAP_MESSAGE_INBOUND = "soap-message-inbound"; 14 | 15 | @Override 16 | protected void log(java.util.logging.Logger logger, String message) { 17 | // just do nothing, because we don´t want CXF-Implementation to log, 18 | // we just want to Push the SOAP-Message to Logback -> Logstash -> Elasticsearch -> Kibana 19 | } 20 | 21 | @Override 22 | protected String formatLoggingMessage(LoggingMessage loggingMessage) { 23 | // Only write the Payload (SOAP-Xml) to Logger 24 | if (loggingMessage.getPayload().length() > 0) { 25 | LOG.info(append(SOAP_MESSAGE_INBOUND, loggingMessage.getPayload().toString()), "Log Inbound-SoapMessage to Elasticseach"); 26 | } 27 | // This is just hook into CXF and get the SOAP-Message. 28 | // The returned String will never be logged somewhere. 29 | return ""; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /step9_soap_message_logging_into_custom_elasticsearch_field/src/main/java/de/jonashackt/tutorial/soapmsglogging/SoapMsgToMdcExtractionLoggingOutInterceptor.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.soapmsglogging; 2 | 3 | import org.apache.cxf.interceptor.LoggingMessage; 4 | import org.apache.cxf.interceptor.LoggingOutInterceptor; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | 8 | import static net.logstash.logback.marker.Markers.append; 9 | 10 | public class SoapMsgToMdcExtractionLoggingOutInterceptor extends LoggingOutInterceptor { 11 | 12 | private static final Logger LOG = LoggerFactory.getLogger(SoapMsgToMdcExtractionLoggingOutInterceptor.class); 13 | private static final String SOAP_MESSAGE_OUTBOUND = "soap-message-outbound"; 14 | 15 | @Override 16 | protected void log(java.util.logging.Logger logger, String message) { 17 | // just do nothing, because we don´t want CXF-Implementation to log, 18 | // we just want to Push the SOAP-Message to Logback -> Logstash -> Elasticsearch -> Kibana 19 | } 20 | 21 | @Override 22 | protected String formatLoggingMessage(LoggingMessage loggingMessage) { 23 | // Only write the Payload (SOAP-Xml) to Logger 24 | if (loggingMessage.getPayload().length() > 0) { 25 | LOG.info(append(SOAP_MESSAGE_OUTBOUND, loggingMessage.getPayload().toString()), "Log Outbound-SoapMessage to Elasticseach"); 26 | } 27 | // This is just hook into CXF and get the SOAP-Message. 28 | // The returned String will never be logged somewhere. 29 | return ""; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /step9_soap_message_logging_into_custom_elasticsearch_field/src/main/resources/META-INF/cxf/org.apache.cxf.Logger: -------------------------------------------------------------------------------- 1 | org.apache.cxf.common.logging.Slf4jLogger -------------------------------------------------------------------------------- /step9_soap_message_logging_into_custom_elasticsearch_field/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jonashackt/tutorial-soap-spring-boot-cxf/3960f26a558a84e4c40474336c115942e528d135/step9_soap_message_logging_into_custom_elasticsearch_field/src/main/resources/application.properties -------------------------------------------------------------------------------- /step9_soap_message_logging_into_custom_elasticsearch_field/src/main/resources/logback-spring.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 192.168.99.100:5000 12 | 13 | 14 | {"service_name":"WeatherService 1.0"} 15 | 16 | log_msg 17 | 18 | 19 | 5 minutes 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /step9_soap_message_logging_into_custom_elasticsearch_field/src/main/resources/service-api-definition/Weather-Schemes/w3c-xmlmime-definition.xsd: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /step9_soap_message_logging_into_custom_elasticsearch_field/src/main/resources/service-api-definition/Weather-Schemes/weather-exception.xsd: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /step9_soap_message_logging_into_custom_elasticsearch_field/src/main/resources/service-api-definition/Weather1.0.xsd: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 12 | 13 | 15 | 16 | -------------------------------------------------------------------------------- /step9_soap_message_logging_into_custom_elasticsearch_field/src/test/java/de/jonashackt/tutorial/ApplicationTestConfiguration.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.context.annotation.Import; 6 | 7 | import de.codecentric.namespace.weatherservice.WeatherService; 8 | import de.jonashackt.tutorial.configuration.ApplicationConfiguration; 9 | import de.jonashackt.tutorial.endpoint.WeatherServiceEndpoint; 10 | 11 | @Configuration 12 | @Import(ApplicationConfiguration.class) 13 | public class ApplicationTestConfiguration { 14 | 15 | @Bean 16 | public WeatherService weatherService() { 17 | return new WeatherServiceEndpoint(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /step9_soap_message_logging_into_custom_elasticsearch_field/src/test/java/de/jonashackt/tutorial/SimpleBootCxfSystemTestApplication.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.context.annotation.Import; 6 | 7 | @SpringBootApplication 8 | @Import(WebServiceSystemTestConfiguration.class) 9 | public class SimpleBootCxfSystemTestApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(SimpleBootCxfSystemTestApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /step9_soap_message_logging_into_custom_elasticsearch_field/src/test/java/de/jonashackt/tutorial/WebServiceIntegrationTestConfiguration.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial; 2 | 3 | import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | import de.codecentric.namespace.weatherservice.WeatherService; 8 | import de.jonashackt.tutorial.configuration.WebServiceConfiguration; 9 | 10 | @Configuration 11 | public class WebServiceIntegrationTestConfiguration { 12 | 13 | @Bean 14 | public WeatherService weatherServiceIntegrationTestClient() { 15 | JaxWsProxyFactoryBean jaxWsProxyFactory = new JaxWsProxyFactoryBean(); 16 | jaxWsProxyFactory.setServiceClass(WeatherService.class); 17 | jaxWsProxyFactory.setAddress("http://localhost:8080" + WebServiceConfiguration.BASE_URL + WebServiceConfiguration.SERVICE_URL); 18 | return (WeatherService) jaxWsProxyFactory.create(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /step9_soap_message_logging_into_custom_elasticsearch_field/src/test/java/de/jonashackt/tutorial/WebServiceSystemTestConfiguration.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial; 2 | 3 | import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | import de.codecentric.namespace.weatherservice.WeatherService; 8 | import de.jonashackt.tutorial.configuration.WebServiceConfiguration; 9 | 10 | @Configuration 11 | public class WebServiceSystemTestConfiguration { 12 | 13 | @Bean 14 | public WeatherService weatherServiceSystemTestClient() { 15 | JaxWsProxyFactoryBean jaxWsProxyFactory = new JaxWsProxyFactoryBean(); 16 | jaxWsProxyFactory.setServiceClass(WeatherService.class); 17 | jaxWsProxyFactory.setAddress("http://localhost:8090" + WebServiceConfiguration.BASE_URL + WebServiceConfiguration.SERVICE_URL); 18 | return (WeatherService) jaxWsProxyFactory.create(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /step9_soap_message_logging_into_custom_elasticsearch_field/src/test/java/de/jonashackt/tutorial/endpoint/WeatherServiceIntegrationTest.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.endpoint; 2 | 3 | import static de.jonashackt.tutorial.utils.TestHelper.generateDummyRequest; 4 | import static org.junit.Assert.assertEquals; 5 | import static org.junit.Assert.assertNotNull; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.test.context.ContextConfiguration; 11 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 12 | 13 | import de.codecentric.namespace.weatherservice.WeatherException; 14 | import de.codecentric.namespace.weatherservice.WeatherService; 15 | import de.codecentric.namespace.weatherservice.general.ForecastRequest; 16 | import de.codecentric.namespace.weatherservice.general.ForecastReturn; 17 | import de.jonashackt.tutorial.WebServiceIntegrationTestConfiguration; 18 | 19 | @RunWith(SpringJUnit4ClassRunner.class) 20 | @ContextConfiguration(classes=WebServiceIntegrationTestConfiguration.class) 21 | public class WeatherServiceIntegrationTest { 22 | 23 | @Autowired 24 | private WeatherService weatherServiceIntegrationTestClient; 25 | 26 | @Test 27 | public void getCityForecastByZIP() throws WeatherException { 28 | // Given 29 | ForecastRequest forecastRequest = generateDummyRequest(); 30 | 31 | // When 32 | ForecastReturn forecastReturn = weatherServiceIntegrationTestClient.getCityForecastByZIP(forecastRequest); 33 | 34 | // Then 35 | assertNotNull(forecastReturn); 36 | assertEquals(true, forecastReturn.isSuccess()); 37 | assertEquals("Weimar", forecastReturn.getCity()); 38 | assertEquals("22%", forecastReturn.getForecastResult().getForecast().get(0).getProbabilityOfPrecipiation().getDaytime()); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /step9_soap_message_logging_into_custom_elasticsearch_field/src/test/java/de/jonashackt/tutorial/endpoint/WeatherServiceSystemTest.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.endpoint; 2 | 3 | import static de.jonashackt.tutorial.utils.TestHelper.generateDummyRequest; 4 | import static org.junit.Assert.assertEquals; 5 | import static org.junit.Assert.assertNotNull; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.boot.test.SpringApplicationConfiguration; 11 | import org.springframework.boot.test.WebIntegrationTest; 12 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 13 | 14 | import de.codecentric.namespace.weatherservice.WeatherException; 15 | import de.codecentric.namespace.weatherservice.WeatherService; 16 | import de.codecentric.namespace.weatherservice.general.ForecastRequest; 17 | import de.codecentric.namespace.weatherservice.general.ForecastReturn; 18 | import de.jonashackt.tutorial.SimpleBootCxfSystemTestApplication; 19 | 20 | @RunWith(SpringJUnit4ClassRunner.class) 21 | @SpringApplicationConfiguration(classes=SimpleBootCxfSystemTestApplication.class) 22 | @WebIntegrationTest("server.port:8090") 23 | public class WeatherServiceSystemTest { 24 | 25 | @Autowired 26 | private WeatherService weatherServiceSystemTestClient; 27 | 28 | @Test 29 | public void getCityForecastByZIP() throws WeatherException { 30 | // Given 31 | ForecastRequest forecastRequest = generateDummyRequest(); 32 | 33 | // When 34 | ForecastReturn forecastReturn = weatherServiceSystemTestClient.getCityForecastByZIP(forecastRequest); 35 | 36 | // Then 37 | assertNotNull(forecastReturn); 38 | assertEquals(true, forecastReturn.isSuccess()); 39 | assertEquals("Weimar", forecastReturn.getCity()); 40 | assertEquals("22%", forecastReturn.getForecastResult().getForecast().get(0).getProbabilityOfPrecipiation().getDaytime()); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /step9_soap_message_logging_into_custom_elasticsearch_field/src/test/java/de/jonashackt/tutorial/endpoint/WeatherServiceTest.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.endpoint; 2 | 3 | import static de.jonashackt.tutorial.utils.TestHelper.generateDummyRequest; 4 | import static org.junit.Assert.assertEquals; 5 | import static org.junit.Assert.assertNotNull; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.test.context.ContextConfiguration; 11 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 12 | 13 | import de.codecentric.namespace.weatherservice.WeatherException; 14 | import de.codecentric.namespace.weatherservice.general.ForecastRequest; 15 | import de.codecentric.namespace.weatherservice.general.ForecastReturn; 16 | import de.jonashackt.tutorial.ApplicationTestConfiguration; 17 | 18 | @RunWith(SpringJUnit4ClassRunner.class) 19 | @ContextConfiguration(classes=ApplicationTestConfiguration.class) 20 | public class WeatherServiceTest { 21 | 22 | @Autowired 23 | private WeatherServiceEndpoint weatherServiceEndpoint; 24 | 25 | @Test 26 | public void getCityForecastByZIP() throws WeatherException { 27 | // Given 28 | ForecastRequest forecastRequest = generateDummyRequest(); 29 | 30 | // When 31 | ForecastReturn forecastReturn = weatherServiceEndpoint.getCityForecastByZIP(forecastRequest); 32 | 33 | // Then 34 | assertNotNull(forecastReturn); 35 | assertEquals(true, forecastReturn.isSuccess()); 36 | assertEquals("Weimar", forecastReturn.getCity()); 37 | assertEquals("22%", forecastReturn.getForecastResult().getForecast().get(0).getProbabilityOfPrecipiation().getDaytime()); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /step9_soap_message_logging_into_custom_elasticsearch_field/src/test/java/de/jonashackt/tutorial/utils/TestHelper.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.utils; 2 | 3 | import de.codecentric.namespace.weatherservice.datatypes.ProductName; 4 | import de.codecentric.namespace.weatherservice.general.ForecastCustomer; 5 | import de.codecentric.namespace.weatherservice.general.ForecastRequest; 6 | 7 | public class TestHelper { 8 | 9 | public static ForecastRequest generateDummyRequest() { 10 | ForecastRequest forecastRequest = new ForecastRequest(); 11 | forecastRequest.setZIP("99425"); 12 | forecastRequest.setFlagcolor("blackblue"); 13 | forecastRequest.setProductName(ProductName.FORECAST_BASIC); 14 | ForecastCustomer customer = new ForecastCustomer(); 15 | customer.setAge(67); 16 | customer.setContribution(500); 17 | customer.setMethodOfPayment("Bitcoin"); 18 | forecastRequest.setForecastCustomer(customer); 19 | return forecastRequest; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /step9_soap_message_logging_into_custom_elasticsearch_field/src/test/java/de/jonashackt/tutorial/utils/XmlUtilsException.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.tutorial.utils; 2 | 3 | public class XmlUtilsException extends Exception { 4 | private static final long serialVersionUID = 1L; 5 | 6 | public XmlUtilsException(Throwable cause) { 7 | super(cause); 8 | } 9 | 10 | public XmlUtilsException(String message, Throwable cause) { 11 | super(message, cause); 12 | } 13 | 14 | public XmlUtilsException(String message) { 15 | super(message); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /step9_soap_message_logging_into_custom_elasticsearch_field/src/test/resources/requests/GetCityForecastByZIPTest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 99425 8 | bluewhite 9 | ForecastBasic 10 | 11 | 30 12 | 5000 13 | Paypal 14 | 15 | 16 | 17 | 18 | --------------------------------------------------------------------------------