├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── cxf-jaxws-basic-authentication ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── codenotfound │ │ │ ├── SpringCxfApplication.java │ │ │ ├── client │ │ │ ├── ClientConfig.java │ │ │ └── TicketAgentClient.java │ │ │ └── endpoint │ │ │ ├── EndpointConfig.java │ │ │ └── TicketAgentImpl.java │ └── resources │ │ ├── application.yml │ │ ├── logback.xml │ │ └── wsdl │ │ └── ticketagent.wsdl │ └── test │ └── java │ └── com │ └── codenotfound │ └── SpringCxfApplicationTests.java ├── cxf-jaxws-digital-signature ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── codenotfound │ │ │ ├── SpringCxfApplication.java │ │ │ ├── client │ │ │ ├── ClientCallbackHandler.java │ │ │ ├── ClientConfig.java │ │ │ └── TicketAgentClient.java │ │ │ └── endpoint │ │ │ ├── EndpointConfig.java │ │ │ ├── ServerCallbackHandler.java │ │ │ └── TicketAgentImpl.java │ └── resources │ │ ├── application.yml │ │ ├── client_key.properties │ │ ├── client_trust.properties │ │ ├── jks │ │ ├── client-keystore.jks │ │ ├── client-truststore.jks │ │ ├── server-keystore.jks │ │ └── server-truststore.jks │ │ ├── logback.xml │ │ ├── server_key.properties │ │ ├── server_trust.properties │ │ └── wsdl │ │ └── ticketagent.wsdl │ └── test │ └── java │ └── com │ └── codenotfound │ └── SpringCxfApplicationTests.java ├── cxf-jaxws-https ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── codenotfound │ │ │ ├── SpringCxfApplication.java │ │ │ ├── client │ │ │ ├── ClientConfig.java │ │ │ └── TicketAgentClient.java │ │ │ └── endpoint │ │ │ ├── EndpointConfig.java │ │ │ └── TicketAgentImpl.java │ └── resources │ │ ├── application.yml │ │ ├── jks │ │ ├── client-truststore.jks │ │ ├── server-keystore.jks │ │ └── server-truststore.jks │ │ ├── logback.xml │ │ └── wsdl │ │ └── ticketagent.wsdl │ └── test │ └── java │ └── com │ └── codenotfound │ └── SpringCxfApplicationTests.java ├── cxf-jaxws-jetty-logging-log4j ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── codenotfound │ │ │ └── soap │ │ │ └── http │ │ │ └── cxf │ │ │ ├── HelloWorldClient.java │ │ │ └── HelloWorldImpl.java │ ├── resources │ │ ├── META-INF │ │ │ ├── cxf │ │ │ │ └── org.apache.cxf.Logger │ │ │ └── spring │ │ │ │ ├── context-provider.xml │ │ │ │ ├── context-requester.xml │ │ │ │ ├── cxf-provider.xml │ │ │ │ └── cxf-requester.xml │ │ ├── cxf.properties │ │ ├── log4j.xml │ │ └── wsdl │ │ │ └── helloworld.wsdl │ └── webapp │ │ └── WEB-INF │ │ └── web.xml │ └── test │ ├── java │ └── com │ │ └── codenotfound │ │ └── soap │ │ └── http │ │ └── cxf │ │ ├── HelloWorldImplIT.java │ │ └── HelloWorldImplTest.java │ └── resources │ └── log4j.xml ├── cxf-jaxws-jetty-logging-log4j2 ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── codenotfound │ │ │ └── soap │ │ │ └── http │ │ │ └── cxf │ │ │ ├── HelloWorldClient.java │ │ │ └── HelloWorldImpl.java │ ├── resources │ │ ├── META-INF │ │ │ ├── cxf │ │ │ │ └── org.apache.cxf.Logger │ │ │ └── spring │ │ │ │ ├── context-provider.xml │ │ │ │ ├── context-requester.xml │ │ │ │ ├── cxf-provider.xml │ │ │ │ └── cxf-requester.xml │ │ ├── cxf.properties │ │ ├── log4j2.xml │ │ └── wsdl │ │ │ └── helloworld.wsdl │ └── webapp │ │ └── WEB-INF │ │ └── web.xml │ └── test │ ├── java │ └── com │ │ └── codenotfound │ │ └── soap │ │ └── http │ │ └── cxf │ │ ├── HelloWorldImplIT.java │ │ └── HelloWorldImplTest.java │ └── resources │ └── log4j2-test.xml ├── cxf-jaxws-jetty-logging-logback ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── codenotfound │ │ │ └── soap │ │ │ └── http │ │ │ └── cxf │ │ │ ├── HelloWorldClient.java │ │ │ └── HelloWorldImpl.java │ ├── resources │ │ ├── META-INF │ │ │ ├── cxf │ │ │ │ └── org.apache.cxf.Logger │ │ │ └── spring │ │ │ │ ├── context-provider.xml │ │ │ │ ├── context-requester.xml │ │ │ │ ├── cxf-provider.xml │ │ │ │ └── cxf-requester.xml │ │ ├── cxf.properties │ │ ├── logback.xml │ │ └── wsdl │ │ │ └── helloworld.wsdl │ └── webapp │ │ └── WEB-INF │ │ └── web.xml │ └── test │ ├── java │ └── com │ │ └── codenotfound │ │ └── soap │ │ └── http │ │ └── cxf │ │ ├── HelloWorldImplIT.java │ │ └── HelloWorldImplTest.java │ └── resources │ └── logback-test.xml ├── cxf-jaxws-jetty-xml-config ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── codenotfound │ │ │ ├── client │ │ │ └── HelloWorldClient.java │ │ │ └── endpoint │ │ │ └── HelloWorldImpl.java │ ├── resources │ │ ├── META-INF │ │ │ └── spring │ │ │ │ ├── context-provider.xml │ │ │ │ ├── context-requester.xml │ │ │ │ ├── cxf-provider.xml │ │ │ │ └── cxf-requester.xml │ │ ├── cxf.properties │ │ ├── logback.xml │ │ └── wsdl │ │ │ └── helloworld.wsdl │ └── webapp │ │ └── WEB-INF │ │ └── web.xml │ └── test │ └── java │ └── com │ └── codenotfound │ ├── HelloWorldImplIT.java │ ├── client │ └── HelloWorldClientTest.java │ └── endpoint │ └── HelloWorldImplTest.java ├── cxf-jaxws-logging-logback ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── codenotfound │ │ │ ├── SpringCxfApplication.java │ │ │ ├── client │ │ │ ├── ClientConfig.java │ │ │ └── TicketAgentClient.java │ │ │ └── endpoint │ │ │ ├── EndpointConfig.java │ │ │ └── TicketAgentImpl.java │ └── resources │ │ ├── application.yml │ │ ├── logback.xml │ │ └── wsdl │ │ └── ticketagent.wsdl │ └── test │ └── java │ └── com │ └── codenotfound │ └── SpringCxfApplicationTests.java ├── cxf-jaxws-soap-header-explicit ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── codenotfound │ │ │ ├── SpringCxfApplication.java │ │ │ ├── client │ │ │ ├── ClientConfig.java │ │ │ └── TicketAgentClient.java │ │ │ └── endpoint │ │ │ ├── EndpointConfig.java │ │ │ └── TicketAgentImpl.java │ └── resources │ │ ├── application.yml │ │ ├── logback.xml │ │ └── wsdl │ │ └── ticketagent.wsdl │ └── test │ └── java │ └── com │ └── codenotfound │ └── SpringCxfApplicationTests.java ├── cxf-jaxws-soap-header ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── codenotfound │ │ │ ├── SpringCxfApplication.java │ │ │ ├── client │ │ │ ├── ClientConfig.java │ │ │ └── TicketAgentClient.java │ │ │ └── endpoint │ │ │ ├── EndpointConfig.java │ │ │ └── TicketAgentImpl.java │ └── resources │ │ ├── application.yml │ │ ├── logback.xml │ │ └── wsdl │ │ └── ticketagent.wsdl │ └── test │ └── java │ └── com │ └── codenotfound │ └── SpringCxfApplicationTests.java ├── cxf-jaxws-spring-boot ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── codenotfound │ │ │ ├── SpringCxfApplication.java │ │ │ ├── client │ │ │ ├── ClientConfig.java │ │ │ └── HelloWorldClient.java │ │ │ └── endpoint │ │ │ ├── EndpointConfig.java │ │ │ └── HelloWorldImpl.java │ └── resources │ │ ├── application.yml │ │ ├── logback.xml │ │ └── wsdl │ │ └── helloworld.wsdl │ └── test │ └── java │ └── com │ └── codenotfound │ └── SpringCxfApplicationTests.java └── cxf-jaxws-ticketagent ├── README.md ├── pom.xml └── src ├── main ├── java │ └── com │ │ └── codenotfound │ │ ├── SpringCxfApplication.java │ │ ├── client │ │ ├── ClientConfig.java │ │ └── TicketAgentClient.java │ │ └── endpoint │ │ ├── EndpointConfig.java │ │ └── TicketAgentImpl.java └── resources │ ├── application.yml │ ├── logback.xml │ └── wsdl │ └── ticketagent.wsdl └── test └── java └── com └── codenotfound └── SpringCxfApplicationTests.java /.gitignore: -------------------------------------------------------------------------------- 1 | ##Maven## 2 | target/ 3 | pom.xml.tag 4 | pom.xml.releaseBackup 5 | pom.xml.next 6 | release.properties 7 | 8 | ##Eclipse## 9 | .classpath 10 | .project 11 | .settings/ 12 | 13 | ##Logs## 14 | *.log 15 | *.log.* 16 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | sudo: false 3 | install: true 4 | 5 | jdk: 6 | - oraclejdk8 7 | 8 | addons: 9 | sonarqube: 10 | organization: code-not-found-cxf-jaxws 11 | token: 12 | secure: $SONAR_TOKEN 13 | 14 | env: 15 | - PROJECT_DIR=cxf-jaxws-basic-authentication 16 | - PROJECT_DIR=cxf-jaxws-digital-signature 17 | - PROJECT_DIR=cxf-jaxws-https 18 | - PROJECT_DIR=cxf-jaxws-jetty-logging-log4j 19 | - PROJECT_DIR=cxf-jaxws-jetty-logging-log4j2 20 | - PROJECT_DIR=cxf-jaxws-jetty-logging-logback 21 | - PROJECT_DIR=cxf-jaxws-jetty-xml-config 22 | - PROJECT_DIR=cxf-jaxws-logging-logback 23 | - PROJECT_DIR=cxf-jaxws-soap-header 24 | - PROJECT_DIR=cxf-jaxws-soap-header-explicit 25 | - PROJECT_DIR=cxf-jaxws-spring-boot 26 | - PROJECT_DIR=cxf-jaxws-ticketagent 27 | 28 | script: 29 | - cd $PROJECT_DIR 30 | - mvn test -B 31 | - mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent install sonar:sonar 32 | 33 | cache: 34 | directories: 35 | - $HOME/.m2/repository 36 | - $HOME/.sonar/cache 37 | 38 | notifications: 39 | email: false 40 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 code-not-found 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # cxf-jaxws 2 | 3 | [![Build Status](https://travis-ci.org/code-not-found/cxf-jaxws.svg?branch=master)](https://travis-ci.org/code-not-found/cxf-jaxws) 4 | [![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE) 5 | 6 | This repository contains the source code for the cxf-jaxws examples posted on [https://www.codenotfound.com/cxf-jaxws/](https://www.codenotfound.com/cxf-jaxws/) 7 | 8 | In case of questions or remarks please leave a comment in the respective blog post. Thanks! 9 | -------------------------------------------------------------------------------- /cxf-jaxws-basic-authentication/README.md: -------------------------------------------------------------------------------- 1 | # cxf-jaxws-basic-authentication 2 | 3 | [![Quality Gate](https://sonarcloud.io/api/badges/gate?key=com.codenotfound:cxf-jaxws-basic-authentication)](https://sonarcloud.io/dashboard/index/com.codenotfound:cxf-jaxws-basic-authentication) 4 | 5 | A detailed step-by-step tutorial on how to configure basic authentication using Apache CXF and Spring Boot. 6 | 7 | [https://www.codenotfound.com/apache-cxf-basic-authentication-example.html](https://www.codenotfound.com/apache-cxf-basic-authentication-example.html) 8 | -------------------------------------------------------------------------------- /cxf-jaxws-basic-authentication/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.codenotfound 7 | cxf-jaxws-basic-authentication 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | cxf-jaxws-basic-authentication 12 | Apache CXF - Basic Authentication Example 13 | https://www.codenotfound.com/cxf-jaxws/ 14 | 15 | 16 | org.springframework.boot 17 | spring-boot-starter-parent 18 | 1.5.9.RELEASE 19 | 20 | 21 | 22 | UTF-8 23 | 1.8 24 | 25 | 3.2.1 26 | 27 | 28 | 29 | 30 | 31 | org.springframework.boot 32 | spring-boot-starter-security 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-starter-test 37 | test 38 | 39 | 40 | 41 | org.apache.cxf 42 | cxf-spring-boot-starter-jaxws 43 | ${cxf.version} 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | org.springframework.boot 52 | spring-boot-maven-plugin 53 | 54 | 55 | 56 | org.apache.cxf 57 | cxf-codegen-plugin 58 | ${cxf.version} 59 | 60 | 61 | generate-sources 62 | generate-sources 63 | 64 | ${project.build.directory}/generated/cxf 65 | 66 | 67 | ${project.basedir}/src/main/resources/wsdl/ticketagent.wsdl 68 | classpath:wsdl/ticketagent.wsdl 69 | 70 | 71 | 72 | 73 | wsdl2java 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /cxf-jaxws-basic-authentication/src/main/java/com/codenotfound/SpringCxfApplication.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringCxfApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringCxfApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /cxf-jaxws-basic-authentication/src/main/java/com/codenotfound/client/ClientConfig.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.client; 2 | 3 | import org.apache.cxf.configuration.security.AuthorizationPolicy; 4 | import org.apache.cxf.endpoint.Client; 5 | import org.apache.cxf.frontend.ClientProxy; 6 | import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; 7 | import org.apache.cxf.transport.http.HTTPConduit; 8 | import org.example.ticketagent_wsdl11.TicketAgent; 9 | import org.springframework.beans.factory.annotation.Value; 10 | import org.springframework.context.annotation.Bean; 11 | import org.springframework.context.annotation.Configuration; 12 | 13 | @Configuration 14 | public class ClientConfig { 15 | 16 | @Value("${client.ticketagent.address}") 17 | private String address; 18 | 19 | @Value("${client.ticketagent.user-name}") 20 | private String userName; 21 | 22 | @Value("${client.ticketagent.password}") 23 | private String password; 24 | 25 | @Bean(name = "ticketAgentProxy") 26 | public TicketAgent ticketAgentProxy() { 27 | JaxWsProxyFactoryBean jaxWsProxyFactoryBean = 28 | new JaxWsProxyFactoryBean(); 29 | jaxWsProxyFactoryBean.setServiceClass(TicketAgent.class); 30 | jaxWsProxyFactoryBean.setAddress(address); 31 | 32 | return (TicketAgent) jaxWsProxyFactoryBean.create(); 33 | } 34 | 35 | @Bean 36 | public Client ticketAgentClientProxy() { 37 | return ClientProxy.getClient(ticketAgentProxy()); 38 | } 39 | 40 | @Bean 41 | public HTTPConduit ticketAgentConduit() { 42 | HTTPConduit httpConduit = 43 | (HTTPConduit) ticketAgentClientProxy().getConduit(); 44 | httpConduit.setAuthorization(basicAuthorization()); 45 | 46 | return httpConduit; 47 | } 48 | 49 | @Bean 50 | public AuthorizationPolicy basicAuthorization() { 51 | AuthorizationPolicy authorizationPolicy = 52 | new AuthorizationPolicy(); 53 | authorizationPolicy.setUserName(userName); 54 | authorizationPolicy.setPassword(password); 55 | authorizationPolicy.setAuthorizationType("Basic"); 56 | 57 | return authorizationPolicy; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /cxf-jaxws-basic-authentication/src/main/java/com/codenotfound/client/TicketAgentClient.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.client; 2 | 3 | import java.math.BigInteger; 4 | import java.util.List; 5 | 6 | import org.example.ticketagent.ObjectFactory; 7 | import org.example.ticketagent.TFlightsResponse; 8 | import org.example.ticketagent.TListFlights; 9 | import org.example.ticketagent_wsdl11.TicketAgent; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.stereotype.Component; 12 | 13 | @Component 14 | public class TicketAgentClient { 15 | 16 | @Autowired 17 | private TicketAgent ticketAgentProxy; 18 | 19 | public List listFlights() { 20 | ObjectFactory factory = new ObjectFactory(); 21 | TListFlights tListFlights = factory.createTListFlights(); 22 | 23 | TFlightsResponse response = 24 | ticketAgentProxy.listFlights(tListFlights); 25 | 26 | return response.getFlightNumber(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /cxf-jaxws-basic-authentication/src/main/java/com/codenotfound/endpoint/EndpointConfig.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.endpoint; 2 | 3 | import javax.xml.ws.Endpoint; 4 | 5 | import org.apache.cxf.Bus; 6 | import org.apache.cxf.jaxws.EndpointImpl; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.context.annotation.Bean; 9 | import org.springframework.context.annotation.Configuration; 10 | 11 | @Configuration 12 | public class EndpointConfig { 13 | 14 | @Autowired 15 | private Bus bus; 16 | 17 | @Bean 18 | public Endpoint endpoint() { 19 | EndpointImpl endpoint = 20 | new EndpointImpl(bus, new TicketAgentImpl()); 21 | endpoint.publish("/ticketagent"); 22 | 23 | return endpoint; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /cxf-jaxws-basic-authentication/src/main/java/com/codenotfound/endpoint/TicketAgentImpl.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.endpoint; 2 | 3 | import java.math.BigInteger; 4 | 5 | import org.apache.cxf.feature.Features; 6 | import org.example.ticketagent.ObjectFactory; 7 | import org.example.ticketagent.TFlightsResponse; 8 | import org.example.ticketagent.TListFlights; 9 | import org.example.ticketagent_wsdl11.TicketAgent; 10 | 11 | @Features(features = "org.apache.cxf.feature.LoggingFeature") 12 | public class TicketAgentImpl implements TicketAgent { 13 | 14 | @Override 15 | public TFlightsResponse listFlights(TListFlights request) { 16 | ObjectFactory factory = new ObjectFactory(); 17 | TFlightsResponse response = factory.createTFlightsResponse(); 18 | response.getFlightNumber().add(BigInteger.valueOf(101)); 19 | 20 | return response; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /cxf-jaxws-basic-authentication/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | client: 2 | ticketagent: 3 | address: http://localhost:9090/codenotfound/ws/ticketagent 4 | user-name: codenotfound 5 | password: p455w0rd 6 | 7 | security: 8 | user: 9 | name: codenotfound 10 | password: p455w0rd 11 | 12 | server: 13 | port: 9090 14 | 15 | cxf: 16 | path: /codenotfound/ws 17 | -------------------------------------------------------------------------------- /cxf-jaxws-basic-authentication/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /cxf-jaxws-basic-authentication/src/main/resources/wsdl/ticketagent.wsdl: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /cxf-jaxws-basic-authentication/src/test/java/com/codenotfound/SpringCxfApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import java.math.BigInteger; 6 | import java.util.List; 7 | 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.boot.test.context.SpringBootTest; 12 | import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; 13 | import org.springframework.test.context.junit4.SpringRunner; 14 | 15 | import com.codenotfound.client.TicketAgentClient; 16 | 17 | @RunWith(SpringRunner.class) 18 | @SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT) 19 | public class SpringCxfApplicationTests { 20 | 21 | @Autowired 22 | private TicketAgentClient ticketAgentClient; 23 | 24 | @Test 25 | public void testListFlights() { 26 | List flights = ticketAgentClient.listFlights(); 27 | 28 | assertThat(flights.get(0)).isEqualTo(BigInteger.valueOf(101)); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /cxf-jaxws-digital-signature/README.md: -------------------------------------------------------------------------------- 1 | # cxf-jaxws-digital-signature 2 | 3 | [![Quality Gate](https://sonarcloud.io/api/badges/gate?key=com.codenotfound:cxf-jaxws-digital-signature)](https://sonarcloud.io/dashboard/index/com.codenotfound:cxf-jaxws-digital-signature) 4 | 5 | A detailed step-by-step tutorial on how generate and validate a digital signature using Apache CXF and Spring Boot. 6 | 7 | [https://www.codenotfound.com/cxf-jaxws/](https://www.codenotfound.com/cxf-jaxws/) 8 | -------------------------------------------------------------------------------- /cxf-jaxws-digital-signature/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.codenotfound 7 | cxf-jaxws-digital-signature 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | cxf-jaxws-digital-signature 12 | Spring WS - Digital Signature Example 13 | https://www.codenotfound.com/jaxws-cxf/ 14 | 15 | 16 | org.springframework.boot 17 | spring-boot-starter-parent 18 | 1.5.9.RELEASE 19 | 20 | 21 | 22 | UTF-8 23 | 1.8 24 | 25 | 3.2.1 26 | 27 | 28 | 29 | 30 | 31 | org.springframework.boot 32 | spring-boot-starter-test 33 | test 34 | 35 | 36 | 37 | org.apache.cxf 38 | cxf-spring-boot-starter-jaxws 39 | ${cxf.version} 40 | 41 | 42 | org.apache.cxf 43 | cxf-rt-ws-security 44 | ${cxf.version} 45 | 46 | 47 | org.apache.cxf 48 | cxf-rt-features-logging 49 | ${cxf.version} 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | org.springframework.boot 58 | spring-boot-maven-plugin 59 | 60 | 61 | 62 | org.apache.cxf 63 | cxf-codegen-plugin 64 | ${cxf.version} 65 | 66 | 67 | generate-sources 68 | generate-sources 69 | 70 | ${project.build.directory}/generated/cxf 71 | 72 | 73 | ${project.basedir}/src/main/resources/wsdl/ticketagent.wsdl 74 | classpath:wsdl/ticketagent.wsdl 75 | 76 | 77 | 78 | 79 | wsdl2java 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /cxf-jaxws-digital-signature/src/main/java/com/codenotfound/SpringCxfApplication.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringCxfApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringCxfApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /cxf-jaxws-digital-signature/src/main/java/com/codenotfound/client/ClientCallbackHandler.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.client; 2 | 3 | import java.io.IOException; 4 | 5 | import javax.security.auth.callback.Callback; 6 | import javax.security.auth.callback.CallbackHandler; 7 | import javax.security.auth.callback.UnsupportedCallbackException; 8 | 9 | public class ClientCallbackHandler implements CallbackHandler { 10 | 11 | @Override 12 | public void handle(Callback[] callbacks) 13 | throws IOException, UnsupportedCallbackException { 14 | // Do nothing 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /cxf-jaxws-digital-signature/src/main/java/com/codenotfound/client/ClientConfig.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.client; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import org.apache.cxf.ext.logging.LoggingInInterceptor; 7 | import org.apache.cxf.ext.logging.LoggingOutInterceptor; 8 | import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; 9 | import org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor; 10 | import org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor; 11 | import org.apache.wss4j.dom.handler.WSHandlerConstants; 12 | import org.example.ticketagent_wsdl11.TicketAgent; 13 | import org.springframework.beans.factory.annotation.Value; 14 | import org.springframework.context.annotation.Bean; 15 | import org.springframework.context.annotation.Configuration; 16 | 17 | @Configuration 18 | public class ClientConfig { 19 | 20 | @Value("${client.ticketagent.address}") 21 | private String address; 22 | 23 | @Value("${client.ticketagent.keystore-alias}") 24 | private String keystoreAlias; 25 | 26 | @Bean(name = "ticketAgentProxyBean") 27 | public TicketAgent ticketAgent() { 28 | JaxWsProxyFactoryBean jaxWsProxyFactoryBean = 29 | new JaxWsProxyFactoryBean(); 30 | jaxWsProxyFactoryBean.setServiceClass(TicketAgent.class); 31 | jaxWsProxyFactoryBean.setAddress(address); 32 | 33 | // add the WSS4J OUT interceptor to sign the request message 34 | jaxWsProxyFactoryBean.getOutInterceptors().add(clientWssOut()); 35 | // add the WSS4J IN interceptor to verify the signature on the response message 36 | jaxWsProxyFactoryBean.getInInterceptors().add(clientWssIn()); 37 | 38 | // log the request and response messages 39 | jaxWsProxyFactoryBean.getInInterceptors() 40 | .add(loggingInInterceptor()); 41 | jaxWsProxyFactoryBean.getOutInterceptors() 42 | .add(loggingOutInterceptor()); 43 | 44 | return (TicketAgent) jaxWsProxyFactoryBean.create(); 45 | } 46 | 47 | @Bean 48 | public Map clientOutProps() { 49 | Map clientOutProps = new HashMap<>(); 50 | clientOutProps.put(WSHandlerConstants.ACTION, 51 | WSHandlerConstants.TIMESTAMP + " " 52 | + WSHandlerConstants.SIGNATURE); 53 | clientOutProps.put(WSHandlerConstants.USER, keystoreAlias); 54 | clientOutProps.put(WSHandlerConstants.PW_CALLBACK_CLASS, 55 | ClientCallbackHandler.class.getName()); 56 | clientOutProps.put(WSHandlerConstants.SIG_PROP_FILE, 57 | "client_key.properties"); 58 | 59 | return clientOutProps; 60 | } 61 | 62 | @Bean 63 | public WSS4JOutInterceptor clientWssOut() { 64 | WSS4JOutInterceptor clientWssOut = new WSS4JOutInterceptor(); 65 | clientWssOut.setProperties(clientOutProps()); 66 | 67 | return clientWssOut; 68 | } 69 | 70 | @Bean 71 | public Map clientInProps() { 72 | Map clientInProps = new HashMap<>(); 73 | clientInProps.put(WSHandlerConstants.ACTION, 74 | WSHandlerConstants.TIMESTAMP + " " 75 | + WSHandlerConstants.SIGNATURE); 76 | clientInProps.put(WSHandlerConstants.SIG_PROP_FILE, 77 | "client_trust.properties"); 78 | 79 | return clientInProps; 80 | } 81 | 82 | @Bean 83 | public WSS4JInInterceptor clientWssIn() { 84 | WSS4JInInterceptor clientWssIn = new WSS4JInInterceptor(); 85 | clientWssIn.setProperties(clientInProps()); 86 | 87 | return clientWssIn; 88 | } 89 | 90 | @Bean 91 | public LoggingInInterceptor loggingInInterceptor() { 92 | return new LoggingInInterceptor(); 93 | } 94 | 95 | @Bean 96 | public LoggingOutInterceptor loggingOutInterceptor() { 97 | return new LoggingOutInterceptor(); 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /cxf-jaxws-digital-signature/src/main/java/com/codenotfound/client/TicketAgentClient.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.client; 2 | 3 | import java.math.BigInteger; 4 | import java.util.List; 5 | 6 | import org.example.ticketagent.ObjectFactory; 7 | import org.example.ticketagent.TFlightsResponse; 8 | import org.example.ticketagent.TListFlights; 9 | import org.example.ticketagent_wsdl11.TicketAgent; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.stereotype.Component; 12 | 13 | @Component 14 | public class TicketAgentClient { 15 | 16 | @Autowired 17 | private TicketAgent ticketAgentProxyBean; 18 | 19 | public List listFlights() { 20 | ObjectFactory factory = new ObjectFactory(); 21 | TListFlights tListFlights = factory.createTListFlights(); 22 | 23 | TFlightsResponse response = 24 | ticketAgentProxyBean.listFlights(tListFlights); 25 | 26 | return response.getFlightNumber(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /cxf-jaxws-digital-signature/src/main/java/com/codenotfound/endpoint/EndpointConfig.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.endpoint; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import javax.xml.ws.Endpoint; 7 | 8 | import org.apache.cxf.Bus; 9 | import org.apache.cxf.jaxws.EndpointImpl; 10 | import org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor; 11 | import org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor; 12 | import org.apache.wss4j.dom.handler.WSHandlerConstants; 13 | import org.springframework.beans.factory.annotation.Autowired; 14 | import org.springframework.beans.factory.annotation.Value; 15 | import org.springframework.context.annotation.Bean; 16 | import org.springframework.context.annotation.Configuration; 17 | 18 | @Configuration 19 | public class EndpointConfig { 20 | 21 | @Value("${server.ticketagent.keystore-alias}") 22 | private String keystoreAlias; 23 | 24 | @Autowired 25 | private Bus bus; 26 | 27 | @Bean 28 | public Endpoint endpoint() { 29 | EndpointImpl endpoint = 30 | new EndpointImpl(bus, new TicketAgentImpl()); 31 | endpoint.publish("/ticketagent"); 32 | 33 | // add the WSS4J IN interceptor to verify the signature on the request message 34 | endpoint.getInInterceptors().add(serverWssIn()); 35 | // add the WSS4J OUT interceptor to sign the response message 36 | endpoint.getOutInterceptors().add(serverWssOut()); 37 | 38 | return endpoint; 39 | } 40 | 41 | @Bean 42 | public Map serverInProps() { 43 | Map serverInProps = new HashMap<>(); 44 | serverInProps.put(WSHandlerConstants.ACTION, 45 | WSHandlerConstants.TIMESTAMP + " " 46 | + WSHandlerConstants.SIGNATURE); 47 | serverInProps.put(WSHandlerConstants.SIG_PROP_FILE, 48 | "server_trust.properties"); 49 | 50 | return serverInProps; 51 | } 52 | 53 | @Bean 54 | public WSS4JInInterceptor serverWssIn() { 55 | WSS4JInInterceptor serverWssIn = new WSS4JInInterceptor(); 56 | serverWssIn.setProperties(serverInProps()); 57 | 58 | return serverWssIn; 59 | } 60 | 61 | @Bean 62 | public Map serverOutProps() { 63 | Map serverOutProps = new HashMap<>(); 64 | serverOutProps.put(WSHandlerConstants.ACTION, 65 | WSHandlerConstants.TIMESTAMP + " " 66 | + WSHandlerConstants.SIGNATURE); 67 | serverOutProps.put(WSHandlerConstants.USER, keystoreAlias); 68 | serverOutProps.put(WSHandlerConstants.PW_CALLBACK_CLASS, 69 | ServerCallbackHandler.class.getName()); 70 | serverOutProps.put(WSHandlerConstants.SIG_PROP_FILE, 71 | "server_key.properties"); 72 | 73 | return serverOutProps; 74 | } 75 | 76 | @Bean 77 | public WSS4JOutInterceptor serverWssOut() { 78 | WSS4JOutInterceptor serverWssOut = new WSS4JOutInterceptor(); 79 | serverWssOut.setProperties(serverOutProps()); 80 | 81 | return serverWssOut; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /cxf-jaxws-digital-signature/src/main/java/com/codenotfound/endpoint/ServerCallbackHandler.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.endpoint; 2 | 3 | import java.io.IOException; 4 | 5 | import javax.security.auth.callback.Callback; 6 | import javax.security.auth.callback.CallbackHandler; 7 | import javax.security.auth.callback.UnsupportedCallbackException; 8 | 9 | public class ServerCallbackHandler implements CallbackHandler { 10 | 11 | @Override 12 | public void handle(Callback[] callbacks) 13 | throws IOException, UnsupportedCallbackException { 14 | // Do nothing 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /cxf-jaxws-digital-signature/src/main/java/com/codenotfound/endpoint/TicketAgentImpl.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.endpoint; 2 | 3 | import java.math.BigInteger; 4 | 5 | import org.example.ticketagent.ObjectFactory; 6 | import org.example.ticketagent.TFlightsResponse; 7 | import org.example.ticketagent.TListFlights; 8 | import org.example.ticketagent_wsdl11.TicketAgent; 9 | 10 | public class TicketAgentImpl implements TicketAgent { 11 | 12 | @Override 13 | public TFlightsResponse listFlights(TListFlights body) { 14 | ObjectFactory factory = new ObjectFactory(); 15 | TFlightsResponse response = factory.createTFlightsResponse(); 16 | response.getFlightNumber().add(BigInteger.valueOf(101)); 17 | 18 | return response; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /cxf-jaxws-digital-signature/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | client: 2 | ticketagent: 3 | address: http://localhost:9090/codenotfound/ws/ticketagent 4 | keystore-alias: client-keypair 5 | 6 | server: 7 | port: 9090 8 | ticketagent: 9 | keystore-alias: server-keypair 10 | 11 | cxf: 12 | path: /codenotfound/ws 13 | -------------------------------------------------------------------------------- /cxf-jaxws-digital-signature/src/main/resources/client_key.properties: -------------------------------------------------------------------------------- 1 | org.apache.ws.security.crypto.provider=org.apache.ws.security.components.crypto.Merlin 2 | org.apache.ws.security.crypto.merlin.keystore.type=jks 3 | org.apache.ws.security.crypto.merlin.keystore.private.password=client-key-p455w0rd 4 | org.apache.ws.security.crypto.merlin.keystore.alias=client-keypair 5 | org.apache.ws.security.crypto.merlin.keystore.password=client-keystore-p455w0rd 6 | org.apache.ws.security.crypto.merlin.keystore.file=jks/client-keystore.jks 7 | -------------------------------------------------------------------------------- /cxf-jaxws-digital-signature/src/main/resources/client_trust.properties: -------------------------------------------------------------------------------- 1 | org.apache.ws.security.crypto.provider=org.apache.ws.security.components.crypto.Merlin 2 | org.apache.ws.security.crypto.merlin.keystore.type=jks 3 | org.apache.ws.security.crypto.merlin.keystore.password=client-truststore-p455w0rd 4 | org.apache.ws.security.crypto.merlin.keystore.file=jks/client-truststore.jks 5 | -------------------------------------------------------------------------------- /cxf-jaxws-digital-signature/src/main/resources/jks/client-keystore.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-not-found/cxf-jaxws/a1e31cc651068a9f15ee10fca14df60dabd9b59e/cxf-jaxws-digital-signature/src/main/resources/jks/client-keystore.jks -------------------------------------------------------------------------------- /cxf-jaxws-digital-signature/src/main/resources/jks/client-truststore.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-not-found/cxf-jaxws/a1e31cc651068a9f15ee10fca14df60dabd9b59e/cxf-jaxws-digital-signature/src/main/resources/jks/client-truststore.jks -------------------------------------------------------------------------------- /cxf-jaxws-digital-signature/src/main/resources/jks/server-keystore.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-not-found/cxf-jaxws/a1e31cc651068a9f15ee10fca14df60dabd9b59e/cxf-jaxws-digital-signature/src/main/resources/jks/server-keystore.jks -------------------------------------------------------------------------------- /cxf-jaxws-digital-signature/src/main/resources/jks/server-truststore.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-not-found/cxf-jaxws/a1e31cc651068a9f15ee10fca14df60dabd9b59e/cxf-jaxws-digital-signature/src/main/resources/jks/server-truststore.jks -------------------------------------------------------------------------------- /cxf-jaxws-digital-signature/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /cxf-jaxws-digital-signature/src/main/resources/server_key.properties: -------------------------------------------------------------------------------- 1 | org.apache.ws.security.crypto.provider=org.apache.ws.security.components.crypto.Merlin 2 | org.apache.ws.security.crypto.merlin.keystore.type=jks 3 | org.apache.ws.security.crypto.merlin.keystore.private.password=server-key-p455w0rd 4 | org.apache.ws.security.crypto.merlin.keystore.alias=server-keypair 5 | org.apache.ws.security.crypto.merlin.keystore.password=server-keystore-p455w0rd 6 | org.apache.ws.security.crypto.merlin.keystore.file=jks/server-keystore.jks 7 | -------------------------------------------------------------------------------- /cxf-jaxws-digital-signature/src/main/resources/server_trust.properties: -------------------------------------------------------------------------------- 1 | org.apache.ws.security.crypto.provider=org.apache.ws.security.components.crypto.Merlin 2 | org.apache.ws.security.crypto.merlin.keystore.type=jks 3 | org.apache.ws.security.crypto.merlin.keystore.password=server-truststore-p455w0rd 4 | org.apache.ws.security.crypto.merlin.keystore.file=jks/server-truststore.jks 5 | -------------------------------------------------------------------------------- /cxf-jaxws-digital-signature/src/main/resources/wsdl/ticketagent.wsdl: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /cxf-jaxws-digital-signature/src/test/java/com/codenotfound/SpringCxfApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import java.math.BigInteger; 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.context.SpringBootTest; 11 | import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; 12 | import org.springframework.test.context.junit4.SpringRunner; 13 | 14 | import com.codenotfound.client.TicketAgentClient; 15 | 16 | @RunWith(SpringRunner.class) 17 | @SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT) 18 | public class SpringCxfApplicationTests { 19 | 20 | @Autowired 21 | private TicketAgentClient ticketAgentClient; 22 | 23 | @Test 24 | public void testListFlights() { 25 | assertThat(ticketAgentClient.listFlights().get(0)) 26 | .isEqualTo(BigInteger.valueOf(101)); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /cxf-jaxws-https/README.md: -------------------------------------------------------------------------------- 1 | # cxf-jaxws-https 2 | 3 | [![Quality Gate](https://sonarcloud.io/api/badges/gate?key=com.codenotfound:cxf-jaxws-https)](https://sonarcloud.io/dashboard/index/com.codenotfound:cxf-jaxws-https) 4 | 5 | A detailed step-by-step tutorial on how to setup HTTPS on client and server side using Apache CXF and Spring Boot. 6 | 7 | [https://www.codenotfound.com/cxf-jaxws/](https://www.codenotfound.com/cxf-jaxws/) 8 | -------------------------------------------------------------------------------- /cxf-jaxws-https/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.codenotfound 7 | cxf-jaxws-https 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | cxf-jaxws-https 12 | Apache CXF - HTTPS Example 13 | https://www.codenotfound.com/jaxws-cxf/ 14 | 15 | 16 | org.springframework.boot 17 | spring-boot-starter-parent 18 | 1.5.9.RELEASE 19 | 20 | 21 | 22 | UTF-8 23 | 1.8 24 | 25 | 3.2.1 26 | 27 | 28 | 29 | 30 | 31 | org.springframework.boot 32 | spring-boot-starter-test 33 | test 34 | 35 | 36 | 37 | org.apache.cxf 38 | cxf-spring-boot-starter-jaxws 39 | ${cxf.version} 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | org.springframework.boot 48 | spring-boot-maven-plugin 49 | 50 | 51 | 52 | org.apache.cxf 53 | cxf-codegen-plugin 54 | ${cxf.version} 55 | 56 | 57 | generate-sources 58 | generate-sources 59 | 60 | ${project.build.directory}/generated/cxf 61 | 62 | 63 | ${project.basedir}/src/main/resources/wsdl/ticketagent.wsdl 64 | classpath:wsdl/ticketagent.wsdl 65 | 66 | 67 | 68 | 69 | wsdl2java 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /cxf-jaxws-https/src/main/java/com/codenotfound/SpringCxfApplication.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringCxfApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringCxfApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /cxf-jaxws-https/src/main/java/com/codenotfound/client/ClientConfig.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.client; 2 | 3 | import java.io.IOException; 4 | import java.security.KeyStore; 5 | import java.security.KeyStoreException; 6 | import java.security.NoSuchAlgorithmException; 7 | import java.security.cert.CertificateException; 8 | 9 | import javax.net.ssl.TrustManager; 10 | import javax.net.ssl.TrustManagerFactory; 11 | 12 | import org.apache.cxf.configuration.jsse.TLSClientParameters; 13 | import org.apache.cxf.configuration.security.FiltersType; 14 | import org.apache.cxf.endpoint.Client; 15 | import org.apache.cxf.frontend.ClientProxy; 16 | import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; 17 | import org.apache.cxf.transport.http.HTTPConduit; 18 | import org.example.ticketagent_wsdl11.TicketAgent; 19 | import org.springframework.beans.factory.annotation.Value; 20 | import org.springframework.context.annotation.Bean; 21 | import org.springframework.context.annotation.Configuration; 22 | import org.springframework.core.io.Resource; 23 | 24 | @Configuration 25 | public class ClientConfig { 26 | 27 | @Value("${client.address}") 28 | private String address; 29 | 30 | @Value("${client.trust-store}") 31 | private Resource trustStoreResource; 32 | 33 | @Value("${client.trust-store-password}") 34 | private String trustStorePassword; 35 | 36 | @Bean 37 | public TicketAgent ticketAgentProxy() { 38 | JaxWsProxyFactoryBean jaxWsProxyFactoryBean = 39 | new JaxWsProxyFactoryBean(); 40 | jaxWsProxyFactoryBean.setServiceClass(TicketAgent.class); 41 | jaxWsProxyFactoryBean.setAddress(address); 42 | 43 | return (TicketAgent) jaxWsProxyFactoryBean.create(); 44 | } 45 | 46 | @Bean 47 | public HTTPConduit ticketAgentConduit() 48 | throws NoSuchAlgorithmException, KeyStoreException, 49 | CertificateException, IOException { 50 | Client client = ClientProxy.getClient(ticketAgentProxy()); 51 | 52 | HTTPConduit httpConduit = (HTTPConduit) client.getConduit(); 53 | httpConduit.setTlsClientParameters(tlsClientParameters()); 54 | 55 | return httpConduit; 56 | } 57 | 58 | @Bean 59 | public TLSClientParameters tlsClientParameters() 60 | throws NoSuchAlgorithmException, KeyStoreException, 61 | CertificateException, IOException { 62 | TLSClientParameters tlsClientParameters = 63 | new TLSClientParameters(); 64 | tlsClientParameters.setSecureSocketProtocol("TLS"); 65 | // should NOT be used in production 66 | tlsClientParameters.setDisableCNCheck(true); 67 | tlsClientParameters.setTrustManagers(trustManagers()); 68 | tlsClientParameters.setCipherSuitesFilter(cipherSuitesFilter()); 69 | 70 | return tlsClientParameters; 71 | } 72 | 73 | @Bean 74 | public TrustManager[] trustManagers() 75 | throws NoSuchAlgorithmException, KeyStoreException, 76 | CertificateException, IOException { 77 | TrustManagerFactory trustManagerFactory = TrustManagerFactory 78 | .getInstance(TrustManagerFactory.getDefaultAlgorithm()); 79 | trustManagerFactory.init(trustStore()); 80 | 81 | return trustManagerFactory.getTrustManagers(); 82 | } 83 | 84 | @Bean 85 | public KeyStore trustStore() throws KeyStoreException, 86 | NoSuchAlgorithmException, CertificateException, IOException { 87 | KeyStore trustStore = KeyStore.getInstance("JKS"); 88 | trustStore.load(trustStoreResource.getInputStream(), 89 | trustStorePassword.toCharArray()); 90 | 91 | return trustStore; 92 | } 93 | 94 | @Bean 95 | public FiltersType cipherSuitesFilter() { 96 | FiltersType filter = new FiltersType(); 97 | filter.getInclude().add("TLS_ECDHE_RSA_.*"); 98 | filter.getInclude().add("TLS_DHE_RSA_.*"); 99 | 100 | return filter; 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /cxf-jaxws-https/src/main/java/com/codenotfound/client/TicketAgentClient.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.client; 2 | 3 | import java.math.BigInteger; 4 | import java.util.List; 5 | 6 | import org.example.ticketagent.ObjectFactory; 7 | import org.example.ticketagent.TFlightsResponse; 8 | import org.example.ticketagent.TListFlights; 9 | import org.example.ticketagent_wsdl11.TicketAgent; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.stereotype.Component; 12 | 13 | @Component 14 | public class TicketAgentClient { 15 | 16 | @Autowired 17 | private TicketAgent ticketAgentProxyBean; 18 | 19 | public List listFlights() { 20 | ObjectFactory factory = new ObjectFactory(); 21 | TListFlights tListFlights = factory.createTListFlights(); 22 | 23 | TFlightsResponse response = 24 | ticketAgentProxyBean.listFlights(tListFlights); 25 | 26 | return response.getFlightNumber(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /cxf-jaxws-https/src/main/java/com/codenotfound/endpoint/EndpointConfig.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.endpoint; 2 | 3 | import javax.xml.ws.Endpoint; 4 | 5 | import org.apache.cxf.Bus; 6 | import org.apache.cxf.jaxws.EndpointImpl; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.context.annotation.Bean; 9 | import org.springframework.context.annotation.Configuration; 10 | 11 | @Configuration 12 | public class EndpointConfig { 13 | 14 | @Autowired 15 | private Bus bus; 16 | 17 | @Bean 18 | public Endpoint endpoint() { 19 | EndpointImpl endpoint = 20 | new EndpointImpl(bus, new TicketAgentImpl()); 21 | endpoint.publish("/ticketagent"); 22 | 23 | return endpoint; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /cxf-jaxws-https/src/main/java/com/codenotfound/endpoint/TicketAgentImpl.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.endpoint; 2 | 3 | import java.math.BigInteger; 4 | 5 | import org.example.ticketagent.ObjectFactory; 6 | import org.example.ticketagent.TFlightsResponse; 7 | import org.example.ticketagent.TListFlights; 8 | import org.example.ticketagent_wsdl11.TicketAgent; 9 | 10 | public class TicketAgentImpl implements TicketAgent { 11 | 12 | @Override 13 | public TFlightsResponse listFlights(TListFlights body) { 14 | ObjectFactory factory = new ObjectFactory(); 15 | TFlightsResponse response = factory.createTFlightsResponse(); 16 | response.getFlightNumber().add(BigInteger.valueOf(101)); 17 | 18 | return response; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /cxf-jaxws-https/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | client: 2 | address: https://localhost:9443/codenotfound/ws/ticketagent 3 | trust-store: classpath:jks/client-truststore.jks 4 | trust-store-password: client-truststore-p455w0rd 5 | 6 | server: 7 | port: 9443 8 | ssl: 9 | key-store: classpath:jks/server-keystore.jks 10 | key-store-password: server-keystore-p455w0rd 11 | key-alias: server-keypair 12 | key-password: server-key-p455w0rd 13 | 14 | cxf: 15 | path: /codenotfound/ws 16 | -------------------------------------------------------------------------------- /cxf-jaxws-https/src/main/resources/jks/client-truststore.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-not-found/cxf-jaxws/a1e31cc651068a9f15ee10fca14df60dabd9b59e/cxf-jaxws-https/src/main/resources/jks/client-truststore.jks -------------------------------------------------------------------------------- /cxf-jaxws-https/src/main/resources/jks/server-keystore.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-not-found/cxf-jaxws/a1e31cc651068a9f15ee10fca14df60dabd9b59e/cxf-jaxws-https/src/main/resources/jks/server-keystore.jks -------------------------------------------------------------------------------- /cxf-jaxws-https/src/main/resources/jks/server-truststore.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-not-found/cxf-jaxws/a1e31cc651068a9f15ee10fca14df60dabd9b59e/cxf-jaxws-https/src/main/resources/jks/server-truststore.jks -------------------------------------------------------------------------------- /cxf-jaxws-https/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /cxf-jaxws-https/src/main/resources/wsdl/ticketagent.wsdl: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /cxf-jaxws-https/src/test/java/com/codenotfound/SpringCxfApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import java.math.BigInteger; 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.context.SpringBootTest; 11 | import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; 12 | import org.springframework.test.context.junit4.SpringRunner; 13 | 14 | import com.codenotfound.client.TicketAgentClient; 15 | 16 | @RunWith(SpringRunner.class) 17 | @SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT) 18 | public class SpringCxfApplicationTests { 19 | 20 | @Autowired 21 | private TicketAgentClient ticketAgentClient; 22 | 23 | @Test 24 | public void testListFlights() { 25 | assertThat(ticketAgentClient.listFlights().get(0)) 26 | .isEqualTo(BigInteger.valueOf(101)); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /cxf-jaxws-jetty-logging-log4j/README.md: -------------------------------------------------------------------------------- 1 | # cxf-jaxws-jetty-logging-log4j 2 | 3 | [![Quality Gate](https://sonarcloud.io/api/badges/gate?key=com.codenotfound:cxf-jaxws-jetty-logging-log4j)](https://sonarcloud.io/dashboard/index/com.codenotfound:cxf-jaxws-jetty-logging-log4j) 4 | 5 | A code sample which shows how to configure CXF to log the request and response SOAP messages using Log4j. 6 | 7 | [https://www.codenotfound.com/jaxws-cxf-logging-request-response-soap-messages-log4j.html](https://www.codenotfound.com/jaxws-cxf-logging-request-response-soap-messages-log4j.html) 8 | -------------------------------------------------------------------------------- /cxf-jaxws-jetty-logging-log4j/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.codenotfound 7 | cxf-jaxws-jetty-logging-log4j 8 | 0.0.1-SNAPSHOT 9 | war 10 | 11 | cxf-jaxws-jetty-logging-log4j 12 | JAX-WS - CXF logging request and response SOAP messages using Log4j 13 | https://codenotfound.com/jaxws-cxf-logging-request-response-soap-messages-log4j.html 14 | 15 | 16 | UTF-8 17 | 1.8 18 | 19 | 1.7.10 20 | 1.2.17 21 | 4.12 22 | 3.0.3 23 | 4.1.4.RELEASE 24 | 25 | 3.1 26 | 8.1.16.v20140903 27 | 2.17 28 | 29 | 30 | 31 | 32 | 33 | org.slf4j 34 | jcl-over-slf4j 35 | ${slf4j.version} 36 | 37 | 38 | org.slf4j 39 | slf4j-log4j12 40 | ${slf4j.version} 41 | 42 | 43 | log4j 44 | log4j 45 | ${log4j.version} 46 | 47 | 48 | 49 | junit 50 | junit 51 | ${junit.version} 52 | test 53 | 54 | 55 | 56 | org.apache.cxf 57 | cxf-rt-frontend-jaxws 58 | ${cxf.version} 59 | 60 | 61 | org.apache.cxf 62 | cxf-rt-transports-http 63 | ${cxf.version} 64 | 65 | 66 | org.apache.cxf 67 | 68 | cxf-rt-transports-http-jetty 69 | ${cxf.version} 70 | 71 | 72 | 73 | org.springframework 74 | spring-context 75 | ${spring.version} 76 | 77 | 78 | commons-logging 79 | commons-logging 80 | 81 | 82 | 83 | 84 | org.springframework 85 | spring-web 86 | ${spring.version} 87 | 88 | 89 | commons-logging 90 | commons-logging 91 | 92 | 93 | 94 | 95 | org.springframework 96 | spring-test 97 | ${spring.version} 98 | test 99 | 100 | 101 | commons-logging 102 | commons-logging 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | org.apache.maven.plugins 112 | maven-compiler-plugin 113 | ${maven-compiler-plugin.version} 114 | 115 | ${java.version} 116 | ${java.version} 117 | 118 | 119 | 120 | 121 | org.mortbay.jetty 122 | jetty-maven-plugin 123 | ${jetty-maven-plugin.version} 124 | 125 | 126 | 128 | 9090 129 | 130 | 131 | 8005 132 | STOP 133 | true 134 | 135 | 136 | 137 | start-jetty 138 | pre-integration-test 139 | 140 | start 141 | 142 | 143 | 144 | stop-jetty 145 | post-integration-test 146 | 147 | stop 148 | 149 | 150 | 151 | 152 | 153 | 154 | org.apache.maven.plugins 155 | maven-failsafe-plugin 156 | ${maven-failsafe-plugin.version} 157 | 158 | 159 | 160 | integration-test 161 | verify 162 | 163 | 164 | 165 | 166 | 167 | 168 | org.apache.cxf 169 | cxf-codegen-plugin 170 | ${cxf.version} 171 | 172 | 173 | generate-sources 174 | generate-sources 175 | 176 | ${project.build.directory}/generated/cxf 177 | 178 | 179 | ${project.basedir}/src/main/resources/wsdl/helloworld.wsdl 180 | classpath:wsdl/helloworld.wsdl 181 | 182 | 183 | 184 | 185 | wsdl2java 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | -------------------------------------------------------------------------------- /cxf-jaxws-jetty-logging-log4j/src/main/java/com/codenotfound/soap/http/cxf/HelloWorldClient.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.soap.http.cxf; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Component; 7 | 8 | import com.codenotfound.services.helloworld.Greeting; 9 | import com.codenotfound.services.helloworld.HelloWorldPortType; 10 | import com.codenotfound.services.helloworld.Person; 11 | 12 | @Component 13 | public class HelloWorldClient { 14 | 15 | private static final Logger LOGGER = 16 | LoggerFactory.getLogger(HelloWorldClient.class); 17 | 18 | @Autowired 19 | private HelloWorldPortType helloWorldRequesterBean; 20 | 21 | public String sayHello(Person person) { 22 | Greeting greeting = helloWorldRequesterBean.sayHello(person); 23 | 24 | String result = greeting.getText(); 25 | LOGGER.info("result={}", result); 26 | return result; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /cxf-jaxws-jetty-logging-log4j/src/main/java/com/codenotfound/soap/http/cxf/HelloWorldImpl.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.soap.http.cxf; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | 6 | import com.codenotfound.services.helloworld.Greeting; 7 | import com.codenotfound.services.helloworld.HelloWorldPortType; 8 | import com.codenotfound.services.helloworld.ObjectFactory; 9 | import com.codenotfound.services.helloworld.Person; 10 | 11 | public class HelloWorldImpl implements HelloWorldPortType { 12 | 13 | private static final Logger LOGGER = 14 | LoggerFactory.getLogger(HelloWorldImpl.class); 15 | 16 | @Override 17 | public Greeting sayHello(Person person) { 18 | 19 | String firstName = person.getFirstName(); 20 | LOGGER.debug("firstName={}", firstName); 21 | String lasttName = person.getLastName(); 22 | 23 | LOGGER.debug("lastName={}", lasttName); 24 | ObjectFactory factory = new ObjectFactory(); 25 | Greeting response = factory.createGreeting(); 26 | 27 | String greeting = "Hello " + firstName + " " + lasttName + "!"; 28 | LOGGER.info("greeting={}", greeting); 29 | 30 | response.setText(greeting); 31 | return response; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /cxf-jaxws-jetty-logging-log4j/src/main/resources/META-INF/cxf/org.apache.cxf.Logger: -------------------------------------------------------------------------------- 1 | org.apache.cxf.common.logging.Slf4jLogger 2 | -------------------------------------------------------------------------------- /cxf-jaxws-jetty-logging-log4j/src/main/resources/META-INF/spring/context-provider.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /cxf-jaxws-jetty-logging-log4j/src/main/resources/META-INF/spring/context-requester.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /cxf-jaxws-jetty-logging-log4j/src/main/resources/META-INF/spring/cxf-provider.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /cxf-jaxws-jetty-logging-log4j/src/main/resources/META-INF/spring/cxf-requester.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 23 | 24 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /cxf-jaxws-jetty-logging-log4j/src/main/resources/cxf.properties: -------------------------------------------------------------------------------- 1 | # HTTP address of the Hello World service 2 | helloworld.address=http://localhost:9090/cnf/services/helloworld 3 | -------------------------------------------------------------------------------- /cxf-jaxws-jetty-logging-log4j/src/main/resources/log4j.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | 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 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /cxf-jaxws-jetty-logging-log4j/src/main/resources/wsdl/helloworld.wsdl: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /cxf-jaxws-jetty-logging-log4j/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | contextConfigLocation 8 | classpath:META-INF/spring/context-provider.xml 9 | 10 | 11 | 12 | org.springframework.web.context.ContextLoaderListener 13 | 14 | 15 | 16 | cxf 17 | org.apache.cxf.transport.servlet.CXFServlet 18 | 1 19 | 20 | 21 | 22 | cxf 23 | /cnf/services/* 24 | 25 | 26 | -------------------------------------------------------------------------------- /cxf-jaxws-jetty-logging-log4j/src/test/java/com/codenotfound/soap/http/cxf/HelloWorldImplIT.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.soap.http.cxf; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import org.junit.Test; 6 | import org.junit.runner.RunWith; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.test.context.ContextConfiguration; 9 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 10 | 11 | import com.codenotfound.services.helloworld.Person; 12 | 13 | @RunWith(SpringJUnit4ClassRunner.class) 14 | @ContextConfiguration( 15 | locations = {"classpath:/META-INF/spring/context-requester.xml"}) 16 | public class HelloWorldImplIT { 17 | 18 | @Autowired 19 | private HelloWorldClient helloWorldClient; 20 | 21 | @Test 22 | public void testSayHello() { 23 | Person person = new Person(); 24 | person.setFirstName("John"); 25 | person.setLastName("Doe"); 26 | 27 | assertEquals("Hello John Doe!", 28 | helloWorldClient.sayHello(person)); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /cxf-jaxws-jetty-logging-log4j/src/test/java/com/codenotfound/soap/http/cxf/HelloWorldImplTest.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.soap.http.cxf; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import org.apache.cxf.feature.LoggingFeature; 6 | import org.apache.cxf.jaxws.JaxWsServerFactoryBean; 7 | import org.junit.BeforeClass; 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.test.context.ContextConfiguration; 12 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 13 | 14 | import com.codenotfound.services.helloworld.Person; 15 | 16 | @RunWith(SpringJUnit4ClassRunner.class) 17 | @ContextConfiguration( 18 | locations = {"classpath:/META-INF/spring/context-requester.xml"}) 19 | public class HelloWorldImplTest { 20 | 21 | private static String ENDPOINT_ADDRESS = 22 | "http://localhost:9090/cnf/services/helloworld"; 23 | 24 | @Autowired 25 | private HelloWorldClient helloWorldClient; 26 | 27 | @BeforeClass 28 | public static void setUpBeforeClass() throws Exception { 29 | // start the HelloWorld service using jaxWsServerFactoryBean 30 | JaxWsServerFactoryBean jaxWsServerFactoryBean = 31 | new JaxWsServerFactoryBean(); 32 | 33 | // adding loggingFeature to print the received/sent messages 34 | LoggingFeature loggingFeature = new LoggingFeature(); 35 | loggingFeature.setPrettyLogging(true); 36 | 37 | jaxWsServerFactoryBean.getFeatures().add(loggingFeature); 38 | 39 | // setting the implementation 40 | HelloWorldImpl implementor = new HelloWorldImpl(); 41 | jaxWsServerFactoryBean.setServiceBean(implementor); 42 | // setting the endpoint 43 | jaxWsServerFactoryBean.setAddress(ENDPOINT_ADDRESS); 44 | jaxWsServerFactoryBean.create(); 45 | } 46 | 47 | @Test 48 | public void testSayHello() { 49 | Person person = new Person(); 50 | person.setFirstName("John"); 51 | person.setLastName("Doe"); 52 | 53 | assertEquals("Hello John Doe!", 54 | helloWorldClient.sayHello(person)); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /cxf-jaxws-jetty-logging-log4j/src/test/resources/log4j.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | 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 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /cxf-jaxws-jetty-logging-log4j2/README.md: -------------------------------------------------------------------------------- 1 | # cxf-jaxws-jetty-logging-log4j2 2 | 3 | [![Quality Gate](https://sonarcloud.io/api/badges/gate?key=com.codenotfound:cxf-jaxws-jetty-logging-log4j2)](https://sonarcloud.io/dashboard/index/com.codenotfound:cxf-jaxws-jetty-logging-log4j2) 4 | 5 | A code sample which shows how to configure CXF to log the request and response SOAP messages using Log4j2. 6 | 7 | [https://www.codenotfound.com/jaxws-cxf-logging-request-response-soap-messages-log4j2.html](https://www.codenotfound.com/jaxws-cxf-logging-request-response-soap-messages-log4j2.html) 8 | -------------------------------------------------------------------------------- /cxf-jaxws-jetty-logging-log4j2/src/main/java/com/codenotfound/soap/http/cxf/HelloWorldClient.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.soap.http.cxf; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Component; 7 | 8 | import com.codenotfound.services.helloworld.Greeting; 9 | import com.codenotfound.services.helloworld.HelloWorldPortType; 10 | import com.codenotfound.services.helloworld.Person; 11 | 12 | @Component 13 | public class HelloWorldClient { 14 | 15 | private static final Logger LOGGER = 16 | LoggerFactory.getLogger(HelloWorldClient.class); 17 | 18 | @Autowired 19 | private HelloWorldPortType helloWorldRequesterBean; 20 | 21 | public String sayHello(Person person) { 22 | Greeting greeting = helloWorldRequesterBean.sayHello(person); 23 | 24 | String result = greeting.getText(); 25 | LOGGER.info("result={}", result); 26 | return result; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /cxf-jaxws-jetty-logging-log4j2/src/main/java/com/codenotfound/soap/http/cxf/HelloWorldImpl.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.soap.http.cxf; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | 6 | import com.codenotfound.services.helloworld.Greeting; 7 | import com.codenotfound.services.helloworld.HelloWorldPortType; 8 | import com.codenotfound.services.helloworld.ObjectFactory; 9 | import com.codenotfound.services.helloworld.Person; 10 | 11 | public class HelloWorldImpl implements HelloWorldPortType { 12 | 13 | private static final Logger LOGGER = 14 | LoggerFactory.getLogger(HelloWorldImpl.class); 15 | 16 | @Override 17 | public Greeting sayHello(Person person) { 18 | 19 | String firstName = person.getFirstName(); 20 | LOGGER.debug("firstName={}", firstName); 21 | String lasttName = person.getLastName(); 22 | 23 | LOGGER.debug("lastName={}", lasttName); 24 | ObjectFactory factory = new ObjectFactory(); 25 | Greeting response = factory.createGreeting(); 26 | 27 | String greeting = "Hello " + firstName + " " + lasttName + "!"; 28 | LOGGER.info("greeting={}", greeting); 29 | 30 | response.setText(greeting); 31 | return response; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /cxf-jaxws-jetty-logging-log4j2/src/main/resources/META-INF/cxf/org.apache.cxf.Logger: -------------------------------------------------------------------------------- 1 | org.apache.cxf.common.logging.Slf4jLogger 2 | -------------------------------------------------------------------------------- /cxf-jaxws-jetty-logging-log4j2/src/main/resources/META-INF/spring/context-provider.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /cxf-jaxws-jetty-logging-log4j2/src/main/resources/META-INF/spring/context-requester.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /cxf-jaxws-jetty-logging-log4j2/src/main/resources/META-INF/spring/cxf-provider.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /cxf-jaxws-jetty-logging-log4j2/src/main/resources/META-INF/spring/cxf-requester.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 23 | 24 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /cxf-jaxws-jetty-logging-log4j2/src/main/resources/cxf.properties: -------------------------------------------------------------------------------- 1 | # HTTP address of the Hello World service 2 | helloworld.address=http://localhost:9090/cnf/services/helloworld 3 | -------------------------------------------------------------------------------- /cxf-jaxws-jetty-logging-log4j2/src/main/resources/log4j2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | %d{HH:mm:ss.SSS} %-5level 7 | [%thread][%logger{0}] %m%n 8 | jaxws-jetty-cxf-logging 9 | jaxws-jetty-cxf-logging-ws 10 | 11 | 12 | 13 | 14 | 16 | 18 | 19 | 20 | 21 | 22 | 24 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /cxf-jaxws-jetty-logging-log4j2/src/main/resources/wsdl/helloworld.wsdl: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /cxf-jaxws-jetty-logging-log4j2/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | contextConfigLocation 8 | classpath:META-INF/spring/context-provider.xml 9 | 10 | 11 | 12 | org.springframework.web.context.ContextLoaderListener 13 | 14 | 15 | 16 | cxf 17 | org.apache.cxf.transport.servlet.CXFServlet 18 | 1 19 | 20 | 21 | 22 | cxf 23 | /cnf/services/* 24 | 25 | 26 | -------------------------------------------------------------------------------- /cxf-jaxws-jetty-logging-log4j2/src/test/java/com/codenotfound/soap/http/cxf/HelloWorldImplIT.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.soap.http.cxf; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import org.junit.Test; 6 | import org.junit.runner.RunWith; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.test.context.ContextConfiguration; 9 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 10 | 11 | import com.codenotfound.services.helloworld.Person; 12 | 13 | @RunWith(SpringJUnit4ClassRunner.class) 14 | @ContextConfiguration( 15 | locations = {"classpath:/META-INF/spring/context-requester.xml"}) 16 | public class HelloWorldImplIT { 17 | 18 | @Autowired 19 | private HelloWorldClient helloWorldClient; 20 | 21 | @Test 22 | public void testSayHello() { 23 | Person person = new Person(); 24 | person.setFirstName("John"); 25 | person.setLastName("Doe"); 26 | 27 | assertEquals("Hello John Doe!", 28 | helloWorldClient.sayHello(person)); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /cxf-jaxws-jetty-logging-log4j2/src/test/java/com/codenotfound/soap/http/cxf/HelloWorldImplTest.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.soap.http.cxf; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import org.apache.cxf.feature.LoggingFeature; 6 | import org.apache.cxf.jaxws.JaxWsServerFactoryBean; 7 | import org.junit.BeforeClass; 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.test.context.ContextConfiguration; 12 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 13 | 14 | import com.codenotfound.services.helloworld.Person; 15 | 16 | @RunWith(SpringJUnit4ClassRunner.class) 17 | @ContextConfiguration( 18 | locations = {"classpath:/META-INF/spring/context-requester.xml"}) 19 | public class HelloWorldImplTest { 20 | 21 | private static String ENDPOINT_ADDRESS = 22 | "http://localhost:9090/cnf/services/helloworld"; 23 | 24 | @Autowired 25 | private HelloWorldClient helloWorldClient; 26 | 27 | @BeforeClass 28 | public static void setUpBeforeClass() throws Exception { 29 | // start the HelloWorld service using jaxWsServerFactoryBean 30 | JaxWsServerFactoryBean jaxWsServerFactoryBean = 31 | new JaxWsServerFactoryBean(); 32 | 33 | // adding loggingFeature to print the received/sent messages 34 | LoggingFeature loggingFeature = new LoggingFeature(); 35 | loggingFeature.setPrettyLogging(true); 36 | 37 | jaxWsServerFactoryBean.getFeatures().add(loggingFeature); 38 | 39 | // setting the implementation 40 | HelloWorldImpl implementor = new HelloWorldImpl(); 41 | jaxWsServerFactoryBean.setServiceBean(implementor); 42 | // setting the endpoint 43 | jaxWsServerFactoryBean.setAddress(ENDPOINT_ADDRESS); 44 | jaxWsServerFactoryBean.create(); 45 | } 46 | 47 | @Test 48 | public void testSayHello() { 49 | Person person = new Person(); 50 | person.setFirstName("John"); 51 | person.setLastName("Doe"); 52 | 53 | assertEquals("Hello John Doe!", 54 | helloWorldClient.sayHello(person)); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /cxf-jaxws-jetty-logging-log4j2/src/test/resources/log4j2-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | %d{HH:mm:ss.SSS} %-5level 7 | [%thread][%logger{0}] %m%n 8 | jaxws-jetty-cxf-logging-test 9 | jaxws-jetty-cxf-logging-ws-test 10 | 11 | 12 | 13 | 14 | 16 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 28 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /cxf-jaxws-jetty-logging-logback/README.md: -------------------------------------------------------------------------------- 1 | # cxf-jaxws-jetty-logging-logback 2 | 3 | [![Quality Gate](https://sonarcloud.io/api/badges/gate?key=com.codenotfound:cxf-jaxws-jetty-logging-logback)](https://sonarcloud.io/dashboard/index/com.codenotfound:cxf-jaxws-jetty-logging-logback) 4 | 5 | A detailed example on how to setup CXF to log request and response SOAP messages using the Logback logging framework. 6 | 7 | [https://www.codenotfound.com/jaxws-cxf-log-request-response-soap-messages-logback.html](https://www.codenotfound.com/jaxws-cxf-log-request-response-soap-messages-logback.html) 8 | -------------------------------------------------------------------------------- /cxf-jaxws-jetty-logging-logback/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.codenotfound 7 | cxf-jaxws-jetty-logging-logback 8 | 0.0.1-SNAPSHOT 9 | war 10 | 11 | cxf-jaxws-jetty-logging-logback 12 | JAX-WS - CXF logging request and response SOAP messages using Log4j2 13 | https://codenotfound.com/2014/09/jaxws-cxf-log-request-response-soap-messages-logback.html 14 | 15 | 16 | UTF-8 17 | 1.8 18 | 19 | 1.7.10 20 | 1.1.7 21 | 4.12 22 | 3.0.3 23 | 4.1.4.RELEASE 24 | 25 | 3.1 26 | 8.1.16.v20140903 27 | 2.17 28 | 29 | 30 | 31 | 32 | 33 | org.slf4j 34 | jcl-over-slf4j 35 | ${slf4j.version} 36 | 37 | 38 | ch.qos.logback 39 | logback-classic 40 | ${logback.version} 41 | 42 | 43 | 44 | junit 45 | junit 46 | ${junit.version} 47 | test 48 | 49 | 50 | 51 | org.apache.cxf 52 | cxf-rt-frontend-jaxws 53 | ${cxf.version} 54 | 55 | 56 | org.apache.cxf 57 | cxf-rt-transports-http 58 | ${cxf.version} 59 | 60 | 61 | org.apache.cxf 62 | 63 | cxf-rt-transports-http-jetty 64 | ${cxf.version} 65 | 66 | 67 | 68 | org.springframework 69 | spring-context 70 | ${spring.version} 71 | 72 | 73 | org.springframework 74 | spring-web 75 | ${spring.version} 76 | 77 | 78 | org.springframework 79 | spring-test 80 | ${spring.version} 81 | test 82 | 83 | 84 | 85 | 86 | 87 | 88 | org.apache.maven.plugins 89 | maven-compiler-plugin 90 | ${maven-compiler-plugin.version} 91 | 92 | ${java.version} 93 | ${java.version} 94 | 95 | 96 | 97 | 98 | org.mortbay.jetty 99 | jetty-maven-plugin 100 | ${jetty-maven-plugin.version} 101 | 102 | 103 | 105 | 9090 106 | 107 | 108 | 8005 109 | STOP 110 | true 111 | 112 | 113 | 114 | start-jetty 115 | pre-integration-test 116 | 117 | start 118 | 119 | 120 | 121 | stop-jetty 122 | post-integration-test 123 | 124 | stop 125 | 126 | 127 | 128 | 129 | 130 | 131 | org.apache.maven.plugins 132 | maven-failsafe-plugin 133 | ${maven-failsafe-plugin.version} 134 | 135 | 136 | 137 | integration-test 138 | verify 139 | 140 | 141 | 142 | 143 | 144 | 145 | org.apache.cxf 146 | cxf-codegen-plugin 147 | ${cxf.version} 148 | 149 | 150 | generate-sources 151 | generate-sources 152 | 153 | ${project.build.directory}/generated/cxf 154 | 155 | 156 | ${project.basedir}/src/main/resources/wsdl/helloworld.wsdl 157 | classpath:wsdl/helloworld.wsdl 158 | 159 | 160 | 161 | 162 | wsdl2java 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | -------------------------------------------------------------------------------- /cxf-jaxws-jetty-logging-logback/src/main/java/com/codenotfound/soap/http/cxf/HelloWorldClient.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.soap.http.cxf; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Component; 7 | 8 | import com.codenotfound.services.helloworld.Greeting; 9 | import com.codenotfound.services.helloworld.HelloWorldPortType; 10 | import com.codenotfound.services.helloworld.Person; 11 | 12 | @Component 13 | public class HelloWorldClient { 14 | 15 | private static final Logger LOGGER = 16 | LoggerFactory.getLogger(HelloWorldClient.class); 17 | 18 | @Autowired 19 | private HelloWorldPortType helloWorldRequesterBean; 20 | 21 | public String sayHello(Person person) { 22 | Greeting greeting = helloWorldRequesterBean.sayHello(person); 23 | 24 | String result = greeting.getText(); 25 | LOGGER.info("result={}", result); 26 | return result; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /cxf-jaxws-jetty-logging-logback/src/main/java/com/codenotfound/soap/http/cxf/HelloWorldImpl.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.soap.http.cxf; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | 6 | import com.codenotfound.services.helloworld.Greeting; 7 | import com.codenotfound.services.helloworld.HelloWorldPortType; 8 | import com.codenotfound.services.helloworld.ObjectFactory; 9 | import com.codenotfound.services.helloworld.Person; 10 | 11 | public class HelloWorldImpl implements HelloWorldPortType { 12 | 13 | private static final Logger LOGGER = 14 | LoggerFactory.getLogger(HelloWorldImpl.class); 15 | 16 | @Override 17 | public Greeting sayHello(Person person) { 18 | 19 | String firstName = person.getFirstName(); 20 | LOGGER.debug("firstName={}", firstName); 21 | String lasttName = person.getLastName(); 22 | 23 | LOGGER.debug("lastName={}", lasttName); 24 | ObjectFactory factory = new ObjectFactory(); 25 | Greeting response = factory.createGreeting(); 26 | 27 | String greeting = "Hello " + firstName + " " + lasttName + "!"; 28 | LOGGER.info("greeting={}", greeting); 29 | 30 | response.setText(greeting); 31 | return response; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /cxf-jaxws-jetty-logging-logback/src/main/resources/META-INF/cxf/org.apache.cxf.Logger: -------------------------------------------------------------------------------- 1 | org.apache.cxf.common.logging.Slf4jLogger 2 | -------------------------------------------------------------------------------- /cxf-jaxws-jetty-logging-logback/src/main/resources/META-INF/spring/context-provider.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /cxf-jaxws-jetty-logging-logback/src/main/resources/META-INF/spring/context-requester.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /cxf-jaxws-jetty-logging-logback/src/main/resources/META-INF/spring/cxf-provider.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /cxf-jaxws-jetty-logging-logback/src/main/resources/META-INF/spring/cxf-requester.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 14 | 15 | 16 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 29 | 30 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /cxf-jaxws-jetty-logging-logback/src/main/resources/cxf.properties: -------------------------------------------------------------------------------- 1 | # HTTP address of the Hello World service 2 | helloworld.address=http://localhost:9090/codenotfound/services/helloworld 3 | -------------------------------------------------------------------------------- /cxf-jaxws-jetty-logging-logback/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 7 | 8 | 9 | 10 | 11 | 13 | ${logFile}.log 14 | 16 | ${logFile}.%d{yyyy-MM-dd}.log 17 | 18 | 30 19 | 20 | 21 | ${layout} 22 | 23 | 24 | 25 | 27 | ${logFile-ws}.log 28 | 30 | ${logFile-ws}.%d{yyyy-MM-dd}.log 31 | 32 | 30 33 | 34 | 35 | ${layout} 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /cxf-jaxws-jetty-logging-logback/src/main/resources/wsdl/helloworld.wsdl: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /cxf-jaxws-jetty-logging-logback/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | contextConfigLocation 8 | classpath:META-INF/spring/context-provider.xml 9 | 10 | 11 | 12 | org.springframework.web.context.ContextLoaderListener 13 | 14 | 15 | 16 | cxf 17 | org.apache.cxf.transport.servlet.CXFServlet 18 | 1 19 | 20 | 21 | 22 | cxf 23 | /codenotfound/services/* 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /cxf-jaxws-jetty-logging-logback/src/test/java/com/codenotfound/soap/http/cxf/HelloWorldImplIT.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.soap.http.cxf; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import org.junit.Test; 6 | import org.junit.runner.RunWith; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.test.context.ContextConfiguration; 9 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 10 | 11 | import com.codenotfound.services.helloworld.Person; 12 | 13 | @RunWith(SpringJUnit4ClassRunner.class) 14 | @ContextConfiguration( 15 | locations = {"classpath:/META-INF/spring/context-requester.xml"}) 16 | public class HelloWorldImplIT { 17 | 18 | @Autowired 19 | private HelloWorldClient helloWorldClientBean; 20 | 21 | @Test 22 | public void testSayHello() { 23 | Person person = new Person(); 24 | person.setFirstName("John"); 25 | person.setLastName("Doe"); 26 | 27 | assertEquals("Hello John Doe!", 28 | helloWorldClientBean.sayHello(person)); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /cxf-jaxws-jetty-logging-logback/src/test/java/com/codenotfound/soap/http/cxf/HelloWorldImplTest.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.soap.http.cxf; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import org.apache.cxf.feature.LoggingFeature; 6 | import org.apache.cxf.interceptor.LoggingInInterceptor; 7 | import org.apache.cxf.interceptor.LoggingOutInterceptor; 8 | import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; 9 | import org.apache.cxf.jaxws.JaxWsServerFactoryBean; 10 | import org.junit.BeforeClass; 11 | import org.junit.Test; 12 | 13 | import com.codenotfound.services.helloworld.Greeting; 14 | import com.codenotfound.services.helloworld.HelloWorldPortType; 15 | import com.codenotfound.services.helloworld.Person; 16 | 17 | public class HelloWorldImplTest { 18 | 19 | private static String ENDPOINT_ADDRESS = 20 | "http://localhost:9080/codenotfound/services/helloworld"; 21 | 22 | private static HelloWorldPortType helloWorldRequesterProxy; 23 | 24 | @BeforeClass 25 | public static void setUpBeforeClass() throws Exception { 26 | createServerEndpoint(); 27 | helloWorldRequesterProxy = createClientProxy(); 28 | } 29 | 30 | @Test 31 | public void testSayHelloProxy() { 32 | Person person = new Person(); 33 | person.setFirstName("Jane"); 34 | person.setLastName("Doe"); 35 | 36 | Greeting greeting = helloWorldRequesterProxy.sayHello(person); 37 | assertEquals("Hello Jane Doe!", greeting.getText()); 38 | } 39 | 40 | private static void createServerEndpoint() { 41 | JaxWsServerFactoryBean jaxWsServerFactoryBean = 42 | new JaxWsServerFactoryBean(); 43 | 44 | // create the loggingFeature 45 | LoggingFeature loggingFeature = new LoggingFeature(); 46 | loggingFeature.setPrettyLogging(true); 47 | 48 | // add the loggingFeature to print the received/sent messages 49 | jaxWsServerFactoryBean.getFeatures().add(loggingFeature); 50 | 51 | HelloWorldImpl implementor = new HelloWorldImpl(); 52 | jaxWsServerFactoryBean.setServiceBean(implementor); 53 | jaxWsServerFactoryBean.setAddress(ENDPOINT_ADDRESS); 54 | 55 | jaxWsServerFactoryBean.create(); 56 | } 57 | 58 | private static HelloWorldPortType createClientProxy() { 59 | JaxWsProxyFactoryBean jaxWsProxyFactoryBean = 60 | new JaxWsProxyFactoryBean(); 61 | 62 | // create the loggingInInterceptor and loggingOutInterceptor 63 | LoggingInInterceptor loggingInInterceptor = 64 | new LoggingInInterceptor(); 65 | loggingInInterceptor.setPrettyLogging(true); 66 | LoggingOutInterceptor loggingOutInterceptor = 67 | new LoggingOutInterceptor(); 68 | loggingOutInterceptor.setPrettyLogging(true); 69 | 70 | // add loggingInterceptor to print the received/sent messages 71 | jaxWsProxyFactoryBean.getInInterceptors() 72 | .add(loggingInInterceptor); 73 | jaxWsProxyFactoryBean.getInFaultInterceptors() 74 | .add(loggingInInterceptor); 75 | jaxWsProxyFactoryBean.getOutInterceptors() 76 | .add(loggingOutInterceptor); 77 | jaxWsProxyFactoryBean.getOutFaultInterceptors() 78 | .add(loggingOutInterceptor); 79 | 80 | jaxWsProxyFactoryBean.setServiceClass(HelloWorldPortType.class); 81 | jaxWsProxyFactoryBean.setAddress(ENDPOINT_ADDRESS); 82 | 83 | return (HelloWorldPortType) jaxWsProxyFactoryBean.create(); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /cxf-jaxws-jetty-logging-logback/src/test/resources/logback-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 7 | 8 | 9 | 10 | 11 | 13 | ${logFile}.log 14 | 16 | ${logFile}.%d{yyyy-MM-dd}.log 17 | 18 | 30 19 | 20 | 21 | ${layout} 22 | 23 | 24 | 25 | 26 | 27 | ${layout} 28 | 29 | 30 | 31 | 33 | ${logFile-ws}.log 34 | 36 | ${logFile-ws}.%d{yyyy-MM-dd}.log 37 | 38 | 30 39 | 40 | 41 | ${layout} 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /cxf-jaxws-jetty-xml-config/README.md: -------------------------------------------------------------------------------- 1 | # cxf-jaxws-jetty-xml-config 2 | 3 | [![Quality Gate](https://sonarcloud.io/api/badges/gate?key=com.codenotfound:cxf-jaxws-jetty-xml-config)](https://sonarcloud.io/dashboard/index/com.codenotfound:cxf-jaxws-jetty-xml-config) 4 | 5 | A detailed step-by-step tutorial on how to implement a CXF contract first Hello World web service. 6 | 7 | [https://www.codenotfound.com/jaxws-cxf-contract-first-hello-world-webservice-tutorial.html](https://www.codenotfound.com/jaxws-cxf-contract-first-hello-world-webservice-tutorial.html) 8 | -------------------------------------------------------------------------------- /cxf-jaxws-jetty-xml-config/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.codenotfound 7 | cxf-jaxws-jetty-xml-config 8 | 0.0.1-SNAPSHOT 9 | war 10 | 11 | cxf-jaxws-jetty-xml-config 12 | JAX-WS - CXF Contract First Hello World Webservice Tutorial 13 | https://codenotfound.com/jaxws-cxf-contract-first-hello-world-webservice-tutorial.html 14 | 15 | 16 | UTF-8 17 | 1.8 18 | 19 | 3.2.1 20 | 4.3.13.RELEASE 21 | 1.2.3 22 | 4.12 23 | 24 | 3.7.0 25 | 9.4.8.v20171121 26 | 2.20.1 27 | 28 | 29 | 30 | 31 | 32 | org.apache.cxf 33 | cxf-rt-frontend-jaxws 34 | ${cxf.version} 35 | 36 | 37 | org.apache.cxf 38 | cxf-rt-transports-http 39 | ${cxf.version} 40 | 41 | 42 | org.apache.cxf 43 | 44 | cxf-rt-transports-http-jetty 45 | ${cxf.version} 46 | 47 | 48 | 49 | org.springframework 50 | spring-context 51 | ${spring.version} 52 | 53 | 54 | org.springframework 55 | spring-web 56 | ${spring.version} 57 | 58 | 59 | org.springframework 60 | spring-test 61 | ${spring.version} 62 | test 63 | 64 | 65 | 66 | ch.qos.logback 67 | logback-classic 68 | ${logback.version} 69 | 70 | 71 | 72 | junit 73 | junit 74 | ${junit.version} 75 | test 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | org.apache.maven.plugins 84 | maven-compiler-plugin 85 | ${maven-compiler-plugin.version} 86 | 87 | ${java.version} 88 | ${java.version} 89 | 90 | 91 | 92 | 93 | org.eclipse.jetty 94 | jetty-maven-plugin 95 | ${jetty-maven-plugin.version} 96 | 97 | 98 | 9090 99 | 100 | 8005 101 | STOP 102 | true 103 | 104 | 105 | 106 | start-jetty 107 | pre-integration-test 108 | 109 | start 110 | 111 | 112 | 113 | stop-jetty 114 | post-integration-test 115 | 116 | stop 117 | 118 | 119 | 120 | 121 | 122 | 123 | org.apache.maven.plugins 124 | maven-failsafe-plugin 125 | ${maven-failsafe-plugin.version} 126 | 127 | 128 | 129 | integration-test 130 | verify 131 | 132 | 133 | 134 | 135 | 136 | 137 | org.apache.cxf 138 | cxf-codegen-plugin 139 | ${cxf.version} 140 | 141 | 142 | generate-sources 143 | generate-sources 144 | 145 | ${project.build.directory}/generated/cxf 146 | 147 | 148 | ${project.basedir}/src/main/resources/wsdl/helloworld.wsdl 149 | classpath:wsdl/helloworld.wsdl 150 | 151 | 152 | 153 | 154 | wsdl2java 155 | 156 | 157 | 158 | 159 | 160 | 161 | -------------------------------------------------------------------------------- /cxf-jaxws-jetty-xml-config/src/main/java/com/codenotfound/client/HelloWorldClient.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.client; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | 7 | import com.codenotfound.services.helloworld.Greeting; 8 | import com.codenotfound.services.helloworld.HelloWorldPortType; 9 | import com.codenotfound.services.helloworld.Person; 10 | 11 | public class HelloWorldClient { 12 | 13 | private static final Logger LOGGER = 14 | LoggerFactory.getLogger(HelloWorldClient.class); 15 | 16 | @Autowired 17 | private HelloWorldPortType helloWorldRequesterBean; 18 | 19 | public String sayHello(Person person) { 20 | Greeting greeting = helloWorldRequesterBean.sayHello(person); 21 | 22 | String result = greeting.getText(); 23 | LOGGER.info("result={}", result); 24 | return result; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /cxf-jaxws-jetty-xml-config/src/main/java/com/codenotfound/endpoint/HelloWorldImpl.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.endpoint; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | 6 | import com.codenotfound.services.helloworld.Greeting; 7 | import com.codenotfound.services.helloworld.HelloWorldPortType; 8 | import com.codenotfound.services.helloworld.ObjectFactory; 9 | import com.codenotfound.services.helloworld.Person; 10 | 11 | public class HelloWorldImpl implements HelloWorldPortType { 12 | 13 | private static final Logger LOGGER = 14 | LoggerFactory.getLogger(HelloWorldImpl.class); 15 | 16 | @Override 17 | public Greeting sayHello(Person person) { 18 | 19 | String firstName = person.getFirstName(); 20 | LOGGER.info("firstName={}", firstName); 21 | String lasttName = person.getLastName(); 22 | LOGGER.info("lastName={}", lasttName); 23 | 24 | ObjectFactory factory = new ObjectFactory(); 25 | Greeting response = factory.createGreeting(); 26 | 27 | String greeting = "Hello " + firstName + " " + lasttName + "!"; 28 | LOGGER.info("greeting={}", greeting); 29 | 30 | response.setText(greeting); 31 | return response; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /cxf-jaxws-jetty-xml-config/src/main/resources/META-INF/spring/context-provider.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /cxf-jaxws-jetty-xml-config/src/main/resources/META-INF/spring/context-requester.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /cxf-jaxws-jetty-xml-config/src/main/resources/META-INF/spring/cxf-provider.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /cxf-jaxws-jetty-xml-config/src/main/resources/META-INF/spring/cxf-requester.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 12 | 13 | 14 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /cxf-jaxws-jetty-xml-config/src/main/resources/cxf.properties: -------------------------------------------------------------------------------- 1 | # HTTP address of the Hello World service 2 | helloworld.client.address=http://localhost:9090/codenotfound/services/helloworld 3 | -------------------------------------------------------------------------------- /cxf-jaxws-jetty-xml-config/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /cxf-jaxws-jetty-xml-config/src/main/resources/wsdl/helloworld.wsdl: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /cxf-jaxws-jetty-xml-config/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | contextConfigLocation 8 | classpath:META-INF/spring/context-provider.xml 9 | 10 | 11 | 12 | org.springframework.web.context.ContextLoaderListener 13 | 14 | 15 | 16 | cxf 17 | org.apache.cxf.transport.servlet.CXFServlet 18 | 1 19 | 20 | 21 | 22 | cxf 23 | /codenotfound/services/* 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /cxf-jaxws-jetty-xml-config/src/test/java/com/codenotfound/HelloWorldImplIT.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import org.junit.Test; 6 | import org.junit.runner.RunWith; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.test.context.ContextConfiguration; 9 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 10 | 11 | import com.codenotfound.client.HelloWorldClient; 12 | import com.codenotfound.services.helloworld.Person; 13 | 14 | @RunWith(SpringJUnit4ClassRunner.class) 15 | @ContextConfiguration( 16 | locations = {"classpath:/META-INF/spring/context-requester.xml"}) 17 | public class HelloWorldImplIT { 18 | 19 | @Autowired 20 | private HelloWorldClient helloWorldClientBean; 21 | 22 | @Test 23 | public void testSayHello() { 24 | Person person = new Person(); 25 | person.setFirstName("John"); 26 | person.setLastName("Doe"); 27 | 28 | assertEquals("Hello John Doe!", 29 | helloWorldClientBean.sayHello(person)); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /cxf-jaxws-jetty-xml-config/src/test/java/com/codenotfound/client/HelloWorldClientTest.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.client; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import org.apache.cxf.jaxws.JaxWsServerFactoryBean; 6 | import org.junit.BeforeClass; 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 com.codenotfound.client.HelloWorldClient; 14 | import com.codenotfound.endpoint.HelloWorldImpl; 15 | import com.codenotfound.services.helloworld.Person; 16 | 17 | @RunWith(SpringJUnit4ClassRunner.class) 18 | @ContextConfiguration( 19 | locations = {"classpath:/META-INF/spring/context-requester.xml"}) 20 | public class HelloWorldClientTest { 21 | 22 | private static String ENDPOINT_ADDRESS = 23 | "http://localhost:9090/codenotfound/services/helloworld"; 24 | 25 | @Autowired 26 | private HelloWorldClient helloWorldClientBean; 27 | 28 | @BeforeClass 29 | public static void setUpBeforeClass() throws Exception { 30 | createServerEndpoint(); 31 | } 32 | 33 | @Test 34 | public void testSayHello() { 35 | Person person = new Person(); 36 | person.setFirstName("Jane"); 37 | person.setLastName("Doe"); 38 | 39 | assertEquals("Hello Jane Doe!", 40 | helloWorldClientBean.sayHello(person)); 41 | } 42 | 43 | private static void createServerEndpoint() { 44 | // use a CXF JaxWsServerFactoryBean to create JAX-WS endpoints 45 | JaxWsServerFactoryBean jaxWsServerFactoryBean = 46 | new JaxWsServerFactoryBean(); 47 | 48 | // set the HelloWorld implementation 49 | HelloWorldImpl implementor = new HelloWorldImpl(); 50 | jaxWsServerFactoryBean.setServiceBean(implementor); 51 | 52 | // set the address at which the HelloWorld endpoint will be exposed 53 | jaxWsServerFactoryBean.setAddress(ENDPOINT_ADDRESS); 54 | 55 | // create the server 56 | jaxWsServerFactoryBean.create(); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /cxf-jaxws-jetty-xml-config/src/test/java/com/codenotfound/endpoint/HelloWorldImplTest.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.endpoint; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; 6 | import org.apache.cxf.jaxws.JaxWsServerFactoryBean; 7 | import org.junit.BeforeClass; 8 | import org.junit.Test; 9 | 10 | import com.codenotfound.endpoint.HelloWorldImpl; 11 | import com.codenotfound.services.helloworld.Greeting; 12 | import com.codenotfound.services.helloworld.HelloWorldPortType; 13 | import com.codenotfound.services.helloworld.Person; 14 | 15 | public class HelloWorldImplTest { 16 | 17 | private static String ENDPOINT_ADDRESS = 18 | "http://localhost:9080/codenotfound/services/helloworld"; 19 | 20 | private static HelloWorldPortType helloWorldRequesterProxy; 21 | 22 | @BeforeClass 23 | public static void setUpBeforeClass() throws Exception { 24 | createServerEndpoint(); 25 | helloWorldRequesterProxy = createClientProxy(); 26 | } 27 | 28 | @Test 29 | public void testSayHelloProxy() { 30 | Person person = new Person(); 31 | person.setFirstName("Jane"); 32 | person.setLastName("Doe"); 33 | 34 | Greeting greeting = helloWorldRequesterProxy.sayHello(person); 35 | assertEquals("Hello Jane Doe!", greeting.getText()); 36 | } 37 | 38 | private static void createServerEndpoint() { 39 | // use a CXF JaxWsServerFactoryBean to create JAX-WS endpoints 40 | JaxWsServerFactoryBean jaxWsServerFactoryBean = 41 | new JaxWsServerFactoryBean(); 42 | 43 | // set the HelloWorld implementation 44 | HelloWorldImpl implementor = new HelloWorldImpl(); 45 | jaxWsServerFactoryBean.setServiceBean(implementor); 46 | 47 | // set the address at which the HelloWorld endpoint will be exposed 48 | jaxWsServerFactoryBean.setAddress(ENDPOINT_ADDRESS); 49 | 50 | // create the server 51 | jaxWsServerFactoryBean.create(); 52 | } 53 | 54 | private static HelloWorldPortType createClientProxy() { 55 | // create a CXF JaxWsProxyFactoryBean for creating JAX-WS proxies 56 | JaxWsProxyFactoryBean jaxWsProxyFactoryBean = 57 | new JaxWsProxyFactoryBean(); 58 | 59 | // // set the HelloWorld portType class 60 | jaxWsProxyFactoryBean.setServiceClass(HelloWorldPortType.class); 61 | // set the address at which the HelloWorld endpoint will be called 62 | jaxWsProxyFactoryBean.setAddress(ENDPOINT_ADDRESS); 63 | 64 | // create a JAX-WS proxy for the HelloWorld portType 65 | return (HelloWorldPortType) jaxWsProxyFactoryBean.create(); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /cxf-jaxws-logging-logback/README.md: -------------------------------------------------------------------------------- 1 | # cxf-jaxws-logging-logback 2 | 3 | [![Quality Gate](https://sonarcloud.io/api/badges/gate?key=com.codenotfound:cxf-jaxws-logging-logback)](https://sonarcloud.io/dashboard/index/com.codenotfound:cxf-jaxws-logging-logback) 4 | 5 | Apache CXF - JAX-WS Ticket Agent project based on the TicketAgent.wsdl example from the [W3C WSDL 1.1 specification](https://www.w3.org/TR/wsdl11elementidentifiers/#Iri-ref-ex). 6 | 7 | [https://www.codenotfound.com/apache-cxf-logging-soap-request-response-fault-messages-example.html](https://www.codenotfound.com/apache-cxf-logging-soap-request-response-fault-messages-example.html) 8 | -------------------------------------------------------------------------------- /cxf-jaxws-logging-logback/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.codenotfound 7 | cxf-jaxws-logging-logback 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | cxf-jaxws-logging-logback 12 | Apache CXF - Logging SOAP Request Response Fault Messages Example 13 | https://www.codenotfound.com/apache-cxf-logging-soap-request-response-fault-messages-example.html 14 | 15 | 16 | org.springframework.boot 17 | spring-boot-starter-parent 18 | 1.5.9.RELEASE 19 | 20 | 21 | 22 | UTF-8 23 | 1.8 24 | 25 | 3.2.1 26 | 27 | 28 | 29 | 30 | 31 | org.springframework.boot 32 | spring-boot-starter-test 33 | test 34 | 35 | 36 | 37 | org.apache.cxf 38 | cxf-spring-boot-starter-jaxws 39 | ${cxf.version} 40 | 41 | 42 | org.apache.cxf 43 | cxf-rt-features-logging 44 | ${cxf.version} 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | org.springframework.boot 53 | spring-boot-maven-plugin 54 | 55 | 56 | 57 | org.apache.cxf 58 | cxf-codegen-plugin 59 | ${cxf.version} 60 | 61 | 62 | generate-sources 63 | generate-sources 64 | 65 | ${project.build.directory}/generated/cxf 66 | 67 | 68 | ${project.basedir}/src/main/resources/wsdl/ticketagent.wsdl 69 | classpath:wsdl/ticketagent.wsdl 70 | 71 | 72 | 73 | 74 | wsdl2java 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /cxf-jaxws-logging-logback/src/main/java/com/codenotfound/SpringCxfApplication.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringCxfApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringCxfApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /cxf-jaxws-logging-logback/src/main/java/com/codenotfound/client/ClientConfig.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.client; 2 | 3 | import org.apache.cxf.ext.logging.LoggingInInterceptor; 4 | import org.apache.cxf.ext.logging.LoggingOutInterceptor; 5 | import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; 6 | import org.example.ticketagent_wsdl11.TicketAgent; 7 | import org.springframework.beans.factory.annotation.Value; 8 | import org.springframework.context.annotation.Bean; 9 | import org.springframework.context.annotation.Configuration; 10 | 11 | @Configuration 12 | public class ClientConfig { 13 | 14 | @Value("${client.ticketagent.address}") 15 | private String address; 16 | 17 | @Bean(name = "ticketAgentProxy") 18 | public TicketAgent ticketAgentProxy() { 19 | JaxWsProxyFactoryBean jaxWsProxyFactoryBean = 20 | new JaxWsProxyFactoryBean(); 21 | jaxWsProxyFactoryBean.setServiceClass(TicketAgent.class); 22 | jaxWsProxyFactoryBean.setAddress(address); 23 | 24 | // add an interceptor to log the outgoing request messages 25 | jaxWsProxyFactoryBean.getOutInterceptors() 26 | .add(loggingOutInterceptor()); 27 | // add an interceptor to log the incoming response messages 28 | jaxWsProxyFactoryBean.getInInterceptors() 29 | .add(loggingInInterceptor()); 30 | // add an interceptor to log the incoming fault messages 31 | jaxWsProxyFactoryBean.getInFaultInterceptors() 32 | .add(loggingInInterceptor()); 33 | 34 | return (TicketAgent) jaxWsProxyFactoryBean.create(); 35 | } 36 | 37 | @Bean 38 | public LoggingOutInterceptor loggingOutInterceptor() { 39 | return new LoggingOutInterceptor(); 40 | } 41 | 42 | @Bean 43 | public LoggingInInterceptor loggingInInterceptor() { 44 | return new LoggingInInterceptor(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /cxf-jaxws-logging-logback/src/main/java/com/codenotfound/client/TicketAgentClient.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.client; 2 | 3 | import java.math.BigInteger; 4 | import java.util.List; 5 | 6 | import org.example.ticketagent.ObjectFactory; 7 | import org.example.ticketagent.TFlightsResponse; 8 | import org.example.ticketagent.TListFlights; 9 | import org.example.ticketagent_wsdl11.ListFlightsFault; 10 | import org.example.ticketagent_wsdl11.TicketAgent; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.stereotype.Component; 13 | 14 | @Component 15 | public class TicketAgentClient { 16 | 17 | @Autowired 18 | private TicketAgent ticketAgentProxy; 19 | 20 | public List listFlights(String startCity, 21 | String endCity) throws ListFlightsFault { 22 | ObjectFactory factory = new ObjectFactory(); 23 | 24 | TListFlights tListFlights = factory.createTListFlights(); 25 | tListFlights.setStartCity(startCity); 26 | tListFlights.setEndCity(endCity); 27 | 28 | TFlightsResponse response = 29 | ticketAgentProxy.listFlights(tListFlights); 30 | 31 | return response.getFlightNumber(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /cxf-jaxws-logging-logback/src/main/java/com/codenotfound/endpoint/EndpointConfig.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.endpoint; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Arrays; 5 | 6 | import javax.xml.ws.Endpoint; 7 | 8 | import org.apache.cxf.Bus; 9 | import org.apache.cxf.ext.logging.LoggingFeature; 10 | import org.apache.cxf.jaxws.EndpointImpl; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.context.annotation.Bean; 13 | import org.springframework.context.annotation.Configuration; 14 | 15 | @Configuration 16 | public class EndpointConfig { 17 | 18 | @Autowired 19 | private Bus cxfBus; 20 | 21 | @Bean 22 | public Endpoint endpoint() { 23 | EndpointImpl endpoint = 24 | new EndpointImpl(bus(), new TicketAgentImpl()); 25 | endpoint.publish("/ticketagent"); 26 | 27 | return endpoint; 28 | } 29 | 30 | @Bean 31 | public Bus bus() { 32 | cxfBus.setFeatures( 33 | new ArrayList<>(Arrays.asList(loggingFeature()))); 34 | 35 | return cxfBus; 36 | } 37 | 38 | @Bean 39 | public LoggingFeature loggingFeature() { 40 | LoggingFeature loggingFeature = new LoggingFeature(); 41 | loggingFeature.setPrettyLogging(true); 42 | 43 | return loggingFeature; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /cxf-jaxws-logging-logback/src/main/java/com/codenotfound/endpoint/TicketAgentImpl.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.endpoint; 2 | 3 | import java.math.BigInteger; 4 | 5 | import org.example.ticketagent.ObjectFactory; 6 | import org.example.ticketagent.TFlightsFault; 7 | import org.example.ticketagent.TFlightsResponse; 8 | import org.example.ticketagent.TListFlights; 9 | import org.example.ticketagent_wsdl11.ListFlightsFault; 10 | import org.example.ticketagent_wsdl11.TicketAgent; 11 | 12 | public class TicketAgentImpl implements TicketAgent { 13 | 14 | @Override 15 | public TFlightsResponse listFlights(TListFlights request) 16 | throws ListFlightsFault { 17 | ObjectFactory factory = new ObjectFactory(); 18 | 19 | if ("XYZ".equals(request.getStartCity())) { 20 | TFlightsFault tFlightsFault = factory.createTFlightsFault(); 21 | tFlightsFault.setErrorMessage("no city named XYZ"); 22 | 23 | throw new ListFlightsFault("unknown city", tFlightsFault); 24 | } 25 | 26 | TFlightsResponse response = factory.createTFlightsResponse(); 27 | response.getFlightNumber().add(BigInteger.valueOf(101)); 28 | 29 | return response; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /cxf-jaxws-logging-logback/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | client: 2 | ticketagent: 3 | address: http://localhost:9090/codenotfound/ws/ticketagent 4 | 5 | server: 6 | port: 9090 7 | 8 | cxf: 9 | path: /codenotfound/ws 10 | -------------------------------------------------------------------------------- /cxf-jaxws-logging-logback/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /cxf-jaxws-logging-logback/src/main/resources/wsdl/ticketagent.wsdl: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /cxf-jaxws-logging-logback/src/test/java/com/codenotfound/SpringCxfApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import java.math.BigInteger; 6 | 7 | import org.example.ticketagent_wsdl11.ListFlightsFault; 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.boot.test.context.SpringBootTest; 12 | import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; 13 | import org.springframework.test.context.junit4.SpringRunner; 14 | 15 | import com.codenotfound.client.TicketAgentClient; 16 | 17 | @RunWith(SpringRunner.class) 18 | @SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT) 19 | public class SpringCxfApplicationTests { 20 | 21 | @Autowired 22 | private TicketAgentClient ticketAgentClient; 23 | 24 | @Test 25 | public void testListFlights() throws ListFlightsFault { 26 | assertThat(ticketAgentClient.listFlights("LAX", "SFO").get(0)) 27 | .isEqualTo(BigInteger.valueOf(101)); 28 | } 29 | 30 | @Test 31 | public void testListFlightsFault() { 32 | try { 33 | ticketAgentClient.listFlights("XYZ", "SFO"); 34 | } catch (Exception exception) { 35 | assertThat(exception.getMessage()).isEqualTo("unknown city"); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /cxf-jaxws-soap-header-explicit/README.md: -------------------------------------------------------------------------------- 1 | # cxf-jaxws-soap-header-explicit 2 | 3 | [![Quality Gate](https://sonarcloud.io/api/badges/gate?key=com.codenotfound:cxf-jaxws-soap-header-explicit)](https://sonarcloud.io/dashboard/index/com.codenotfound:cxf-jaxws-soap-header-explicit) 4 | 5 | A detailed step-by-step tutorial on how to add and get a SOAP header using Apache CXF and Spring Boot. 6 | 7 | [https://www.codenotfound.com/cxf-jaxws/](https://www.codenotfound.com/cxf-jaxws/) 8 | -------------------------------------------------------------------------------- /cxf-jaxws-soap-header-explicit/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.codenotfound 7 | cxf-jaxws-soap-header-explicit 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | cxf-jaxws-soap-header-explicit 12 | Apache CXF - Explicit SOAP Header Example 13 | https://www.codenotfound.com/cxf-jaxws/ 14 | 15 | 16 | org.springframework.boot 17 | spring-boot-starter-parent 18 | 1.5.9.RELEASE 19 | 20 | 21 | 22 | UTF-8 23 | 1.8 24 | 25 | 3.2.1 26 | 27 | 28 | 29 | 30 | 31 | org.springframework.boot 32 | spring-boot-starter-test 33 | test 34 | 35 | 36 | 37 | org.apache.cxf 38 | cxf-spring-boot-starter-jaxws 39 | ${cxf.version} 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | org.springframework.boot 48 | spring-boot-maven-plugin 49 | 50 | 51 | 52 | org.apache.cxf 53 | cxf-codegen-plugin 54 | ${cxf.version} 55 | 56 | 57 | generate-sources 58 | generate-sources 59 | 60 | ${project.build.directory}/generated/cxf 61 | 62 | 63 | ${project.basedir}/src/main/resources/wsdl/ticketagent.wsdl 64 | classpath:wsdl/ticketagent.wsdl 65 | 66 | 67 | 68 | 69 | wsdl2java 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /cxf-jaxws-soap-header-explicit/src/main/java/com/codenotfound/SpringCxfApplication.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringCxfApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringCxfApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /cxf-jaxws-soap-header-explicit/src/main/java/com/codenotfound/client/ClientConfig.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.client; 2 | 3 | import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; 4 | import org.example.ticketagent_wsdl11.TicketAgent; 5 | import org.springframework.beans.factory.annotation.Value; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | 9 | @Configuration 10 | public class ClientConfig { 11 | 12 | @Value("${client.ticketagent.address}") 13 | private String address; 14 | 15 | @Bean(name = "ticketAgentProxy") 16 | public TicketAgent ticketAgentProxy() { 17 | JaxWsProxyFactoryBean jaxWsProxyFactoryBean = 18 | new JaxWsProxyFactoryBean(); 19 | jaxWsProxyFactoryBean.setServiceClass(TicketAgent.class); 20 | jaxWsProxyFactoryBean.setAddress(address); 21 | 22 | return (TicketAgent) jaxWsProxyFactoryBean.create(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /cxf-jaxws-soap-header-explicit/src/main/java/com/codenotfound/client/TicketAgentClient.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.client; 2 | 3 | import java.math.BigInteger; 4 | import java.util.List; 5 | 6 | import org.example.ticketagent.ObjectFactory; 7 | import org.example.ticketagent.TFlightsResponse; 8 | import org.example.ticketagent.TListFlights; 9 | import org.example.ticketagent.TListFlightsHeader; 10 | import org.example.ticketagent_wsdl11.TicketAgent; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.stereotype.Component; 13 | 14 | @Component 15 | public class TicketAgentClient { 16 | 17 | @Autowired 18 | private TicketAgent ticketAgentProxy; 19 | 20 | public List listFlights() { 21 | ObjectFactory factory = new ObjectFactory(); 22 | TListFlights tListFlights = factory.createTListFlights(); 23 | 24 | // create the SOAP header 25 | TListFlightsHeader tListFlightsHeader = 26 | factory.createTListFlightsHeader(); 27 | tListFlightsHeader.setClientId("abc123"); 28 | 29 | TFlightsResponse response = ticketAgentProxy 30 | .listFlights(tListFlightsHeader, tListFlights); 31 | 32 | return response.getFlightNumber(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /cxf-jaxws-soap-header-explicit/src/main/java/com/codenotfound/endpoint/EndpointConfig.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.endpoint; 2 | 3 | import javax.xml.ws.Endpoint; 4 | 5 | import org.apache.cxf.Bus; 6 | import org.apache.cxf.jaxws.EndpointImpl; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.context.annotation.Bean; 9 | import org.springframework.context.annotation.Configuration; 10 | 11 | @Configuration 12 | public class EndpointConfig { 13 | 14 | @Autowired 15 | private Bus bus; 16 | 17 | @Bean 18 | public Endpoint endpoint() { 19 | EndpointImpl endpoint = 20 | new EndpointImpl(bus, new TicketAgentImpl()); 21 | endpoint.publish("/ticketagent"); 22 | 23 | return endpoint; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /cxf-jaxws-soap-header-explicit/src/main/java/com/codenotfound/endpoint/TicketAgentImpl.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.endpoint; 2 | 3 | import java.math.BigInteger; 4 | 5 | import org.apache.cxf.feature.Features; 6 | import org.example.ticketagent.ObjectFactory; 7 | import org.example.ticketagent.TFlightsResponse; 8 | import org.example.ticketagent.TListFlights; 9 | import org.example.ticketagent.TListFlightsHeader; 10 | import org.example.ticketagent_wsdl11.TicketAgent; 11 | 12 | @Features(features = "org.apache.cxf.feature.LoggingFeature") 13 | public class TicketAgentImpl implements TicketAgent { 14 | 15 | @Override 16 | public TFlightsResponse listFlights(TListFlightsHeader header, 17 | TListFlights body) { 18 | ObjectFactory factory = new ObjectFactory(); 19 | TFlightsResponse response = factory.createTFlightsResponse(); 20 | response.getFlightNumber().add(BigInteger.valueOf(101)); 21 | 22 | // add an extra flightNumber in the case of a clientId == abc123 23 | if ("abc123".equals(header.getClientId())) { 24 | response.getFlightNumber().add(BigInteger.valueOf(202)); 25 | } 26 | 27 | return response; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /cxf-jaxws-soap-header-explicit/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | client: 2 | ticketagent: 3 | address: http://localhost:9090/codenotfound/ws/ticketagent 4 | 5 | server: 6 | port: 9090 7 | 8 | cxf: 9 | path: /codenotfound/ws 10 | -------------------------------------------------------------------------------- /cxf-jaxws-soap-header-explicit/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /cxf-jaxws-soap-header-explicit/src/main/resources/wsdl/ticketagent.wsdl: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 56 | 57 | 58 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /cxf-jaxws-soap-header-explicit/src/test/java/com/codenotfound/SpringCxfApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import java.math.BigInteger; 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.context.SpringBootTest; 11 | import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; 12 | import org.springframework.test.context.junit4.SpringRunner; 13 | 14 | import com.codenotfound.client.TicketAgentClient; 15 | 16 | @RunWith(SpringRunner.class) 17 | @SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT) 18 | public class SpringCxfApplicationTests { 19 | 20 | @Autowired 21 | private TicketAgentClient ticketAgentClient; 22 | 23 | @Test 24 | public void testListFlights() { 25 | assertThat(ticketAgentClient.listFlights().get(1)) 26 | .isEqualTo(BigInteger.valueOf(202)); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /cxf-jaxws-soap-header/README.md: -------------------------------------------------------------------------------- 1 | # cxf-jaxws-soap-header 2 | 3 | [![Quality Gate](https://sonarcloud.io/api/badges/gate?key=com.codenotfound:cxf-jaxws-soap-header)](https://sonarcloud.io/dashboard/index/com.codenotfound:cxf-jaxws-soap-header) 4 | 5 | A detailed step-by-step tutorial on how to add and get a SOAP header using Apache CXF and Spring Boot. 6 | 7 | [https://www.codenotfound.com/apache-cxf-soap-header-example.html](https://www.codenotfound.com/apache-cxf-soap-header-example.html) 8 | -------------------------------------------------------------------------------- /cxf-jaxws-soap-header/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.codenotfound 7 | cxf-jaxws-soap-header 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | cxf-jaxws-soap-header 12 | Apache CXF - SOAP Header Example 13 | https://www.codenotfound.com/apache-cxf-soap-header-example.html 14 | 15 | 16 | org.springframework.boot 17 | spring-boot-starter-parent 18 | 1.5.9.RELEASE 19 | 20 | 21 | 22 | UTF-8 23 | 1.8 24 | 25 | 3.2.1 26 | 27 | 28 | 29 | 30 | 31 | org.springframework.boot 32 | spring-boot-starter-test 33 | test 34 | 35 | 36 | 37 | org.apache.cxf 38 | cxf-spring-boot-starter-jaxws 39 | ${cxf.version} 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | org.springframework.boot 48 | spring-boot-maven-plugin 49 | 50 | 51 | 52 | org.apache.cxf 53 | cxf-codegen-plugin 54 | ${cxf.version} 55 | 56 | 57 | generate-sources 58 | generate-sources 59 | 60 | ${project.build.directory}/generated/cxf 61 | 62 | 63 | ${project.basedir}/src/main/resources/wsdl/ticketagent.wsdl 64 | classpath:wsdl/ticketagent.wsdl 65 | 67 | true 68 | 69 | 70 | 71 | 72 | wsdl2java 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /cxf-jaxws-soap-header/src/main/java/com/codenotfound/SpringCxfApplication.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringCxfApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringCxfApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /cxf-jaxws-soap-header/src/main/java/com/codenotfound/client/ClientConfig.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.client; 2 | 3 | import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; 4 | import org.example.ticketagent_wsdl11.TicketAgent; 5 | import org.springframework.beans.factory.annotation.Value; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | 9 | @Configuration 10 | public class ClientConfig { 11 | 12 | @Value("${client.ticketagent.address}") 13 | private String address; 14 | 15 | @Bean(name = "ticketAgentProxy") 16 | public TicketAgent ticketAgentProxy() { 17 | JaxWsProxyFactoryBean jaxWsProxyFactoryBean = 18 | new JaxWsProxyFactoryBean(); 19 | jaxWsProxyFactoryBean.setServiceClass(TicketAgent.class); 20 | jaxWsProxyFactoryBean.setAddress(address); 21 | 22 | return (TicketAgent) jaxWsProxyFactoryBean.create(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /cxf-jaxws-soap-header/src/main/java/com/codenotfound/client/TicketAgentClient.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.client; 2 | 3 | import java.math.BigInteger; 4 | import java.util.List; 5 | 6 | import org.example.ticketagent.ObjectFactory; 7 | import org.example.ticketagent.TFlightsResponse; 8 | import org.example.ticketagent.TListFlights; 9 | import org.example.ticketagent.TListFlightsHeader; 10 | import org.example.ticketagent_wsdl11.TicketAgent; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.stereotype.Component; 13 | 14 | @Component 15 | public class TicketAgentClient { 16 | 17 | @Autowired 18 | private TicketAgent ticketAgentProxy; 19 | 20 | public List listFlights(String clientId) { 21 | ObjectFactory factory = new ObjectFactory(); 22 | TListFlights tListFlights = factory.createTListFlights(); 23 | 24 | // create the SOAP header 25 | TListFlightsHeader tListFlightsHeader = 26 | factory.createTListFlightsHeader(); 27 | tListFlightsHeader.setClientId(clientId); 28 | 29 | TFlightsResponse response = ticketAgentProxy 30 | .listFlights(tListFlights, tListFlightsHeader); 31 | 32 | return response.getFlightNumber(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /cxf-jaxws-soap-header/src/main/java/com/codenotfound/endpoint/EndpointConfig.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.endpoint; 2 | 3 | import javax.xml.ws.Endpoint; 4 | 5 | import org.apache.cxf.Bus; 6 | import org.apache.cxf.jaxws.EndpointImpl; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.context.annotation.Bean; 9 | import org.springframework.context.annotation.Configuration; 10 | 11 | @Configuration 12 | public class EndpointConfig { 13 | 14 | @Autowired 15 | private Bus bus; 16 | 17 | @Bean 18 | public Endpoint endpoint() { 19 | EndpointImpl endpoint = 20 | new EndpointImpl(bus, new TicketAgentImpl()); 21 | endpoint.publish("/ticketagent"); 22 | 23 | return endpoint; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /cxf-jaxws-soap-header/src/main/java/com/codenotfound/endpoint/TicketAgentImpl.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.endpoint; 2 | 3 | import java.math.BigInteger; 4 | 5 | import org.apache.cxf.feature.Features; 6 | import org.example.ticketagent.ObjectFactory; 7 | import org.example.ticketagent.TFlightsResponse; 8 | import org.example.ticketagent.TListFlights; 9 | import org.example.ticketagent.TListFlightsHeader; 10 | import org.example.ticketagent_wsdl11.TicketAgent; 11 | 12 | @Features(features = "org.apache.cxf.feature.LoggingFeature") 13 | public class TicketAgentImpl implements TicketAgent { 14 | 15 | @Override 16 | public TFlightsResponse listFlights(TListFlights body, 17 | TListFlightsHeader header) { 18 | ObjectFactory factory = new ObjectFactory(); 19 | TFlightsResponse response = factory.createTFlightsResponse(); 20 | response.getFlightNumber().add(BigInteger.valueOf(101)); 21 | 22 | // add an extra flightNumber in the case of a clientId == abc123 23 | if ("abc123".equals(header.getClientId())) { 24 | response.getFlightNumber().add(BigInteger.valueOf(202)); 25 | } 26 | 27 | return response; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /cxf-jaxws-soap-header/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | client: 2 | ticketagent: 3 | address: http://localhost:9090/codenotfound/ws/ticketagent 4 | 5 | server: 6 | port: 9090 7 | 8 | cxf: 9 | path: /codenotfound/ws 10 | -------------------------------------------------------------------------------- /cxf-jaxws-soap-header/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /cxf-jaxws-soap-header/src/main/resources/wsdl/ticketagent.wsdl: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 59 | 60 | 61 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /cxf-jaxws-soap-header/src/test/java/com/codenotfound/SpringCxfApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import java.math.BigInteger; 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.context.SpringBootTest; 11 | import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; 12 | import org.springframework.test.context.junit4.SpringRunner; 13 | 14 | import com.codenotfound.client.TicketAgentClient; 15 | 16 | @RunWith(SpringRunner.class) 17 | @SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT) 18 | public class SpringCxfApplicationTests { 19 | 20 | @Autowired 21 | private TicketAgentClient ticketAgentClient; 22 | 23 | @Test 24 | public void testListFlights() { 25 | assertThat(ticketAgentClient.listFlights("abc123").get(1)) 26 | .isEqualTo(BigInteger.valueOf(202)); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /cxf-jaxws-spring-boot/README.md: -------------------------------------------------------------------------------- 1 | # cxf-jaxws-spring-boot 2 | 3 | [![Quality Gate](https://sonarcloud.io/api/badges/gate?key=com.codenotfound:cxf-jaxws-spring-boot)](https://sonarcloud.io/dashboard/index/com.codenotfound:cxf-jaxws-spring-boot) 4 | 5 | A detailed step-by-step tutorial on how to implement a Hello World web service starting from a WSDL and using Apache CXF and Spring Boot. 6 | 7 | [https://www.codenotfound.com/apache-cxf-spring-boot-soap-web-service-client-server-example.html](https://www.codenotfound.com/apache-cxf-spring-boot-soap-web-service-client-server-example.html) 8 | -------------------------------------------------------------------------------- /cxf-jaxws-spring-boot/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.codenotfound 7 | cxf-jaxws-spring-boot 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | cxf-jaxws-spring-boot 12 | Apache CXF - Spring Boot SOAP Web Service Client Server Example 13 | https://www.codenotfound.com/apache-cxf-spring-boot-soap-web-service-client-server-example.html 14 | 15 | 16 | org.springframework.boot 17 | spring-boot-starter-parent 18 | 1.5.9.RELEASE 19 | 20 | 21 | 22 | UTF-8 23 | 1.8 24 | 25 | 3.2.1 26 | 27 | 28 | 29 | 30 | 31 | org.springframework.boot 32 | spring-boot-starter-test 33 | test 34 | 35 | 36 | 37 | org.apache.cxf 38 | cxf-spring-boot-starter-jaxws 39 | ${cxf.version} 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | org.springframework.boot 48 | spring-boot-maven-plugin 49 | 50 | 51 | 52 | org.apache.cxf 53 | cxf-codegen-plugin 54 | ${cxf.version} 55 | 56 | 57 | generate-sources 58 | generate-sources 59 | 60 | ${project.build.directory}/generated/cxf 61 | 62 | 63 | ${project.basedir}/src/main/resources/wsdl/helloworld.wsdl 64 | classpath:wsdl/helloworld.wsdl 65 | 66 | 67 | 68 | 69 | wsdl2java 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /cxf-jaxws-spring-boot/src/main/java/com/codenotfound/SpringCxfApplication.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringCxfApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringCxfApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /cxf-jaxws-spring-boot/src/main/java/com/codenotfound/client/ClientConfig.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.client; 2 | 3 | import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; 4 | import org.springframework.beans.factory.annotation.Value; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | 8 | import com.codenotfound.services.helloworld.HelloWorldPortType; 9 | 10 | @Configuration 11 | public class ClientConfig { 12 | 13 | @Value("${client.ticketagent.address}") 14 | private String address; 15 | 16 | @Bean(name = "helloWorldProxy") 17 | public HelloWorldPortType helloWorldProxy() { 18 | JaxWsProxyFactoryBean jaxWsProxyFactoryBean = 19 | new JaxWsProxyFactoryBean(); 20 | jaxWsProxyFactoryBean.setServiceClass(HelloWorldPortType.class); 21 | jaxWsProxyFactoryBean.setAddress(address); 22 | 23 | return (HelloWorldPortType) jaxWsProxyFactoryBean.create(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /cxf-jaxws-spring-boot/src/main/java/com/codenotfound/client/HelloWorldClient.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.client; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.stereotype.Component; 5 | 6 | import com.codenotfound.services.helloworld.HelloWorldPortType; 7 | import com.codenotfound.types.helloworld.Greeting; 8 | import com.codenotfound.types.helloworld.ObjectFactory; 9 | import com.codenotfound.types.helloworld.Person; 10 | 11 | @Component 12 | public class HelloWorldClient { 13 | 14 | @Autowired 15 | private HelloWorldPortType helloWorldProxy; 16 | 17 | public String sayHello(String firstName, String lastName) { 18 | 19 | ObjectFactory factory = new ObjectFactory(); 20 | Person person = factory.createPerson(); 21 | person.setFirstName(firstName); 22 | person.setLastName(lastName); 23 | 24 | Greeting response = helloWorldProxy.sayHello(person); 25 | 26 | return response.getGreeting(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /cxf-jaxws-spring-boot/src/main/java/com/codenotfound/endpoint/EndpointConfig.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.endpoint; 2 | 3 | import javax.xml.ws.Endpoint; 4 | 5 | import org.apache.cxf.Bus; 6 | import org.apache.cxf.jaxws.EndpointImpl; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.context.annotation.Bean; 9 | import org.springframework.context.annotation.Configuration; 10 | 11 | @Configuration 12 | public class EndpointConfig { 13 | 14 | @Autowired 15 | private Bus bus; 16 | 17 | @Bean 18 | public Endpoint endpoint() { 19 | EndpointImpl endpoint = 20 | new EndpointImpl(bus, new HelloWorldImpl()); 21 | endpoint.publish("/helloworld"); 22 | 23 | return endpoint; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /cxf-jaxws-spring-boot/src/main/java/com/codenotfound/endpoint/HelloWorldImpl.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.endpoint; 2 | 3 | import com.codenotfound.services.helloworld.HelloWorldPortType; 4 | import com.codenotfound.types.helloworld.Greeting; 5 | import com.codenotfound.types.helloworld.ObjectFactory; 6 | import com.codenotfound.types.helloworld.Person; 7 | 8 | public class HelloWorldImpl implements HelloWorldPortType { 9 | 10 | @Override 11 | public Greeting sayHello(Person request) { 12 | String greeting = "Hello " + request.getFirstName() + " " 13 | + request.getLastName() + "!"; 14 | 15 | ObjectFactory factory = new ObjectFactory(); 16 | Greeting response = factory.createGreeting(); 17 | response.setGreeting(greeting); 18 | 19 | return response; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /cxf-jaxws-spring-boot/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | client: 2 | ticketagent: 3 | address: http://localhost:9090/codenotfound/ws/helloworld 4 | 5 | server: 6 | port: 9090 7 | 8 | cxf: 9 | path: /codenotfound/ws 10 | -------------------------------------------------------------------------------- /cxf-jaxws-spring-boot/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /cxf-jaxws-spring-boot/src/main/resources/wsdl/helloworld.wsdl: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 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 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 49 | 50 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | Hello World service 63 | 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /cxf-jaxws-spring-boot/src/test/java/com/codenotfound/SpringCxfApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import org.junit.Test; 6 | import org.junit.runner.RunWith; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.boot.test.context.SpringBootTest; 9 | import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; 10 | import org.springframework.test.context.junit4.SpringRunner; 11 | 12 | import com.codenotfound.client.HelloWorldClient; 13 | 14 | @RunWith(SpringRunner.class) 15 | @SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT) 16 | public class SpringCxfApplicationTests { 17 | 18 | @Autowired 19 | private HelloWorldClient helloWorldClient; 20 | 21 | @Test 22 | public void testSayHello() { 23 | assertThat(helloWorldClient.sayHello("John", "Doe")) 24 | .isEqualTo("Hello John Doe!"); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /cxf-jaxws-ticketagent/README.md: -------------------------------------------------------------------------------- 1 | # cxf-jaxws-ticketagent 2 | 3 | [![Quality Gate](https://sonarcloud.io/api/badges/gate?key=com.codenotfound:cxf-jaxws-ticketagent)](https://sonarcloud.io/dashboard/index/com.codenotfound:cxf-jaxws-ticketagent) 4 | 5 | Apache CXF - JAX-WS Ticket Agent project based on the TicketAgent.wsdl example from the [W3C WSDL 1.1 specification](https://www.w3.org/TR/wsdl11elementidentifiers/#Iri-ref-ex). 6 | 7 | [https://www.codenotfound.com/cxf-jaxws/](https://www.codenotfound.com/cxf-jaxws/) 8 | -------------------------------------------------------------------------------- /cxf-jaxws-ticketagent/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.codenotfound 7 | cxf-jaxws-ticketagent 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | cxf-jaxws-ticketagent 12 | Apache CXF - Ticket Agent Example 13 | https://www.codenotfound.com/cxf-jaxws/ 14 | 15 | 16 | org.springframework.boot 17 | spring-boot-starter-parent 18 | 1.5.9.RELEASE 19 | 20 | 21 | 22 | UTF-8 23 | 1.8 24 | 25 | 3.2.1 26 | 27 | 28 | 29 | 30 | 31 | org.springframework.boot 32 | spring-boot-starter-test 33 | test 34 | 35 | 36 | 37 | org.apache.cxf 38 | cxf-spring-boot-starter-jaxws 39 | ${cxf.version} 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | org.springframework.boot 48 | spring-boot-maven-plugin 49 | 50 | 51 | 52 | org.apache.cxf 53 | cxf-codegen-plugin 54 | ${cxf.version} 55 | 56 | 57 | generate-sources 58 | generate-sources 59 | 60 | ${project.build.directory}/generated/cxf 61 | 62 | 63 | ${project.basedir}/src/main/resources/wsdl/ticketagent.wsdl 64 | classpath:wsdl/ticketagent.wsdl 65 | 66 | 67 | 68 | 69 | wsdl2java 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /cxf-jaxws-ticketagent/src/main/java/com/codenotfound/SpringCxfApplication.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringCxfApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringCxfApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /cxf-jaxws-ticketagent/src/main/java/com/codenotfound/client/ClientConfig.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.client; 2 | 3 | import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; 4 | import org.example.ticketagent_wsdl11.TicketAgent; 5 | import org.springframework.beans.factory.annotation.Value; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | 9 | @Configuration 10 | public class ClientConfig { 11 | 12 | @Value("${client.ticketagent.address}") 13 | private String address; 14 | 15 | @Bean(name = "ticketAgentProxy") 16 | public TicketAgent ticketAgentProxy() { 17 | JaxWsProxyFactoryBean jaxWsProxyFactoryBean = 18 | new JaxWsProxyFactoryBean(); 19 | jaxWsProxyFactoryBean.setServiceClass(TicketAgent.class); 20 | jaxWsProxyFactoryBean.setAddress(address); 21 | 22 | return (TicketAgent) jaxWsProxyFactoryBean.create(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /cxf-jaxws-ticketagent/src/main/java/com/codenotfound/client/TicketAgentClient.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.client; 2 | 3 | import java.math.BigInteger; 4 | import java.util.List; 5 | 6 | import org.example.ticketagent.ObjectFactory; 7 | import org.example.ticketagent.TFlightsResponse; 8 | import org.example.ticketagent.TListFlights; 9 | import org.example.ticketagent_wsdl11.TicketAgent; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.stereotype.Component; 12 | 13 | @Component 14 | public class TicketAgentClient { 15 | 16 | @Autowired 17 | private TicketAgent ticketAgentProxy; 18 | 19 | public List listFlights() { 20 | ObjectFactory factory = new ObjectFactory(); 21 | TListFlights tListFlights = factory.createTListFlights(); 22 | 23 | TFlightsResponse response = 24 | ticketAgentProxy.listFlights(tListFlights); 25 | 26 | return response.getFlightNumber(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /cxf-jaxws-ticketagent/src/main/java/com/codenotfound/endpoint/EndpointConfig.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.endpoint; 2 | 3 | import javax.xml.ws.Endpoint; 4 | 5 | import org.apache.cxf.Bus; 6 | import org.apache.cxf.jaxws.EndpointImpl; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.context.annotation.Bean; 9 | import org.springframework.context.annotation.Configuration; 10 | 11 | @Configuration 12 | public class EndpointConfig { 13 | 14 | @Autowired 15 | private Bus bus; 16 | 17 | @Bean 18 | public Endpoint endpoint() { 19 | EndpointImpl endpoint = 20 | new EndpointImpl(bus, new TicketAgentImpl()); 21 | endpoint.publish("/ticketagent"); 22 | 23 | return endpoint; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /cxf-jaxws-ticketagent/src/main/java/com/codenotfound/endpoint/TicketAgentImpl.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound.endpoint; 2 | 3 | import java.math.BigInteger; 4 | 5 | import org.example.ticketagent.ObjectFactory; 6 | import org.example.ticketagent.TFlightsResponse; 7 | import org.example.ticketagent.TListFlights; 8 | import org.example.ticketagent_wsdl11.TicketAgent; 9 | 10 | public class TicketAgentImpl implements TicketAgent { 11 | 12 | @Override 13 | public TFlightsResponse listFlights(TListFlights request) { 14 | ObjectFactory factory = new ObjectFactory(); 15 | TFlightsResponse response = factory.createTFlightsResponse(); 16 | response.getFlightNumber().add(BigInteger.valueOf(101)); 17 | 18 | return response; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /cxf-jaxws-ticketagent/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | client: 2 | ticketagent: 3 | address: http://localhost:9090/codenotfound/ws/ticketagent 4 | 5 | server: 6 | port: 9090 7 | 8 | cxf: 9 | path: /codenotfound/ws 10 | -------------------------------------------------------------------------------- /cxf-jaxws-ticketagent/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /cxf-jaxws-ticketagent/src/main/resources/wsdl/ticketagent.wsdl: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /cxf-jaxws-ticketagent/src/test/java/com/codenotfound/SpringCxfApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.codenotfound; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import java.math.BigInteger; 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.context.SpringBootTest; 11 | import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; 12 | import org.springframework.test.context.junit4.SpringRunner; 13 | 14 | import com.codenotfound.client.TicketAgentClient; 15 | 16 | @RunWith(SpringRunner.class) 17 | @SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT) 18 | public class SpringCxfApplicationTests { 19 | 20 | @Autowired 21 | private TicketAgentClient ticketAgentClient; 22 | 23 | @Test 24 | public void testListFlights() { 25 | assertThat(ticketAgentClient.listFlights().get(0)) 26 | .isEqualTo(BigInteger.valueOf(101)); 27 | } 28 | } 29 | --------------------------------------------------------------------------------