<dfn id="w48us"></dfn><ul id="w48us"></ul>
  • <ul id="w48us"></ul>
  • <del id="w48us"></del>
    <ul id="w48us"></ul>
  • 如何傳輸Java對象

    時間:2024-10-28 13:48:38 J2EE培訓 我要投稿
    • 相關推薦

    如何傳輸Java對象

      JavaEE 是 J2EE的一個新的名稱,之所以改名,目的還是讓大家清楚J2EE只是Java企業應用。下面yjbys小編為大家準備了關于如何傳輸Java對象的文章,歡迎閱讀。

      1. 首先是一個普通的pojo對象,用來表示一個實體類

      package com.googlecode.garbagecan.cxfstudy.jaxws;

      import java.util.Date;

      public class Customer {

      private String id;

      private String name;

      private Date birthday;

      public String getId() {

      return id;

      }

      public void setId(String id) {

      this.id = id;

      }

      public String getName() {

      return name;

      }

      public void setName(String name) {

      this.name = name;

      }

      public Date getBirthday() {

      return birthday;

      }

      public void setBirthday(Date birthday) {

      this.birthday = birthday;

      }

      @Override

      public String toString() {

      return org.apache.commons.lang.builder.ToStringBuilder.reflectionToString(this);

      }

      }

      2. 創建Web Service接口類

      package com.googlecode.garbagecan.cxfstudy.jaxws;

      import javax.jws.WebMethod;

      import javax.jws.WebParam;

      import javax.jws.WebResult;

      import javax.jws.WebService;

      @WebService

      public interface CustomerService {

      @WebMethod

      @WebResult Customer findCustomer(@WebParam String id);

      }

      3. 創建Web Service接口的實現類

      package com.googlecode.garbagecan.cxfstudy.jaxws;

      import java.util.Calendar;

      public class CustomerServiceImpl implements CustomerService {

      public Customer findCustomer(String id) {

      Customer customer = new Customer();

      customer.setId("customer_" + id);

      customer.setName("customer_name");

      customer.setBirthday(Calendar.getInstance().getTime());

      return customer;

      }

      }

      4. 下面是Server端的代碼

      package com.googlecode.garbagecan.cxfstudy.jaxws;

      import javax.xml.ws.Endpoint;

      import org.apache.cxf.interceptor.LoggingInInterceptor;

      import org.apache.cxf.interceptor.LoggingOutInterceptor;

      import org.apache.cxf.jaxws.JaxWsServerFactoryBean;

      public class MyServer {

      private static final String address = "http://localhost:9000/ws/jaxws/customerService";

      public static void main(String[] args) throws Exception {

      // http://localhost:9000/ws/jaxws/customerService?wsdl

      JaxWsServerFactoryBean factoryBean = new JaxWsServerFactoryBean();

      factoryBean.getInInterceptors().add(new LoggingInInterceptor());

      factoryBean.getOutInterceptors().add(new LoggingOutInterceptor());

      factoryBean.setServiceClass(CustomerServiceImpl.class);

      factoryBean.setAddress(address);

      factoryBean.create();

      }

      }

      5. 下面是Client端的代碼

      package com.googlecode.garbagecan.cxfstudy.jaxws;

      import java.net.SocketTimeoutException;

      import javax.xml.ws.WebServiceException;

      import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;

      public class MyClient {

      public static void main(String[] args) throws Exception {

      JaxWsProxyFactoryBean factoryBean = new JaxWsProxyFactoryBean();

      factoryBean.setAddress("http://localhost:9000/ws/jaxws/customerService");

      factoryBean.setServiceClass(CustomerService.class);

      Object obj = factoryBean.create();

      CustomerService customerService = (CustomerService) obj;

      try {

      Customer customer = customerService.findCustomer("123");

      System.out.println("Customer: " + customer);

      } catch(Exception e) {

      if (e instanceof WebServiceException

      && e.getCause() instanceof SocketTimeoutException) {

      System.err.println("This is timeout exception.");

      } else {

      e.printStackTrace();

      }

      }

      }

      }

      6.測試

      首先運行MyServer類,然后運行MyClient類來驗證Web Service。

    【如何傳輸Java對象】相關文章:

    JAVA認證開源技術:關于Java的對象equals方法06-26

    java面向對象編程題庫及答案07-28

    JAVA面向對象的三大特性06-14

    如何編譯java程序09-28

    2016年java面向對象編程題庫及答案10-24

    如何讓JAVA代碼更高效07-18

    Java如何實現簡單的whois查詢09-21

    Java byte[]轉int如何實現05-24

    Java中如何構造、生成XML簡明07-17

    用Java如何處理XML數據10-22

    主站蜘蛛池模板: 国产精品成人精品久久久| 老司机精品影院91| 污污网站国产精品白丝袜| 国产精品视频网站| 亚洲一区二区精品视频| 国产精品亚洲专区无码WEB| 97国产精品视频| 亚洲AV成人精品网站在线播放| 国产亚洲精品AA片在线观看不加载| 国99精品无码一区二区三区| 亚洲AV无码成人精品区在线观看 | 国产精品JIZZ在线观看老狼| 精品人妻大屁股白浆无码| 亚洲精品无码专区2| 精品国偷自产在线视频| 久久久久夜夜夜精品国产| 国产成人无码精品一区二区三区| 野狼第一精品社区| 欧美精品亚洲日韩aⅴ| 国产精品高清免费网站| 欧美一区二区精品| 国产精品久久永久免费| 国产精品原创巨作av女教师| 亚洲国产精品无码专区在线观看| 久久久久国产精品麻豆AR影院| 97久久精品人人澡人人爽| 久久99精品国产麻豆宅宅| 97久久精品国产精品青草 | 国内精品伊人久久久久影院对白| 欧美久久精品一级c片片| 国内精品免费在线观看| 久久99精品久久久久久hb无码| 久久精品国产免费| 精品性影院一区二区三区内射| 亚洲福利精品电影在线观看| 欧美精品区一级片免费播放| 老湿亚洲永久精品ww47香蕉图片| 精品精品国产理论在线观看| 国内精品久久久久久麻豆 | 国精品无码A区一区二区| 国产精品自产拍在线观看花钱看 |