WebService CXF学习(入门篇3):对象传递
前面几节都是讲一些理论知识,现在又用一个例子来说明一下,这一节我们就CXF框架对象传递进行讲解。 @XmlRootElement(name="Customer") @XmlAccessorType(XmlAccessType.FIELD) @XmlType(propOrder = {"name","age"}) public class Customer { private int age; private String name; public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String getName() { return name; } public void setName(String name) { this.name = name; } }
@WebService public interface HelloService { public void save(Customer c1,Customer c2); public void test(String args); public Customer get(int id); }
@WebService public class HelloServiceImpl implements HelloService { public void save(Customer c1,Customer c2) { System.out.println(c1.getAge()+"---"+c2.getAge()); System.out.println(c1.getName()+"---"+c2.getName()); } public void test(String args) { System.out.println(args); } public Customer get(int id) { Customer cus = new Customer(); cus.setAge(100); cus.setName("Josen"); return cus; } }
public class SoapServer { public static void main(String[] args){ //两种方法,任选一种发布WebService接口 //Endpoint.publish("http://localhost:8080/helloService",new HelloServiceImpl()); JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean(); factory.setAddress("http://localhost:8080/helloService"); factory.setServiceClass(HelloServiceImpl.class); factory.getInInterceptors().add(new LoggingInInterceptor()); factory.getOutInterceptors().add(new LoggingOutInterceptor()); factory.create(); } }
public class SoapClient { public static void main(String[] args){ JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean(); factory.setAddress("http://localhost:8080/helloService"); factory.setServiceClass(HelloService.class); factory.setServiceClass(HelloServiceImpl.class); factory.getInInterceptors().add(new LoggingInInterceptor()); HelloService service = (HelloService)factory.create(); Customer c1 = new Customer(); c1.setAge(1); c1.setName("aaa"); Customer c2 = new Customer(); c2.setAge(2); c2.setName("bbb"); service.save(c1,c2); service.test("aaaaaaaaaaaaa"); } }
引用
信息: Inbound Message ---------------------------- ID: 1 Address: /HelloWorld Encoding: UTF-8 Content-Type: text/xml; charset=UTF-8 Headers: {content-type=[text/xml; charset=UTF-8],connection=[keep-alive],Host=[localhost:9000],Content-Length=[184],SOAPAction=[""],User-Agent=[Apache CXF 2.2.2],Content-Type=[text/xml; charset=UTF-8],Accept=[*/*],Pragma=[no-cache],Cache-Control=[no-cache]} Payload: <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns1:say xmlns:ns1="http://client.itdcl.com/"><text> Josen</text></ns1:say></soap:Body></soap:Envelope> -------------------------------------- 2010-1-9 20:41:56 org.apache.cxf.interceptor.LoggingOutInterceptor$LoggingCallback onClose 信息: Outbound Message --------------------------- ID: 1 Encoding: UTF-8 Content-Type: text/xml Headers: {} Payload: <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Header><text xmlns="http://client.itdcl.com/">hi Josen</text></soap:Header><soap:Body><ns1:sayResponse xmlns:ns1="http://client.itdcl.com/"></ns1:sayResponse></soap:Body></soap:Envelope> -------------------------------------- 2010-01-09 20:41:56.578::INFO:? seeing JVM BUG(s) - cancelling interestOps==0
引用
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <ns1:sayHi xmlns:ns1="http://client.itdcl.com/"> <text>Josen</text> </ns1:sayHi> </soap:Body> </soap:Envelope>
引用
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Header> <text xmlns="http://client.itdcl.com/">hi Josen</text> </soap:Header> <soap:Body> <ns1:sayResponse xmlns:ns1="http://client.itdcl.com/"></ns1:sayResponse> </soap:Body> </soap:Envelope>
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |