Skip to content

Commit ab6dd58

Browse files
committed
Merge branch 'master' of https://github.com/eugenp/tutorials
2 parents b467d8f + 0c1aeb4 commit ab6dd58

43 files changed

Lines changed: 493 additions & 137 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apache-cxf/cxf-spring/.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
target/

‎apache-cxf/cxf-spring/pom.xml‎

Lines changed: 43 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,42 @@
88
<artifactId>apache-cxf</artifactId>
99
<version>0.0.1-SNAPSHOT</version>
1010
</parent>
11-
<properties>
12-
<cxf.version>3.1.6</cxf.version>
13-
<spring.version>4.3.1.RELEASE</spring.version>
14-
<surefire.version>2.19.1</surefire.version>
15-
</properties>
11+
12+
<dependencies>
13+
<dependency>
14+
<groupId>org.apache.cxf</groupId>
15+
<artifactId>cxf-rt-frontend-jaxws</artifactId>
16+
<version>${cxf.version}</version>
17+
</dependency>
18+
<dependency>
19+
<groupId>org.apache.cxf</groupId>
20+
<artifactId>cxf-rt-transports-http-jetty</artifactId>
21+
<version>${cxf.version}</version>
22+
</dependency>
23+
<dependency>
24+
<groupId>org.springframework</groupId>
25+
<artifactId>spring-context</artifactId>
26+
<version>${spring.version}</version>
27+
</dependency>
28+
<dependency>
29+
<groupId>org.springframework</groupId>
30+
<artifactId>spring-webmvc</artifactId>
31+
<version>${spring.version}</version>
32+
</dependency>
33+
<dependency>
34+
<groupId>javax.servlet</groupId>
35+
<artifactId>javax.servlet-api</artifactId>
36+
<version>3.1.0</version>
37+
</dependency>
38+
</dependencies>
39+
1640
<build>
1741
<plugins>
1842
<plugin>
1943
<artifactId>maven-war-plugin</artifactId>
2044
<version>2.6</version>
2145
<configuration>
22-
<webXml>src/main/webapp/WEB-INF/web.xml</webXml>
46+
<failOnMissingWebXml>false</failOnMissingWebXml>
2347
</configuration>
2448
</plugin>
2549
<plugin>
@@ -33,6 +57,7 @@
3357
</plugin>
3458
</plugins>
3559
</build>
60+
3661
<profiles>
3762
<profile>
3863
<id>integration</id>
@@ -41,16 +66,16 @@
4166
<plugin>
4267
<groupId>org.codehaus.cargo</groupId>
4368
<artifactId>cargo-maven2-plugin</artifactId>
44-
<version>1.5.0</version>
69+
<version>1.4.19</version>
4570
<configuration>
4671
<container>
47-
<containerId>jetty9x</containerId>
72+
<containerId>tomcat8x</containerId>
4873
<type>embedded</type>
4974
</container>
5075
<configuration>
5176
<properties>
5277
<cargo.hostname>localhost</cargo.hostname>
53-
<cargo.servlet.port>8080</cargo.servlet.port>
78+
<cargo.servlet.port>8081</cargo.servlet.port>
5479
</properties>
5580
</configuration>
5681
</configuration>
@@ -71,6 +96,7 @@
7196
</execution>
7297
</executions>
7398
</plugin>
99+
74100
<plugin>
75101
<artifactId>maven-surefire-plugin</artifactId>
76102
<version>${surefire.version}</version>
@@ -91,27 +117,13 @@
91117
</plugins>
92118
</build>
93119
</profile>
120+
94121
</profiles>
95-
<dependencies>
96-
<dependency>
97-
<groupId>org.apache.cxf</groupId>
98-
<artifactId>cxf-rt-frontend-jaxws</artifactId>
99-
<version>${cxf.version}</version>
100-
</dependency>
101-
<dependency>
102-
<groupId>org.apache.cxf</groupId>
103-
<artifactId>cxf-rt-transports-http-jetty</artifactId>
104-
<version>${cxf.version}</version>
105-
</dependency>
106-
<dependency>
107-
<groupId>org.springframework</groupId>
108-
<artifactId>spring-context</artifactId>
109-
<version>${spring.version}</version>
110-
</dependency>
111-
<dependency>
112-
<groupId>org.springframework</groupId>
113-
<artifactId>spring-web</artifactId>
114-
<version>${spring.version}</version>
115-
</dependency>
116-
</dependencies>
122+
123+
<properties>
124+
<cxf.version>3.1.6</cxf.version>
125+
<spring.version>4.3.1.RELEASE</spring.version>
126+
<surefire.version>2.19.1</surefire.version>
127+
</properties>
128+
117129
</project>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.baeldung.cxf.spring;
2+
3+
import javax.servlet.ServletContext;
4+
import javax.servlet.ServletRegistration;
5+
6+
import org.apache.cxf.transport.servlet.CXFServlet;
7+
import org.springframework.web.WebApplicationInitializer;
8+
import org.springframework.web.context.ContextLoaderListener;
9+
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
10+
11+
public class AppInitializer implements WebApplicationInitializer {
12+
@Override
13+
public void onStartup(ServletContext container) {
14+
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
15+
context.register(ServiceConfiguration.class);
16+
container.addListener(new ContextLoaderListener(context));
17+
18+
ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcher", new CXFServlet());
19+
dispatcher.addMapping("/services/*");
20+
}
21+
}

