中文字幕在线一区二区在线,久久久精品免费观看国产,无码日日模日日碰夜夜爽,天堂av在线最新版在线,日韩美精品无码一本二本三本,麻豆精品三级国产国语,精品无码AⅤ片,国产区在线观看视频

      如何傳輸Java對象

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

      如何傳輸Java對象

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

        1. 首先是一個(gè)普通的pojo對象,用來表示一個(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.測試

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

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

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

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

      如何編譯java程序09-28

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

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

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

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

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

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

      主站蜘蛛池模板: 亚洲区一区二区中文字幕| 亚洲一区二区三区熟女少妇| 在线观看国产精品91| 亚洲电影一区二区| 国产丰满乱子伦无码专| 国产毛片av一区二区三区网站| 金乡县| 国产欧美久久久精品影院| 国产亚洲精选美女久久久久| 亚洲成AV人国产毛片| 桓台县| 韶山市| 亚洲在战AV极品无码| 国产精品人人爱一区二区白浆| 亚洲欧美成人在线免费| 凤城市| 无码人妻中文中字幕一区二区| 乌兰浩特市| 龙川县| 伽师县| 国产真实二区一区在线亚洲| 亚洲VR永久无码一区| 精品人妻免费看一区二区三区| 日韩偷拍视频一区二区三区| 免费人成网上在线观看免费| 河津市| 亚洲AⅤ男人的天堂在线观看| 淫妇日韩中文字幕在线| 国产成人亚洲精品2020| 上饶市| 沽源县| 亚洲天堂一区二区久久| 麻豆久久久国内精品| 精品久久久亚洲中文字幕| 一本一本久久a久久精品综| 91精品91久久久久久| 在线视频中文字幕二区| 国产裸体AV久无码无遮挡| 古丈县| 亚洲专区在线观看第三页| 井研县|