先放一个HelloWold的aegis的配置:
一、server 端:
1. HelloWorld.java
Java代码
package demo.spring;
import javax.jws.WebService;
@WebService
public interface HelloWorld {
String sayHi(String text);
}
package demo.spring;
import javax.jws.WebService;
@WebService
public interface HelloWorld {
String sayHi(String text);
}
2.HelloWorldImpl.java
Java代码
package demo.spring;
import javax.jws.WebService;
@WebService(endpointInterface = "demo.spring.HelloWorld")
public class HelloWorldImpl implements HelloWorld {
public String sayHi(String text) {
return "Hello " + text;
}
}
package demo.spring;
import javax.jws.WebService;
@WebService(endpointInterface = "demo.spring.HelloWorld")
public class HelloWorldImpl implements HelloWorld {
public String sayHi(String text) {
return "Hello " + text;
}
}
3.beans.xml
Java代码
xmlns:jaxws="http://cxf.apache.org/jaxws"
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">
xmlns:jaxws="http://cxf.apache.org/jaxws"
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">
4.web.xml
Java代码
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
org.springframework.web.context.ContextLoaderListener
org.apache.cxf.transport.servlet.CXFServlet
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
org.springframework.web.context.ContextLoaderListener
org.apache.cxf.transport.servlet.CXFServlet
二、客户端
1.ClientTest.java
Java代码
package demo.spring.client;
import static org.junit.Assert.assertEquals;
import org.apache.cxf.aegis.databinding.AegisDatabinding;
import org.apache.cxf.frontend.ClientProxyFactoryBean;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import demo.spring.HelloWorld;
public final class ClientTest {
private static ClassPathXmlApplicationContext context;
@BeforeClass
public static void beforeClass() {
context = new ClassPathXmlApplicationContext(
new String[] { "demo/spring/client/client-beans.xml" });
}
@AfterClass
public static void afterClass() {
context = null;
}
@Test
public void testSayHiWithSpringConfig() throws Exception {
HelloWorld client = (HelloWorld) context.getBean("client");
String response = client.sayHi("Joe");
assertEquals("Hello Joe", response);
}
/**
* 这个官方有例子(http://cwiki.apache.org/CXF20DOC/aegis-databinding.html)
*
* @throws Exception
*/
@Test
public void testSayHiByCode() throws Exception {
ClientProxyFactoryBean factory = new ClientProxyFactoryBean();
factory.setServiceClass(HelloWorld.class);
factory.setAddress("http://localhost:8080/testCxf/ws/HelloWorld");
factory.getServiceFactory().setDataBinding(new AegisDatabinding());
HelloWorld client = (HelloWorld) factory.create();
assertEquals("Hello Joe", client.sayHi("Joe"));
}
}
package demo.spring.client;
import static org.junit.Assert.assertEquals;
import org.apache.cxf.aegis.databinding.AegisDatabinding;
import org.apache.cxf.frontend.ClientProxyFactoryBean;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import demo.spring.HelloWorld;
public final class ClientTest {
private static ClassPathXmlApplicationContext context;
@BeforeClass
public static void beforeClass() {
context = new ClassPathXmlApplicationContext(
new String[] { "demo/spring/client/client-beans.xml" });
}
@AfterClass
public static void afterClass() {
context = null;
}
@Test
public void testSayHiWithSpringConfig() throws Exception {
HelloWorld client = (HelloWorld) context.getBean("client");
String response = client.sayHi("Joe");
assertEquals("Hello Joe", response);
}
/**
* 这个官方有例子(http://cwiki.apache.org/CXF20DOC/aegis-databinding.html)
*
* @throws Exception
*/
@Test
public void testSayHiByCode() throws Exception {
ClientProxyFactoryBean factory = new ClientProxyFactoryBean();
factory.setServiceClass(HelloWorld.class);
factory.setAddress("http://localhost:8080/testCxf/ws/HelloWorld");
factory.getServiceFactory().setDataBinding(new AegisDatabinding());
HelloWorld client = (HelloWorld) factory.create();
assertEquals("Hello Joe", client.sayHi("Joe"));
}
}
2.client_beans.xml(testSayHiWithSpringConfig()中需要使用的配置文件)
Java代码
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schema/jaxws.xsd">