‎apache-cxf/cxf-spring/src/main/java/com/baeldung/cxf/spring/Baeldung.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
@WebService
66
public interface Baeldung {
77
String hello(String name);
8+
89
String register(Student student);
910
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.baeldung.cxf.spring;
2+
3+
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
4+
import org.springframework.context.annotation.Bean;
5+
import org.springframework.context.annotation.Configuration;
6+
7+
@Configuration
8+
public class ClientConfiguration {
9+
@Bean(name = "client")
10+
public Object generateProxy() {
11+
return proxyFactoryBean().create();
12+
}
13+
14+
@Bean
15+
public JaxWsProxyFactoryBean proxyFactoryBean() {
16+
JaxWsProxyFactoryBean proxyFactory = new JaxWsProxyFactoryBean();
17+
proxyFactory.setServiceClass(Baeldung.class);
18+
proxyFactory.setAddress("http://localhost:8081/services/baeldung");
19+
return proxyFactory;
20+
}
21+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.baeldung.cxf.spring;
2+
3+
import javax.xml.ws.Endpoint;
4+
5+
import org.apache.cxf.Bus;
6+
import org.apache.cxf.bus.spring.SpringBus;
7+
import org.apache.cxf.jaxws.EndpointImpl;
8+
import org.springframework.context.annotation.Bean;
9+
import org.springframework.context.annotation.Configuration;
10+
11+
@Configuration
12+
public class ServiceConfiguration {
13+
@Bean(name = Bus.DEFAULT_BUS_ID)
14+
public SpringBus springBus() {
15+
return new SpringBus();
16+
}
17+
18+
@Bean
19+
public Endpoint endpoint() {
20+
EndpointImpl endpoint = new EndpointImpl(springBus(), new BaeldungImpl());
21+
endpoint.publish("http://localhost:8081/services/baeldung");
22+
return endpoint;
23+
}
24+
}

‎apache-cxf/cxf-spring/src/main/resources/client-beans.xml‎

Lines changed: 0 additions & 10 deletions
This file was deleted.

‎apache-cxf/cxf-spring/src/main/webapp/WEB-INF/cxf-servlet.xml‎

Lines changed: 0 additions & 7 deletions
This file was deleted.

‎apache-cxf/cxf-spring/src/main/webapp/WEB-INF/web.xml‎

Lines changed: 0 additions & 14 deletions
This file was deleted.

‎apache-cxf/cxf-spring/src/test/java/com/baeldung/cxf/spring/StudentTest.java‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,12 @@
33
import static org.junit.Assert.assertEquals;
44

55
import org.junit.Test;
6-
import org.springframework.context.support.ClassPathXmlApplicationContext;
6+
import org.springframework.context.ApplicationContext;
7+
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
78

89
public class StudentTest {
9-
private ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] { "client-beans.xml" });
10-
private Baeldung baeldungProxy;
11-
12-
{
13-
baeldungProxy = (Baeldung) context.getBean("client");
14-
}
10+
private ApplicationContext context = new AnnotationConfigApplicationContext(ClientConfiguration.class);
11+
private Baeldung baeldungProxy = (Baeldung) context.getBean("client");
1512

1613
@Test
1714
public void whenUsingHelloMethod_thenCorrect() {
@@ -25,7 +22,7 @@ public void whenUsingRegisterMethod_thenCorrect() {
2522
Student student2 = new Student("Eve");
2623
String student1Response = baeldungProxy.register(student1);
2724
String student2Response = baeldungProxy.register(student2);
28-
25+
2926
assertEquals("Adam is registered student number 1", student1Response);
3027
assertEquals("Eve is registered student number 2", student2Response);
3128
}

0 commit comments

Comments
 (0)