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

    時(shí)間:2024-10-28 13:48:38 J2EE培訓(xùn) 我要投稿
    • 相關(guān)推薦

    如何傳輸Java對(duì)象

      JavaEE 是 J2EE的一個(gè)新的名稱,之所以改名,目的還是讓大家清楚J2EE只是Java企業(yè)應(yīng)用。下面yjbys小編為大家準(zhǔn)備了關(guān)于如何傳輸Java對(duì)象的文章,歡迎閱讀。

      1. 首先是一個(gè)普通的pojo對(duì)象,用來表示一個(gè)實(shí)體類

      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. 創(chuàng)建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. 創(chuàng)建Web Service接口的實(shí)現(xiàn)類

      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.測(cè)試

      首先運(yùn)行MyServer類,然后運(yùn)行MyClient類來驗(yàn)證Web Service。

    【如何傳輸Java對(duì)象】相關(guān)文章:

    JAVA認(rèn)證開源技術(shù):關(guān)于Java的對(duì)象equals方法06-26

    java面向?qū)ο缶幊填}庫及答案07-28

    如何編譯java程序09-28

    2016年java面向?qū)ο缶幊填}庫及答案10-24

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

    Java如何實(shí)現(xiàn)簡(jiǎn)單的whois查詢09-21

    Java byte[]轉(zhuǎn)int如何實(shí)現(xiàn)05-24

    Java中如何構(gòu)造、生成XML簡(jiǎn)明07-17

    用Java如何處理XML數(shù)據(jù)10-22

    主站蜘蛛池模板: MM1313亚洲国产精品| 日韩精品一区二区三区四区| 久久久久人妻精品一区三寸蜜桃| 国产精品亚洲欧美大片在线看 | 久久久久国产精品麻豆AR影院| 亚洲精品美女久久久久99小说| 久久久精品2019免费观看| 欧美精品福利视频| 亚洲国产精品ⅴa在线观看| 2022国内精品免费福利视频 | 国产精品嫩草影院久久| 亚洲国产一成久久精品国产成人综合 | 国产成人精品无码片区在线观看| 国产精品 视频一区 二区三区| 最新国产在线精品观看| 精品一区二区三区在线视频| 亚洲欧洲自拍拍偷精品 美利坚| 国产原创精品视频| 中文字幕无码精品亚洲资源网久久| 国产精品久久久久久福利69堂| 日韩亚洲精品福利| 99久久国产综合精品成人影院| 日韩精品久久久久久免费| 亚洲Av永久无码精品三区在线| 国产在线精品国自产拍影院| 国产成人精品日本亚洲专一区 | 黑人巨大精品欧美一区二区| 免费欧美精品a在线| 精品国产一区二区三区无码| 日韩经典精品无码一区| 亚洲国产成人久久精品动漫 | 国产精品99久久久久久宅男| 国产精品v欧美精品v日韩精品| 中文精品久久久久人妻| 狠狠色伊人久久精品综合网| 在线精品国产一区二区| 精品国产麻豆免费人成网站| 97久久精品午夜一区二区| 精品无码日韩一区二区三区不卡| 亚洲Av永久无码精品三区在线| 亚洲欧美日韩精品久久亚洲区|