1. <tt id="5hhch"><source id="5hhch"></source></tt>
    1. <xmp id="5hhch"></xmp>

  2. <xmp id="5hhch"><rt id="5hhch"></rt></xmp>

    <rp id="5hhch"></rp>
        <dfn id="5hhch"></dfn>

      1. 如何傳輸Java對象

        時間:2020-10-09 12:04:06 J2EE培訓(xùn) 我要投稿

        如何傳輸Java對象

          JavaEE 是 J2EE的一個新的名稱,之所以改名,目的還是讓大家清楚J2EE只是Java企業(yè)應(yīng)用。下面yjbys小編為大家準(zhǔn)備了關(guān)于如何傳輸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. 創(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接口的.實現(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類來驗證Web Service。

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

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

        java調(diào)用linux命令傳輸遠(yuǎn)程大文件05-24

        Java面向?qū)ο笤O(shè)計的經(jīng)驗原則01-02

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

        sun認(rèn)證考試:java子對象創(chuàng)建過程10-16

        s("download_bottom");

        国产高潮无套免费视频_久久九九兔免费精品6_99精品热6080YY久久_国产91久久久久久无码

        1. <tt id="5hhch"><source id="5hhch"></source></tt>
          1. <xmp id="5hhch"></xmp>

        2. <xmp id="5hhch"><rt id="5hhch"></rt></xmp>

          <rp id="5hhch"></rp>
              <dfn id="5hhch"></dfn>