Skip to content

Commit 9f27df3

Browse files
committed
Apache CXF with Spring
1 parent b5a3fab commit 9f27df3

9 files changed

Lines changed: 266 additions & 39 deletions

File tree

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

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<artifactId>cxf-spring</artifactId>
5+
<packaging>war</packaging>
6+
<parent>
7+
<groupId>com.baeldung</groupId>
8+
<artifactId>apache-cxf</artifactId>
9+
<version>0.0.1-SNAPSHOT</version>
10+
</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>
16+
<build>
17+
<plugins>
18+
<plugin>
19+
<artifactId>maven-war-plugin</artifactId>
20+
<version>2.6</version>
21+
<configuration>
22+
<webXml>src/main/webapp/WEB-INF/web.xml</webXml>
23+
</configuration>
24+
</plugin>
25+
<plugin>
26+
<artifactId>maven-surefire-plugin</artifactId>
27+
<version>${surefire.version}</version>
28+
<configuration>
29+
<excludes>
30+
<exclude>StudentTest.java</exclude>
31+
</excludes>
32+
</configuration>
33+
</plugin>
34+
</plugins>
35+
</build>
36+
<profiles>
37+
<profile>
38+
<id>integration</id>
39+
<build>
40+
<plugins>
41+
<plugin>
42+
<groupId>org.codehaus.cargo</groupId>
43+
<artifactId>cargo-maven2-plugin</artifactId>
44+
<version>1.5.0</version>
45+
<configuration>
46+
<container>
47+
<containerId>jetty9x</containerId>
48+
<type>embedded</type>
49+
</container>
50+
<configuration>
51+
<properties>
52+
<cargo.hostname>localhost</cargo.hostname>
53+
<cargo.servlet.port>8080</cargo.servlet.port>
54+
</properties>
55+
</configuration>
56+
</configuration>
57+
<executions>
58+
<execution>
59+
<id>start-server</id>
60+
<phase>pre-integration-test</phase>
61+
<goals>
62+
<goal>start</goal>
63+
</goals>
64+
</execution>
65+
<execution>
66+
<id>stop-server</id>
67+
<phase>post-integration-test</phase>
68+
<goals>
69+
<goal>stop</goal>
70+
</goals>
71+
</execution>
72+
</executions>
73+
</plugin>
74+
<plugin>
75+
<artifactId>maven-surefire-plugin</artifactId>
76+
<version>${surefire.version}</version>
77+
<executions>
78+
<execution>
79+
<phase>integration-test</phase>
80+
<goals>
81+
<goal>test</goal>
82+
</goals>
83+
<configuration>
84+
<excludes>
85+
<exclude>none</exclude>
86+
</excludes>
87+
</configuration>
88+
</execution>
89+
</executions>
90+
</plugin>
91+
</plugins>
92+
</build>
93+
</profile>
94+
</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>
117+
</project>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.baeldung.cxf.spring;
2+
3+
import javax.jws.WebService;
4+
5+
@WebService
6+
public interface Baeldung {
7+
String hello(String name);
8+
String register(Student student);
9+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.baeldung.cxf.spring;
2+
3+
import javax.jws.WebService;
4+
5+
@WebService(endpointInterface = "com.baeldung.cxf.spring.Baeldung")
6+
public class BaeldungImpl implements Baeldung {
7+
private int counter;
8+
9+
public String hello(String name) {
10+
return "Hello " + name + "!";
11+
}
12+
13+
public String register(Student student) {
14+
counter++;
15+
return student.getName() + " is registered student number " + counter;
16+
}
17+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.baeldung.cxf.spring;
2+
3+
public class Student {
4+
private String name;
5+
6+
Student() {
7+
}
8+
9+
public Student(String name) {
10+
this.name = name;
11+
}
12+
13+
public String getName() {
14+
return name;
15+
}
16+
17+
public void setName(String name) {
18+
this.name = name;
19+
}
20+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<beans xmlns="http://www.springframework.org/schema/beans"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws"
4+
xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schema/jaxws.xsd">
5+
<bean id="client" factory-bean="clientFactory" factory-method="create" />
6+
<bean id="clientFactory" class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean">
7+
<property name="serviceClass" value="com.baeldung.cxf.spring.Baeldung" />
8+
<property name="address" value="http://localhost:8080/services/baeldung" />
9+
</bean>
10+
</beans>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<beans xmlns="http://www.springframework.org/schema/beans"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws"
4+
xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
5+
<jaxws:endpoint id="baeldung"
6+
implementor="com.baeldung.cxf.spring.BaeldungImpl" address="http://localhost:8080/services/baeldung" />
7+
</beans>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
version="3.0"
4+
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
5+
<servlet>
6+
<servlet-name>cxf</servlet-name>
7+
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
8+
<load-on-startup>1</load-on-startup>
9+
</servlet>
10+
<servlet-mapping>
11+
<servlet-name>cxf</servlet-name>
12+
<url-pattern>/services/*</url-pattern>
13+
</servlet-mapping>
14+
</web-app>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.baeldung.cxf.spring;
2+
3+
import static org.junit.Assert.assertEquals;
4+
5+
import org.junit.Test;
6+
import org.springframework.context.support.ClassPathXmlApplicationContext;
7+
8+
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+
}
15+
16+
@Test
17+
public void whenUsingHelloMethod_thenCorrect() {
18+
String response = baeldungProxy.hello("John Doe");
19+
assertEquals("Hello John Doe!", response);
20+
}
21+
22+
@Test
23+
public void whenUsingRegisterMethod_thenCorrect() {
24+
Student student1 = new Student("Adam");
25+
Student student2 = new Student("Eve");
26+
String student1Response = baeldungProxy.register(student1);
27+
String student2Response = baeldungProxy.register(student2);
28+
29+
assertEquals("Adam is registered student number 1", student1Response);
30+
assertEquals("Eve is registered student number 2", student2Response);
31+
}
32+
}

‎apache-cxf/pom.xml‎

Lines changed: 40 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,41 @@
11
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3-
<modelVersion>4.0.0</modelVersion>
4-
<groupId>com.baeldung</groupId>
5-
<artifactId>apache-cxf</artifactId>
6-
<version>0.0.1-SNAPSHOT</version>
7-
<packaging>pom</packaging>
8-
<modules>
9-
<module>cxf-introduction</module>
10-
</modules>
11-
<dependencies>
12-
<dependency>
13-
<groupId>junit</groupId>
14-
<artifactId>junit</artifactId>
15-
<version>4.12</version>
16-
<scope>test</scope>
17-
</dependency>
18-
</dependencies>
19-
<build>
20-
<defaultGoal>install</defaultGoal>
21-
<pluginManagement>
22-
<plugins>
23-
<plugin>
24-
<groupId>org.apache.maven.plugins</groupId>
25-
<artifactId>maven-compiler-plugin</artifactId>
26-
<version>3.5.1</version>
27-
<configuration>
28-
<source>1.8</source>
29-
<target>1.8</target>
30-
</configuration>
31-
</plugin>
32-
<plugin>
33-
<groupId>org.codehaus.mojo</groupId>
34-
<artifactId>exec-maven-plugin</artifactId>
35-
<version>1.5.0</version>
36-
</plugin>
37-
</plugins>
38-
</pluginManagement>
39-
</build>
40-
</project>
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.baeldung</groupId>
5+
<artifactId>apache-cxf</artifactId>
6+
<version>0.0.1-SNAPSHOT</version>
7+
<packaging>pom</packaging>
8+
<modules>
9+
<module>cxf-introduction</module>
10+
<module>cxf-spring</module>
11+
</modules>
12+
<dependencies>
13+
<dependency>
14+
<groupId>junit</groupId>
15+
<artifactId>junit</artifactId>
16+
<version>4.12</version>
17+
<scope>test</scope>
18+
</dependency>
19+
</dependencies>
20+
<build>
21+
<defaultGoal>install</defaultGoal>
22+
<pluginManagement>
23+
<plugins>
24+
<plugin>
25+
<groupId>org.apache.maven.plugins</groupId>
26+
<artifactId>maven-compiler-plugin</artifactId>
27+
<version>3.5.1</version>
28+
<configuration>
29+
<source>1.8</source>
30+
<target>1.8</target>
31+
</configuration>
32+
</plugin>
33+
<plugin>
34+
<groupId>org.codehaus.mojo</groupId>
35+
<artifactId>exec-maven-plugin</artifactId>
36+
<version>1.5.0</version>
37+
</plugin>
38+
</plugins>
39+
</pluginManagement>
40+
</build>
41+
</project>

0 commit comments

Comments
 (0)