乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      CXF之動(dòng)態(tài)客戶端實(shí)例

       江江385 2013-01-30

      通常創(chuàng)建一個(gè)web服務(wù)的客戶端包括SEI的java接口和客戶端輸入輸出應(yīng)用的一些java類,這不總是可取的或?qū)嵱玫摹?/p>

      CXF支持不同的選擇,允許一個(gè)應(yīng)用連接到服務(wù)而不使用SEI和一些數(shù)據(jù)類。本頁面介紹CXF的動(dòng)態(tài)客戶端工具,有了動(dòng)態(tài)客戶端,CXF就可以在運(yùn)行時(shí)生成SEI和一些Bean類,也允許你通過API調(diào)用操作,即采取對(duì)象或使用反射來應(yīng)用代理。

      服務(wù)接口:

      [java:firstline[1]] view plaincopyprint?
      1. package test.cxf;
      2. import javax.jws.WebParam;
      3. import javax.jws.WebService;
      4. @WebService
      5. public interface HelloWorld {
      6. public Person sayPerson(
      7. @WebParam(name="personName")String personName,
      8. @WebParam(name="address")Address address);
      9. }

      服務(wù)實(shí)現(xiàn)類:

      [java:firstline[1]] view plaincopyprint?
      1. package test.cxf;
      2. import javax.jws.WebService;
      3. @WebService(endpointInterface="test.cxf.HelloWorld")
      4. public class HelloWorldImpl implements HelloWorld {
      5. public Person sayPerson(String personName, Address address) {
      6. Person p = new Person();
      7. p.setPersonName(personName);
      8. p.setAddress(address);
      9. p.setAge(30);
      10. System.out.println("server--" + p.getPersonName());
      11. System.out.println("server--" + p.getAge());
      12. System.out.println("server--" + p.getAddress().getAddress1()+":" + p.getAddress().getAddress2());
      13. return p;
      14. }
      15. }

      對(duì)象 Person:

      [java:firstline[1]] view plaincopyprint?
      1. package test.cxf;
      2. import java.io.Serializable;
      3. import javax.xml.bind.annotation.XmlAccessType;
      4. import javax.xml.bind.annotation.XmlAccessorType;
      5. @XmlAccessorType(XmlAccessType.FIELD)
      6. public class Person implements Serializable{
      7. private String personName;
      8. private Integer age;
      9. private Address address;
      10. public String getPersonName() {
      11. return personName;
      12. }
      13. public void setPersonName(String personName) {
      14. this.personName = personName;
      15. }
      16. public Integer getAge() {
      17. return age;
      18. }
      19. public void setAge(Integer age) {
      20. this.age = age;
      21. }
      22. public Address getAddress() {
      23. return address;
      24. }
      25. public void setAddress(Address address) {
      26. this.address = address;
      27. }
      28. }

      對(duì)象Address:

      [java:firstline[1]] view plaincopyprint?
      1. package test.cxf;
      2. import java.io.Serializable;
      3. import javax.xml.bind.annotation.XmlAccessType;
      4. import javax.xml.bind.annotation.XmlAccessorType;
      5. @XmlAccessorType(XmlAccessType.FIELD)
      6. public class Address implements Serializable{
      7. private String address1;
      8. private String address2;
      9. public String getAddress1() {
      10. return address1;
      11. }
      12. public void setAddress1(String address1) {
      13. this.address1 = address1;
      14. }
      15. public String getAddress2() {
      16. return address2;
      17. }
      18. public void setAddress2(String address2) {
      19. this.address2 = address2;
      20. }
      21. }

      異常定義:

      [java:firstline[1]] view plaincopyprint?
      1. package test.cxf;
      2. import javax.xml.bind.annotation.XmlAccessType;
      3. import javax.xml.bind.annotation.XmlAccessorType;
      4. import javax.xml.ws.WebFault;
      5. @XmlAccessorType(XmlAccessType.FIELD)
      6. @WebFault(name="DynamicClientException")
      7. public class DynamicClientException extends Exception {
      8. public DynamicClientException(){
      9. super();
      10. System.out.println("DynamicClientException!!!");
      11. }
      12. }

      服務(wù)端配置:

      [java:firstline[1]] view plaincopyprint?
      1. <?xml version="1.0" encoding="UTF-8"?>
      2. <beans xmlns="http://www./schema/beans"
      3. xmlns:xsi="http://www./2001/XMLSchema-instance"
      4. xmlns:jaxws="http://cxf./jaxws"
      5. xsi:schemaLocation="
      6. http://www./schema/beans http://www./schema/beans/spring-beans.xsd
      7. http://cxf./jaxws http://cxf./schemas/jaxws.xsd">
      8. <import resource="classpath:META-INF/cxf/cxf.xml" />
      9. <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
      10. <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
      11. <bean id="helloworldImpl" class="test.cxf.HelloWorldImpl"/>
      12. <jaxws:endpoint id="helloworldService" implementor="#helloworldImpl" address="/helloworld"/>
      13. </beans>

      客戶端調(diào)用-----關(guān)鍵就在這里:

      [java:firstline[1]] view plaincopyprint?
      1. package test.cxf;
      2. import java.lang.reflect.Method;
      3. import org.apache.cxf.endpoint.Client;
      4. import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
      5. public class ClientObj {
      6. public static void main(String[] args){
      7. JaxWsDynamicClientFactory dynamicClient = JaxWsDynamicClientFactory.newInstance();
      8. Client client = dynamicClient.createClient("http://localhost:8085/cxf-dynamicClientFactory/service/helloworld?wsdl");
      9. Object address = null;
      10. try {
      11. address = Thread.currentThread().getContextClassLoader().loadClass("test.cxf.Address").newInstance();
      12. Method m2 = address.getClass().getMethod("setAddress1",String.class);
      13. Method m3 = address.getClass().getMethod("setAddress2",String.class);
      14. m2.invoke(address, "qqqqqqq");
      15. m3.invoke(address, "ttttttt");
      16. Object[] rspArr = client.invoke("sayPerson", "fhd", address);
      17. if (null != rspArr && rspArr.length > 0) {
      18. Method m4 = rspArr[0].getClass().getMethod("getAge");
      19. Object obj1 = m4.invoke(rspArr[0]);
      20. System.out.println("ggggg:" + (Integer)obj1);
      21. Method m5 = rspArr[0].getClass().getMethod("getPersonName");
      22. Object obj2 = m5.invoke(rspArr[0]);
      23. System.out.println("vvvvv" + (String)obj2);
      24. Method m6 = rspArr[0].getClass().getMethod("getAddress");
      25. Object obj3 = m6.invoke(rspArr[0]);
      26. Method m7 = obj3.getClass().getMethod("getAddress1");
      27. Method m8 = obj3.getClass().getMethod("getAddress2");
      28. Object o1 = m7.invoke(obj3);
      29. Object o2 = m8.invoke(obj3);
      30. System.out.println("ssssss" + (String)o1 + "<<>>" + (String)o2);
      31. }
      32. } catch (Exception e) {
      33. e.printStackTrace();
      34. }
      35. }
      36. }

      你可能會(huì)問自己下面這個(gè)問題:“類名'com.acme.Person'從哪里來”?是通過運(yùn)行"wsdl2java'并審查結(jié)果來得到類名。

        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶 評(píng)論公約

        類似文章 更多