奶头挺立呻吟高潮av全片,成人试看120秒体验区,性欧美极品v,A片高潮抽搐揉捏奶头视频

J2EE培訓(xùn)

如何傳輸Java對(duì)象

時(shí)間:2024-07-29 08:52:08 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ì)象,用來(lái)表示一個(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類來(lái)驗(yàn)證Web Service。

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

java面向?qū)ο缶幊填}庫(kù)及答案09-24

如何實(shí)現(xiàn)多個(gè)硬盤同步數(shù)據(jù)傳輸10-02

如何在Word中精確移動(dòng)對(duì)象06-22

java程序中如何調(diào)用linux命令06-13

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

2017年計(jì)算機(jī)java面向?qū)ο笾R(shí)點(diǎn)07-18

Javascript中如何判斷對(duì)象是否為空06-06

Java與Java web的區(qū)別08-22

Java與Java web有什么不同01-22

javascript面向?qū)ο笾械膶?duì)象怎么理解07-23

主站蜘蛛池模板: 怀宁县| 黎城县| 忻城县| 德惠市| 凤庆县| 鄂托克旗| 寿光市| 安顺市| 翁牛特旗| 偏关县| 台南市| 泾阳县| 丹东市| 汤原县| 雅安市| 永安市| 彰化市| 庄河市| 莱阳市| 若尔盖县| 甘孜县| 嘉善县| 漠河县| 长宁县| 全州县| 蒙山县| 耒阳市| 永年县| 十堰市| 吉木萨尔县| 蕲春县| 大丰市| 泰来县| 健康| 冀州市| 高安市| 德清县| 东平县| 碌曲县| 睢宁县| 葫芦岛市|